@@ -192,35 +192,52 @@ func TestUserCertificateHandling(t *testing.T) {
192192 testCases := []struct {
193193 desc string
194194 cert * ssh.Certificate
195+ featureFlagValue string
195196 expectedErr error
196197 expectedPermissions * ssh.Permissions
197198 }{
198199 {
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" ),
202204 }, {
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" ),
206209 }, {
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" },
210214 }, {
211- desc : "successful request" ,
212- cert : validUserCert ,
215+ desc : "successful request" ,
216+ cert : validUserCert ,
217+ featureFlagValue : "1" ,
213218 expectedPermissions : & ssh.Permissions {
214219 Extensions : map [string ]string {
215220 "username" : "root" ,
216221 "namespace" : "namespace" ,
217222 },
218223 },
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 ,
219235 },
220236 }
221237
222238 for _ , tc := range testCases {
223239 t .Run (tc .desc , func (t * testing.T ) {
240+ t .Setenv ("FF_GITLAB_SHELL_SSH_CERTIFICATES" , tc .featureFlagValue )
224241 permissions , err := cfg .handleUserCertificate (context .Background (), "user" , tc .cert )
225242 require .Equal (t , tc .expectedErr , err )
226243 require .Equal (t , tc .expectedPermissions , permissions )
0 commit comments