@@ -155,7 +155,7 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
155
155
let verifyCodeExpectation = expectation ( description: " verifying code " )
156
156
let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy ( expectation: verifyCodeExpectation)
157
157
158
- signInDelegateSpy . newStateCodeRequired? . submitCode ( code: code, delegate: signInVerifyCodeDelegateSpy)
158
+ signInDelegateSpy2 . newStateCodeRequired? . submitCode ( code: code, delegate: signInVerifyCodeDelegateSpy)
159
159
160
160
await fulfillment ( of: [ verifyCodeExpectation] )
161
161
@@ -174,34 +174,45 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
174
174
175
175
// User Case 1.2.7. Sign In - User email is registered with email OTP auth method, which is supported by the developer
176
176
func test_signInWithOTPSufficientChallengeResultsInSuccess( ) async throws {
177
- guard let sut = initialisePublicClientApplication ( ) , let username = retrieveUsernameForSignInUsernameAndPassword ( ) , let password = await retrievePasswordForSignInUsername ( ) else {
177
+ throw XCTSkip ( " Retrieving OTP failure " )
178
+
179
+ guard let sut = initialisePublicClientApplication ( ) , let username = retrieveUsernameForSignInCode ( ) , let password = await retrievePasswordForSignInUsername ( ) else {
178
180
XCTFail ( " Missing information " )
179
181
return
180
182
}
181
183
182
184
let signInExpectation = expectation ( description: " signing in " )
183
- let passwordRequiredExpectation = expectation ( description: " verifying password " )
184
185
let signInDelegateSpy = SignInStartDelegateSpy ( expectation: signInExpectation)
185
- let signInPasswordRequiredDelegateSpy = SignInPasswordRequiredDelegateSpy ( expectation: passwordRequiredExpectation)
186
186
187
- sut. signIn ( username: username, correlationId: correlationId, delegate: signInDelegateSpy)
187
+ sut. signIn ( username: username, password : password , correlationId: correlationId, delegate: signInDelegateSpy)
188
188
189
189
await fulfillment ( of: [ signInExpectation] )
190
190
191
- guard signInDelegateSpy. onSignInPasswordRequiredCalled else {
192
- XCTFail ( " onSignInPasswordRequired not called" )
191
+ guard signInDelegateSpy. onSignInCodeRequiredCalled else {
192
+ XCTFail ( " onSignInCodeRequired not called" )
193
193
return
194
194
}
195
195
196
- XCTAssertNotNil ( signInDelegateSpy. newStatePasswordRequired)
196
+ XCTAssertNotNil ( signInDelegateSpy. newStateCodeRequired)
197
+ XCTAssertNotNil ( signInDelegateSpy. sentTo)
198
+
199
+ // Now submit the code..
200
+ guard let code = await retrieveCodeFor ( email: username) else {
201
+ XCTFail ( " OTP code could not be retrieved " )
202
+ return
203
+ }
197
204
198
- // Now submit the password..
205
+ let verifyCodeExpectation = expectation ( description: " verifying code " )
206
+ let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy ( expectation: verifyCodeExpectation)
199
207
200
- signInDelegateSpy. newStatePasswordRequired ? . submitPassword ( password : password , delegate: signInPasswordRequiredDelegateSpy )
208
+ signInDelegateSpy. newStateCodeRequired ? . submitCode ( code : code , delegate: signInVerifyCodeDelegateSpy )
201
209
202
- await fulfillment ( of: [ passwordRequiredExpectation ] )
210
+ await fulfillment ( of: [ verifyCodeExpectation ] )
203
211
204
- XCTAssertTrue ( signInPasswordRequiredDelegateSpy. onSignInCompletedCalled)
212
+ XCTAssertTrue ( signInVerifyCodeDelegateSpy. onSignInCompletedCalled)
213
+ XCTAssertNotNil ( signInVerifyCodeDelegateSpy. result)
214
+ XCTAssertNotNil ( signInVerifyCodeDelegateSpy. result? . idToken)
215
+ XCTAssertEqual ( signInVerifyCodeDelegateSpy. result? . account. username, username)
205
216
}
206
217
207
218
/* User Case 1.2.8. Sign In - User attempts to sign in with email and password, but server requires second factor authentication (MFA OTP)
@@ -215,7 +226,7 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
215
226
216
227
// User Case 1.2.9. Sign In - User email is registered with email OTP auth method, which is not supported by the developer (aka redirect flow)
217
228
func test_signInWithOTPInsufficientChallengeResultsInError( ) async throws {
218
- guard let sut = initialisePublicClientApplication ( ) , let username = retrieveUsernameForSignInUsernameAndPassword ( ) , let password = await retrievePasswordForSignInUsername ( ) else {
229
+ guard let sut = initialisePublicClientApplication ( challengeTypes : [ . password ] ) , let username = retrieveUsernameForSignInCode ( ) , let password = await retrievePasswordForSignInUsername ( ) else {
219
230
XCTFail ( " Missing information " )
220
231
return
221
232
}
0 commit comments