-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathauth_test.go
More file actions
86 lines (72 loc) · 2.66 KB
/
auth_test.go
File metadata and controls
86 lines (72 loc) · 2.66 KB
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
80
81
82
83
84
85
86
// +build integration
package tests
import (
"testing"
"github.com/deis/deis/tests/utils"
)
var (
authLoginCmd = "auth:login http://deis.{{.Domain}} --username={{.UserName}} --password={{.Password}}"
authLogoutCmd = "auth:logout"
authRegisterCmd = "auth:register http://deis.{{.Domain}} --username={{.UserName}} --password={{.Password}} --email={{.Email}}"
authCancelCmd = "auth:cancel --username={{.UserName}} --password={{.Password}} --yes"
authRegenerateCmd = "auth:regenerate"
authRegenerateUsrCmd = "auth:regenerate -u {{.UserName}}"
authRegenerateAllCmd = "auth:regenerate --all"
checkTokenCmd = "apps:list"
)
func TestAuth(t *testing.T) {
params := authSetup(t)
authRegisterTest(t, params)
authLogoutTest(t, params)
authRegenerateTest(t)
authLoginTest(t, params)
authWhoamiTest(t, params)
authPasswdTest(t, params)
authCancel(t, params)
}
func authSetup(t *testing.T) *utils.DeisTestConfig {
user := utils.GetGlobalConfig()
user.UserName, user.Password = utils.NewID(), utils.NewID()
return user
}
func authCancel(t *testing.T, params *utils.DeisTestConfig) {
utils.Execute(t, authCancelCmd, params, false, "Account cancelled")
}
func authLoginTest(t *testing.T, params *utils.DeisTestConfig) {
cmd := authLoginCmd
utils.Execute(t, cmd, params, false, "")
params = authSetup(t)
utils.Execute(t, cmd, params, true, "400 BAD REQUEST")
}
func authLogoutTest(t *testing.T, params *utils.DeisTestConfig) {
utils.Execute(t, authLogoutCmd, params, false, "")
}
func authPasswdTest(t *testing.T, params *utils.DeisTestConfig) {
password := "aNewPassword"
utils.AuthPasswd(t, params, password)
cmd := authLoginCmd
utils.Execute(t, cmd, params, true, "400 BAD REQUEST")
params.Password = password
utils.Execute(t, cmd, params, false, "")
}
func authRegisterTest(t *testing.T, params *utils.DeisTestConfig) {
cmd := authRegisterCmd
utils.Execute(t, cmd, params, false, "")
utils.Execute(t, cmd, params, true, "Registration failed")
}
func authWhoamiTest(t *testing.T, params *utils.DeisTestConfig) {
utils.Execute(t, "auth:whoami", params, true, params.UserName)
}
func authRegenerateTest(t *testing.T) {
params := utils.GetGlobalConfig()
regenCmd := authRegenerateUsrCmd
loginCmd := authLoginCmd
utils.Execute(t, loginCmd, params, false, "")
utils.Execute(t, authRegenerateCmd, params, false, "")
utils.Execute(t, loginCmd, params, false, "")
utils.Execute(t, regenCmd, params, false, "")
utils.Execute(t, checkTokenCmd, params, true, "401 UNAUTHORIZED")
utils.Execute(t, loginCmd, params, false, "")
utils.Execute(t, authRegenerateAllCmd, params, false, "")
utils.Execute(t, checkTokenCmd, params, true, "401 UNAUTHORIZED")
}