@@ -33,53 +33,14 @@ final class MSALNativeAuthSignInJITEndToEndTests: MSALNativeAuthEndToEndPassword
33
33
#if os(macOS)
34
34
throw XCTSkip ( " For some reason this test now requires Keychain access, reason needs to be investigated " )
35
35
#endif
36
-
37
- // Step 1: Create User
38
- guard let application = initialisePublicClientApplication ( ) else {
39
- XCTFail ( " Failed to initialize public client application " )
40
- return
41
- }
42
-
43
36
let username = generateSignUpRandomEmail ( )
44
- let password = generateRandomPassword ( )
45
-
46
- let codeRequiredExp = expectation ( description: " code required " )
47
- let signUpStartDelegate = SignUpPasswordStartDelegateSpy ( expectation: codeRequiredExp)
48
-
49
- let signUpParam = MSALNativeAuthSignUpParameters ( username: username)
50
- signUpParam. password = password
51
- signUpParam. correlationId = correlationId
52
-
53
- application. signUp ( parameters: signUpParam, delegate: signUpStartDelegate)
54
-
55
- await fulfillment ( of: [ codeRequiredExp] )
56
- checkSignUpStartDelegate ( signUpStartDelegate)
57
-
58
- guard signUpStartDelegate. onSignUpCodeRequiredCalled else {
59
- XCTFail ( " onSignUpCodeRequired not called " )
60
- return
61
- }
62
-
63
- // Step 2: Get & Submit Code for Sign Up
64
- guard let code = await retrieveCodeFor ( email: username) else {
65
- XCTFail ( " OTP code could not be retrieved " )
66
- return
67
- }
68
-
69
- let signUpCompleteExp = expectation ( description: " sign-up complete " )
70
- let signUpVerifyCodeDelegate = SignUpVerifyCodeDelegateSpy ( expectation: signUpCompleteExp)
71
-
72
- signUpStartDelegate. newState? . submitCode ( code: code, delegate: signUpVerifyCodeDelegate)
73
-
74
- await fulfillment ( of: [ signUpCompleteExp] )
75
-
76
- guard signUpVerifyCodeDelegate. onSignUpCompletedCalled,
77
- let signInAfterSignUpState = signUpVerifyCodeDelegate. signInAfterSignUpState else {
37
+ // Step 1: Create User
38
+ guard let signInAfterSignUpState = await signUpInternally ( username: username, password: generateRandomPassword ( ) , application: initialisePublicClientApplication ( ) ) else {
78
39
XCTFail ( " onSignUpCompleted not called or state is nil " )
79
40
return
80
41
}
81
42
82
- // Step 3 : Attempt to Sign In automtically
43
+ // Step 2 : Attempt to Sign In automtically
83
44
let signInExpectation = expectation ( description: " signing in " )
84
45
let signInDelegateSpy = SignInAfterSignUpDelegateSpy ( expectation: signInExpectation)
85
46
@@ -96,7 +57,7 @@ final class MSALNativeAuthSignInJITEndToEndTests: MSALNativeAuthEndToEndPassword
96
57
return
97
58
}
98
59
99
- // Step 4 : Add Strong Auth Method, but don't specify verification contact so it's preverified
60
+ // Step 3 : Add Strong Auth Method, but don't specify verification contact so it's preverified
100
61
let challengeParameters = MSALNativeAuthChallengeAuthMethodParameters ( authMethod: authMethod)
101
62
let challengeExpectation = expectation ( description: " challenging auth method " )
102
63
let challengeDelegateSpy = RegisterStrongAuthChallengeDelegateSpy ( expectation: challengeExpectation)
@@ -117,52 +78,14 @@ final class MSALNativeAuthSignInJITEndToEndTests: MSALNativeAuthEndToEndPassword
117
78
throw XCTSkip ( " For some reason this test now requires Keychain access, reason needs to be investigated " )
118
79
#endif
119
80
120
- // Step 1: Create User
121
- guard let application = initialisePublicClientApplication ( ) else {
122
- XCTFail ( " Failed to initialize public client application " )
123
- return
124
- }
125
-
126
81
let username = generateSignUpRandomEmail ( )
127
- let password = generateRandomPassword ( )
128
-
129
- let codeRequiredExp = expectation ( description: " code required " )
130
- let signUpStartDelegate = SignUpPasswordStartDelegateSpy ( expectation: codeRequiredExp)
131
-
132
- let signUpParam = MSALNativeAuthSignUpParameters ( username: username)
133
- signUpParam. password = password
134
- signUpParam. correlationId = correlationId
135
-
136
- application. signUp ( parameters: signUpParam, delegate: signUpStartDelegate)
137
-
138
- await fulfillment ( of: [ codeRequiredExp] )
139
- checkSignUpStartDelegate ( signUpStartDelegate)
140
-
141
- guard signUpStartDelegate. onSignUpCodeRequiredCalled else {
142
- XCTFail ( " onSignUpCodeRequired not called " )
143
- return
144
- }
145
-
146
- // Step 2: Get & Submit Code for Sign Up
147
- guard let code = await retrieveCodeFor ( email: username) else {
148
- XCTFail ( " OTP code could not be retrieved " )
149
- return
150
- }
151
-
152
- let signUpCompleteExp = expectation ( description: " sign-up complete " )
153
- let signUpVerifyCodeDelegate = SignUpVerifyCodeDelegateSpy ( expectation: signUpCompleteExp)
154
-
155
- signUpStartDelegate. newState? . submitCode ( code: code, delegate: signUpVerifyCodeDelegate)
156
-
157
- await fulfillment ( of: [ signUpCompleteExp] )
158
-
159
- guard signUpVerifyCodeDelegate. onSignUpCompletedCalled,
160
- let signInAfterSignUpState = signUpVerifyCodeDelegate. signInAfterSignUpState else {
82
+ // Step 1: Create User
83
+ guard let signInAfterSignUpState = await signUpInternally ( username: username, password: generateRandomPassword ( ) , application: initialisePublicClientApplication ( ) ) else {
161
84
XCTFail ( " onSignUpCompleted not called or state is nil " )
162
85
return
163
86
}
164
87
165
- // Step 3 : Attempt to Sign In automatically
88
+ // Step 2 : Attempt to Sign In automatically
166
89
let signInExpectation = expectation ( description: " signing in " )
167
90
let signInDelegateSpy = SignInAfterSignUpDelegateSpy ( expectation: signInExpectation)
168
91
@@ -179,7 +102,7 @@ final class MSALNativeAuthSignInJITEndToEndTests: MSALNativeAuthEndToEndPassword
179
102
return
180
103
}
181
104
182
- // Step 4 : Add Strong Auth Method and specify different email
105
+ // Step 3 : Add Strong Auth Method and specify different email
183
106
let newEmail = generateSignUpRandomEmail ( )
184
107
let challengeParameters = MSALNativeAuthChallengeAuthMethodParameters ( authMethod: authMethod)
185
108
challengeParameters. verificationContact = newEmail
@@ -196,13 +119,13 @@ final class MSALNativeAuthSignInJITEndToEndTests: MSALNativeAuthEndToEndPassword
196
119
return
197
120
}
198
121
199
- // Step 5 : Get Code for Register Strong Auth
122
+ // Step 4 : Get Code for Register Strong Auth
200
123
guard let code = await retrieveCodeFor ( email: newEmail) else {
201
124
XCTFail ( " OTP code could not be retrieved " )
202
125
return
203
126
}
204
127
205
- // Step 6 : Submit Code to Register Strong Auth
128
+ // Step 5 : Submit Code to Register Strong Auth
206
129
let submitChallengeExpectation = expectation ( description: " submitChallenge " )
207
130
let submitChallengeDelegateSpy = RegisterStrongAuthSubmitChallengeDelegateSpy ( expectation: submitChallengeExpectation)
208
131
@@ -214,56 +137,24 @@ final class MSALNativeAuthSignInJITEndToEndTests: MSALNativeAuthEndToEndPassword
214
137
}
215
138
216
139
func test_createUserAndAddDifferentEmailAsStrongAuthMethod_thenSignInSuccessfully( ) async throws {
217
- throw XCTSkip ( " Retrieving OTP failure " )
140
+ throw XCTSkip ( " Capabilities feature not available in eSTS production " )
218
141
#if os(macOS)
219
142
throw XCTSkip ( " For some reason this test now requires Keychain access, reason needs to be investigated " )
220
143
#endif
221
144
222
- // Step 1: Create User
223
- guard let application = initialisePublicClientApplication ( ) else {
224
- XCTFail ( " Failed to initialize public client application " )
225
- return
226
- }
227
-
228
145
let username = generateSignUpRandomEmail ( )
229
146
let password = generateRandomPassword ( )
230
-
231
- let codeRequiredExp = expectation ( description: " code required " )
232
- let signUpStartDelegate = SignUpPasswordStartDelegateSpy ( expectation: codeRequiredExp)
233
-
234
- let signUpParam = MSALNativeAuthSignUpParameters ( username: username)
235
- signUpParam. password = password
236
- signUpParam. correlationId = correlationId
237
-
238
- application. signUp ( parameters: signUpParam, delegate: signUpStartDelegate)
239
-
240
- await fulfillment ( of: [ codeRequiredExp] )
241
- checkSignUpStartDelegate ( signUpStartDelegate)
242
-
243
- guard signUpStartDelegate. onSignUpCodeRequiredCalled else {
244
- XCTFail ( " onSignUpCodeRequired not called " )
245
- return
246
- }
247
-
248
- // Step 2: Get & Submit Code for Sign Up
249
- guard let code = await retrieveCodeFor ( email: username) else {
250
- XCTFail ( " OTP code could not be retrieved " )
147
+ guard let application = initialisePublicClientApplication ( ) else {
148
+ XCTFail ( " Failed to initialize public client application " )
251
149
return
252
150
}
253
-
254
- let signUpCompleteExp = expectation ( description: " sign-up complete " )
255
- let signUpVerifyCodeDelegate = SignUpVerifyCodeDelegateSpy ( expectation: signUpCompleteExp)
256
-
257
- signUpStartDelegate. newState? . submitCode ( code: code, delegate: signUpVerifyCodeDelegate)
258
-
259
- await fulfillment ( of: [ signUpCompleteExp] )
260
-
261
- guard signUpVerifyCodeDelegate. onSignUpCompletedCalled else {
262
- XCTFail ( " onSignUpCompleted not called " )
151
+ // Step 1: Create User
152
+ guard let _ = await signUpInternally ( username: username, password: password, application: application) else {
153
+ XCTFail ( " onSignUpCompleted not called or state is nil " )
263
154
return
264
155
}
265
156
266
- // Step 3 : Attempt to Sign In with new flow
157
+ // Step 2 : Attempt to Sign In with new flow
267
158
let signInExpectation = expectation ( description: " signing in " )
268
159
let signInDelegateSpy = SignInPasswordStartDelegateSpy ( expectation: signInExpectation)
269
160
@@ -282,7 +173,7 @@ final class MSALNativeAuthSignInJITEndToEndTests: MSALNativeAuthEndToEndPassword
282
173
return
283
174
}
284
175
285
- // Step 4 : Add Strong Auth Method and specify different email
176
+ // Step 3 : Add Strong Auth Method and specify different email
286
177
let newEmail = generateSignUpRandomEmail ( )
287
178
let challengeParameters = MSALNativeAuthChallengeAuthMethodParameters ( authMethod: authMethod)
288
179
challengeParameters. verificationContact = newEmail
@@ -299,13 +190,13 @@ final class MSALNativeAuthSignInJITEndToEndTests: MSALNativeAuthEndToEndPassword
299
190
return
300
191
}
301
192
302
- // Step 5 : Get Code for Register Strong Auth
193
+ // Step 4 : Get Code for Register Strong Auth
303
194
guard let code = await retrieveCodeFor ( email: newEmail) else {
304
195
XCTFail ( " OTP code could not be retrieved " )
305
196
return
306
197
}
307
198
308
- // Step 6 : Submit Code to Register Strong Auth
199
+ // Step 5 : Submit Code to Register Strong Auth
309
200
let submitChallengeExpectation = expectation ( description: " submitChallenge " )
310
201
let submitChallengeDelegateSpy = RegisterStrongAuthSubmitChallengeDelegateSpy ( expectation: submitChallengeExpectation)
311
202
@@ -315,6 +206,95 @@ final class MSALNativeAuthSignInJITEndToEndTests: MSALNativeAuthEndToEndPassword
315
206
316
207
checkSubmitChallengeDelegate ( submitChallengeDelegateSpy, username: username)
317
208
}
209
+
210
+ func test_createUserAndDoNotSendCapabilities_thenBrowserRequiredIsExpected( ) async throws {
211
+ throw XCTSkip ( " Retrieving OTP failure " )
212
+ #if os(macOS)
213
+ throw XCTSkip ( " For some reason this test now requires Keychain access, reason needs to be investigated " )
214
+ #endif
215
+
216
+ let username = generateSignUpRandomEmail ( )
217
+ let password = generateRandomPassword ( )
218
+ guard let application = initialisePublicClientApplication ( capabilities: [ ] ) else {
219
+ XCTFail ( " Failed to initialize public client application " )
220
+ return
221
+ }
222
+ // Step 1: Create User
223
+ guard let _ = await signUpInternally ( username: username, password: password, application: application) else {
224
+ XCTFail ( " onSignUpCompleted not called or state is nil " )
225
+ return
226
+ }
227
+
228
+ // Step 2: Attempt to Sign In with new flow
229
+ let signInExpectation = expectation ( description: " signing in " )
230
+ let signInDelegateSpy = SignInPasswordStartDelegateSpy ( expectation: signInExpectation)
231
+
232
+ let signInParameters = MSALNativeAuthSignInParameters ( username: username)
233
+ signInParameters. password = password
234
+ signInParameters. claimsRequest = MSALClaimsRequest ( jsonString: " { \" access_token \" :{ \" acrs \" :{ \" essential \" :true, \" value \" : \" c4 \" }}} " , error: nil )
235
+
236
+ application. signIn ( parameters: signInParameters, delegate: signInDelegateSpy)
237
+
238
+ await fulfillment ( of: [ signInExpectation] )
239
+
240
+ guard signInDelegateSpy. onSignInStrongAuthMethodRegistrationCalled,
241
+ let strongAuthState = signInDelegateSpy. newStateStrongAuthMethodRegistration,
242
+ let authMethod = signInDelegateSpy. authMethods? . first else {
243
+ XCTFail ( " Sign in failed or strong auth method registration not required " )
244
+ return
245
+ }
246
+
247
+ // browser required is expected here
248
+ XCTAssertTrue ( signInDelegateSpy. onSignInPasswordErrorCalled)
249
+ XCTAssertTrue ( signInDelegateSpy. error? . isBrowserRequired ?? false )
250
+ XCTAssertNotNil ( signInDelegateSpy. error? . errorDescription)
251
+ }
252
+
253
+ // MARK: private methods
254
+
255
+ private func signUpInternally( username: String , password: String , application: MSALNativeAuthPublicClientApplication ? ) async -> SignInAfterSignUpState ? {
256
+ // Step 1: Create User
257
+ guard let application = application else {
258
+ XCTFail ( " Failed to initialize public client application " )
259
+ return nil
260
+ }
261
+
262
+ let codeRequiredExp = expectation ( description: " code required " )
263
+ let signUpStartDelegate = SignUpPasswordStartDelegateSpy ( expectation: codeRequiredExp)
264
+
265
+ let signUpParam = MSALNativeAuthSignUpParameters ( username: username)
266
+ signUpParam. password = password
267
+ signUpParam. correlationId = correlationId
268
+
269
+ application. signUp ( parameters: signUpParam, delegate: signUpStartDelegate)
270
+
271
+ await fulfillment ( of: [ codeRequiredExp] )
272
+ checkSignUpStartDelegate ( signUpStartDelegate)
273
+
274
+ guard signUpStartDelegate. onSignUpCodeRequiredCalled else {
275
+ XCTFail ( " onSignUpCodeRequired not called " )
276
+ return nil
277
+ }
278
+
279
+ // Step 2: Get & Submit Code for Sign Up
280
+ guard let code = await retrieveCodeFor ( email: username) else {
281
+ XCTFail ( " OTP code could not be retrieved " )
282
+ return nil
283
+ }
284
+
285
+ let signUpCompleteExp = expectation ( description: " sign-up complete " )
286
+ let signUpVerifyCodeDelegate = SignUpVerifyCodeDelegateSpy ( expectation: signUpCompleteExp)
287
+
288
+ signUpStartDelegate. newState? . submitCode ( code: code, delegate: signUpVerifyCodeDelegate)
289
+
290
+ await fulfillment ( of: [ signUpCompleteExp] )
291
+
292
+ guard signUpVerifyCodeDelegate. onSignUpCompletedCalled else {
293
+ XCTFail ( " onSignUpCompleted not called or state is nil " )
294
+ return nil
295
+ }
296
+ return signUpVerifyCodeDelegate. signInAfterSignUpState
297
+ }
318
298
319
299
private func checkSignUpStartDelegate( _ delegate: SignUpPasswordStartDelegateSpy ) {
320
300
XCTAssertTrue ( delegate. onSignUpCodeRequiredCalled)
0 commit comments