@@ -48,6 +48,44 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {
48
48
49
49
XCTAssertEqual ( authSession. startCallCount, 0 )
50
50
}
51
+
52
+ func test_executeInAppLogin_noTokenExchange_doesNotIncludeCodeChallenge( ) {
53
+
54
+ configurationProvider. isInstalledHandler = { _, _ in
55
+ true
56
+ }
57
+
58
+ let applicationLauncher = ApplicationLaunchingMock ( )
59
+ applicationLauncher. openHandler = { _, _, completion in
60
+ completion ? ( true )
61
+ }
62
+
63
+ var hasCalledAuthenticationSessionBuilder : Bool = false
64
+
65
+ let authenticationSessionBuilder : AuthorizationCodeAuthProvider . AuthenticationSessionBuilder = { _, _, url, _ in
66
+ XCTAssertFalse ( url. absoluteString. contains ( " code_challenge " ) )
67
+ XCTAssertFalse ( url. absoluteString. contains ( " code_challenge_method " ) )
68
+ hasCalledAuthenticationSessionBuilder = true
69
+ return AuthenticationSessioningMock ( )
70
+ }
71
+
72
+ let provider = AuthorizationCodeAuthProvider (
73
+ authenticationSessionBuilder: authenticationSessionBuilder,
74
+ shouldExchangeAuthCode: false ,
75
+ configurationProvider: configurationProvider,
76
+ applicationLauncher: applicationLauncher
77
+ )
78
+
79
+ provider. execute (
80
+ authDestination: . inApp,
81
+ completion: { result in }
82
+ )
83
+
84
+ let url = URL ( string: " test://app?code=123 " ) !
85
+ _ = provider. handle ( response: url)
86
+
87
+ XCTAssertTrue ( hasCalledAuthenticationSessionBuilder)
88
+ }
51
89
52
90
func test_execute_existingSession_returnsExistingAuthSessionError( ) {
53
91
let provider = AuthorizationCodeAuthProvider (
@@ -257,6 +295,47 @@ final class AuthorizationCodeAuthProviderTests: XCTestCase {
257
295
XCTAssertEqual ( authenticationSession. startCallCount, 1 )
258
296
}
259
297
298
+ func test_executeNativeLogin_noTokenExchange_doesNotIncludeCodeChallenge( ) {
299
+
300
+ let applicationLauncher = ApplicationLaunchingMock ( )
301
+ applicationLauncher. openHandler = { url, _, completion in
302
+ XCTAssertFalse ( url. absoluteString. contains ( " code_challenge " ) )
303
+ XCTAssertFalse ( url. absoluteString. contains ( " code_challenge_method " ) )
304
+ completion ? ( false )
305
+ }
306
+
307
+ configurationProvider. isInstalledHandler = { _, _ in
308
+ true
309
+ }
310
+
311
+ let expectation = XCTestExpectation ( )
312
+
313
+ let authenticationSession = AuthenticationSessioningMock ( )
314
+ let authenticationSessionBuilder : AuthorizationCodeAuthProvider . AuthenticationSessionBuilder = { _, _, _, _ in
315
+ expectation. fulfill ( )
316
+ return authenticationSession
317
+ }
318
+
319
+ let provider = AuthorizationCodeAuthProvider (
320
+ authenticationSessionBuilder: authenticationSessionBuilder,
321
+ shouldExchangeAuthCode: false ,
322
+ configurationProvider: configurationProvider,
323
+ applicationLauncher: applicationLauncher
324
+ )
325
+
326
+ XCTAssertEqual ( applicationLauncher. openCallCount, 0 )
327
+
328
+ provider. execute (
329
+ authDestination: . native( appPriority: [ . eats] ) ,
330
+ prefill: nil ,
331
+ completion: { _ in }
332
+ )
333
+
334
+ wait ( for: [ expectation] , timeout: 0.2 )
335
+
336
+ XCTAssertEqual ( applicationLauncher. openCallCount, 1 )
337
+ }
338
+
260
339
func test_handleResponse_true_callsResponseParser( ) {
261
340
262
341
let responseParser = AuthorizationCodeResponseParsingMock ( )
0 commit comments