package Ġcom . work os . test . m fa Ċ Ċ import Ġcom . work os . common . exceptions . Unauthorized Exception Ċ import Ġcom . work os . common . exceptions . Un process able Entity Exception Ċ import Ġcom . work os . m fa . M fa Api Ċ import Ġcom . work os . test . TestBase Ċ import Ġorg . junit . jupiter . api . Assertions . assert Throws Ċ import Ġkotlin . test . Test Ċ import Ġkotlin . test . assertEquals Ċ import Ġkotlin . test . assertNotNull Ċ import Ġkotlin . test . assertNull Ċ Ċ class ĠM fa Api Test Ġ: ĠTest Base () Ġ{ ĊĠ Ġ@ Test ĊĠ Ġfun Ġdelete Factor Should Not Error () Ġ{ ĊĠĠĠ Ġval Ġwork os Ġ= Ġcreate Work OS Client () ĊĊĠĠĠ Ġval Ġid Ġ= Ġ" auth _ factor _ 0 1 FJ Y CNT BC 2 Z TK T 4 CS 1 BX 0 WJ 2 B " ĊĊĠĠĠ Ġstub Response ( ĊĠĠĠĠĠ Ġ"/ auth / factors /$ id ", ĊĠĠĠĠĠ Ġ"{} " ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġval Ġresponse Ġ= Ġwork os . m fa . delete Factor ( id ) ĊĊĠĠĠ ĠassertEquals ( Unit , Ġresponse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġdelete Factor Should Throw Error () Ġ{ ĊĠĠĠ Ġval Ġwork os Ġ= Ġcreate Work OS Client () ĊĊĠĠĠ Ġval Ġid Ġ= Ġ" auth _ factor _ 0 1 FJ Y CNT BC 2 Z TK T 4 CS 1 BX 0 WJ 2 B " ĊĊĠĠĠ Ġstub Response ( ĊĠĠĠĠĠ Ġ"/ auth / factors /$ id ", ĊĠĠĠĠĠ Ġ"{}", ĊĠĠĠĠĠĠ 4 0 1 ĊĠĠĠ Ġ) ĊĊĠĠĠ ĠassertThrows ( Unauthorized Exception :: class . java ) Ġ{ ĊĠĠĠĠĠ Ġwork os . m fa . delete Factor ( id ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġget Factor Should Return Factor () Ġ{ ĊĠĠĠ Ġval Ġwork os Ġ= Ġcreate Work OS Client () ĊĊĠĠĠ Ġval Ġid Ġ= Ġ" auth _ factor _ 1 2 3 4 " ĊĊĠĠĠ Ġstub Response ( ĊĠĠĠĠĠ Ġ"/ auth / factors /$ id ", ĊĠĠĠĠĠ Ġ""" { ĊĠĠĠĠĠĠĠ Ġ" object ": Ġ" authentication _ factor ", ĊĠĠĠĠĠĠĠ Ġ" id ": Ġ" auth _ factor _ 1 2 3 4 ", ĊĠĠĠĠĠĠĠ Ġ" created _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 0 : 3 9 : 1 9 . 8 9 2 Z ", ĊĠĠĠĠĠĠĠ Ġ" updated _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 0 : 3 9 : 1 9 . 8 9 2 Z ", ĊĠĠĠĠĠĠĠ Ġ" type ": Ġ" generic _ otp " ĊĠĠĠĠĠ Ġ} """ ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġval Ġfactor Ġ= Ġwork os . m fa . get Factor ( id ) ĊĊĠĠĠ ĠassertEquals ( id , Ġfactor . id ) ĊĠĠĠ ĠassertEquals (" generic _ otp ", Ġfactor . type ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġen roll Factor General () Ġ{ ĊĠĠĠ Ġval Ġwork os Ġ= Ġcreate Work OS Client () ĊĊĠĠĠ Ġstub Response ( ĊĠĠĠĠĠ Ġurl Ġ= Ġ"/ auth / factors / enroll ", ĊĠĠĠĠĠ Ġresponse Body Ġ= Ġ""" { ĊĠĠĠĠĠĠĠ Ġ" object ": Ġ" authentication _ factor ", ĊĠĠĠĠĠĠĠ Ġ" id ": Ġ" auth _ factor _ 1 2 3 4 ", ĊĠĠĠĠĠĠĠ Ġ" created _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 0 : 3 9 : 1 9 . 8 9 2 Z ", ĊĠĠĠĠĠĠĠ Ġ" updated _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 0 : 3 9 : 1 9 . 8 9 2 Z ", ĊĠĠĠĠĠĠĠ Ġ" type ": Ġ" generic _ otp " ĊĠĠĠĠĠ Ġ} """, ĊĠĠĠĠĠ Ġrequest Body Ġ= Ġ""" { ĊĠĠĠĠĠĠĠ Ġ" type ": Ġ" generic _ otp " ĊĠĠĠĠĠ Ġ} """ ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġval Ġoptions Ġ= ĠM fa Api . En roll Factor Options . builder (). type (" generic _ otp "). build () ĊĊĠĠĠ Ġval Ġfactor Ġ= Ġwork os . m fa . enroll Factor ( options ) ĊĊĠĠĠ ĠassertEquals (" generic _ otp ", Ġfactor . type ) ĊĠĠĠ ĠassertEquals (" auth _ factor _ 1 2 3 4 ", Ġfactor . id ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġen roll Factor T otp () Ġ{ ĊĠĠĠ Ġval Ġwork os Ġ= Ġcreate Work OS Client () ĊĊĠĠĠ Ġstub Response ( ĊĠĠĠĠĠ Ġurl Ġ= Ġ"/ auth / factors / enroll ", ĊĠĠĠĠĠ Ġresponse Body Ġ= Ġ""" { ĊĠĠĠĠĠĠĠ Ġ" object ": Ġ" authentication _ factor ", ĊĠĠĠĠĠĠĠ Ġ" id ": Ġ" auth _ factor _ 1 2 3 4 ", ĊĠĠĠĠĠĠĠ Ġ" created _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 0 : 3 9 : 1 9 . 8 9 2 Z ", ĊĠĠĠĠĠĠĠ Ġ" updated _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 0 : 3 9 : 1 9 . 8 9 2 Z ", ĊĠĠĠĠĠĠĠ Ġ" type ": Ġ" tot p ", ĊĠĠĠĠĠĠĠ Ġ" tot p ": Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġ" qr _ code ": Ġ" qr - code - test ", ĊĠĠĠĠĠĠĠĠĠ Ġ" secret ": Ġ" secret - test " ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} """, ĊĠĠĠĠĠ Ġrequest Body Ġ= Ġ""" { ĊĠĠĠĠĠĠĠ Ġ" type ": Ġ" tot p ", ĊĠĠĠĠĠĠĠ Ġ" tot p _ issuer ": Ġ" Work OS ", ĊĠĠĠĠĠĠĠ Ġ" tot p _ user ": Ġ" some _ user " ĊĠĠĠĠĠ Ġ} """ ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġval Ġoptions Ġ= ĠM fa Api . En roll Factor Options . builder () ĊĠĠĠĠĠ Ġ. type (" tot p ") ĊĠĠĠĠĠ Ġ. issuer (" Work OS ") ĊĠĠĠĠĠ Ġ. user (" some _ user ") ĊĠĠĠĠĠ Ġ. build () ĊĊĠĠĠ Ġval Ġfactor Ġ= Ġwork os . m fa . enroll Factor ( options ) ĊĊĠĠĠ ĠassertEquals (" tot p ", Ġfactor . type ) ĊĠĠĠ ĠassertEquals (" auth _ factor _ 1 2 3 4 ", Ġfactor . id ) ĊĠĠĠ ĠassertNotNull ( factor . tot p ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġen roll Factor Sms () Ġ{ ĊĠĠĠ Ġval Ġwork os Ġ= Ġcreate Work OS Client () ĊĊĠĠĠ Ġstub Response ( ĊĠĠĠĠĠ Ġurl Ġ= Ġ"/ auth / factors / enroll ", ĊĠĠĠĠĠ Ġresponse Body Ġ= Ġ""" { ĊĠĠĠĠĠĠĠ Ġ" object ": Ġ" authentication _ factor ", ĊĠĠĠĠĠĠĠ Ġ" id ": Ġ" auth _ factor _ 1 2 3 4 ", ĊĠĠĠĠĠĠĠ Ġ" created _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 0 : 3 9 : 1 9 . 8 9 2 Z ", ĊĠĠĠĠĠĠĠ Ġ" updated _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 0 : 3 9 : 1 9 . 8 9 2 Z ", ĊĠĠĠĠĠĠĠ Ġ" type ": Ġ" sms ", ĊĠĠĠĠĠĠĠ Ġ" sms ": Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġ" phone _ number ": Ġ"+ 1 5 5 5 5 5 5 5 5 5 5 " ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} """, ĊĠĠĠĠĠ Ġrequest Body Ġ= Ġ""" { ĊĠĠĠĠĠĠĠ Ġ" type ": Ġ" sms ", ĊĠĠĠĠĠĠĠ Ġ" phone _ number ": Ġ"+ 1 5 5 5 5 5 5 5 5 5 5 " ĊĠĠĠĠĠ Ġ} """ ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġval Ġoptions Ġ= ĠM fa Api . En roll Factor Options . builder () ĊĠĠĠĠĠ Ġ. type (" sms ") ĊĠĠĠĠĠ Ġ. phoneNumber ("+ 1 5 5 5 5 5 5 5 5 5 5 ") ĊĠĠĠĠĠ Ġ. build () ĊĊĠĠĠ Ġval Ġfactor Ġ= Ġwork os . m fa . enroll Factor ( options ) ĊĊĠĠĠ ĠassertEquals (" sms ", Ġfactor . type ) ĊĠĠĠ ĠassertEquals (" auth _ factor _ 1 2 3 4 ", Ġfactor . id ) ĊĠĠĠ ĠassertNotNull ( factor . sms ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġchallenge Factor () Ġ{ ĊĠĠĠ Ġval Ġwork os Ġ= Ġcreate Work OS Client () ĊĊĠĠĠ Ġstub Response ( ĊĠĠĠĠĠ Ġ"/ auth / factors / challenge ", ĊĠĠĠĠĠ Ġ""" { ĊĠĠĠĠĠĠĠĠĠ Ġ" authentication _ factor _ id ": Ġ" auth _ factor _ 1 2 3 4 ", ĊĠĠĠĠĠĠĠĠĠ Ġ" code ": Ġ" 1 2 3 4 5 ", ĊĠĠĠĠĠĠĠĠĠ Ġ" created _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 0 : 3 9 : 1 9 . 8 9 2 Z ", ĊĠĠĠĠĠĠĠĠĠ Ġ" expires _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 1 : 3 9 : 1 9 . 8 9 2 Z ", ĊĠĠĠĠĠĠĠĠĠ Ġ" id ": Ġ" auth _ challenge _ 1 2 3 4 ", ĊĠĠĠĠĠĠĠĠĠ Ġ" object ": Ġ" authentication _ challenge ", ĊĠĠĠĠĠĠĠĠĠ Ġ" updated _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 0 : 3 9 : 1 9 . 8 9 2 Z " ĊĠĠĠĠĠ Ġ} """ ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġval Ġoptions Ġ= ĠM fa Api . Challenge Factor Options . builder () ĊĠĠĠĠĠ Ġ. authentication Factor Id (" auth _ challenge _ 1 2 3 4 ") ĊĠĠĠĠĠ Ġ. build () ĊĊĠĠĠ Ġval Ġchallenge Factor Ġ= Ġwork os . m fa . challenge Factor ( options ) ĊĊĠĠĠ ĠassertEquals (" 1 2 3 4 5 ", Ġchallenge Factor . code ) ĊĠĠĠ ĠassertEquals (" auth _ factor _ 1 2 3 4 ", Ġchallenge Factor . authentication Factor Id ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġchallenge Factor With Sms Template () Ġ{ ĊĠĠĠ Ġval Ġwork os Ġ= Ġcreate Work OS Client () ĊĊĠĠĠ Ġstub Response ( ĊĠĠĠĠĠ Ġ"/ auth / factors / challenge ", ĊĠĠĠĠĠ Ġ""" { ĊĠĠĠĠĠĠĠĠĠ Ġ" authentication _ factor _ id ": Ġ" auth _ factor _ 1 2 3 4 ", ĊĠĠĠĠĠĠĠĠĠ Ġ" created _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 0 : 3 9 : 1 9 . 8 9 2 Z ", ĊĠĠĠĠĠĠĠĠĠ Ġ" expires _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 1 : 3 9 : 1 9 . 8 9 2 Z ", ĊĠĠĠĠĠĠĠĠĠ Ġ" id ": Ġ" auth _ challenge _ 1 2 3 4 ", ĊĠĠĠĠĠĠĠĠĠ Ġ" object ": Ġ" authentication _ challenge ", ĊĠĠĠĠĠĠĠĠĠ Ġ" updated _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 0 : 3 9 : 1 9 . 8 9 2 Z " ĊĠĠĠĠĠ Ġ} """ ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġval Ġoptions Ġ= ĠM fa Api . Challenge Factor Options . builder () ĊĠĠĠĠĠ Ġ. authentication Factor Id (" auth _ factor _ 1 2 3 4 ") ĊĠĠĠĠĠ Ġ. sms Template (" sms Ġtemplate Ġhere ") ĊĠĠĠĠĠ Ġ. build () ĊĊĠĠĠ Ġval Ġchallenge Factor Ġ= Ġwork os . m fa . challenge Factor ( options ) ĊĊĠĠĠ ĠassertEquals (" auth _ factor _ 1 2 3 4 ", Ġchallenge Factor . authentication Factor Id ) ĊĠĠĠ ĠassertNull ( challenge Factor . code ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġverify Factor () Ġ{ ĊĠĠĠ Ġval Ġwork os Ġ= Ġcreate Work OS Client () ĊĊĠĠĠ Ġstub Response ( ĊĠĠĠĠĠ Ġ"/ auth / factors / verify ", ĊĠĠĠĠĠ Ġ""" { ĊĠĠĠĠĠĠĠĠĠ Ġ" challenge ": Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" authentication _ factor _ id ": Ġ" auth _ factor _ 1 2 3 4 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" code ": Ġ" 1 2 3 4 5 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" created _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 0 : 3 9 : 1 9 . 8 9 2 Z ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" expires _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 1 : 3 9 : 1 9 . 8 9 2 Z ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" id ": Ġ" auth _ challenge _ 1 2 3 4 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" object ": Ġ" authentication _ challenge ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" updated _ at ": Ġ" 2 0 2 2 - 0 3 - 1 5 T 2 0 : 3 9 : 1 9 . 8 9 2 Z " ĊĠĠĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠĠĠ Ġ" valid ": Ġtrue ĊĠĠĠĠĠ Ġ} """ ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġval Ġoptions Ġ= ĠM fa Api . Verify Factor Options . builder () ĊĠĠĠĠĠ Ġ. authentication Challenge Id (" auth _ challenge _ 1 2 3 4 ") ĊĠĠĠĠĠ Ġ. code (" 1 2 3 4 5 ") ĊĠĠĠĠĠ Ġ. build () ĊĊĠĠĠ Ġval Ġverify Response Ġ= Ġwork os . m fa . verify Factor ( options ) ĊĊĠĠĠ ĠassertEquals ( true , Ġverify Response . valid ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġverify Factor Already Verified () Ġ{ ĊĠĠĠ Ġval Ġwork os Ġ= Ġcreate Work OS Client () ĊĊĠĠĠ Ġstub Response ( ĊĠĠĠĠĠ Ġurl Ġ= Ġ"/ auth / factors / verify ", ĊĠĠĠĠĠ Ġresponse Body Ġ= Ġ""" { ĊĠĠĠĠĠĠĠ Ġ" code ": Ġ" Already Ġverified ", ĊĠĠĠĠĠĠĠ Ġ" message ": Ġ" Already Ġverified " ĊĠĠĠĠĠ Ġ} """, ĊĠĠĠĠĠ Ġresponse Status Ġ= Ġ 4 2 2 , ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġval Ġoptions Ġ= ĠM fa Api . Verify Factor Options . builder () ĊĠĠĠĠĠ Ġ. authentication Challenge Id (" auth _ challenge _ 1 2 3 4 ") ĊĠĠĠĠĠ Ġ. code (" 1 2 3 4 5 ") ĊĠĠĠĠĠ Ġ. build () ĊĊĠĠĠ ĠassertThrows ( Un process able Entity Exception :: class . java ) Ġ{ ĊĠĠĠĠĠ Ġwork os . m fa . verify Factor ( options ) ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ