-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeb-drop_test.go
79 lines (69 loc) · 1.99 KB
/
deb-drop_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"testing"
)
func TestCheckPackageName(t *testing.T) {
// Valid naming
name := "test_1.3_amd64"
if validatePackageName(name, true) != nil {
t.Errorf("Check of package name forbid correct name: %s", name)
}
// Valid naming
name = "test-package_1.2.34-56_all"
if validatePackageName(name, true) != nil {
t.Errorf("Check of package name forbid correct name: %s", name)
}
// Invalid naming
name = "test_1.3_2_amd64"
if validatePackageName(name, true) == nil {
t.Errorf("Check of package name allowed wrong name schema: %s", name)
}
// Invalid naming
name = "test_amd64"
if validatePackageName(name, true) == nil {
t.Errorf("Check of package name allowed wrong name schema: %s", name)
}
}
func TestValidateToken(t *testing.T) {
config := Config{Token: []Token{
{"validToken1", "oleg", []Repo{{"oleg-stable-amd64"}}},
{"validToken2", "patrick", []Repo{{"patrick-stable-amd64"}}},
{"validToken3", "patrick", []Repo{{"patrick-stable-amd64"}}},
}}
h := newHandler(config)
// Valid token, valid repo
testToken := "validToken1"
testRepo := "oleg-stable-amd64"
ok := h.validateToken(testRepo, testToken)
if !ok {
t.Errorf("Valid token for valid repo has failed")
}
// Invalid token, valid repo
testToken = "invalidToken"
testRepo = "oleg-stable-amd64"
ok = h.validateToken(testRepo, testToken)
if ok {
t.Errorf("Invalid token for valid repo has failed")
}
// Valid token, invalid repo
testToken = "validToken1"
testRepo = "forbidden-repo-amd64"
ok = h.validateToken(testRepo, testToken)
if ok {
t.Errorf("Allowed token to access forbidden repo")
}
// Multiple valid tokens for a repo
testRepo = "patrick-stable-amd64"
ok = h.validateToken(testRepo, "validToken1")
if ok {
t.Errorf("Allowed invalid token to access repo")
}
ok = h.validateToken(testRepo, "validToken2")
if !ok {
t.Errorf("Valid token for valid repo has failed")
}
ok = h.validateToken(testRepo, "validToken3")
if !ok {
t.Errorf("Valid token for valid repo has failed")
}
}