-
-
Notifications
You must be signed in to change notification settings - Fork 930
/
helper_test.go
52 lines (49 loc) · 976 Bytes
/
helper_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
package session
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBearerTokenFromRequest(t *testing.T) {
for k, tc := range []struct {
h http.Header
t string
f bool
}{
{
h: http.Header{"Authorization": {"Bearer token"}},
t: "token", f : true,
},
{
h: http.Header{"Authorization": {"bearer token"}},
t: "token", f : true,
},
{
h: http.Header{"Authorization": {"beaRer token"}},
t: "token", f : true,
},
{
h: http.Header{"Authorization": {"BEARER token"}},
t: "token", f : true,
},
{
h: http.Header{"Authorization": {"notbearer token"}},
},
{
h: http.Header{"Authorization": {"token"}},
},
{
h: http.Header{"Authorization": {}},
},
{
h: http.Header{},
},
} {
t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) {
token, found := bearerTokenFromRequest(&http.Request{Header: tc.h})
assert.Equal(t, tc.f, found)
assert.Equal(t, tc.t, token)
})
}
}