-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolicies_test.go
More file actions
57 lines (46 loc) · 1.56 KB
/
policies_test.go
File metadata and controls
57 lines (46 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package sanitize_test
import (
"bytes"
"testing"
"github.com/sonalys/sanitize"
"github.com/stretchr/testify/require"
"golang.org/x/net/html/atom"
)
func Test_SanitizeEmail(t *testing.T) {
content := []byte(`<html><head></head><body style="color:red"></body></html>`)
out := bytes.NewBuffer(make([]byte, 0, 1024))
err := sanitize.HTML(bytes.NewReader(content), out,
sanitize.DefaultEmailPolicies(),
sanitize.AllowAttrs("style"),
)
require.NoError(t, err)
require.Equal(t, string(content), out.String())
}
func Test_BlockAttrs(t *testing.T) {
content := []byte(`<html><head></head><body Style="color:red"></body></html>`)
out := bytes.NewBuffer(make([]byte, 0, 1024))
err := sanitize.HTML(bytes.NewReader(content), out,
sanitize.BlockAttrs("style"),
)
require.NoError(t, err)
require.Equal(t, "<html><head></head><body></body></html>", out.String())
}
func Test_BlockTags(t *testing.T) {
content := []byte(`<html><head></head><body><A/></body></html>`)
out := bytes.NewBuffer(make([]byte, 0, 1024))
err := sanitize.HTML(bytes.NewReader(content), out,
sanitize.BlockTags(atom.A),
)
require.NoError(t, err)
require.Equal(t, "<html><head></head><body></body></html>", out.String())
}
func Test_AllowTags(t *testing.T) {
content := []byte(`<html><head></head><body><A/></body></html>`)
out := bytes.NewBuffer(make([]byte, 0, 1024))
err := sanitize.HTML(bytes.NewReader(content), out,
sanitize.Blacklist(),
sanitize.AllowTags(atom.Html, atom.Body, atom.A),
)
require.NoError(t, err)
require.Equal(t, "<html><body><a></a></body></html>", out.String())
}