Skip to content

Commit 0fb20f0

Browse files
committed
1.2.7 & 1.2.9
1 parent c2500c8 commit 0fb20f0

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

MSAL/test/integration/native_auth/end_to_end/sign_in/MSALNativeAuthSignInUserNameAndPasswordEndToEndTests.swift

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
155155
let verifyCodeExpectation = expectation(description: "verifying code")
156156
let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy(expectation: verifyCodeExpectation)
157157

158-
signInDelegateSpy.newStateCodeRequired?.submitCode(code: code, delegate: signInVerifyCodeDelegateSpy)
158+
signInDelegateSpy2.newStateCodeRequired?.submitCode(code: code, delegate: signInVerifyCodeDelegateSpy)
159159

160160
await fulfillment(of: [verifyCodeExpectation])
161161

@@ -174,34 +174,45 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
174174

175175
// User Case 1.2.7. Sign In - User email is registered with email OTP auth method, which is supported by the developer
176176
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 {
178180
XCTFail("Missing information")
179181
return
180182
}
181183

182184
let signInExpectation = expectation(description: "signing in")
183-
let passwordRequiredExpectation = expectation(description: "verifying password")
184185
let signInDelegateSpy = SignInStartDelegateSpy(expectation: signInExpectation)
185-
let signInPasswordRequiredDelegateSpy = SignInPasswordRequiredDelegateSpy(expectation: passwordRequiredExpectation)
186186

187-
sut.signIn(username: username, correlationId: correlationId, delegate: signInDelegateSpy)
187+
sut.signIn(username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy)
188188

189189
await fulfillment(of: [signInExpectation])
190190

191-
guard signInDelegateSpy.onSignInPasswordRequiredCalled else {
192-
XCTFail("onSignInPasswordRequired not called")
191+
guard signInDelegateSpy.onSignInCodeRequiredCalled else {
192+
XCTFail("onSignInCodeRequired not called")
193193
return
194194
}
195195

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+
}
197204

198-
// Now submit the password..
205+
let verifyCodeExpectation = expectation(description: "verifying code")
206+
let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy(expectation: verifyCodeExpectation)
199207

200-
signInDelegateSpy.newStatePasswordRequired?.submitPassword(password: password, delegate: signInPasswordRequiredDelegateSpy)
208+
signInDelegateSpy.newStateCodeRequired?.submitCode(code: code, delegate: signInVerifyCodeDelegateSpy)
201209

202-
await fulfillment(of: [passwordRequiredExpectation])
210+
await fulfillment(of: [verifyCodeExpectation])
203211

204-
XCTAssertTrue(signInPasswordRequiredDelegateSpy.onSignInCompletedCalled)
212+
XCTAssertTrue(signInVerifyCodeDelegateSpy.onSignInCompletedCalled)
213+
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result)
214+
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result?.idToken)
215+
XCTAssertEqual(signInVerifyCodeDelegateSpy.result?.account.username, username)
205216
}
206217

207218
/* 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
215226

216227
// 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)
217228
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 {
219230
XCTFail("Missing information")
220231
return
221232
}

0 commit comments

Comments
 (0)