@@ -23,14 +23,7 @@ import (
23
23
)
24
24
25
25
func TestGPGGit (t * testing.T ) {
26
- onGiteaRun (t , testGPGGit )
27
- }
28
-
29
- func testGPGGit (t * testing.T , u * url.URL ) {
30
26
username := "user2"
31
- baseAPITestContext := NewAPITestContext (t , username , "repo1" )
32
-
33
- u .Path = baseAPITestContext .GitPath ()
34
27
35
28
// OK Set a new GPG home
36
29
tmpDir , err := ioutil .TempDir ("" , "temp-gpg" )
@@ -65,130 +58,218 @@ func testGPGGit(t *testing.T, u *url.URL) {
65
58
setting .
Repository .
Signing .
SigningEmail = "[email protected] "
66
59
user := models .AssertExistsAndLoadBean (t , & models.User {Name : username }).(* models.User )
67
60
68
- t .Run ("Unsigned-Initial" , func (t * testing.T ) {
69
- PrintCurrentTest (t )
70
- setting .Repository .Signing .InitialCommit = []string {"never" }
71
- testCtx := NewAPITestContext (t , username , "initial-unsigned" )
72
- t .Run ("CreateRepository" , doAPICreateRepository (testCtx , false ))
73
- t .Run ("CheckMasterBranchUnsigned" , doAPIGetBranch (testCtx , "master" , func (t * testing.T , branch api.Branch ) {
74
- assert .NotNil (t , branch .Commit )
75
- assert .NotNil (t , branch .Commit .Verification )
76
- assert .False (t , branch .Commit .Verification .Verified )
77
- assert .Empty (t , branch .Commit .Verification .Signature )
78
- }))
79
- setting .Repository .Signing .CRUDActions = []string {"never" }
80
- t .Run ("CreateCRUDFile-Never" , crudActionCreateFile (
81
- t , testCtx , user , "master" , "never" , "unsigned-never.txt" , func (t * testing.T , response api.FileResponse ) {
82
- assert .False (t , response .Verification .Verified )
83
- }))
84
- t .Run ("CreateCRUDFile-Never" , crudActionCreateFile (
85
- t , testCtx , user , "never" , "never2" , "unsigned-never2.txt" , func (t * testing.T , response api.FileResponse ) {
86
- assert .False (t , response .Verification .Verified )
87
- }))
88
- setting .Repository .Signing .CRUDActions = []string {"parentsigned" }
89
- t .Run ("CreateCRUDFile-ParentSigned" , crudActionCreateFile (
90
- t , testCtx , user , "master" , "parentsigned" , "signed-parent.txt" , func (t * testing.T , response api.FileResponse ) {
91
- assert .False (t , response .Verification .Verified )
92
- }))
93
- t .Run ("CreateCRUDFile-ParentSigned" , crudActionCreateFile (
94
- t , testCtx , user , "parentsigned" , "parentsigned2" , "signed-parent2.txt" , func (t * testing.T , response api.FileResponse ) {
95
- assert .False (t , response .Verification .Verified )
96
- }))
97
- setting .Repository .Signing .CRUDActions = []string {"never" }
98
- t .Run ("CreateCRUDFile-Never" , crudActionCreateFile (
99
- t , testCtx , user , "parentsigned" , "parentsigned-never" , "unsigned-never2.txt" , func (t * testing.T , response api.FileResponse ) {
100
- assert .False (t , response .Verification .Verified )
101
- }))
102
- setting .Repository .Signing .CRUDActions = []string {"always" }
103
- t .Run ("CreateCRUDFile-Always" , crudActionCreateFile (
104
- t , testCtx , user , "master" , "always" , "signed-always.txt" , func (t * testing.T , response api.FileResponse ) {
105
- assert .True (t , response .Verification .Verified )
106
- assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
107
- }))
108
- t .Run ("CreateCRUDFile-ParentSigned-always" , crudActionCreateFile (
109
- t , testCtx , user , "parentsigned" , "parentsigned-always" , "signed-parent2.txt" , func (t * testing.T , response api.FileResponse ) {
110
- assert .True (t , response .Verification .Verified )
111
- assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
61
+ setting .Repository .Signing .InitialCommit = []string {"never" }
62
+ setting .Repository .Signing .CRUDActions = []string {"never" }
63
+
64
+ baseAPITestContext := NewAPITestContext (t , username , "repo1" )
65
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
66
+ u .Path = baseAPITestContext .GitPath ()
67
+
68
+ t .Run ("Unsigned-Initial" , func (t * testing.T ) {
69
+ PrintCurrentTest (t )
70
+ testCtx := NewAPITestContext (t , username , "initial-unsigned" )
71
+ t .Run ("CreateRepository" , doAPICreateRepository (testCtx , false ))
72
+ t .Run ("CheckMasterBranchUnsigned" , doAPIGetBranch (testCtx , "master" , func (t * testing.T , branch api.Branch ) {
73
+ assert .NotNil (t , branch .Commit )
74
+ assert .NotNil (t , branch .Commit .Verification )
75
+ assert .False (t , branch .Commit .Verification .Verified )
76
+ assert .Empty (t , branch .Commit .Verification .Signature )
112
77
}))
113
- setting .Repository .Signing .CRUDActions = []string {"parentsigned" }
114
- t .Run ("CreateCRUDFile-Always-ParentSigned" , crudActionCreateFile (
115
- t , testCtx , user , "always" , "always-parentsigned" , "signed-always-parentsigned.txt" , func (t * testing.T , response api.FileResponse ) {
116
- assert .True (t , response .Verification .Verified )
117
- assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
78
+ t .Run ("CreateCRUDFile-Never" , crudActionCreateFile (
79
+ t , testCtx , user , "master" , "never" , "unsigned-never.txt" , func (t * testing.T , response api.FileResponse ) {
80
+ assert .False (t , response .Verification .Verified )
81
+ }))
82
+ t .Run ("CreateCRUDFile-Never" , crudActionCreateFile (
83
+ t , testCtx , user , "never" , "never2" , "unsigned-never2.txt" , func (t * testing.T , response api.FileResponse ) {
84
+ assert .False (t , response .Verification .Verified )
85
+ }))
86
+ })
87
+ }, false )
88
+ setting .Repository .Signing .CRUDActions = []string {"parentsigned" }
89
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
90
+ u .Path = baseAPITestContext .GitPath ()
91
+
92
+ t .Run ("Unsigned-Initial-CRUD-ParentSigned" , func (t * testing.T ) {
93
+ PrintCurrentTest (t )
94
+ testCtx := NewAPITestContext (t , username , "initial-unsigned" )
95
+ t .Run ("CreateCRUDFile-ParentSigned" , crudActionCreateFile (
96
+ t , testCtx , user , "master" , "parentsigned" , "signed-parent.txt" , func (t * testing.T , response api.FileResponse ) {
97
+ assert .False (t , response .Verification .Verified )
98
+ }))
99
+ t .Run ("CreateCRUDFile-ParentSigned" , crudActionCreateFile (
100
+ t , testCtx , user , "parentsigned" , "parentsigned2" , "signed-parent2.txt" , func (t * testing.T , response api.FileResponse ) {
101
+ assert .False (t , response .Verification .Verified )
102
+ }))
103
+ })
104
+ }, false )
105
+ setting .Repository .Signing .CRUDActions = []string {"never" }
106
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
107
+ u .Path = baseAPITestContext .GitPath ()
108
+
109
+ t .Run ("Unsigned-Initial-CRUD-Never" , func (t * testing.T ) {
110
+ PrintCurrentTest (t )
111
+ testCtx := NewAPITestContext (t , username , "initial-unsigned" )
112
+ t .Run ("CreateCRUDFile-Never" , crudActionCreateFile (
113
+ t , testCtx , user , "parentsigned" , "parentsigned-never" , "unsigned-never2.txt" , func (t * testing.T , response api.FileResponse ) {
114
+ assert .False (t , response .Verification .Verified )
115
+ }))
116
+ })
117
+ }, false )
118
+ setting .Repository .Signing .CRUDActions = []string {"always" }
119
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
120
+ u .Path = baseAPITestContext .GitPath ()
121
+
122
+ t .Run ("Unsigned-Initial-CRUD-Always" , func (t * testing.T ) {
123
+ PrintCurrentTest (t )
124
+ testCtx := NewAPITestContext (t , username , "initial-unsigned" )
125
+ t .Run ("CreateCRUDFile-Always" , crudActionCreateFile (
126
+ t , testCtx , user , "master" , "always" , "signed-always.txt" , func (t * testing.T , response api.FileResponse ) {
127
+ assert .True (t , response .Verification .Verified )
128
+ assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
129
+ }))
130
+ t .Run ("CreateCRUDFile-ParentSigned-always" , crudActionCreateFile (
131
+ t , testCtx , user , "parentsigned" , "parentsigned-always" , "signed-parent2.txt" , func (t * testing.T , response api.FileResponse ) {
132
+ assert .True (t , response .Verification .Verified )
133
+ assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
134
+ }))
135
+ })
136
+ }, false )
137
+ setting .Repository .Signing .CRUDActions = []string {"parentsigned" }
138
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
139
+ u .Path = baseAPITestContext .GitPath ()
140
+
141
+ t .Run ("Unsigned-Initial-CRUD-ParentSigned" , func (t * testing.T ) {
142
+ PrintCurrentTest (t )
143
+ testCtx := NewAPITestContext (t , username , "initial-unsigned" )
144
+ t .Run ("CreateCRUDFile-Always-ParentSigned" , crudActionCreateFile (
145
+ t , testCtx , user , "always" , "always-parentsigned" , "signed-always-parentsigned.txt" , func (t * testing.T , response api.FileResponse ) {
146
+ assert .True (t , response .Verification .Verified )
147
+ assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
148
+ }))
149
+ })
150
+ }, false )
151
+ setting .Repository .Signing .InitialCommit = []string {"always" }
152
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
153
+ u .Path = baseAPITestContext .GitPath ()
154
+
155
+ t .Run ("AlwaysSign-Initial" , func (t * testing.T ) {
156
+ PrintCurrentTest (t )
157
+ testCtx := NewAPITestContext (t , username , "initial-always" )
158
+ t .Run ("CreateRepository" , doAPICreateRepository (testCtx , false ))
159
+ t .Run ("CheckMasterBranchSigned" , doAPIGetBranch (testCtx , "master" , func (t * testing.T , branch api.Branch ) {
160
+ assert .NotNil (t , branch .Commit )
161
+ assert .NotNil (t , branch .Commit .Verification )
162
+ assert .True (t , branch .Commit .Verification .Verified )
163
+ assert .
Equal (
t ,
"[email protected] " ,
branch .
Commit .
Verification .
Signer .
Email )
118
164
}))
119
- })
120
- t .Run ("AlwaysSign-Initial" , func (t * testing.T ) {
121
- PrintCurrentTest (t )
122
- setting .Repository .Signing .InitialCommit = []string {"always" }
123
- testCtx := NewAPITestContext (t , username , "initial-always" )
124
- t .Run ("CreateRepository" , doAPICreateRepository (testCtx , false ))
125
- t .Run ("CheckMasterBranchSigned" , doAPIGetBranch (testCtx , "master" , func (t * testing.T , branch api.Branch ) {
126
- assert .NotNil (t , branch .Commit )
127
- assert .NotNil (t , branch .Commit .Verification )
128
- assert .True (t , branch .Commit .Verification .Verified )
129
- assert .
Equal (
t ,
"[email protected] " ,
branch .
Commit .
Verification .
Signer .
Email )
130
- }))
131
- setting .Repository .Signing .CRUDActions = []string {"never" }
132
- t .Run ("CreateCRUDFile-Never" , crudActionCreateFile (
133
- t , testCtx , user , "master" , "never" , "unsigned-never.txt" , func (t * testing.T , response api.FileResponse ) {
134
- assert .False (t , response .Verification .Verified )
165
+ })
166
+ }, false )
167
+ setting .Repository .Signing .CRUDActions = []string {"never" }
168
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
169
+ u .Path = baseAPITestContext .GitPath ()
170
+
171
+ t .Run ("AlwaysSign-Initial-CRUD-Never" , func (t * testing.T ) {
172
+ PrintCurrentTest (t )
173
+ testCtx := NewAPITestContext (t , username , "initial-always" )
174
+ t .Run ("CreateCRUDFile-Never" , crudActionCreateFile (
175
+ t , testCtx , user , "master" , "never" , "unsigned-never.txt" , func (t * testing.T , response api.FileResponse ) {
176
+ assert .False (t , response .Verification .Verified )
177
+ }))
178
+ })
179
+ }, false )
180
+ setting .Repository .Signing .CRUDActions = []string {"parentsigned" }
181
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
182
+ u .Path = baseAPITestContext .GitPath ()
183
+
184
+ t .Run ("AlwaysSign-Initial-CRUD-ParentSigned-On-Always" , func (t * testing.T ) {
185
+ PrintCurrentTest (t )
186
+ testCtx := NewAPITestContext (t , username , "initial-always" )
187
+ t .Run ("CreateCRUDFile-ParentSigned" , crudActionCreateFile (
188
+ t , testCtx , user , "master" , "parentsigned" , "signed-parent.txt" , func (t * testing.T , response api.FileResponse ) {
189
+ assert .True (t , response .Verification .Verified )
190
+ assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
191
+ }))
192
+ })
193
+ }, false )
194
+ setting .Repository .Signing .CRUDActions = []string {"always" }
195
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
196
+ u .Path = baseAPITestContext .GitPath ()
197
+
198
+ t .Run ("AlwaysSign-Initial-CRUD-Always" , func (t * testing.T ) {
199
+ PrintCurrentTest (t )
200
+ testCtx := NewAPITestContext (t , username , "initial-always" )
201
+ t .Run ("CreateCRUDFile-Always" , crudActionCreateFile (
202
+ t , testCtx , user , "master" , "always" , "signed-always.txt" , func (t * testing.T , response api.FileResponse ) {
203
+ assert .True (t , response .Verification .Verified )
204
+ assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
205
+ }))
206
+
207
+ })
208
+ }, false )
209
+ var pr api.PullRequest
210
+ setting .Repository .Signing .Merges = []string {"commitssigned" }
211
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
212
+ u .Path = baseAPITestContext .GitPath ()
213
+
214
+ t .Run ("UnsignedMerging" , func (t * testing.T ) {
215
+ PrintCurrentTest (t )
216
+ testCtx := NewAPITestContext (t , username , "initial-unsigned" )
217
+ var err error
218
+ t .Run ("CreatePullRequest" , func (t * testing.T ) {
219
+ pr , err = doAPICreatePullRequest (testCtx , testCtx .Username , testCtx .Reponame , "master" , "never2" )(t )
220
+ assert .NoError (t , err )
221
+ })
222
+ t .Run ("MergePR" , doAPIMergePullRequest (testCtx , testCtx .Username , testCtx .Reponame , pr .Index ))
223
+ t .Run ("CheckMasterBranchUnsigned" , doAPIGetBranch (testCtx , "master" , func (t * testing.T , branch api.Branch ) {
224
+ assert .NotNil (t , branch .Commit )
225
+ assert .NotNil (t , branch .Commit .Verification )
226
+ assert .False (t , branch .Commit .Verification .Verified )
227
+ assert .Empty (t , branch .Commit .Verification .Signature )
135
228
}))
136
- setting .Repository .Signing .CRUDActions = []string {"parentsigned" }
137
- t .Run ("CreateCRUDFile-ParentSigned" , crudActionCreateFile (
138
- t , testCtx , user , "master" , "parentsigned" , "signed-parent.txt" , func (t * testing.T , response api.FileResponse ) {
139
- assert .True (t , response .Verification .Verified )
140
- assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
229
+ })
230
+ }, false )
231
+ setting .Repository .Signing .Merges = []string {"basesigned" }
232
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
233
+ u .Path = baseAPITestContext .GitPath ()
234
+
235
+ t .Run ("BaseSignedMerging" , func (t * testing.T ) {
236
+ PrintCurrentTest (t )
237
+ testCtx := NewAPITestContext (t , username , "initial-unsigned" )
238
+ var err error
239
+ t .Run ("CreatePullRequest" , func (t * testing.T ) {
240
+ pr , err = doAPICreatePullRequest (testCtx , testCtx .Username , testCtx .Reponame , "master" , "parentsigned2" )(t )
241
+ assert .NoError (t , err )
242
+ })
243
+ t .Run ("MergePR" , doAPIMergePullRequest (testCtx , testCtx .Username , testCtx .Reponame , pr .Index ))
244
+ t .Run ("CheckMasterBranchUnsigned" , doAPIGetBranch (testCtx , "master" , func (t * testing.T , branch api.Branch ) {
245
+ assert .NotNil (t , branch .Commit )
246
+ assert .NotNil (t , branch .Commit .Verification )
247
+ assert .False (t , branch .Commit .Verification .Verified )
248
+ assert .Empty (t , branch .Commit .Verification .Signature )
141
249
}))
142
- setting .Repository .Signing .CRUDActions = []string {"always" }
143
- t .Run ("CreateCRUDFile-Always" , crudActionCreateFile (
144
- t , testCtx , user , "master" , "always" , "signed-always.txt" , func (t * testing.T , response api.FileResponse ) {
145
- assert .True (t , response .Verification .Verified )
146
- assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
250
+ })
251
+ }, false )
252
+ setting .Repository .Signing .Merges = []string {"commitssigned" }
253
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
254
+ u .Path = baseAPITestContext .GitPath ()
255
+
256
+ t .Run ("CommitsSignedMerging" , func (t * testing.T ) {
257
+ PrintCurrentTest (t )
258
+ testCtx := NewAPITestContext (t , username , "initial-unsigned" )
259
+ var err error
260
+ t .Run ("CreatePullRequest" , func (t * testing.T ) {
261
+ pr , err = doAPICreatePullRequest (testCtx , testCtx .Username , testCtx .Reponame , "master" , "always-parentsigned" )(t )
262
+ assert .NoError (t , err )
263
+ })
264
+ t .Run ("MergePR" , doAPIMergePullRequest (testCtx , testCtx .Username , testCtx .Reponame , pr .Index ))
265
+ t .Run ("CheckMasterBranchUnsigned" , doAPIGetBranch (testCtx , "master" , func (t * testing.T , branch api.Branch ) {
266
+ assert .NotNil (t , branch .Commit )
267
+ assert .NotNil (t , branch .Commit .Verification )
268
+ assert .True (t , branch .Commit .Verification .Verified )
147
269
}))
148
270
149
- })
150
- t .Run ("UnsignedMerging" , func (t * testing.T ) {
151
- PrintCurrentTest (t )
152
- testCtx := NewAPITestContext (t , username , "initial-unsigned" )
153
- var pr api.PullRequest
154
- var err error
155
- t .Run ("CreatePullRequest" , func (t * testing.T ) {
156
- pr , err = doAPICreatePullRequest (testCtx , testCtx .Username , testCtx .Reponame , "master" , "never2" )(t )
157
- assert .NoError (t , err )
158
- })
159
- setting .Repository .Signing .Merges = []string {"commitssigned" }
160
- t .Run ("MergePR" , doAPIMergePullRequest (testCtx , testCtx .Username , testCtx .Reponame , pr .Index ))
161
- t .Run ("CheckMasterBranchUnsigned" , doAPIGetBranch (testCtx , "master" , func (t * testing.T , branch api.Branch ) {
162
- assert .NotNil (t , branch .Commit )
163
- assert .NotNil (t , branch .Commit .Verification )
164
- assert .False (t , branch .Commit .Verification .Verified )
165
- assert .Empty (t , branch .Commit .Verification .Signature )
166
- }))
167
- setting .Repository .Signing .Merges = []string {"basesigned" }
168
- t .Run ("CreatePullRequest" , func (t * testing.T ) {
169
- pr , err = doAPICreatePullRequest (testCtx , testCtx .Username , testCtx .Reponame , "master" , "parentsigned2" )(t )
170
- assert .NoError (t , err )
171
- })
172
- t .Run ("MergePR" , doAPIMergePullRequest (testCtx , testCtx .Username , testCtx .Reponame , pr .Index ))
173
- t .Run ("CheckMasterBranchUnsigned" , doAPIGetBranch (testCtx , "master" , func (t * testing.T , branch api.Branch ) {
174
- assert .NotNil (t , branch .Commit )
175
- assert .NotNil (t , branch .Commit .Verification )
176
- assert .False (t , branch .Commit .Verification .Verified )
177
- assert .Empty (t , branch .Commit .Verification .Signature )
178
- }))
179
- setting .Repository .Signing .Merges = []string {"commitssigned" }
180
- t .Run ("CreatePullRequest" , func (t * testing.T ) {
181
- pr , err = doAPICreatePullRequest (testCtx , testCtx .Username , testCtx .Reponame , "master" , "always-parentsigned" )(t )
182
- assert .NoError (t , err )
183
271
})
184
- t .Run ("MergePR" , doAPIMergePullRequest (testCtx , testCtx .Username , testCtx .Reponame , pr .Index ))
185
- t .Run ("CheckMasterBranchUnsigned" , doAPIGetBranch (testCtx , "master" , func (t * testing.T , branch api.Branch ) {
186
- assert .NotNil (t , branch .Commit )
187
- assert .NotNil (t , branch .Commit .Verification )
188
- assert .True (t , branch .Commit .Verification .Verified )
189
- }))
190
-
191
- })
272
+ }, false )
192
273
}
193
274
194
275
func crudActionCreateFile (t * testing.T , ctx APITestContext , user * models.User , from , to , path string , callback ... func (* testing.T , api.FileResponse )) func (* testing.T ) {
0 commit comments