-
Notifications
You must be signed in to change notification settings - Fork 3
/
basic_authenticator_test.go
47 lines (43 loc) · 1.26 KB
/
basic_authenticator_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewBasicAuthenticator(t *testing.T) {
_, err := NewBasicAuthenticatorFromConfigString("user:password,becky:hello")
require.NoError(t, err)
}
func TestParseAllowedUsersString(t *testing.T) {
type args struct {
userString string
}
tests := []struct {
name string
args args
expected map[string]string
expectErr bool
}{
{"simple valid test", args{"user:password"}, map[string]string{"user": "password"}, false},
{
"more than one valid test",
args{"user:password,user2:password2"},
map[string]string{"user": "password", "user2": "password2"},
false,
},
{"should throw error test", args{"user/password"}, nil, true},
{"empty string test", args{""}, nil, true},
{"string contains only commas", args{"user1,user2,user3"}, nil, true},
{"string contains only colons", args{"user1:user2:user3"}, nil, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseAllowedUsersString(tt.args.userString)
if (err != nil) != tt.expectErr {
t.Errorf("parseAllowedUsersString() error = %v, wantErr %v", err, tt.expectErr)
return
}
assert.Equal(t, tt.expected, got)
})
}
}