@@ -192,35 +192,52 @@ func TestUserCertificateHandling(t *testing.T) {
192
192
testCases := []struct {
193
193
desc string
194
194
cert * ssh.Certificate
195
+ featureFlagValue string
195
196
expectedErr error
196
197
expectedPermissions * ssh.Permissions
197
198
}{
198
199
{
199
- desc : "wrong cert type" ,
200
- cert : userCert (t , ssh .HostCert , time .Now ().Add (time .Hour )),
201
- expectedErr : errors .New ("handleUserCertificate: cert has type 2" ),
200
+ desc : "wrong cert type" ,
201
+ cert : userCert (t , ssh .HostCert , time .Now ().Add (time .Hour )),
202
+ featureFlagValue : "1" ,
203
+ expectedErr : errors .New ("handleUserCertificate: cert has type 2" ),
202
204
}, {
203
- desc : "expired cert" ,
204
- cert : userCert (t , ssh .UserCert , time .Now ().Add (- time .Hour )),
205
- expectedErr : errors .New ("ssh: cert has expired" ),
205
+ desc : "expired cert" ,
206
+ cert : userCert (t , ssh .UserCert , time .Now ().Add (- time .Hour )),
207
+ featureFlagValue : "1" ,
208
+ expectedErr : errors .New ("ssh: cert has expired" ),
206
209
}, {
207
- desc : "API error" ,
208
- cert : userCert (t , ssh .UserCert , time .Now ().Add (time .Hour )),
209
- expectedErr : & client.ApiError {Msg : "Internal API unreachable" },
210
+ desc : "API error" ,
211
+ cert : userCert (t , ssh .UserCert , time .Now ().Add (time .Hour )),
212
+ featureFlagValue : "1" ,
213
+ expectedErr : & client.ApiError {Msg : "Internal API unreachable" },
210
214
}, {
211
- desc : "successful request" ,
212
- cert : validUserCert ,
215
+ desc : "successful request" ,
216
+ cert : validUserCert ,
217
+ featureFlagValue : "1" ,
213
218
expectedPermissions : & ssh.Permissions {
214
219
Extensions : map [string ]string {
215
220
"username" : "root" ,
216
221
"namespace" : "namespace" ,
217
222
},
218
223
},
224
+ }, {
225
+ desc : "feature flag is not enabled" ,
226
+ cert : validUserCert ,
227
+ expectedErr : errors .New ("handleUserCertificate: feature is disabled" ),
228
+ expectedPermissions : nil ,
229
+ }, {
230
+ desc : "feature flag is disabled" ,
231
+ cert : validUserCert ,
232
+ featureFlagValue : "0" ,
233
+ expectedErr : errors .New ("handleUserCertificate: feature is disabled" ),
234
+ expectedPermissions : nil ,
219
235
},
220
236
}
221
237
222
238
for _ , tc := range testCases {
223
239
t .Run (tc .desc , func (t * testing.T ) {
240
+ t .Setenv ("FF_GITLAB_SHELL_SSH_CERTIFICATES" , tc .featureFlagValue )
224
241
permissions , err := cfg .handleUserCertificate (context .Background (), "user" , tc .cert )
225
242
require .Equal (t , tc .expectedErr , err )
226
243
require .Equal (t , tc .expectedPermissions , permissions )
0 commit comments