4
0

security_test.go 523 B

12345678910111213141516171819202122
  1. package security
  2. import (
  3. "strings"
  4. "testing"
  5. )
  6. func TestCSPKeepsFontsFirstParty(t *testing.T) {
  7. for _, h := range Headers {
  8. if h.K != "Content-Security-Policy" {
  9. continue
  10. }
  11. if strings.Contains(h.V, "fonts.googleapis.com") || strings.Contains(h.V, "fonts.gstatic.com") {
  12. t.Fatalf("CSP still allows third-party fonts: %s", h.V)
  13. }
  14. if !strings.Contains(h.V, "font-src 'self'") {
  15. t.Fatalf("CSP must allow first-party fonts: %s", h.V)
  16. }
  17. return
  18. }
  19. t.Fatal("Content-Security-Policy header missing")
  20. }