@@ -125,4 +125,130 @@ final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBas
125
125
XCTAssertNotNil ( signInVerifyCodeDelegateSpy. result? . idToken)
126
126
XCTAssertEqual ( signInVerifyCodeDelegateSpy. result? . account. username, username)
127
127
}
128
+
129
+ // Sign In - Verify Custom URL Domain - "https://<tenantName>.ciamlogin.com/<tenantName>.onmicrosoft.com"
130
+ func test_signInCustomSubdomainLongInSuccess( ) async throws {
131
+ guard let sut = initialisePublicClientApplication ( clientIdType: . code, customAuthorityURLFormat: . tenantSubdomainLongVersion) , let username = retrieveUsernameForSignInCode ( ) else {
132
+ XCTFail ( " Missing information " )
133
+ return
134
+ }
135
+
136
+ let signInExpectation = expectation ( description: " signing in " )
137
+ let signInDelegateSpy = SignInStartDelegateSpy ( expectation: signInExpectation)
138
+
139
+ sut. signIn ( username: username, correlationId: correlationId, delegate: signInDelegateSpy)
140
+
141
+ await fulfillment ( of: [ signInExpectation] )
142
+
143
+ guard signInDelegateSpy. onSignInCodeRequiredCalled else {
144
+ XCTFail ( " onSignInCodeRequired not called " )
145
+ return
146
+ }
147
+
148
+ XCTAssertNotNil ( signInDelegateSpy. newStateCodeRequired)
149
+ XCTAssertNotNil ( signInDelegateSpy. sentTo)
150
+
151
+ // Now submit the code..
152
+
153
+ guard let code = await retrieveCodeFor ( email: username) else {
154
+ XCTFail ( " OTP code could not be retrieved " )
155
+ return
156
+ }
157
+
158
+ let verifyCodeExpectation = expectation ( description: " verifying code " )
159
+ let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy ( expectation: verifyCodeExpectation)
160
+
161
+ signInDelegateSpy. newStateCodeRequired? . submitCode ( code: code, delegate: signInVerifyCodeDelegateSpy)
162
+
163
+ await fulfillment ( of: [ verifyCodeExpectation] )
164
+
165
+ XCTAssertTrue ( signInVerifyCodeDelegateSpy. onSignInCompletedCalled)
166
+ XCTAssertNotNil ( signInVerifyCodeDelegateSpy. result)
167
+ XCTAssertNotNil ( signInVerifyCodeDelegateSpy. result? . idToken)
168
+ XCTAssertEqual ( signInVerifyCodeDelegateSpy. result? . account. username, username)
169
+ }
170
+
171
+ // Sign In - Verify Custom URL Domain - "https://<tenantName>.ciamlogin.com/<tenantId>"
172
+ func test_signInCustomSubdomainIdInSuccess( ) async throws {
173
+ guard let sut = initialisePublicClientApplication ( clientIdType: . code, customAuthorityURLFormat: . tenantSubdomainTenantId) , let username = retrieveUsernameForSignInCode ( ) else {
174
+ XCTFail ( " Missing information " )
175
+ return
176
+ }
177
+
178
+ let signInExpectation = expectation ( description: " signing in " )
179
+ let signInDelegateSpy = SignInStartDelegateSpy ( expectation: signInExpectation)
180
+
181
+ sut. signIn ( username: username, correlationId: correlationId, delegate: signInDelegateSpy)
182
+
183
+ await fulfillment ( of: [ signInExpectation] )
184
+
185
+ guard signInDelegateSpy. onSignInCodeRequiredCalled else {
186
+ XCTFail ( " onSignInCodeRequired not called " )
187
+ return
188
+ }
189
+
190
+ XCTAssertNotNil ( signInDelegateSpy. newStateCodeRequired)
191
+ XCTAssertNotNil ( signInDelegateSpy. sentTo)
192
+
193
+ // Now submit the code..
194
+
195
+ guard let code = await retrieveCodeFor ( email: username) else {
196
+ XCTFail ( " OTP code could not be retrieved " )
197
+ return
198
+ }
199
+
200
+ let verifyCodeExpectation = expectation ( description: " verifying code " )
201
+ let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy ( expectation: verifyCodeExpectation)
202
+
203
+ signInDelegateSpy. newStateCodeRequired? . submitCode ( code: code, delegate: signInVerifyCodeDelegateSpy)
204
+
205
+ await fulfillment ( of: [ verifyCodeExpectation] )
206
+
207
+ XCTAssertTrue ( signInVerifyCodeDelegateSpy. onSignInCompletedCalled)
208
+ XCTAssertNotNil ( signInVerifyCodeDelegateSpy. result)
209
+ XCTAssertNotNil ( signInVerifyCodeDelegateSpy. result? . idToken)
210
+ XCTAssertEqual ( signInVerifyCodeDelegateSpy. result? . account. username, username)
211
+ }
212
+
213
+ // Sign In - Verify Custom URL Domain - "https://<tenantName>.ciamlogin.com/"
214
+ func test_signInCustomSubdomainShortInSuccess( ) async throws {
215
+ guard let sut = initialisePublicClientApplication ( clientIdType: . code, customAuthorityURLFormat: . tenantSubdomainShortVersion) , let username = retrieveUsernameForSignInCode ( ) else {
216
+ XCTFail ( " Missing information " )
217
+ return
218
+ }
219
+
220
+ let signInExpectation = expectation ( description: " signing in " )
221
+ let signInDelegateSpy = SignInStartDelegateSpy ( expectation: signInExpectation)
222
+
223
+ sut. signIn ( username: username, correlationId: correlationId, delegate: signInDelegateSpy)
224
+
225
+ await fulfillment ( of: [ signInExpectation] )
226
+
227
+ guard signInDelegateSpy. onSignInCodeRequiredCalled else {
228
+ XCTFail ( " onSignInCodeRequired not called " )
229
+ return
230
+ }
231
+
232
+ XCTAssertNotNil ( signInDelegateSpy. newStateCodeRequired)
233
+ XCTAssertNotNil ( signInDelegateSpy. sentTo)
234
+
235
+ // Now submit the code..
236
+
237
+ guard let code = await retrieveCodeFor ( email: username) else {
238
+ XCTFail ( " OTP code could not be retrieved " )
239
+ return
240
+ }
241
+
242
+ let verifyCodeExpectation = expectation ( description: " verifying code " )
243
+ let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy ( expectation: verifyCodeExpectation)
244
+
245
+ signInDelegateSpy. newStateCodeRequired? . submitCode ( code: code, delegate: signInVerifyCodeDelegateSpy)
246
+
247
+ await fulfillment ( of: [ verifyCodeExpectation] )
248
+
249
+ XCTAssertTrue ( signInVerifyCodeDelegateSpy. onSignInCompletedCalled)
250
+ XCTAssertNotNil ( signInVerifyCodeDelegateSpy. result)
251
+ XCTAssertNotNil ( signInVerifyCodeDelegateSpy. result? . idToken)
252
+ XCTAssertEqual ( signInVerifyCodeDelegateSpy. result? . account. username, username)
253
+ }
128
254
}
0 commit comments