-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_test.go
More file actions
41 lines (35 loc) · 838 Bytes
/
basic_test.go
File metadata and controls
41 lines (35 loc) · 838 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
40
41
package auth
import "testing"
func TestEncodeDecodeBasic(t *testing.T) {
const (
username = "testuser"
password = "testpass"
)
encoded := EncodeBasic(username, password)
decodedUser, decodedPass, ok := DecodeBasic(encoded)
if !ok {
t.Fatal("failed to decode basic auth")
}
if decodedUser != username {
t.Fatalf("username mismatch: got %s, want %s", decodedUser, username)
}
if decodedPass != password {
t.Fatalf("password mismatch: got %s, want %s", decodedPass, password)
}
}
func TestDecodeBasicInvalid(t *testing.T) {
testCases := []string{
"",
"NotBasic",
"Basic invalid-base64",
"Basic dXNlcjEyMw==", // Base64 of "user123", no colon
}
for _, tc := range testCases {
t.Run(tc, func(t *testing.T) {
_, _, ok := DecodeBasic(tc)
if ok {
t.Fatal("expected decode to fail")
}
})
}
}