package seaglass_test import ( "slices" "strings" "testing" "git.golem15.com/golem15/summercms/modules/seaglass" ) // TestSeaglassSmoke checks the two promises of the sanitizer: clean HTML // comes back byte for byte with an empty report, and unsafe constructs are // removed and named. func TestSeaglassSmoke(t *testing.T) { clean := "

Mushrooms can help:

\n\n

Call us or write.

" got, report := seaglass.SanitizeReport(clean) if got != clean || report.Changed || report.ElementCount+report.AttributeCount+report.Comments != 0 { t.Fatalf("clean HTML changed: %q %+v", got, report) } if err := seaglass.Check(clean); err != nil { t.Fatalf("Check(clean) = %v", err) } // Re-escaping alone is not a change: bluemonday writes ' here. quoted := `

It's "fine"

` if got := seaglass.Sanitize(quoted); got != quoted { t.Fatalf("re-escaped text changed: %q", got) } dirty := `

Hi there

` got, report = seaglass.SanitizeReport(dirty) for _, bad := range []string{"onclick", "javascript", "`, `x`, ``, `x`} { if err := seaglass.Check(payload); err == nil { t.Fatalf("payload passed: %s", payload) } } }