-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathsetup_test.go
More file actions
39 lines (33 loc) · 980 Bytes
/
setup_test.go
File metadata and controls
39 lines (33 loc) · 980 Bytes
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
package beyond
import (
"testing"
"github.com/presbrey/beyond/internal/authn"
"github.com/stretchr/testify/assert"
)
func init() {
*authn.CookieKey = "a8b91cde2e3eb7fcd544ece2bdf3ce6d0599fbbcbb1cfc144e1c2bf3cd7a13de"
}
func TestSetupAutoGenerate(t *testing.T) {
prev := *authn.CookieKey
*authn.CookieKey = ""
err := Setup()
assert.NoError(t, err)
assert.Len(t, *authn.CookieKey, 64) // Should be 64 hex chars
*authn.CookieKey = prev
}
func TestSetupBadKeyLength(t *testing.T) {
prev := *authn.CookieKey
*authn.CookieKey = "short"
err := Setup()
assert.Error(t, err)
assert.Contains(t, err.Error(), "cookie key must be exactly 64 hex characters")
*authn.CookieKey = prev
}
func TestSetupBadKeyFormat(t *testing.T) {
prev := *authn.CookieKey
*authn.CookieKey = "gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg"
err := Setup()
assert.Error(t, err)
assert.Contains(t, err.Error(), "cookie key must be valid hex")
*authn.CookieKey = prev
}