forked from couchbaselabs/cbgb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth_test.go
39 lines (36 loc) · 869 Bytes
/
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 main
import (
"testing"
)
func TestBasicAuthParsing(t *testing.T) {
tests := []struct {
input, user, pass string
ok bool
}{
{"Notbasic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", "", "", false},
{"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", "Aladdin", "open sesame", true},
{"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=x", "", "", false},
}
for _, test := range tests {
gu, gp, err := parseBasicAuth(test.input)
if test.ok {
if err != nil {
t.Errorf("Expected no error on %v, got %v",
test.input, err)
}
if gu != test.user {
t.Errorf("Expected user=%v for %v, got %v",
test.user, test.input, gu)
}
if gp != test.pass {
t.Errorf("Expected pass=%v for %v, got %v",
test.pass, test.input, gp)
}
} else {
if err == nil {
t.Errorf("Expected error on %v, got %v/%v",
test.input, gu, gp)
}
}
}
}