33 lines
630 B
Go
33 lines
630 B
Go
package store
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestComment_Sanitize(t *testing.T) {
|
|
|
|
tbl := []struct {
|
|
inp Comment
|
|
out Comment
|
|
}{
|
|
{inp: Comment{}, out: Comment{}},
|
|
{
|
|
inp: Comment{
|
|
Text: `blah <a href="javascript:alert('XSS1')" onmouseover="alert('XSS2')">XSS<a>` + "\n\t",
|
|
User: User{ID: `<a href="http://blah.com">username</a>`},
|
|
},
|
|
out: Comment{
|
|
Text: `blah XSS`,
|
|
User: User{ID: `<a href="http://blah.com">username</a>`},
|
|
},
|
|
},
|
|
}
|
|
|
|
for n, tt := range tbl {
|
|
tt.inp.Sanitize()
|
|
assert.Equal(t, tt.out, tt.inp, "check #%d", n)
|
|
}
|
|
}
|