Skip to content

Commit 01764fb

Browse files
committed
Fulfill the mfa and scopes
1 parent 2b53576 commit 01764fb

File tree

4 files changed

+83
-7
lines changed

4 files changed

+83
-7
lines changed

MSAL/test/integration/native_auth/end_to_end/credentials/MSALNativeAuthUserAccountEndToEndTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,38 @@ final class MSALNativeAuthUserAccountEndToEndTests: MSALNativeAuthEndToEndPasswo
9393
XCTAssertTrue(credentialsDelegateSpy.onAccessTokenRetrieveErrorCalled)
9494
XCTAssertTrue(credentialsDelegateSpy.error!.errorDescription!.contains("Send an interactive authorization request for this user and resource."))
9595
}
96+
97+
// Sign in with username and password with extra scopes to get access token and validate the scopes
98+
func test_signInWithExtraScopes() async throws {
99+
#if os(macOS)
100+
throw XCTSkip("Bundle id for macOS is not added to the client id, test is not needed on both iOS and macOS")
101+
#endif
102+
guard let sut = initialisePublicClientApplication(), let username = retrieveUsernameForSignInUsernameAndPassword(), let password = await retrievePasswordForSignInUsername() else {
103+
XCTFail("Missing information")
104+
return
105+
}
106+
107+
let signInExpectation = expectation(description: "signing in")
108+
let signInDelegateSpy = SignInPasswordStartDelegateSpy(expectation: signInExpectation)
109+
110+
sut.signIn(username: username, password: password, scopes: ["User.Read"], correlationId: correlationId, delegate: signInDelegateSpy)
111+
112+
await fulfillment(of: [signInExpectation])
113+
114+
XCTAssertTrue(signInDelegateSpy.onSignInCompletedCalled)
115+
XCTAssertNotNil(signInDelegateSpy.result?.idToken)
116+
XCTAssertEqual(signInDelegateSpy.result?.account.username, username)
117+
118+
let getAccessTokenExpectation = expectation(description: "getting access token")
119+
let credentialsDelegateSpy = CredentialsDelegateSpy(expectation: getAccessTokenExpectation)
120+
121+
signInDelegateSpy.result?.getAccessToken(scopes: ["User.Read"], delegate: credentialsDelegateSpy)
122+
123+
await fulfillment(of: [getAccessTokenExpectation])
124+
125+
XCTAssertTrue(credentialsDelegateSpy.onAccessTokenRetrieveCompletedCalled)
126+
XCTAssertNotNil(credentialsDelegateSpy.result?.accessToken)
127+
XCTAssertNotNil(credentialsDelegateSpy.result?.scopes)
128+
XCTAssertTrue(credentialsDelegateSpy.result!.scopes.contains("User.Read"))
129+
}
96130
}

MSAL/test/integration/native_auth/end_to_end/reset_password/MSALNativeAuthResetPasswordEndToEndTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
236236
return
237237
}
238238

239-
let username = "invalid"
239+
let username = "invalid" // TODO: use social account instead
240240

241241
let resetPasswordFailureExp = expectation(description: "reset password user not found")
242242
let resetPasswordStartDelegate = ResetPasswordStartDelegateSpy(expectation: resetPasswordFailureExp)

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

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,41 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
113113
}
114114

115115
// User Case 1.2.5. Sign In - User signs in with account B, while data for account A already exists in SDK persistence
116-
// The same as 1.2.4
116+
func test_signInWithAccountSigned() async throws {
117+
guard let sut = initialisePublicClientApplication(), let username = retrieveUsernameForSignInUsernameAndPassword(), let password = await retrievePasswordForSignInUsername() else {
118+
XCTFail("Missing information")
119+
return
120+
}
121+
122+
let signInExpectation = expectation(description: "signing in")
123+
let signInDelegateSpy = SignInPasswordStartDelegateSpy(expectation: signInExpectation)
124+
125+
sut.signIn(username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy)
126+
127+
await fulfillment(of: [signInExpectation])
128+
129+
XCTAssertTrue(signInDelegateSpy.onSignInCompletedCalled)
130+
XCTAssertNotNil(signInDelegateSpy.result?.idToken)
131+
XCTAssertEqual(signInDelegateSpy.result?.account.username, username)
132+
133+
// Now signed in the account again
134+
let signInExpectation2 = expectation(description: "signing in")
135+
let signInDelegateSpy2 = SignInPasswordStartDelegateSpy(expectation: signInExpectation2)
136+
137+
let uesrname2 = retrieveUsernameForSignInCode()
138+
139+
sut.signIn(username: uesrname2, password: password, correlationId: correlationId, delegate: signInDelegateSpy2)
140+
141+
XCTAssertTrue(signInDelegateSpy2.error!.description, "An account is already signed in.")
142+
}
117143

118-
// User Case 1.2.6. Sign In - Ability to provide scope to control auth strength of the token
144+
/* User Case 1.2.6. Sign In - Ability to provide scope to control auth strength of the token
145+
Please refer to Crendentials test (test_signInWithExtraScopes())
146+
147+
sut.signIn(username: username, password: password, scopes: ["User.Read"], correlationId: correlationId, delegate: signInDelegateSpy)
148+
...
149+
XCTAssertTrue(credentialsDelegateSpy.result!.scopes.contains("User.Read"))
150+
*/
119151

120152
// User Case 1.2.7. Sign In - User email is registered with email OTP auth method, which is supported by the developer
121153
func test_signInWithOTPSufficientChallengeResultsInSuccess() async throws {
@@ -149,8 +181,14 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
149181
XCTAssertTrue(signInPasswordRequiredDelegateSpy.onSignInCompletedCalled)
150182
}
151183

152-
// User Case 1.2.8. Sign In - User attempts to sign in with email and password, but server requires second factor authentication (MFA OTP)
153-
// Please refer to MFA End to End Test
184+
/* User Case 1.2.8. Sign In - User attempts to sign in with email and password, but server requires second factor authentication (MFA OTP)
185+
Please refer to MFA Test (test_signInAuthenticationContextClaim_mfaFlowIsTriggeredAndAccessTokenContainsClaims)
186+
187+
awaitingMFAState.requestChallenge(delegate: mfaDelegateSpy)
188+
...
189+
newMfaRequiredState.submitChallenge(challenge: code, delegate: mfaSubmitChallengeDelegateSpy)
190+
...
191+
*/
154192

155193
// 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)
156194
func test_signInWithOTPInsufficientChallengeResultsInError() async throws {
@@ -170,7 +208,6 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
170208
XCTAssertTrue(signInDelegateSpy.error!.isBrowserRequired)
171209
}
172210

173-
174211
// Sign in - Password is incorrect (sent over delegate.newStatePasswordRequired)
175212
func test_signInAndSendingIncorrectPasswordResultsInError() async throws {
176213
guard let sut = initialisePublicClientApplication(), let username = retrieveUsernameForSignInUsernameAndPassword() else {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,12 @@ final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBas
162162
}
163163

164164
/* User Case 2.2.6 Sign In - Ability to provide scope to control auth strength of the token
165-
Please refer to SignInUsernameAndPasswordEndToEndTests 1.2.6 for the test*/
165+
Please refer to Crendentials test (test_signInWithExtraScopes())
166+
167+
sut.signIn(username: username, password: password, scopes: ["User.Read"], correlationId: correlationId, delegate: signInDelegateSpy)
168+
...
169+
XCTAssertTrue(credentialsDelegateSpy.result!.scopes.contains("User.Read"))
170+
*/
166171

167172
// Hero Scenario 2.2.7. Sign in - Invalid OTP code
168173
func test_signInAndSendingIncorrectOTPResultsInError() async throws {

0 commit comments

Comments
 (0)