Skip to content

Commit 32c0f70

Browse files
authored
Merge pull request #2259 from AzureAD/feature/password-reset-e2e-tests
Converted SSPR E2E tests to use labs tenant
2 parents 245a251 + 26d0748 commit 32c0f70

File tree

2 files changed

+58
-16
lines changed

2 files changed

+58
-16
lines changed

MSAL/test/integration/native_auth/end_to_end/MSALNativeAuthEndToEndBaseTestCase.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ class MSALNativeAuthEndToEndBaseTestCase: XCTestCase {
9595
return MSALNativeAuthEndToEndBaseTestCase.nativeAuthConfFileContent?[Constants.signInEmailPasswordUsernameKey]
9696
}
9797

98+
func retrieveUsernameForResetPassword() -> String? {
99+
return MSALNativeAuthEndToEndBaseTestCase.nativeAuthConfFileContent?[Constants.resetPasswordUsernameKey]
100+
}
101+
98102
func fulfillment(of expectations: [XCTestExpectation], timeout seconds: TimeInterval = 20) async {
99103
await fulfillment(of: expectations, timeout: seconds, enforceOrder: false)
100104
}

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

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,27 @@ import Foundation
2626
import XCTest
2727

2828
final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBaseTestCase {
29-
30-
private let usernameOTP = ProcessInfo.processInfo.environment["existingOTPUserEmail"] ?? "<existingOTPUserEmail not set>"
31-
32-
// Hero Scenario 2.3.1. SSPR – without automatic sign in
29+
// Hero Scenario 3.1.1. SSPR – without automatic sign in
3330
func test_resetPassword_withoutAutomaticSignIn_succeeds() async throws {
34-
throw XCTSkip("Skipping this test because native auth KeyVault is missing")
35-
guard let sut = initialisePublicClientApplication() else {
31+
guard let sut = initialisePublicClientApplication(),
32+
let username = retrieveUsernameForResetPassword()
33+
else {
3634
XCTFail("Missing information")
3735
return
3836
}
3937
let codeRequiredExp = expectation(description: "code required")
4038
let resetPasswordStartDelegate = ResetPasswordStartDelegateSpy(expectation: codeRequiredExp)
4139

42-
sut.resetPassword(username: usernameOTP, delegate: resetPasswordStartDelegate)
40+
sut.resetPassword(username: username, delegate: resetPasswordStartDelegate)
4341

4442
await fulfillment(of: [codeRequiredExp])
4543
XCTAssertTrue(resetPasswordStartDelegate.onResetPasswordCodeRequiredCalled)
44+
45+
guard resetPasswordStartDelegate.onResetPasswordCodeRequiredCalled else {
46+
XCTFail("onResetPasswordCodeRequired not called")
47+
return
48+
}
49+
4650
XCTAssertEqual(resetPasswordStartDelegate.channelTargetType, .email)
4751
XCTAssertFalse(resetPasswordStartDelegate.sentTo?.isEmpty ?? true)
4852
XCTAssertNotNil(resetPasswordStartDelegate.codeLength)
@@ -51,36 +55,54 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
5155

5256
let passwordRequiredExp = expectation(description: "password required")
5357
let resetPasswordVerifyDelegate = ResetPasswordVerifyCodeDelegateSpy(expectation: passwordRequiredExp)
58+
59+
guard let code = await retrieveCodeFor(email: username) else {
60+
XCTFail("OTP code not retrieved from email")
61+
return
62+
}
5463

55-
resetPasswordStartDelegate.newState?.submitCode(code: "1234", delegate: resetPasswordVerifyDelegate)
64+
resetPasswordStartDelegate.newState?.submitCode(code: code, delegate: resetPasswordVerifyDelegate)
5665

5766
await fulfillment(of: [passwordRequiredExp])
5867
XCTAssertTrue(resetPasswordVerifyDelegate.onPasswordRequiredCalled)
68+
69+
guard resetPasswordVerifyDelegate.onPasswordRequiredCalled else {
70+
XCTFail("onPasswordRequired not called")
71+
return
72+
}
5973

6074
// Now submit the password...
6175
let resetPasswordCompletedExp = expectation(description: "reset password completed")
6276
let resetPasswordRequiredDelegate = ResetPasswordRequiredDelegateSpy(expectation: resetPasswordCompletedExp)
6377

64-
resetPasswordVerifyDelegate.newPasswordRequiredState?.submitPassword(password: "password", delegate: resetPasswordRequiredDelegate)
78+
let uniquePassword = generateRandomPassword()
79+
resetPasswordVerifyDelegate.newPasswordRequiredState?.submitPassword(password: uniquePassword, delegate: resetPasswordRequiredDelegate)
6580

6681
await fulfillment(of: [resetPasswordCompletedExp])
6782
XCTAssertTrue(resetPasswordRequiredDelegate.onResetPasswordCompletedCalled)
6883
}
6984

7085
// SSPR - with automatic sign in
7186
func test_resetPassword_withAutomaticSignIn_succeeds() async throws {
72-
throw XCTSkip("Skipping this test because native auth KeyVault is missing")
73-
guard let sut = initialisePublicClientApplication() else {
87+
guard let sut = initialisePublicClientApplication(),
88+
let username = retrieveUsernameForResetPassword()
89+
else {
7490
XCTFail("Missing information")
7591
return
7692
}
7793
let codeRequiredExp = expectation(description: "code required")
7894
let resetPasswordStartDelegate = ResetPasswordStartDelegateSpy(expectation: codeRequiredExp)
7995

80-
sut.resetPassword(username: usernameOTP, delegate: resetPasswordStartDelegate)
96+
sut.resetPassword(username: username, delegate: resetPasswordStartDelegate)
8197

8298
await fulfillment(of: [codeRequiredExp])
8399
XCTAssertTrue(resetPasswordStartDelegate.onResetPasswordCodeRequiredCalled)
100+
101+
guard resetPasswordStartDelegate.onResetPasswordCodeRequiredCalled else {
102+
XCTFail("onResetPasswordCodeRequired not called")
103+
return
104+
}
105+
84106
XCTAssertEqual(resetPasswordStartDelegate.channelTargetType, .email)
85107
XCTAssertFalse(resetPasswordStartDelegate.sentTo?.isEmpty ?? true)
86108
XCTAssertNotNil(resetPasswordStartDelegate.codeLength)
@@ -89,20 +111,36 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
89111

90112
let passwordRequiredExp = expectation(description: "password required")
91113
let resetPasswordVerifyDelegate = ResetPasswordVerifyCodeDelegateSpy(expectation: passwordRequiredExp)
114+
115+
guard let code = await retrieveCodeFor(email: username) else {
116+
XCTFail("OTP code not retrieved from email")
117+
return
118+
}
92119

93-
resetPasswordStartDelegate.newState?.submitCode(code: "1234", delegate: resetPasswordVerifyDelegate)
120+
resetPasswordStartDelegate.newState?.submitCode(code: code, delegate: resetPasswordVerifyDelegate)
94121

95122
await fulfillment(of: [passwordRequiredExp])
96123
XCTAssertTrue(resetPasswordVerifyDelegate.onPasswordRequiredCalled)
124+
125+
guard resetPasswordVerifyDelegate.onPasswordRequiredCalled else {
126+
XCTFail("onPasswordRequired not called")
127+
return
128+
}
97129

98130
// Now submit the password...
99131
let resetPasswordCompletedExp = expectation(description: "reset password completed")
100132
let resetPasswordRequiredDelegate = ResetPasswordRequiredDelegateSpy(expectation: resetPasswordCompletedExp)
101133

102-
resetPasswordVerifyDelegate.newPasswordRequiredState?.submitPassword(password: "password", delegate: resetPasswordRequiredDelegate)
134+
let uniquePassword = generateRandomPassword()
135+
resetPasswordVerifyDelegate.newPasswordRequiredState?.submitPassword(password: uniquePassword, delegate: resetPasswordRequiredDelegate)
103136

104137
await fulfillment(of: [resetPasswordCompletedExp])
105138
XCTAssertTrue(resetPasswordRequiredDelegate.onResetPasswordCompletedCalled)
139+
140+
guard resetPasswordRequiredDelegate.onResetPasswordCompletedCalled else {
141+
XCTFail("onResetPasswordCompleted not called")
142+
return
143+
}
106144

107145
// Now sign in...
108146

@@ -113,8 +151,8 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
113151

114152
await fulfillment(of: [signInAfterResetPasswordExp])
115153
XCTAssertTrue(signInAfterResetPasswordDelegate.onSignInCompletedCalled)
116-
XCTAssertEqual(signInAfterResetPasswordDelegate.result?.account.username, usernameOTP)
154+
XCTAssertEqual(signInAfterResetPasswordDelegate.result?.account.username, username)
117155
XCTAssertNotNil(signInAfterResetPasswordDelegate.result?.idToken)
118-
XCTAssertNil(signInAfterResetPasswordDelegate.result?.account.accountClaims)
156+
XCTAssertNotNil(signInAfterResetPasswordDelegate.result?.account.accountClaims)
119157
}
120158
}

0 commit comments

Comments
 (0)