@@ -196,3 +196,121 @@ func TestAuthConnectionsList_JSONOutput_PrintsRawResponse(t *testing.T) {
196196 assert .Contains (t , out , "\" profile_name\" " )
197197 assert .Contains (t , out , "\" raf-leaseweb\" " )
198198}
199+
200+ func newFakeWithMfaOptions (options []kernel.ManagedAuthMfaOption ) * FakeAuthConnectionService {
201+ return & FakeAuthConnectionService {
202+ GetFunc : func (ctx context.Context , id string , opts ... option.RequestOption ) (* kernel.ManagedAuth , error ) {
203+ return & kernel.ManagedAuth {
204+ ID : id ,
205+ MfaOptions : options ,
206+ }, nil
207+ },
208+ SubmitFunc : func (ctx context.Context , id string , body kernel.AuthConnectionSubmitParams , opts ... option.RequestOption ) (* kernel.SubmitFieldsResponse , error ) {
209+ return & kernel.SubmitFieldsResponse {Accepted : true }, nil
210+ },
211+ }
212+ }
213+
214+ func TestSubmit_MfaOptionResolvesType (t * testing.T ) {
215+ fake := newFakeWithMfaOptions ([]kernel.ManagedAuthMfaOption {
216+ {Label : "Get a text" , Type : "sms" },
217+ {Label : "Have us call you" , Type : "call" },
218+ })
219+
220+ var submittedID string
221+ fake .SubmitFunc = func (ctx context.Context , id string , body kernel.AuthConnectionSubmitParams , opts ... option.RequestOption ) (* kernel.SubmitFieldsResponse , error ) {
222+ submittedID = body .SubmitFieldsRequest .MfaOptionID .Value
223+ return & kernel.SubmitFieldsResponse {Accepted : true }, nil
224+ }
225+
226+ c := AuthConnectionCmd {svc : fake }
227+ err := c .Submit (context .Background (), AuthConnectionSubmitInput {
228+ ID : "conn-1" ,
229+ MfaOptionID : "sms" ,
230+ Output : "json" ,
231+ })
232+ require .NoError (t , err )
233+ assert .Equal (t , "sms" , submittedID )
234+ }
235+
236+ func TestSubmit_MfaOptionResolvesLabel (t * testing.T ) {
237+ fake := newFakeWithMfaOptions ([]kernel.ManagedAuthMfaOption {
238+ {Label : "Get a text" , Type : "sms" },
239+ {Label : "Have us call you" , Type : "call" },
240+ })
241+
242+ var submittedID string
243+ fake .SubmitFunc = func (ctx context.Context , id string , body kernel.AuthConnectionSubmitParams , opts ... option.RequestOption ) (* kernel.SubmitFieldsResponse , error ) {
244+ submittedID = body .SubmitFieldsRequest .MfaOptionID .Value
245+ return & kernel.SubmitFieldsResponse {Accepted : true }, nil
246+ }
247+
248+ c := AuthConnectionCmd {svc : fake }
249+ err := c .Submit (context .Background (), AuthConnectionSubmitInput {
250+ ID : "conn-1" ,
251+ MfaOptionID : "Get a text" ,
252+ Output : "json" ,
253+ })
254+ require .NoError (t , err )
255+ assert .Equal (t , "sms" , submittedID )
256+ }
257+
258+ func TestSubmit_MfaOptionResolvesDisplayString (t * testing.T ) {
259+ fake := newFakeWithMfaOptions ([]kernel.ManagedAuthMfaOption {
260+ {Label : "Get a text" , Type : "sms" },
261+ })
262+
263+ var submittedID string
264+ fake .SubmitFunc = func (ctx context.Context , id string , body kernel.AuthConnectionSubmitParams , opts ... option.RequestOption ) (* kernel.SubmitFieldsResponse , error ) {
265+ submittedID = body .SubmitFieldsRequest .MfaOptionID .Value
266+ return & kernel.SubmitFieldsResponse {Accepted : true }, nil
267+ }
268+
269+ c := AuthConnectionCmd {svc : fake }
270+ err := c .Submit (context .Background (), AuthConnectionSubmitInput {
271+ ID : "conn-1" ,
272+ MfaOptionID : "Get a text (sms)" ,
273+ Output : "json" ,
274+ })
275+ require .NoError (t , err )
276+ assert .Equal (t , "sms" , submittedID )
277+ }
278+
279+ func TestSubmit_MfaOptionResolvesLabelCaseInsensitive (t * testing.T ) {
280+ fake := newFakeWithMfaOptions ([]kernel.ManagedAuthMfaOption {
281+ {Label : "Get a text" , Type : "sms" },
282+ })
283+
284+ var submittedID string
285+ fake .SubmitFunc = func (ctx context.Context , id string , body kernel.AuthConnectionSubmitParams , opts ... option.RequestOption ) (* kernel.SubmitFieldsResponse , error ) {
286+ submittedID = body .SubmitFieldsRequest .MfaOptionID .Value
287+ return & kernel.SubmitFieldsResponse {Accepted : true }, nil
288+ }
289+
290+ c := AuthConnectionCmd {svc : fake }
291+ err := c .Submit (context .Background (), AuthConnectionSubmitInput {
292+ ID : "conn-1" ,
293+ MfaOptionID : "get a TEXT" ,
294+ Output : "json" ,
295+ })
296+ require .NoError (t , err )
297+ assert .Equal (t , "sms" , submittedID )
298+ }
299+
300+ func TestSubmit_MfaOptionRejectsUnknown (t * testing.T ) {
301+ fake := newFakeWithMfaOptions ([]kernel.ManagedAuthMfaOption {
302+ {Label : "Get a text" , Type : "sms" },
303+ {Label : "Have us call you" , Type : "call" },
304+ })
305+
306+ c := AuthConnectionCmd {svc : fake }
307+ err := c .Submit (context .Background (), AuthConnectionSubmitInput {
308+ ID : "conn-1" ,
309+ MfaOptionID : "carrier pigeon" ,
310+ Output : "json" ,
311+ })
312+ require .Error (t , err )
313+ assert .Contains (t , err .Error (), "unknown MFA option" )
314+ assert .Contains (t , err .Error (), "carrier pigeon" )
315+ assert .Contains (t , err .Error (), "Get a text (sms)" )
316+ }
0 commit comments