-
Notifications
You must be signed in to change notification settings - Fork 0
/
credentials_test.go
106 lines (83 loc) · 2.81 KB
/
credentials_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package gojenkins
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)
var (
cm CredentialsManager
domain = "_"
dockerID = "dockerIDCred"
sshID = "sshIdCred"
usernameID = "usernameIDcred"
scope = "GLOBAL"
)
func TestCreateUsernameCredentials(t *testing.T) {
cred := UsernameCredentials{
ID: usernameID,
Scope: scope,
Username: "usernameTest",
Password: "pass",
}
err := cm.Add(domain, cred)
assert.Nil(t, err, "Could not create credential")
getCred := UsernameCredentials{}
err = cm.GetSingle(domain, cred.ID, &getCred)
assert.Nil(t, err, "Could not get credential")
assert.Equal(t, cred.Scope, getCred.Scope, "Scope is not equal")
assert.Equal(t, cred.ID, cred.ID, "ID is not equal")
assert.Equal(t, cred.Username, cred.Username, "Username is not equal")
}
func TestCreateDockerCredentials(t *testing.T) {
cred := DockerServerCredentials{
Scope: scope,
ID: dockerID,
Username: "docker-name",
ClientCertificate: "some secret value",
ClientKey: "client key",
}
err := cm.Add(domain, cred)
assert.Nil(t, err, "Could not create credential")
getCred := DockerServerCredentials{}
err = cm.GetSingle(domain, cred.ID, &getCred)
assert.Nil(t, err, "Could not get credential")
assert.Equal(t, cred.Scope, getCred.Scope, "Scope is not equal")
assert.Equal(t, cred.ID, cred.ID, "ID is not equal")
assert.Equal(t, cred.Username, cred.Username, "Username is not equal")
assert.Equal(t, cred.ClientCertificate, cred.ClientCertificate, "ClientCertificate is not equal")
assert.Equal(t, cred.ClientKey, cred.ClientKey, "Username is not equal")
}
func TestCreateSSHCredentialsFullFlow(t *testing.T) {
sshCred := SSHCredentials{
Scope: scope,
ID: sshID,
Username: "RANDONMANE",
Passphrase: "password",
PrivateKeySource: &PrivateKeyFile{
Value: "testValueofkey",
Class: KeySourceOnMasterType,
},
}
err := cm.Add(domain, sshCred)
assert.Nil(t, err, "Could not create credential")
sshCred.Username = "new_username"
err = cm.Update(domain, sshCred.ID, sshCred)
assert.Nil(t, err, "Could not update credential")
getSSH := SSHCredentials{}
err = cm.GetSingle(domain, sshCred.ID, &getSSH)
assert.Nil(t, err, "Could not get ssh credential")
assert.Equal(t, sshCred.Scope, getSSH.Scope, "Scope is not equal")
assert.Equal(t, sshCred.ID, getSSH.ID, "ID is not equal")
assert.Equal(t, sshCred.Username, getSSH.Username, "Username is not equal")
assert.Equal(t, sshCred.Scope, getSSH.Scope, "Scope is not equal")
err = cm.Delete(domain, getSSH.ID)
assert.Nil(t, err, "Could not delete credentials")
}
func TestMain(m *testing.M) {
//setup
jenkins := CreateJenkins(nil, "http://localhost:8080", "admin", "admin")
jenkins.Init()
cm = CredentialsManager{J: jenkins}
//execute tests
os.Exit(m.Run())
}