Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
spetrescu84 committed Oct 16, 2024
1 parent f687672 commit 06049a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MSALNativeAuthEmailCodeRetriever: XCTestCase {
dateFormatter.timeZone = TimeZone(secondsFromGMT: 0) //We ignore the timezone
return dateFormatter
}()
private let secondsToWaitForEmail = 5.0
private let maximumSecondsSinceEmailReceive = 5.0

func retrieveEmailOTPCode(email: String) async -> String? {
let comps = email.components(separatedBy: "@")
Expand Down Expand Up @@ -89,7 +89,7 @@ class MSALNativeAuthEmailCodeRetriever: XCTestCase {
let currentDate = Date()
// Email should be newer than 5 seconds otherwise it could be from previous test
// This retry will help with the delay in receiving the emails
if currentDate.timeIntervalSince1970 - emailDate.timeIntervalSince1970 < secondsToWaitForEmail {
if currentDate.timeIntervalSince1970 - emailDate.timeIntervalSince1970 < maximumSecondsSinceEmailReceive {
print ("Email is for current test, last receive date: \(emailDate) current date: \(currentDate)")
return dataDictionary.first?["id"] as? Int
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import MSAL

final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBaseTestCase {
// Hero Scenario 3.1.1. SSPR – without automatic sign in
let numberOfRetries = 3
let codeRetryCount = 3

func test_resetPassword_withoutAutomaticSignIn_succeeds() async throws {
guard let sut = initialisePublicClientApplication(),
Expand All @@ -55,9 +55,9 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
XCTAssertNotNil(resetPasswordStartDelegate.codeLength)

// Now submit the code...
let newPasswordRequiredState = await submitCode(resetPasswordStartDelegate: resetPasswordStartDelegate,
let newPasswordRequiredState = await retrieveAndSubmitCode(resetPasswordStartDelegate: resetPasswordStartDelegate,
username: username,
retries: numberOfRetries)
retries: codeRetryCount)

// Now submit the password...
let resetPasswordCompletedExp = expectation(description: "reset password completed")
Expand Down Expand Up @@ -96,9 +96,9 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
XCTAssertNotNil(resetPasswordStartDelegate.codeLength)

// Now submit the code...
let newPasswordRequiredState = await submitCode(resetPasswordStartDelegate: resetPasswordStartDelegate,
let newPasswordRequiredState = await retrieveAndSubmitCode(resetPasswordStartDelegate: resetPasswordStartDelegate,
username: username,
retries: numberOfRetries)
retries: codeRetryCount)

// Now submit the password...
let resetPasswordCompletedExp = expectation(description: "reset password completed")
Expand Down Expand Up @@ -129,7 +129,8 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
XCTAssertNotNil(signInAfterResetPasswordDelegate.result?.account.accountClaims)
}

func submitCode(resetPasswordStartDelegate: ResetPasswordStartDelegateSpy, username: String, retries: Int) async -> ResetPasswordRequiredState? {
// This method tries to fetch a code from 1secmail API and submit it
private func retrieveAndSubmitCode(resetPasswordStartDelegate: ResetPasswordStartDelegateSpy, username: String, retries: Int) async -> ResetPasswordRequiredState? {
let passwordRequiredExp = expectation(description: "password required")
let resetPasswordVerifyDelegate = ResetPasswordVerifyCodeDelegateSpy(expectation: passwordRequiredExp)

Expand All @@ -142,7 +143,7 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase

await fulfillment(of: [passwordRequiredExp])
if resetPasswordVerifyDelegate.onResetPasswordVerifyCodeErrorCalled && resetPasswordVerifyDelegate.error?.isInvalidCode == true && retries > 0 {
return await submitCode(resetPasswordStartDelegate: resetPasswordStartDelegate, username: username, retries: retries - 1)
return await retrieveAndSubmitCode(resetPasswordStartDelegate: resetPasswordStartDelegate, username: username, retries: retries - 1)
}
guard resetPasswordVerifyDelegate.onPasswordRequiredCalled else {
XCTFail("onPasswordRequired not called")
Expand Down

0 comments on commit 06049a6

Please sign in to comment.