mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-05-13 08:29:53 +00:00
Co-authored-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com> Co-authored-by: Kyle Mendell <kmendell@ofkm.us> Co-authored-by: Elias Schneider <login@eliasschneider.com>
25 lines
615 B
Go
25 lines
615 B
Go
package middleware
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestBuildCSP(t *testing.T) {
|
|
t.Run("uses self form action by default", func(t *testing.T) {
|
|
csp := BuildCSP("test-nonce")
|
|
|
|
assert.Contains(t, csp, "form-action 'self';")
|
|
assert.Contains(t, csp, "script-src 'self' 'nonce-test-nonce'")
|
|
})
|
|
|
|
t.Run("adds validated form action targets", func(t *testing.T) {
|
|
csp := BuildCSP("test-nonce", "https://example.com/callback")
|
|
|
|
assert.Contains(t, csp, "form-action 'self' https://example.com/callback;")
|
|
assert.Equal(t, 1, strings.Count(csp, "form-action"))
|
|
})
|
|
}
|