@@ -26,23 +26,27 @@ import Foundation
26
26
import XCTest
27
27
28
28
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
33
30
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 {
36
34
XCTFail ( " Missing information " )
37
35
return
38
36
}
39
37
let codeRequiredExp = expectation ( description: " code required " )
40
38
let resetPasswordStartDelegate = ResetPasswordStartDelegateSpy ( expectation: codeRequiredExp)
41
39
42
- sut. resetPassword ( username: usernameOTP , delegate: resetPasswordStartDelegate)
40
+ sut. resetPassword ( username: username , delegate: resetPasswordStartDelegate)
43
41
44
42
await fulfillment ( of: [ codeRequiredExp] )
45
43
XCTAssertTrue ( resetPasswordStartDelegate. onResetPasswordCodeRequiredCalled)
44
+
45
+ guard resetPasswordStartDelegate. onResetPasswordCodeRequiredCalled else {
46
+ XCTFail ( " onResetPasswordCodeRequired not called " )
47
+ return
48
+ }
49
+
46
50
XCTAssertEqual ( resetPasswordStartDelegate. channelTargetType, . email)
47
51
XCTAssertFalse ( resetPasswordStartDelegate. sentTo? . isEmpty ?? true )
48
52
XCTAssertNotNil ( resetPasswordStartDelegate. codeLength)
@@ -51,36 +55,54 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
51
55
52
56
let passwordRequiredExp = expectation ( description: " password required " )
53
57
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
+ }
54
63
55
- resetPasswordStartDelegate. newState? . submitCode ( code: " 1234 " , delegate: resetPasswordVerifyDelegate)
64
+ resetPasswordStartDelegate. newState? . submitCode ( code: code , delegate: resetPasswordVerifyDelegate)
56
65
57
66
await fulfillment ( of: [ passwordRequiredExp] )
58
67
XCTAssertTrue ( resetPasswordVerifyDelegate. onPasswordRequiredCalled)
68
+
69
+ guard resetPasswordVerifyDelegate. onPasswordRequiredCalled else {
70
+ XCTFail ( " onPasswordRequired not called " )
71
+ return
72
+ }
59
73
60
74
// Now submit the password...
61
75
let resetPasswordCompletedExp = expectation ( description: " reset password completed " )
62
76
let resetPasswordRequiredDelegate = ResetPasswordRequiredDelegateSpy ( expectation: resetPasswordCompletedExp)
63
77
64
- resetPasswordVerifyDelegate. newPasswordRequiredState? . submitPassword ( password: " password " , delegate: resetPasswordRequiredDelegate)
78
+ let uniquePassword = generateRandomPassword ( )
79
+ resetPasswordVerifyDelegate. newPasswordRequiredState? . submitPassword ( password: uniquePassword, delegate: resetPasswordRequiredDelegate)
65
80
66
81
await fulfillment ( of: [ resetPasswordCompletedExp] )
67
82
XCTAssertTrue ( resetPasswordRequiredDelegate. onResetPasswordCompletedCalled)
68
83
}
69
84
70
85
// SSPR - with automatic sign in
71
86
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 {
74
90
XCTFail ( " Missing information " )
75
91
return
76
92
}
77
93
let codeRequiredExp = expectation ( description: " code required " )
78
94
let resetPasswordStartDelegate = ResetPasswordStartDelegateSpy ( expectation: codeRequiredExp)
79
95
80
- sut. resetPassword ( username: usernameOTP , delegate: resetPasswordStartDelegate)
96
+ sut. resetPassword ( username: username , delegate: resetPasswordStartDelegate)
81
97
82
98
await fulfillment ( of: [ codeRequiredExp] )
83
99
XCTAssertTrue ( resetPasswordStartDelegate. onResetPasswordCodeRequiredCalled)
100
+
101
+ guard resetPasswordStartDelegate. onResetPasswordCodeRequiredCalled else {
102
+ XCTFail ( " onResetPasswordCodeRequired not called " )
103
+ return
104
+ }
105
+
84
106
XCTAssertEqual ( resetPasswordStartDelegate. channelTargetType, . email)
85
107
XCTAssertFalse ( resetPasswordStartDelegate. sentTo? . isEmpty ?? true )
86
108
XCTAssertNotNil ( resetPasswordStartDelegate. codeLength)
@@ -89,20 +111,36 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
89
111
90
112
let passwordRequiredExp = expectation ( description: " password required " )
91
113
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
+ }
92
119
93
- resetPasswordStartDelegate. newState? . submitCode ( code: " 1234 " , delegate: resetPasswordVerifyDelegate)
120
+ resetPasswordStartDelegate. newState? . submitCode ( code: code , delegate: resetPasswordVerifyDelegate)
94
121
95
122
await fulfillment ( of: [ passwordRequiredExp] )
96
123
XCTAssertTrue ( resetPasswordVerifyDelegate. onPasswordRequiredCalled)
124
+
125
+ guard resetPasswordVerifyDelegate. onPasswordRequiredCalled else {
126
+ XCTFail ( " onPasswordRequired not called " )
127
+ return
128
+ }
97
129
98
130
// Now submit the password...
99
131
let resetPasswordCompletedExp = expectation ( description: " reset password completed " )
100
132
let resetPasswordRequiredDelegate = ResetPasswordRequiredDelegateSpy ( expectation: resetPasswordCompletedExp)
101
133
102
- resetPasswordVerifyDelegate. newPasswordRequiredState? . submitPassword ( password: " password " , delegate: resetPasswordRequiredDelegate)
134
+ let uniquePassword = generateRandomPassword ( )
135
+ resetPasswordVerifyDelegate. newPasswordRequiredState? . submitPassword ( password: uniquePassword, delegate: resetPasswordRequiredDelegate)
103
136
104
137
await fulfillment ( of: [ resetPasswordCompletedExp] )
105
138
XCTAssertTrue ( resetPasswordRequiredDelegate. onResetPasswordCompletedCalled)
139
+
140
+ guard resetPasswordRequiredDelegate. onResetPasswordCompletedCalled else {
141
+ XCTFail ( " onResetPasswordCompleted not called " )
142
+ return
143
+ }
106
144
107
145
// Now sign in...
108
146
@@ -113,8 +151,8 @@ final class MSALNativeAuthResetPasswordEndToEndTests: MSALNativeAuthEndToEndBase
113
151
114
152
await fulfillment ( of: [ signInAfterResetPasswordExp] )
115
153
XCTAssertTrue ( signInAfterResetPasswordDelegate. onSignInCompletedCalled)
116
- XCTAssertEqual ( signInAfterResetPasswordDelegate. result? . account. username, usernameOTP )
154
+ XCTAssertEqual ( signInAfterResetPasswordDelegate. result? . account. username, username )
117
155
XCTAssertNotNil ( signInAfterResetPasswordDelegate. result? . idToken)
118
- XCTAssertNil ( signInAfterResetPasswordDelegate. result? . account. accountClaims)
156
+ XCTAssertNotNil ( signInAfterResetPasswordDelegate. result? . account. accountClaims)
119
157
}
120
158
}
0 commit comments