-
Notifications
You must be signed in to change notification settings - Fork 15
/
basic_auth_test.go
39 lines (34 loc) · 1023 Bytes
/
basic_auth_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
package lmdrouter
import (
"testing"
"github.com/aws/aws-lambda-go/events"
"github.com/jgroeneveld/trial/assert"
)
func TestBasicAuth(t *testing.T) {
t.Run("no auth header", func(t *testing.T) {
req := events.APIGatewayProxyRequest{}
user, pass := BasicAuth(req)
assert.Equal(t, "", user, "user must be empty")
assert.Equal(t, "", pass, "pass must be empty")
})
t.Run("invalid auth header", func(t *testing.T) {
req := events.APIGatewayProxyRequest{
Headers: map[string]string{
"Authorization": "Bla",
},
}
user, pass := BasicAuth(req)
assert.Equal(t, "", user, "user must be empty")
assert.Equal(t, "", pass, "pass must be empty")
})
t.Run("valid auth header", func(t *testing.T) {
req := events.APIGatewayProxyRequest{
Headers: map[string]string{
"Authorization": "Basic dXNlcm5hbWU6cGFzc3BocmFzZQ==",
},
}
user, pass := BasicAuth(req)
assert.Equal(t, "username", user, "user must be correct")
assert.Equal(t, "passphrase", pass, "pass must be correct")
})
}