-
Notifications
You must be signed in to change notification settings - Fork 1
/
basic_test.go
61 lines (56 loc) · 1.06 KB
/
basic_test.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package auth
import (
"testing"
"github.com/nbio/st"
)
func TestParseAuthHeaders(t *testing.T) {
headers := []struct {
kind, value, header string
errored bool
}{
{"", "", "", false},
{"", "foo", "foo", false},
{"whut", "foo", "Whut foo", false},
{"basic", "Shmasic", "Basic Shmasic", true},
{"basic", "YW55IGNhcm5hbCBwbGVhcw==", "Basic YW55IGNhcm5hbCBwbGVhcw==", true},
}
for _, h := range headers {
token, err := ParseAuthHeader(h.header)
st.Expect(t, err != nil, h.errored)
st.Expect(t, token.Type, h.kind)
st.Expect(t, token.Value, h.value)
}
}
func TestDecodeBasicAuthHeader(t *testing.T) {
headers := []struct {
header string
expect string
errored bool
}{
{
"blablabla",
"",
true,
},
{
"",
"",
true,
},
{
"QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
"Aladdin:open sesame",
false,
},
{
"QWxhZGRpbjo=",
"Aladdin:",
false,
},
}
for _, h := range headers {
decoded, err := DecodeBasicAuthHeader(h.header)
st.Expect(t, err != nil, h.errored)
st.Expect(t, decoded, h.expect)
}
}