Skip to content

Commit c2500c8

Browse files
committed
signed account
1 parent 973c21b commit c2500c8

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,16 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
109109

110110
sut.signIn(username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy2)
111111

112-
XCTAssertEqual(signInDelegateSpy2.error!.description, "An account is already signed in.")
112+
XCTAssertTrue(signInDelegateSpy.onSignInCompletedCalled)
113+
XCTAssertNotNil(signInDelegateSpy.result?.idToken)
114+
XCTAssertEqual(signInDelegateSpy.result?.account.username, username)
113115
}
114116

115117
// User Case 1.2.5. Sign In - User signs in with account B, while data for account A already exists in SDK persistence
116118
func test_signInWithDifferentAccountSigned() async throws {
117-
guard let sut = initialisePublicClientApplication(), let username = retrieveUsernameForSignInUsernameAndPassword(), let uesrname2 = retrieveUsernameForSignInCode(), let password = await retrievePasswordForSignInUsername() else {
119+
throw XCTSkip("Retrieving OTP failure")
120+
121+
guard let sut = initialisePublicClientApplication(), let username = retrieveUsernameForSignInUsernameAndPassword(), let username2 = retrieveUsernameForSignInCode(), let password = await retrievePasswordForSignInUsername() else {
118122
XCTFail("Missing information")
119123
return
120124
}
@@ -132,11 +136,32 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
132136

133137
// Now signed in the account again
134138
let signInExpectation2 = expectation(description: "signing in")
135-
let signInDelegateSpy2 = SignInPasswordStartDelegateSpy(expectation: signInExpectation2)
139+
let signInDelegateSpy2 = SignInStartDelegateSpy(expectation: signInExpectation)
140+
141+
sut.signIn(username: username2, correlationId: correlationId, delegate: signInDelegateSpy2)
136142

137-
sut.signIn(username: uesrname2, password: password, correlationId: correlationId, delegate: signInDelegateSpy2)
143+
await fulfillment(of: [signInExpectation2])
144+
145+
guard signInDelegateSpy2.onSignInCodeRequiredCalled else {
146+
XCTFail("onSignInCodeRequired not called")
147+
return
148+
}
138149

139-
XCTAssertEqual(signInDelegateSpy2.error!.description, "An account is already signed in.")
150+
guard let code = await retrieveCodeFor(email: username) else {
151+
XCTFail("OTP code could not be retrieved")
152+
return
153+
}
154+
155+
let verifyCodeExpectation = expectation(description: "verifying code")
156+
let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy(expectation: verifyCodeExpectation)
157+
158+
signInDelegateSpy.newStateCodeRequired?.submitCode(code: code, delegate: signInVerifyCodeDelegateSpy)
159+
160+
await fulfillment(of: [verifyCodeExpectation])
161+
162+
XCTAssertTrue(signInVerifyCodeDelegateSpy.onSignInCompletedCalled)
163+
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result)
164+
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result?.account.username, username2)
140165
}
141166

142167
/* User Case 1.2.6. Sign In - Ability to provide scope to control auth strength of the token

0 commit comments

Comments
 (0)