Skip to content

Commit 7598e15

Browse files
committed
2.2.5 & 2.2.6
1 parent a032c70 commit 7598e15

File tree

2 files changed

+85
-3
lines changed

2 files changed

+85
-3
lines changed

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

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import XCTest
2828
final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBaseTestCase {
2929
// Hero Scenario 2.2.1. Sign in - Use email and OTP to get token and sign in
3030
func test_signInAndSendingCorrectOTPResultsInSuccess() async throws {
31-
3231
guard let sut = initialisePublicClientApplication(clientIdType: .code), let username = retrieveUsernameForSignInCode() else {
3332
XCTFail("Missing information")
3433
return
@@ -90,10 +89,10 @@ final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBas
9089
}
9190

9291
// User Case 2.2.3 Sign In - User email is registered with password method, which is not supported by client (aka redirect flow)
93-
func test_signInWithInsufficientChallengeInError() async throws {
92+
func test_signInWithPasswordConfigInsufficientChallengeInError() async throws {
9493
throw XCTSkip("Retrieving OTP failure")
9594

96-
guard let sut = initialisePublicClientApplication(clientIdType: .code), let username = retrieveUsernameForSignInCode() else {
95+
guard let sut = initialisePublicClientApplication(clientIdType: .password, challengeTypes: .OOB), let username = retrieveUsernameForSignInCode() else {
9796
XCTFail("Missing information")
9897
return
9998
}
@@ -109,7 +108,60 @@ final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBas
109108
XCTAssertTrue(signInDelegateSpy.onSignInErrorCalled)
110109
XCTAssertEqual(signInDelegateSpy.error?.isBrowserRequired, true)
111110
}
111+
112+
// User Case 2.2.5 Sign In - Resend email OTP
113+
func test_signUpWithEmailOTP_resendEmail_success() async throws {
114+
guard let sut = initialisePublicClientApplication(clientIdType: .code), let username = retrieveUsernameForSignInCode() else {
115+
XCTFail("Missing information")
116+
return
117+
}
112118

119+
let signInExpectation = expectation(description: "signing in")
120+
let signInDelegate = SignInStartDelegateSpy(expectation: signInExpectation)
121+
122+
sut.signIn(username: username, correlationId: correlationId, delegate: signInDelegate)
123+
124+
await fulfillment(of: [signInExpectation])
125+
126+
guard signInDelegate.onSignInCodeRequiredCalled else {
127+
XCTFail("OTP not sent")
128+
return
129+
}
130+
XCTAssertNotNil(signInDelegate.newStateCodeRequired)
131+
XCTAssertNotNil(signInDelegate.sentTo)
132+
133+
// Now get code1...
134+
guard let code1 = await retrieveCodeFor(email: username) else {
135+
XCTFail("OTP code could not be retrieved")
136+
return
137+
}
138+
139+
// Resend code
140+
let resendCodeRequiredExp = expectation(description: "code required again")
141+
let signInResendCodeDelegate = SignInResendCodeDelegateSpy(expectation: resendCodeRequiredExp)
142+
143+
// Call resend code method
144+
signInDelegate.newStateCodeRequired?.resendCode(delegate: signInResendCodeDelegate)
145+
146+
await fulfillment(of: [resendCodeRequiredExp])
147+
148+
// Verify that resend code method was called
149+
XCTAssertTrue(signInResendCodeDelegate.onSignInResendCodeCodeRequiredCalled,
150+
"Resend code method should have been called")
151+
152+
// Now get code2...
153+
guard let code2 = await retrieveCodeFor(email: username) else {
154+
XCTFail("OTP code could not be retrieved")
155+
return
156+
}
157+
158+
// Verify that the codes are different
159+
XCTAssertNotEqual(code1, code2, "Resent code should be different from the original code")
160+
}
161+
162+
/* User Case 2.2.6 Sign In - Ability to provide scope to control auth strength of the token
163+
Please refer to SignInUsernameAndPasswordEndToEndTests 1.2.6 for the test*/
164+
113165
// Hero Scenario 2.2.7. Sign in - Invalid OTP code
114166
func test_signInAndSendingIncorrectOTPResultsInError() async throws {
115167
throw XCTSkip("The test account is locked")

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,33 @@ class SignInPasswordRequiredDelegateSpy: SignInPasswordRequiredDelegate {
159159
expectation.fulfill()
160160
}
161161
}
162+
163+
class SignInResendCodeDelegateSpy: SignInResendCodeDelegate {
164+
private let expectation: XCTestExpectation
165+
private(set) var onSignInResendCodeErrorCalled = false
166+
private(set) var error: ResendCodeError?
167+
private(set) var onSignInResendCodeCodeRequiredCalled = false
168+
private(set) var signInCodeRequiredState: SignInCodeRequiredState?
169+
private(set) var sentTo: String?
170+
private(set) var channelTargetType: MSALNativeAuthChannelType?
171+
private(set) var codeLength: Int?
172+
173+
init(expectation: XCTestExpectation) {
174+
self.expectation = expectation
175+
}
176+
177+
func onSignInResendCodeError(error: MSAL.ResendCodeError, newState: MSAL.SignInCodeRequiredState?) {
178+
onSignInResendCodeErrorCalled = true
179+
self.error = error
180+
}
181+
182+
func onSignInResendCodeCodeRequired(newState: SignInCodeRequiredState, sentTo: String, channelTargetType: MSALNativeAuthChannelType, codeLength: Int) {
183+
onSignInResendCodeCodeRequiredCalled = true
184+
signInCodeRequiredState = newState
185+
self.sentTo = sentTo
186+
self.channelTargetType = channelTargetType
187+
self.codeLength = codeLength
188+
189+
expectation.fulfill()
190+
}
191+
}

0 commit comments

Comments
 (0)