forked from google/syzkaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_test.go
65 lines (58 loc) · 1.48 KB
/
api_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
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2017 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package main
import (
"testing"
)
func TestClientSecretOK(t *testing.T) {
got, err := checkClient(&GlobalConfig{
Clients: map[string]string{
"user": "secr1t",
},
}, "user", "secr1t", "")
if err != nil || got != "" {
t.Errorf("Unexpected error %v %v", got, err)
}
}
func TestClientOauthOK(t *testing.T) {
got, err := checkClient(&GlobalConfig{
Clients: map[string]string{
"user": "OauthSubject:public",
},
}, "user", "", "OauthSubject:public")
if err != nil || got != "" {
t.Errorf("Unexpected error %v %v", got, err)
}
}
func TestClientSecretFail(t *testing.T) {
got, err := checkClient(&GlobalConfig{
Clients: map[string]string{
"user": "secr1t",
},
}, "user", "wrong", "")
if err != ErrAccess || got != "" {
t.Errorf("Unexpected error %v %v", got, err)
}
}
func TestClientSecretMissing(t *testing.T) {
got, err := checkClient(&GlobalConfig{
Clients: map[string]string{},
}, "user", "ignored", "")
if err != ErrAccess || got != "" {
t.Errorf("Unexpected error %v %v", got, err)
}
}
func TestClientNamespaceOK(t *testing.T) {
got, err := checkClient(&GlobalConfig{
Namespaces: map[string]*Config{
"ns1": {
Clients: map[string]string{
"user": "secr1t",
},
},
},
}, "user", "secr1t", "")
if err != nil || got != "ns1" {
t.Errorf("Unexpected error %v %v", got, err)
}
}