@@ -23,6 +23,7 @@ import (
23
23
)
24
24
25
25
func TestGPGGit (t * testing.T ) {
26
+ prepareTestEnv (t )
26
27
username := "user2"
27
28
28
29
// OK Set a new GPG home
@@ -125,11 +126,19 @@ func TestGPGGit(t *testing.T) {
125
126
t .Run ("CreateCRUDFile-Always" , crudActionCreateFile (
126
127
t , testCtx , user , "master" , "always" , "signed-always.txt" , func (t * testing.T , response api.FileResponse ) {
127
128
assert .True (t , response .Verification .Verified )
129
+ if ! response .Verification .Verified {
130
+ t .FailNow ()
131
+ return
132
+ }
128
133
assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
129
134
}))
130
135
t .Run ("CreateCRUDFile-ParentSigned-always" , crudActionCreateFile (
131
136
t , testCtx , user , "parentsigned" , "parentsigned-always" , "signed-parent2.txt" , func (t * testing.T , response api.FileResponse ) {
132
137
assert .True (t , response .Verification .Verified )
138
+ if ! response .Verification .Verified {
139
+ t .FailNow ()
140
+ return
141
+ }
133
142
assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
134
143
}))
135
144
})
@@ -144,6 +153,10 @@ func TestGPGGit(t *testing.T) {
144
153
t .Run ("CreateCRUDFile-Always-ParentSigned" , crudActionCreateFile (
145
154
t , testCtx , user , "always" , "always-parentsigned" , "signed-always-parentsigned.txt" , func (t * testing.T , response api.FileResponse ) {
146
155
assert .True (t , response .Verification .Verified )
156
+ if ! response .Verification .Verified {
157
+ t .FailNow ()
158
+ return
159
+ }
147
160
assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
148
161
}))
149
162
})
@@ -160,6 +173,10 @@ func TestGPGGit(t *testing.T) {
160
173
assert .NotNil (t , branch .Commit )
161
174
assert .NotNil (t , branch .Commit .Verification )
162
175
assert .True (t , branch .Commit .Verification .Verified )
176
+ if ! branch .Commit .Verification .Verified {
177
+ t .FailNow ()
178
+ return
179
+ }
163
180
assert .
Equal (
t ,
"[email protected] " ,
branch .
Commit .
Verification .
Signer .
Email )
164
181
}))
165
182
})
@@ -170,7 +187,8 @@ func TestGPGGit(t *testing.T) {
170
187
171
188
t .Run ("AlwaysSign-Initial-CRUD-Never" , func (t * testing.T ) {
172
189
defer PrintCurrentTest (t )()
173
- testCtx := NewAPITestContext (t , username , "initial-always" )
190
+ testCtx := NewAPITestContext (t , username , "initial-always-never" )
191
+ t .Run ("CreateRepository" , doAPICreateRepository (testCtx , false ))
174
192
t .Run ("CreateCRUDFile-Never" , crudActionCreateFile (
175
193
t , testCtx , user , "master" , "never" , "unsigned-never.txt" , func (t * testing.T , response api.FileResponse ) {
176
194
assert .False (t , response .Verification .Verified )
@@ -180,13 +198,17 @@ func TestGPGGit(t *testing.T) {
180
198
setting .Repository .Signing .CRUDActions = []string {"parentsigned" }
181
199
onGiteaRun (t , func (t * testing.T , u * url.URL ) {
182
200
u .Path = baseAPITestContext .GitPath ()
183
-
184
201
t .Run ("AlwaysSign-Initial-CRUD-ParentSigned-On-Always" , func (t * testing.T ) {
185
202
defer PrintCurrentTest (t )()
186
- testCtx := NewAPITestContext (t , username , "initial-always" )
203
+ testCtx := NewAPITestContext (t , username , "initial-always-parent" )
204
+ t .Run ("CreateRepository" , doAPICreateRepository (testCtx , false ))
187
205
t .Run ("CreateCRUDFile-ParentSigned" , crudActionCreateFile (
188
206
t , testCtx , user , "master" , "parentsigned" , "signed-parent.txt" , func (t * testing.T , response api.FileResponse ) {
189
207
assert .True (t , response .Verification .Verified )
208
+ if ! response .Verification .Verified {
209
+ t .FailNow ()
210
+ return
211
+ }
190
212
assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
191
213
}))
192
214
})
@@ -197,10 +219,15 @@ func TestGPGGit(t *testing.T) {
197
219
198
220
t .Run ("AlwaysSign-Initial-CRUD-Always" , func (t * testing.T ) {
199
221
defer PrintCurrentTest (t )()
200
- testCtx := NewAPITestContext (t , username , "initial-always" )
222
+ testCtx := NewAPITestContext (t , username , "initial-always-always" )
223
+ t .Run ("CreateRepository" , doAPICreateRepository (testCtx , false ))
201
224
t .Run ("CreateCRUDFile-Always" , crudActionCreateFile (
202
225
t , testCtx , user , "master" , "always" , "signed-always.txt" , func (t * testing.T , response api.FileResponse ) {
203
226
assert .True (t , response .Verification .Verified )
227
+ if ! response .Verification .Verified {
228
+ t .FailNow ()
229
+ return
230
+ }
204
231
assert .
Equal (
t ,
"[email protected] " ,
response .
Verification .
Signer .
Email )
205
232
}))
206
233
@@ -287,7 +314,7 @@ func crudActionCreateFile(t *testing.T, ctx APITestContext, user *models.User, f
287
314
Email : user .Email ,
288
315
},
289
316
},
290
- Content : base64 .StdEncoding .EncodeToString ([]byte ("This is new text" )),
317
+ Content : base64 .StdEncoding .EncodeToString ([]byte (fmt . Sprintf ( "This is new text for %s" , path ) )),
291
318
}, callback ... )
292
319
}
293
320
0 commit comments