@@ -20,16 +20,18 @@ type makeRequestFunc func(testing.TB, *http.Request, int) *httptest.ResponseReco
20
20
func TestGPGKeys (t * testing.T ) {
21
21
prepareTestEnv (t )
22
22
session := loginUser (t , "user2" )
23
+ token := getTokenForLoggedInUser (t , session )
23
24
24
25
tt := []struct {
25
26
name string
26
27
makeRequest makeRequestFunc
28
+ token string
27
29
results []int
28
30
}{
29
- {name : "NoLogin" , makeRequest : MakeRequest ,
31
+ {name : "NoLogin" , makeRequest : MakeRequest , token : "" ,
30
32
results : []int {http .StatusUnauthorized , http .StatusUnauthorized , http .StatusUnauthorized , http .StatusUnauthorized , http .StatusUnauthorized , http .StatusUnauthorized , http .StatusUnauthorized , http .StatusUnauthorized },
31
33
},
32
- {name : "LoggedAsUser2" , makeRequest : session .MakeRequest ,
34
+ {name : "LoggedAsUser2" , makeRequest : session .MakeRequest , token : token ,
33
35
results : []int {http .StatusOK , http .StatusOK , http .StatusNotFound , http .StatusNoContent , http .StatusInternalServerError , http .StatusInternalServerError , http .StatusCreated , http .StatusCreated }},
34
36
}
35
37
@@ -38,29 +40,29 @@ func TestGPGKeys(t *testing.T) {
38
40
//Basic test on result code
39
41
t .Run (tc .name , func (t * testing.T ) {
40
42
t .Run ("ViewOwnGPGKeys" , func (t * testing.T ) {
41
- testViewOwnGPGKeys (t , tc .makeRequest , tc .results [0 ])
43
+ testViewOwnGPGKeys (t , tc .makeRequest , tc .token , tc . results [0 ])
42
44
})
43
45
t .Run ("ViewGPGKeys" , func (t * testing.T ) {
44
- testViewGPGKeys (t , tc .makeRequest , tc .results [1 ])
46
+ testViewGPGKeys (t , tc .makeRequest , tc .token , tc . results [1 ])
45
47
})
46
48
t .Run ("GetGPGKey" , func (t * testing.T ) {
47
- testGetGPGKey (t , tc .makeRequest , tc .results [2 ])
49
+ testGetGPGKey (t , tc .makeRequest , tc .token , tc . results [2 ])
48
50
})
49
51
t .Run ("DeleteGPGKey" , func (t * testing.T ) {
50
- testDeleteGPGKey (t , tc .makeRequest , tc .results [3 ])
52
+ testDeleteGPGKey (t , tc .makeRequest , tc .token , tc . results [3 ])
51
53
})
52
54
53
55
t .Run ("CreateInvalidGPGKey" , func (t * testing.T ) {
54
- testCreateInvalidGPGKey (t , tc .makeRequest , tc .results [4 ])
56
+ testCreateInvalidGPGKey (t , tc .makeRequest , tc .token , tc . results [4 ])
55
57
})
56
58
t .Run ("CreateNoneRegistredEmailGPGKey" , func (t * testing.T ) {
57
- testCreateNoneRegistredEmailGPGKey (t , tc .makeRequest , tc .results [5 ])
59
+ testCreateNoneRegistredEmailGPGKey (t , tc .makeRequest , tc .token , tc . results [5 ])
58
60
})
59
61
t .Run ("CreateValidGPGKey" , func (t * testing.T ) {
60
- testCreateValidGPGKey (t , tc .makeRequest , tc .results [6 ])
62
+ testCreateValidGPGKey (t , tc .makeRequest , tc .token , tc . results [6 ])
61
63
})
62
64
t .Run ("CreateValidSecondaryEmailGPGKey" , func (t * testing.T ) {
63
- testCreateValidSecondaryEmailGPGKey (t , tc .makeRequest , tc .results [7 ])
65
+ testCreateValidSecondaryEmailGPGKey (t , tc .makeRequest , tc .token , tc . results [7 ])
64
66
})
65
67
})
66
68
}
@@ -70,7 +72,7 @@ func TestGPGKeys(t *testing.T) {
70
72
71
73
var keys []* api.GPGKey
72
74
73
- req := NewRequest (t , "GET" , "/api/v1/user/gpg_keys" ) //GET all keys
75
+ req := NewRequest (t , "GET" , "/api/v1/user/gpg_keys?token=" + token ) //GET all keys
74
76
resp := session .MakeRequest (t , req , http .StatusOK )
75
77
DecodeJSON (t , resp , & keys )
76
78
@@ -91,21 +93,21 @@ func TestGPGKeys(t *testing.T) {
91
93
assert .EqualValues (t , false , primaryKey2 .Emails [0 ].Verified )
92
94
93
95
var key api.GPGKey
94
- req = NewRequest (t , "GET" , "/api/v1/user/gpg_keys/" + strconv .FormatInt (primaryKey1 .ID , 10 )) //Primary key 1
96
+ req = NewRequest (t , "GET" , "/api/v1/user/gpg_keys/" + strconv .FormatInt (primaryKey1 .ID , 10 )+ "?token=" + token ) //Primary key 1
95
97
resp = session .MakeRequest (t , req , http .StatusOK )
96
98
DecodeJSON (t , resp , & key )
97
99
assert .EqualValues (t , "38EA3BCED732982C" , key .KeyID )
98
100
assert .EqualValues (t , 1 , len (key .Emails ))
99
101
assert .EqualValues (t , "user2@example.com" , key .Emails [0 ].Email )
100
102
assert .EqualValues (t , true , key .Emails [0 ].Verified )
101
103
102
- req = NewRequest (t , "GET" , "/api/v1/user/gpg_keys/" + strconv .FormatInt (subKey .ID , 10 )) //Subkey of 38EA3BCED732982C
104
+ req = NewRequest (t , "GET" , "/api/v1/user/gpg_keys/" + strconv .FormatInt (subKey .ID , 10 )+ "?token=" + token ) //Subkey of 38EA3BCED732982C
103
105
resp = session .MakeRequest (t , req , http .StatusOK )
104
106
DecodeJSON (t , resp , & key )
105
107
assert .EqualValues (t , "70D7C694D17D03AD" , key .KeyID )
106
108
assert .EqualValues (t , 0 , len (key .Emails ))
107
109
108
- req = NewRequest (t , "GET" , "/api/v1/user/gpg_keys/" + strconv .FormatInt (primaryKey2 .ID , 10 )) //Primary key 2
110
+ req = NewRequest (t , "GET" , "/api/v1/user/gpg_keys/" + strconv .FormatInt (primaryKey2 .ID , 10 )+ "?token=" + token ) //Primary key 2
109
111
resp = session .MakeRequest (t , req , http .StatusOK )
110
112
DecodeJSON (t , resp , & key )
111
113
assert .EqualValues (t , "FABF39739FE1E927" , key .KeyID )
@@ -119,63 +121,63 @@ func TestGPGKeys(t *testing.T) {
119
121
t .Run ("CheckCommits" , func (t * testing.T ) {
120
122
t .Run ("NotSigned" , func (t * testing.T ) {
121
123
var branch api.Branch
122
- req := NewRequest (t , "GET" , "/api/v1/repos/user2/repo16/branches/not-signed" )
124
+ req := NewRequest (t , "GET" , "/api/v1/repos/user2/repo16/branches/not-signed?token=" + token )
123
125
resp := session .MakeRequest (t , req , http .StatusOK )
124
126
DecodeJSON (t , resp , & branch )
125
127
assert .EqualValues (t , false , branch .Commit .Verification .Verified )
126
128
})
127
129
128
130
t .Run ("SignedWithNotValidatedEmail" , func (t * testing.T ) {
129
131
var branch api.Branch
130
- req := NewRequest (t , "GET" , "/api/v1/repos/user2/repo16/branches/good-sign-not-yet-validated" )
132
+ req := NewRequest (t , "GET" , "/api/v1/repos/user2/repo16/branches/good-sign-not-yet-validated?token=" + token )
131
133
resp := session .MakeRequest (t , req , http .StatusOK )
132
134
DecodeJSON (t , resp , & branch )
133
135
assert .EqualValues (t , false , branch .Commit .Verification .Verified )
134
136
})
135
137
136
138
t .Run ("SignedWithValidEmail" , func (t * testing.T ) {
137
139
var branch api.Branch
138
- req := NewRequest (t , "GET" , "/api/v1/repos/user2/repo16/branches/good-sign" )
140
+ req := NewRequest (t , "GET" , "/api/v1/repos/user2/repo16/branches/good-sign?token=" + token )
139
141
resp := session .MakeRequest (t , req , http .StatusOK )
140
142
DecodeJSON (t , resp , & branch )
141
143
assert .EqualValues (t , true , branch .Commit .Verification .Verified )
142
144
})
143
145
})
144
146
}
145
147
146
- func testViewOwnGPGKeys (t * testing.T , makeRequest makeRequestFunc , expected int ) {
147
- req := NewRequest (t , "GET" , "/api/v1/user/gpg_keys" )
148
+ func testViewOwnGPGKeys (t * testing.T , makeRequest makeRequestFunc , token string , expected int ) {
149
+ req := NewRequest (t , "GET" , "/api/v1/user/gpg_keys?token=" + token )
148
150
makeRequest (t , req , expected )
149
151
}
150
152
151
- func testViewGPGKeys (t * testing.T , makeRequest makeRequestFunc , expected int ) {
152
- req := NewRequest (t , "GET" , "/api/v1/users/user2/gpg_keys" )
153
+ func testViewGPGKeys (t * testing.T , makeRequest makeRequestFunc , token string , expected int ) {
154
+ req := NewRequest (t , "GET" , "/api/v1/users/user2/gpg_keys?token=" + token )
153
155
makeRequest (t , req , expected )
154
156
}
155
157
156
- func testGetGPGKey (t * testing.T , makeRequest makeRequestFunc , expected int ) {
157
- req := NewRequest (t , "GET" , "/api/v1/user/gpg_keys/1" )
158
+ func testGetGPGKey (t * testing.T , makeRequest makeRequestFunc , token string , expected int ) {
159
+ req := NewRequest (t , "GET" , "/api/v1/user/gpg_keys/1?token=" + token )
158
160
makeRequest (t , req , expected )
159
161
}
160
162
161
- func testDeleteGPGKey (t * testing.T , makeRequest makeRequestFunc , expected int ) {
162
- req := NewRequest (t , "DELETE" , "/api/v1/user/gpg_keys/1" )
163
+ func testDeleteGPGKey (t * testing.T , makeRequest makeRequestFunc , token string , expected int ) {
164
+ req := NewRequest (t , "DELETE" , "/api/v1/user/gpg_keys/1?token=" + token )
163
165
makeRequest (t , req , expected )
164
166
}
165
167
166
- func testCreateGPGKey (t * testing.T , makeRequest makeRequestFunc , expected int , publicKey string ) {
167
- req := NewRequestWithJSON (t , "POST" , "/api/v1/user/gpg_keys" , api.CreateGPGKeyOption {
168
+ func testCreateGPGKey (t * testing.T , makeRequest makeRequestFunc , token string , expected int , publicKey string ) {
169
+ req := NewRequestWithJSON (t , "POST" , "/api/v1/user/gpg_keys?token=" + token , api.CreateGPGKeyOption {
168
170
ArmoredKey : publicKey ,
169
171
})
170
172
makeRequest (t , req , expected )
171
173
}
172
174
173
- func testCreateInvalidGPGKey (t * testing.T , makeRequest makeRequestFunc , expected int ) {
174
- testCreateGPGKey (t , makeRequest , expected , "invalid_key" )
175
+ func testCreateInvalidGPGKey (t * testing.T , makeRequest makeRequestFunc , token string , expected int ) {
176
+ testCreateGPGKey (t , makeRequest , token , expected , "invalid_key" )
175
177
}
176
178
177
- func testCreateNoneRegistredEmailGPGKey (t * testing.T , makeRequest makeRequestFunc , expected int ) {
178
- testCreateGPGKey (t , makeRequest , expected , `-----BEGIN PGP PUBLIC KEY BLOCK-----
179
+ func testCreateNoneRegistredEmailGPGKey (t * testing.T , makeRequest makeRequestFunc , token string , expected int ) {
180
+ testCreateGPGKey (t , makeRequest , token , expected , `-----BEGIN PGP PUBLIC KEY BLOCK-----
179
181
180
182
mQENBFmGUygBCACjCNbKvMGgp0fd5vyFW9olE1CLCSyyF9gQN2hSuzmZLuAZF2Kh
181
183
dCMCG2T1UwzUB/yWUFWJ2BtCwSjuaRv+cGohqEy6bhEBV90peGA33lHfjx7wP25O
@@ -194,9 +196,9 @@ INx/MmBfmtCq05FqNclvU+sj2R3N1JJOtBOjZrJHQbJhzoILou8AkxeX1A+q9OAz
194
196
-----END PGP PUBLIC KEY BLOCK-----` )
195
197
}
196
198
197
- func testCreateValidGPGKey (t * testing.T , makeRequest makeRequestFunc , expected int ) {
199
+ func testCreateValidGPGKey (t * testing.T , makeRequest makeRequestFunc , token string , expected int ) {
198
200
//User2 <user2@example.com> //primary & activated
199
- testCreateGPGKey (t , makeRequest , expected , `-----BEGIN PGP PUBLIC KEY BLOCK-----
201
+ testCreateGPGKey (t , makeRequest , token , expected , `-----BEGIN PGP PUBLIC KEY BLOCK-----
200
202
201
203
mQENBFmGVsMBCACuxgZ7W7rI9xN08Y4M7B8yx/6/I4Slm94+wXf8YNRvAyqj30dW
202
204
VJhyBcnfNRDLKSQp5o/hhfDkCgdqBjLa1PnHlGS3PXJc0hP/FyYPD2BFvNMPpCYS
@@ -228,9 +230,9 @@ uy6MA3VSB99SK9ducGmE1Jv8mcziREroz2TEGr0zPs6h
228
230
-----END PGP PUBLIC KEY BLOCK-----` )
229
231
}
230
232
231
- func testCreateValidSecondaryEmailGPGKey (t * testing.T , makeRequest makeRequestFunc , expected int ) {
233
+ func testCreateValidSecondaryEmailGPGKey (t * testing.T , makeRequest makeRequestFunc , token string , expected int ) {
232
234
//User2 <user21@example.com> //secondary and not activated
233
- testCreateGPGKey (t , makeRequest , expected , `-----BEGIN PGP PUBLIC KEY BLOCK-----
235
+ testCreateGPGKey (t , makeRequest , token , expected , `-----BEGIN PGP PUBLIC KEY BLOCK-----
234
236
235
237
mQENBFmGWN4BCAC18V4tVGO65VLCV7p14FuXJlUtZ5CuYMvgEkcOqrvRaBSW9ao4
236
238
PGESOhJpfWpnW3QgJniYndLzPpsmdHEclEER6aZjiNgReWPOjHD5tykWocZAJqXD
0 commit comments