@@ -20,16 +20,18 @@ type makeRequestFunc func(testing.TB, *http.Request, int) *httptest.ResponseReco
2020func  TestGPGKeys (t  * testing.T ) {
2121	prepareTestEnv (t )
2222	session  :=  loginUser (t , "user2" )
23+ 	token  :=  getTokenForLoggedInUser (t , session )
2324
2425	tt  :=  []struct  {
2526		name         string 
2627		makeRequest  makeRequestFunc 
28+ 		token        string 
2729		results      []int 
2830	}{
29- 		{name : "NoLogin" , makeRequest : MakeRequest ,
31+ 		{name : "NoLogin" , makeRequest : MakeRequest ,  token :  "" , 
3032			results : []int {http .StatusUnauthorized , http .StatusUnauthorized , http .StatusUnauthorized , http .StatusUnauthorized , http .StatusUnauthorized , http .StatusUnauthorized , http .StatusUnauthorized , http .StatusUnauthorized },
3133		},
32- 		{name : "LoggedAsUser2" , makeRequest : session .MakeRequest ,
34+ 		{name : "LoggedAsUser2" , makeRequest : session .MakeRequest ,  token :  token , 
3335			results : []int {http .StatusOK , http .StatusOK , http .StatusNotFound , http .StatusNoContent , http .StatusInternalServerError , http .StatusInternalServerError , http .StatusCreated , http .StatusCreated }},
3436	}
3537
@@ -38,29 +40,29 @@ func TestGPGKeys(t *testing.T) {
3840		//Basic test on result code 
3941		t .Run (tc .name , func (t  * testing.T ) {
4042			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 ])
4244			})
4345			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 ])
4547			})
4648			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 ])
4850			})
4951			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 ])
5153			})
5254
5355			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 ])
5557			})
5658			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 ])
5860			})
5961			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 ])
6163			})
6264			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 ])
6466			})
6567		})
6668	}
@@ -70,7 +72,7 @@ func TestGPGKeys(t *testing.T) {
7072
7173		var  keys  []* api.GPGKey 
7274
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 
7476		resp  :=  session .MakeRequest (t , req , http .StatusOK )
7577		DecodeJSON (t , resp , & keys )
7678
@@ -91,21 +93,21 @@ func TestGPGKeys(t *testing.T) {
9193		assert .EqualValues (t , false , primaryKey2 .Emails [0 ].Verified )
9294
9395		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 
9597		resp  =  session .MakeRequest (t , req , http .StatusOK )
9698		DecodeJSON (t , resp , & key )
9799		assert .EqualValues (t , "38EA3BCED732982C" , key .KeyID )
98100		assert .EqualValues (t , 1 , len (key .Emails ))
99101		assert .EqualValues (t , "user2@example.com" , key .Emails [0 ].Email )
100102		assert .EqualValues (t , true , key .Emails [0 ].Verified )
101103
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 
103105		resp  =  session .MakeRequest (t , req , http .StatusOK )
104106		DecodeJSON (t , resp , & key )
105107		assert .EqualValues (t , "70D7C694D17D03AD" , key .KeyID )
106108		assert .EqualValues (t , 0 , len (key .Emails ))
107109
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 
109111		resp  =  session .MakeRequest (t , req , http .StatusOK )
110112		DecodeJSON (t , resp , & key )
111113		assert .EqualValues (t , "FABF39739FE1E927" , key .KeyID )
@@ -119,63 +121,63 @@ func TestGPGKeys(t *testing.T) {
119121	t .Run ("CheckCommits" , func (t  * testing.T ) {
120122		t .Run ("NotSigned" , func (t  * testing.T ) {
121123			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 )
123125			resp  :=  session .MakeRequest (t , req , http .StatusOK )
124126			DecodeJSON (t , resp , & branch )
125127			assert .EqualValues (t , false , branch .Commit .Verification .Verified )
126128		})
127129
128130		t .Run ("SignedWithNotValidatedEmail" , func (t  * testing.T ) {
129131			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 )
131133			resp  :=  session .MakeRequest (t , req , http .StatusOK )
132134			DecodeJSON (t , resp , & branch )
133135			assert .EqualValues (t , false , branch .Commit .Verification .Verified )
134136		})
135137
136138		t .Run ("SignedWithValidEmail" , func (t  * testing.T ) {
137139			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 )
139141			resp  :=  session .MakeRequest (t , req , http .StatusOK )
140142			DecodeJSON (t , resp , & branch )
141143			assert .EqualValues (t , true , branch .Commit .Verification .Verified )
142144		})
143145	})
144146}
145147
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 )
148150	makeRequest (t , req , expected )
149151}
150152
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 )
153155	makeRequest (t , req , expected )
154156}
155157
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 )
158160	makeRequest (t , req , expected )
159161}
160162
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 )
163165	makeRequest (t , req , expected )
164166}
165167
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 {
168170		ArmoredKey : publicKey ,
169171	})
170172	makeRequest (t , req , expected )
171173}
172174
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" )
175177}
176178
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----- 
179181
180182mQENBFmGUygBCACjCNbKvMGgp0fd5vyFW9olE1CLCSyyF9gQN2hSuzmZLuAZF2Kh 
181183dCMCG2T1UwzUB/yWUFWJ2BtCwSjuaRv+cGohqEy6bhEBV90peGA33lHfjx7wP25O 
@@ -194,9 +196,9 @@ INx/MmBfmtCq05FqNclvU+sj2R3N1JJOtBOjZrJHQbJhzoILou8AkxeX1A+q9OAz
194196-----END PGP PUBLIC KEY BLOCK-----` )
195197}
196198
197- func  testCreateValidGPGKey (t  * testing.T , makeRequest  makeRequestFunc , expected  int ) {
199+ func  testCreateValidGPGKey (t  * testing.T , makeRequest  makeRequestFunc , token   string ,  expected  int ) {
198200	//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----- 
200202
201203mQENBFmGVsMBCACuxgZ7W7rI9xN08Y4M7B8yx/6/I4Slm94+wXf8YNRvAyqj30dW 
202204VJhyBcnfNRDLKSQp5o/hhfDkCgdqBjLa1PnHlGS3PXJc0hP/FyYPD2BFvNMPpCYS 
@@ -228,9 +230,9 @@ uy6MA3VSB99SK9ducGmE1Jv8mcziREroz2TEGr0zPs6h
228230-----END PGP PUBLIC KEY BLOCK-----` )
229231}
230232
231- func  testCreateValidSecondaryEmailGPGKey (t  * testing.T , makeRequest  makeRequestFunc , expected  int ) {
233+ func  testCreateValidSecondaryEmailGPGKey (t  * testing.T , makeRequest  makeRequestFunc , token   string ,  expected  int ) {
232234	//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----- 
234236
235237mQENBFmGWN4BCAC18V4tVGO65VLCV7p14FuXJlUtZ5CuYMvgEkcOqrvRaBSW9ao4 
236238PGESOhJpfWpnW3QgJniYndLzPpsmdHEclEER6aZjiNgReWPOjHD5tykWocZAJqXD 
0 commit comments