From 4ea72d32505cc4f18ea2154bc41398520e6519e3 Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:38:50 -0700 Subject: [PATCH 01/13] g-orchestrated: add OIDFakeAuthorizationService to AppAuthTestHelpers --- .../OIDFakeAuthorizationService.h | 74 ++++++++++ .../OIDFakeAuthorizationService.m | 67 +++++++++ UnitTests/OIDFakeAuthorizationServiceTests.m | 135 ++++++++++++++++++ 3 files changed, 276 insertions(+) create mode 100644 Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h create mode 100644 Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m create mode 100644 UnitTests/OIDFakeAuthorizationServiceTests.m diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h new file mode 100644 index 000000000..5c245df75 --- /dev/null +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h @@ -0,0 +1,74 @@ +/*! @file OIDFakeAuthorizationService.h + @brief AppAuth iOS SDK + @copyright + Copyright 2026 The AppAuth Authors. All Rights Reserved. + @copydetails + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#import + +#import "OIDAuthorizationService.h" +#import "OIDFakeExternalUserAgentSession.h" + +NS_ASSUME_NONNULL_BEGIN + +/*! @brief An @c OIDAuthorizationService whose instance methods record their arguments and keep the + callbacks for the test to invoke, instead of presenting UI or making network requests. + @discussion Inject an instance where production code would otherwise call the class methods of + @c OIDAuthorizationService. The class methods of this fake are inherited unchanged and still + perform real work; only the instance methods are faked. + */ +@interface OIDFakeAuthorizationService : OIDAuthorizationService + +/*! @brief The request passed to the most recent @c -presentAuthorizationRequest:externalUserAgent:callback:. */ +@property(nonatomic, readonly, nullable) OIDAuthorizationRequest *lastAuthorizationRequest; + +/*! @brief The external user agent passed to the most recent authorization request. For the + platform convenience methods this is the agent AppAuth built, e.g. an + @c OIDExternalUserAgentIOS whose @c presentingViewController is the one the caller supplied. */ +@property(nonatomic, readonly, nullable) id lastExternalUserAgent; + +/*! @brief The callback of the most recent authorization request. Invoke it to complete the flow. */ +@property(nonatomic, readonly, copy, nullable) OIDAuthorizationCallback lastAuthorizationCallback; + +/*! @brief The session returned from the most recent authorization request. */ +@property(nonatomic, readonly, nullable) OIDFakeExternalUserAgentSession *lastAuthorizationSession; + +/*! @brief The request passed to the most recent @c -presentEndSessionRequest:externalUserAgent:callback:. */ +@property(nonatomic, readonly, nullable) OIDEndSessionRequest *lastEndSessionRequest; + +/*! @brief The callback of the most recent end-session request. */ +@property(nonatomic, readonly, copy, nullable) OIDEndSessionCallback lastEndSessionCallback; + +/*! @brief How many token requests have been performed. */ +@property(nonatomic, readonly) NSUInteger tokenRequestCount; + +/*! @brief The request passed to the most recent @c -performTokenRequest:originalAuthorizationResponse:callback:. */ +@property(nonatomic, readonly, nullable) OIDTokenRequest *lastTokenRequest; + +/*! @brief The authorization response passed alongside the most recent token request, if any. */ +@property(nonatomic, readonly, nullable) OIDAuthorizationResponse *lastOriginalAuthorizationResponse; + +/*! @brief The callback of the most recent token request. Invoke it to complete the request. */ +@property(nonatomic, readonly, copy, nullable) OIDTokenCallback lastTokenCallback; + +/*! @brief The request passed to the most recent @c -performRegistrationRequest:completion:. */ +@property(nonatomic, readonly, nullable) OIDRegistrationRequest *lastRegistrationRequest; + +/*! @brief The completion of the most recent registration request. */ +@property(nonatomic, readonly, copy, nullable) OIDRegistrationCompletion lastRegistrationCompletion; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m new file mode 100644 index 000000000..f5f9b03a3 --- /dev/null +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m @@ -0,0 +1,67 @@ +/*! @file OIDFakeAuthorizationService.m + @brief AppAuth iOS SDK + @copyright + Copyright 2026 The AppAuth Authors. All Rights Reserved. + @copydetails + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#import "OIDFakeAuthorizationService.h" + +#import "OIDAuthorizationRequest.h" +#import "OIDAuthorizationResponse.h" +#import "OIDEndSessionRequest.h" +#import "OIDExternalUserAgent.h" +#import "OIDRegistrationRequest.h" +#import "OIDTokenRequest.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation OIDFakeAuthorizationService + +- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request + externalUserAgent:(id)externalUserAgent + callback:(OIDAuthorizationCallback)callback { + _lastAuthorizationRequest = request; + _lastExternalUserAgent = externalUserAgent; + _lastAuthorizationCallback = [callback copy]; + _lastAuthorizationSession = [[OIDFakeExternalUserAgentSession alloc] init]; + return _lastAuthorizationSession; +} + +- (id)presentEndSessionRequest:(OIDEndSessionRequest *)request + externalUserAgent:(id)externalUserAgent + callback:(OIDEndSessionCallback)callback { + _lastEndSessionRequest = request; + _lastEndSessionCallback = [callback copy]; + return [[OIDFakeExternalUserAgentSession alloc] init]; +} + +- (void)performTokenRequest:(OIDTokenRequest *)request + originalAuthorizationResponse:(nullable OIDAuthorizationResponse *)authorizationResponse + callback:(OIDTokenCallback)callback { + _tokenRequestCount++; + _lastTokenRequest = request; + _lastOriginalAuthorizationResponse = authorizationResponse; + _lastTokenCallback = [callback copy]; +} + +- (void)performRegistrationRequest:(OIDRegistrationRequest *)request + completion:(OIDRegistrationCompletion)completion { + _lastRegistrationRequest = request; + _lastRegistrationCompletion = [completion copy]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/UnitTests/OIDFakeAuthorizationServiceTests.m b/UnitTests/OIDFakeAuthorizationServiceTests.m new file mode 100644 index 000000000..a54b92e33 --- /dev/null +++ b/UnitTests/OIDFakeAuthorizationServiceTests.m @@ -0,0 +1,135 @@ +/*! @file OIDFakeAuthorizationServiceTests.m + @brief AppAuth iOS SDK + @copyright + Copyright 2026 The AppAuth Authors. All Rights Reserved. + @copydetails + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#import + +#if SWIFT_PACKAGE +@import AppAuthCore; +@import AppAuthTestHelpers; +#else +#import "Sources/AppAuthCore.h" +#import "Sources/AppAuthTestHelpers/AppAuthTestHelpers.h" +#endif +#import "OIDAuthorizationRequestTests.h" +#import "OIDAuthorizationResponseTests.h" +#import "OIDTokenRequestTests.h" + +@interface OIDNoOpExternalUserAgent : NSObject +@end + +@implementation OIDNoOpExternalUserAgent + +- (BOOL)presentExternalUserAgentRequest:(id)request + session:(id)session { + return NO; +} + +- (void)dismissExternalUserAgentAnimated:(BOOL)animated completion:(void (^)(void))completion { +} + +@end + +@interface OIDFakeAuthorizationServiceTests : XCTestCase +@end + +@implementation OIDFakeAuthorizationServiceTests + +- (void)testPerformTokenRequestIsRecordedAndCallbackIsReturned { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + OIDTokenRequest *request = [OIDTokenRequestTests testInstance]; + OIDAuthorizationResponse *authorizationResponse = [OIDAuthorizationResponseTests testInstance]; + __block OIDTokenResponse *receivedResponse = nil; + __block NSError *receivedError = nil; + + [service performTokenRequest:request + originalAuthorizationResponse:authorizationResponse + callback:^(OIDTokenResponse *_Nullable tokenResponse, + NSError *_Nullable error) { + receivedResponse = tokenResponse; + receivedError = error; + }]; + + XCTAssertEqual(service.tokenRequestCount, 1u); + XCTAssertEqual(service.lastTokenRequest, request); + XCTAssertEqual(service.lastOriginalAuthorizationResponse, authorizationResponse); + XCTAssertNotNil(service.lastTokenCallback); + + NSError *someError = [NSError errorWithDomain:@"com.example" code:42 userInfo:nil]; + service.lastTokenCallback(nil, someError); + XCTAssertNil(receivedResponse); + XCTAssertEqual(receivedError, someError); +} + +- (void)testTwoArgumentPerformTokenRequestRoutesToThreeArgument { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + OIDTokenRequest *request = [OIDTokenRequestTests testInstance]; + + [service performTokenRequest:request + callback:^(OIDTokenResponse *_Nullable tokenResponse, + NSError *_Nullable error) { + }]; + + XCTAssertEqual(service.tokenRequestCount, 1u); + XCTAssertEqual(service.lastTokenRequest, request); + XCTAssertNil(service.lastOriginalAuthorizationResponse); +} + +- (void)testPresentAuthorizationRequestReturnsFakeSession { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + OIDAuthorizationRequest *request = [OIDAuthorizationRequestTests testInstance]; + OIDNoOpExternalUserAgent *userAgent = [[OIDNoOpExternalUserAgent alloc] init]; + __block BOOL callbackInvoked = NO; + + id session = + [service presentAuthorizationRequest:request + externalUserAgent:userAgent + callback:^(OIDAuthorizationResponse *_Nullable response, + NSError *_Nullable error) { + callbackInvoked = YES; + }]; + + XCTAssertEqual(session, service.lastAuthorizationSession); + XCTAssertTrue([session isKindOfClass:[OIDFakeExternalUserAgentSession class]]); + XCTAssertEqual(service.lastAuthorizationRequest, request); + XCTAssertEqual(service.lastExternalUserAgent, userAgent); + + [session cancel]; + XCTAssertEqual(service.lastAuthorizationSession.cancelCount, 1u); + XCTAssertFalse(callbackInvoked); +} + +- (void)testFakeSessionResumeRecordsURLAndHonoursResumeResult { + OIDFakeExternalUserAgentSession *session = [[OIDFakeExternalUserAgentSession alloc] init]; + NSURL *firstURL = [NSURL URLWithString:@"https://example.com/callback?code=1"]; + NSURL *secondURL = [NSURL URLWithString:@"https://example.com/callback?code=2"]; + + session.resumeResult = NO; + NSError *error = nil; + XCTAssertFalse([session resumeExternalUserAgentFlowWithURL:firstURL error:&error]); + XCTAssertEqualObjects(session.lastResumedURL, firstURL); + XCTAssertEqualObjects(error.domain, OIDGeneralErrorDomain); + XCTAssertEqual(error.code, OIDErrorCodeURLMismatch); + + session.resumeResult = YES; + error = nil; + XCTAssertTrue([session resumeExternalUserAgentFlowWithURL:secondURL error:&error]); + XCTAssertEqualObjects(session.lastResumedURL, secondURL); + XCTAssertNil(error); +} + +@end From ca92dcec2ae5bf523e24851d24aa8bccb8d71d78 Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:45:32 -0700 Subject: [PATCH 02/13] g-orchestrated: tidy the fake service and its tests --- CHANGELOG.md | 2 +- .../AppAuthTestHelpers/AppAuthTestHelpers.h | 1 + .../OIDFakeAuthorizationService.h | 44 +++++++++----- .../OIDFakeAuthorizationService.m | 14 +++-- UnitTests/OIDFakeAuthorizationServiceTests.m | 59 ++++++++----------- 5 files changed, 66 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b250ebbc5..fec6a202c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ - Added instance-method counterparts of the `OIDAuthorizationService` class methods, and made `-init` public, so the service can be injected and faked in tests. `OIDAuthorizationServiceProtocol` declares them, and `OIDAuthorizationServiceIOSProtocol` / `OIDAuthorizationServiceMacProtocol` declare the platform convenience methods. - Deprecated `OIDAuthorizationService.configuration`. It is never set and is always `nil`; use the request's `configuration` instead. It will be removed in 4.0. - Added instance-method counterparts of the iOS and macOS `OIDAuthorizationService` convenience methods, and read-only `presentingViewController` / `presentingWindow` properties on the external user agents. -- Added the `AppAuthTestHelpers` Swift package product, with `OIDFakeExternalUserAgentSession`, for testing code that depends on AppAuth. +- Added the `AppAuthTestHelpers` Swift package product, with `OIDFakeAuthorizationService` and `OIDFakeExternalUserAgentSession`, for testing code that depends on AppAuth. # 3.0.0 - BREAKING: Updates made to support Xcode 27. ([#972](https://github.com/openid/AppAuth-iOS/pull/972), [#973](https://github.com/openid/AppAuth-iOS/pull/973)) diff --git a/Sources/AppAuthTestHelpers/AppAuthTestHelpers.h b/Sources/AppAuthTestHelpers/AppAuthTestHelpers.h index ec07d2698..aa6954c63 100644 --- a/Sources/AppAuthTestHelpers/AppAuthTestHelpers.h +++ b/Sources/AppAuthTestHelpers/AppAuthTestHelpers.h @@ -16,4 +16,5 @@ limitations under the License. */ +#import "OIDFakeAuthorizationService.h" #import "OIDFakeExternalUserAgentSession.h" diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h index 5c245df75..504146819 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h @@ -31,42 +31,58 @@ NS_ASSUME_NONNULL_BEGIN */ @interface OIDFakeAuthorizationService : OIDAuthorizationService -/*! @brief The request passed to the most recent @c -presentAuthorizationRequest:externalUserAgent:callback:. */ +/*! @brief The request passed to the most recent + @c -presentAuthorizationRequest:externalUserAgent:callback:. + */ @property(nonatomic, readonly, nullable) OIDAuthorizationRequest *lastAuthorizationRequest; /*! @brief The external user agent passed to the most recent authorization request. For the - platform convenience methods this is the agent AppAuth built, e.g. an - @c OIDExternalUserAgentIOS whose @c presentingViewController is the one the caller supplied. */ + platform convenience methods, this is the agent AppAuth built for the caller's view + controller or window. + */ @property(nonatomic, readonly, nullable) id lastExternalUserAgent; -/*! @brief The callback of the most recent authorization request. Invoke it to complete the flow. */ +/*! @brief The callback of the most recent authorization request. Invoke it to complete the flow. + */ @property(nonatomic, readonly, copy, nullable) OIDAuthorizationCallback lastAuthorizationCallback; -/*! @brief The session returned from the most recent authorization request. */ +/*! @brief The session returned from the most recent authorization request. + */ @property(nonatomic, readonly, nullable) OIDFakeExternalUserAgentSession *lastAuthorizationSession; -/*! @brief The request passed to the most recent @c -presentEndSessionRequest:externalUserAgent:callback:. */ +/*! @brief The request passed to the most recent + @c -presentEndSessionRequest:externalUserAgent:callback:. + */ @property(nonatomic, readonly, nullable) OIDEndSessionRequest *lastEndSessionRequest; -/*! @brief The callback of the most recent end-session request. */ +/*! @brief The callback of the most recent end-session request. + */ @property(nonatomic, readonly, copy, nullable) OIDEndSessionCallback lastEndSessionCallback; -/*! @brief How many token requests have been performed. */ +/*! @brief How many token requests have been performed. + */ @property(nonatomic, readonly) NSUInteger tokenRequestCount; -/*! @brief The request passed to the most recent @c -performTokenRequest:originalAuthorizationResponse:callback:. */ +/*! @brief The request passed to the most recent + @c -performTokenRequest:originalAuthorizationResponse:callback:. + */ @property(nonatomic, readonly, nullable) OIDTokenRequest *lastTokenRequest; -/*! @brief The authorization response passed alongside the most recent token request, if any. */ -@property(nonatomic, readonly, nullable) OIDAuthorizationResponse *lastOriginalAuthorizationResponse; +/*! @brief The authorization response passed alongside the most recent token request, if any. + */ +@property(nonatomic, readonly, nullable) + OIDAuthorizationResponse *lastOriginalAuthorizationResponse; -/*! @brief The callback of the most recent token request. Invoke it to complete the request. */ +/*! @brief The callback of the most recent token request. Invoke it to complete the request. + */ @property(nonatomic, readonly, copy, nullable) OIDTokenCallback lastTokenCallback; -/*! @brief The request passed to the most recent @c -performRegistrationRequest:completion:. */ +/*! @brief The request passed to the most recent @c -performRegistrationRequest:completion:. + */ @property(nonatomic, readonly, nullable) OIDRegistrationRequest *lastRegistrationRequest; -/*! @brief The completion of the most recent registration request. */ +/*! @brief The completion of the most recent registration request. + */ @property(nonatomic, readonly, copy, nullable) OIDRegistrationCompletion lastRegistrationCompletion; @end diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m index f5f9b03a3..68a443282 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m @@ -29,9 +29,10 @@ @implementation OIDFakeAuthorizationService -- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request - externalUserAgent:(id)externalUserAgent - callback:(OIDAuthorizationCallback)callback { +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + externalUserAgent:(id)externalUserAgent + callback:(OIDAuthorizationCallback)callback { _lastAuthorizationRequest = request; _lastExternalUserAgent = externalUserAgent; _lastAuthorizationCallback = [callback copy]; @@ -39,9 +40,10 @@ @implementation OIDFakeAuthorizationService return _lastAuthorizationSession; } -- (id)presentEndSessionRequest:(OIDEndSessionRequest *)request - externalUserAgent:(id)externalUserAgent - callback:(OIDEndSessionCallback)callback { +- (id) + presentEndSessionRequest:(OIDEndSessionRequest *)request + externalUserAgent:(id)externalUserAgent + callback:(OIDEndSessionCallback)callback { _lastEndSessionRequest = request; _lastEndSessionCallback = [callback copy]; return [[OIDFakeExternalUserAgentSession alloc] init]; diff --git a/UnitTests/OIDFakeAuthorizationServiceTests.m b/UnitTests/OIDFakeAuthorizationServiceTests.m index a54b92e33..905a5b3e9 100644 --- a/UnitTests/OIDFakeAuthorizationServiceTests.m +++ b/UnitTests/OIDFakeAuthorizationServiceTests.m @@ -1,19 +1,19 @@ /*! @file OIDFakeAuthorizationServiceTests.m - @brief AppAuth iOS SDK - @copyright + @brief AppAuth iOS SDK + @copyright Copyright 2026 The AppAuth Authors. All Rights Reserved. - @copydetails - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + @copydetails + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ #import @@ -29,6 +29,8 @@ #import "OIDAuthorizationResponseTests.h" #import "OIDTokenRequestTests.h" +/*! @brief An external user agent that never presents anything. + */ @interface OIDNoOpExternalUserAgent : NSObject @end @@ -40,15 +42,21 @@ - (BOOL)presentExternalUserAgentRequest:(id)request } - (void)dismissExternalUserAgentAnimated:(BOOL)animated completion:(void (^)(void))completion { + if (completion) { + completion(); + } } @end +/*! @brief Unit tests for @c OIDFakeAuthorizationService. + */ @interface OIDFakeAuthorizationServiceTests : XCTestCase @end @implementation OIDFakeAuthorizationServiceTests +/*! @brief A token request is recorded, and invoking the kept callback reaches the caller. */ - (void)testPerformTokenRequestIsRecordedAndCallbackIsReturned { OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; OIDTokenRequest *request = [OIDTokenRequestTests testInstance]; @@ -75,6 +83,7 @@ - (void)testPerformTokenRequestIsRecordedAndCallbackIsReturned { XCTAssertEqual(receivedError, someError); } +/*! @brief The two-argument token request is recorded with no authorization response. */ - (void)testTwoArgumentPerformTokenRequestRoutesToThreeArgument { OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; OIDTokenRequest *request = [OIDTokenRequestTests testInstance]; @@ -89,6 +98,9 @@ - (void)testTwoArgumentPerformTokenRequestRoutesToThreeArgument { XCTAssertNil(service.lastOriginalAuthorizationResponse); } +/*! @brief An authorization request is recorded and returns a fake session, which counts a cancel + without calling back. + */ - (void)testPresentAuthorizationRequestReturnsFakeSession { OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; OIDAuthorizationRequest *request = [OIDAuthorizationRequestTests testInstance]; @@ -113,23 +125,4 @@ - (void)testPresentAuthorizationRequestReturnsFakeSession { XCTAssertFalse(callbackInvoked); } -- (void)testFakeSessionResumeRecordsURLAndHonoursResumeResult { - OIDFakeExternalUserAgentSession *session = [[OIDFakeExternalUserAgentSession alloc] init]; - NSURL *firstURL = [NSURL URLWithString:@"https://example.com/callback?code=1"]; - NSURL *secondURL = [NSURL URLWithString:@"https://example.com/callback?code=2"]; - - session.resumeResult = NO; - NSError *error = nil; - XCTAssertFalse([session resumeExternalUserAgentFlowWithURL:firstURL error:&error]); - XCTAssertEqualObjects(session.lastResumedURL, firstURL); - XCTAssertEqualObjects(error.domain, OIDGeneralErrorDomain); - XCTAssertEqual(error.code, OIDErrorCodeURLMismatch); - - session.resumeResult = YES; - error = nil; - XCTAssertTrue([session resumeExternalUserAgentFlowWithURL:secondURL error:&error]); - XCTAssertEqualObjects(session.lastResumedURL, secondURL); - XCTAssertNil(error); -} - @end From 264000f4185521c4d20e06f8e21c78341ead9049 Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Wed, 11 Nov 2026 13:29:25 -0800 Subject: [PATCH 03/13] g-orchestrated: add the fake service and its tests to the Xcode test targets --- AppAuth.xcodeproj/project.pbxproj | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/AppAuth.xcodeproj/project.pbxproj b/AppAuth.xcodeproj/project.pbxproj index 0c1afb824..879b71081 100644 --- a/AppAuth.xcodeproj/project.pbxproj +++ b/AppAuth.xcodeproj/project.pbxproj @@ -551,6 +551,7 @@ 34D5EC451E6D1AD900814354 /* OIDSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D5EC441E6D1AD900814354 /* OIDSwiftTests.swift */; }; 34FEA6AE1DB6E083005C9212 /* OIDLoopbackHTTPServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 34FEA6AC1DB6E083005C9212 /* OIDLoopbackHTTPServer.h */; }; 34FEA6AF1DB6E083005C9212 /* OIDLoopbackHTTPServer.m in Sources */ = {isa = PBXBuildFile; fileRef = 34FEA6AD1DB6E083005C9212 /* OIDLoopbackHTTPServer.m */; }; + 3FCB7E7F03D56BFC508468CC /* OIDFakeAuthorizationService.m in Sources */ = {isa = PBXBuildFile; fileRef = 98F28C97D4A3EC0E6491BA78 /* OIDFakeAuthorizationService.m */; }; 4042060AFEB6D5DE8A86B483 /* OIDAuthorizationServiceInstanceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 459EB273F7CD3FCE6BEA1EA9 /* OIDAuthorizationServiceInstanceTests.m */; }; 55A094CF20DFBB10000045D1 /* OIDURLSessionProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 039697441FA8258D003D1FB2 /* OIDURLSessionProvider.h */; settings = {ATTRIBUTES = (Public, ); }; }; 55A094D020DFBB11000045D1 /* OIDURLSessionProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 039697441FA8258D003D1FB2 /* OIDURLSessionProvider.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -564,6 +565,7 @@ 60140F861DE43CC700DA0DC3 /* OIDRegistrationResponseTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 60140F851DE43CC700DA0DC3 /* OIDRegistrationResponseTests.m */; }; 6BAAE1371FA75D57506027DB /* OIDFakeExternalUserAgentSession.m in Sources */ = {isa = PBXBuildFile; fileRef = B5FB594568F5DAA341E261F5 /* OIDFakeExternalUserAgentSession.m */; }; 6C9154FEA8F907C759672BD2 /* OIDFakeExternalUserAgentSession.m in Sources */ = {isa = PBXBuildFile; fileRef = B5FB594568F5DAA341E261F5 /* OIDFakeExternalUserAgentSession.m */; }; + 6EC35A668CCAE107D5C4F983 /* OIDFakeAuthorizationService.m in Sources */ = {isa = PBXBuildFile; fileRef = 98F28C97D4A3EC0E6491BA78 /* OIDFakeAuthorizationService.m */; }; 73F574342B7C42690023FFF0 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 73F574332B7C42690023FFF0 /* PrivacyInfo.xcprivacy */; }; 73F574352B7C42690023FFF0 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 73F574332B7C42690023FFF0 /* PrivacyInfo.xcprivacy */; }; 73F574362B7C42690023FFF0 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 73F574332B7C42690023FFF0 /* PrivacyInfo.xcprivacy */; }; @@ -572,6 +574,9 @@ 73F574392B7C42690023FFF0 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 73F574332B7C42690023FFF0 /* PrivacyInfo.xcprivacy */; }; 7C8FC04BF7D3FA45950EEDC3 /* OIDFakeExternalUserAgentSessionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 006AFE509B9AA12E7203154D /* OIDFakeExternalUserAgentSessionTests.m */; }; 7F1EA0AC51A93928019E09BF /* OIDFakeExternalUserAgentSession.m in Sources */ = {isa = PBXBuildFile; fileRef = B5FB594568F5DAA341E261F5 /* OIDFakeExternalUserAgentSession.m */; }; + 7F9FD7EBFBC828904F80547A /* OIDFakeAuthorizationService.m in Sources */ = {isa = PBXBuildFile; fileRef = 98F28C97D4A3EC0E6491BA78 /* OIDFakeAuthorizationService.m */; }; + 869B3B05A87137E1D0085826 /* OIDFakeAuthorizationServiceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 606F68661B550F6F822BE4C8 /* OIDFakeAuthorizationServiceTests.m */; }; + 987F98D95DC498D36CEBA89B /* OIDFakeAuthorizationService.m in Sources */ = {isa = PBXBuildFile; fileRef = 98F28C97D4A3EC0E6491BA78 /* OIDFakeAuthorizationService.m */; }; 9BE107A4CCBF0579E2354D3B /* OIDAuthorizationServiceInstanceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 459EB273F7CD3FCE6BEA1EA9 /* OIDAuthorizationServiceInstanceTests.m */; }; A592292659F68909AE332653 /* OIDFakeExternalUserAgentSessionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 006AFE509B9AA12E7203154D /* OIDFakeExternalUserAgentSessionTests.m */; }; A5EEF29720D821120044F470 /* OIDTokenUtilitiesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = A5EEF1FD20CF07760044F470 /* OIDTokenUtilitiesTests.m */; }; @@ -620,12 +625,17 @@ A6DEABB52018ECF30022AC32 /* OIDEndSessionResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = CF6431F21F228A980075B6B5 /* OIDEndSessionResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; A6DEABB62018ECF30022AC32 /* OIDEndSessionResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = CF6431F21F228A980075B6B5 /* OIDEndSessionResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; A6DEABB72018ECF40022AC32 /* OIDEndSessionResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = CF6431F21F228A980075B6B5 /* OIDEndSessionResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; + AA05B11331E4CEE5BFCC6046 /* OIDFakeAuthorizationServiceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 606F68661B550F6F822BE4C8 /* OIDFakeAuthorizationServiceTests.m */; }; ABC445C387A0FBA5E0F2ED72 /* OIDFakeExternalUserAgentSession.m in Sources */ = {isa = PBXBuildFile; fileRef = B5FB594568F5DAA341E261F5 /* OIDFakeExternalUserAgentSession.m */; }; B794C1C6F75082B099F84438 /* OIDFakeExternalUserAgentSessionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 006AFE509B9AA12E7203154D /* OIDFakeExternalUserAgentSessionTests.m */; }; + B7DAD3185B79D5D8FE503603 /* OIDFakeAuthorizationServiceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 606F68661B550F6F822BE4C8 /* OIDFakeAuthorizationServiceTests.m */; }; + B99F22B7DECC1FEDBD38FFBC /* OIDFakeAuthorizationService.m in Sources */ = {isa = PBXBuildFile; fileRef = 98F28C97D4A3EC0E6491BA78 /* OIDFakeAuthorizationService.m */; }; + C0CC1373332B72C28D75D56E /* OIDFakeAuthorizationServiceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 606F68661B550F6F822BE4C8 /* OIDFakeAuthorizationServiceTests.m */; }; C14E3B6827E3BEFB00CF05A9 /* OIDExternalUserAgentIOSCustomBrowser.h in Headers */ = {isa = PBXBuildFile; fileRef = C14E3B6627E3BEFB00CF05A9 /* OIDExternalUserAgentIOSCustomBrowser.h */; settings = {ATTRIBUTES = (Public, ); }; }; C14E3B6927E3BEFB00CF05A9 /* OIDExternalUserAgentIOSCustomBrowser.m in Sources */ = {isa = PBXBuildFile; fileRef = C14E3B6727E3BEFB00CF05A9 /* OIDExternalUserAgentIOSCustomBrowser.m */; }; C14E3B6A27E3BFB800CF05A9 /* OIDExternalUserAgentIOSCustomBrowser.m in Sources */ = {isa = PBXBuildFile; fileRef = C14E3B6727E3BEFB00CF05A9 /* OIDExternalUserAgentIOSCustomBrowser.m */; }; C278E4687E3AD74270EF88DA /* OIDFakeExternalUserAgentSessionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 006AFE509B9AA12E7203154D /* OIDFakeExternalUserAgentSessionTests.m */; }; + CF1C5DEAA01896E9EBBEC074 /* OIDFakeAuthorizationServiceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 606F68661B550F6F822BE4C8 /* OIDFakeAuthorizationServiceTests.m */; }; CF37C06E1F1FC21A00662E41 /* OIDEndSessionRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = CF37C06C1F1FC21A00662E41 /* OIDEndSessionRequest.m */; }; CF37C06F1F1FC21A00662E41 /* OIDEndSessionRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = CF37C06C1F1FC21A00662E41 /* OIDEndSessionRequest.m */; }; CF37C0701F1FC21A00662E41 /* OIDEndSessionRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = CF37C06C1F1FC21A00662E41 /* OIDEndSessionRequest.m */; }; @@ -633,8 +643,10 @@ CF6431F41F228A980075B6B5 /* OIDEndSessionResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = CF6431F31F228A980075B6B5 /* OIDEndSessionResponse.m */; }; D07958F60AC2A47A79500914 /* OIDFakeExternalUserAgentSession.m in Sources */ = {isa = PBXBuildFile; fileRef = B5FB594568F5DAA341E261F5 /* OIDFakeExternalUserAgentSession.m */; }; DD05E93BBBA3AB6BF88CAB8D /* OIDAuthorizationServiceInstanceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 459EB273F7CD3FCE6BEA1EA9 /* OIDAuthorizationServiceInstanceTests.m */; }; + DD8D4B26F435BEF787C63052 /* OIDFakeAuthorizationService.m in Sources */ = {isa = PBXBuildFile; fileRef = 98F28C97D4A3EC0E6491BA78 /* OIDFakeAuthorizationService.m */; }; E56963F03064815800AC4DFE /* OIDExternalUserAgentIOSTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E56963EF3064815800AC4DFE /* OIDExternalUserAgentIOSTests.m */; }; E56963F13064815800AC4DFE /* OIDExternalUserAgentIOSTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E56963EF3064815800AC4DFE /* OIDExternalUserAgentIOSTests.m */; }; + EB66273FF8DFEFBB0871BDE6 /* OIDFakeAuthorizationServiceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 606F68661B550F6F822BE4C8 /* OIDFakeAuthorizationServiceTests.m */; }; F1A717E418CCA5400B300540 /* OIDAuthorizationServiceInstanceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 459EB273F7CD3FCE6BEA1EA9 /* OIDAuthorizationServiceInstanceTests.m */; }; F7DA76425730ACDA2D3107BF /* OIDFakeExternalUserAgentSession.m in Sources */ = {isa = PBXBuildFile; fileRef = B5FB594568F5DAA341E261F5 /* OIDFakeExternalUserAgentSession.m */; }; F9A7082E2355ED74004B3E6D /* OIDExternalUserAgentCatalyst.h in Headers */ = {isa = PBXBuildFile; fileRef = F9A7082C2355ED74004B3E6D /* OIDExternalUserAgentCatalyst.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -869,8 +881,11 @@ 60140F821DE43BAF00DA0DC3 /* OIDRegistrationRequestTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OIDRegistrationRequestTests.m; sourceTree = ""; }; 60140F841DE43C8C00DA0DC3 /* OIDRegistrationResponseTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OIDRegistrationResponseTests.h; sourceTree = ""; }; 60140F851DE43CC700DA0DC3 /* OIDRegistrationResponseTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OIDRegistrationResponseTests.m; sourceTree = ""; }; + 606F68661B550F6F822BE4C8 /* OIDFakeAuthorizationServiceTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OIDFakeAuthorizationServiceTests.m; sourceTree = ""; }; + 6314127B4C217751880C08C6 /* OIDFakeAuthorizationService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OIDFakeAuthorizationService.h; sourceTree = ""; }; 73F574332B7C42690023FFF0 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 988AF8BA66200AFC0A60FB14 /* AppAuthTestHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppAuthTestHelpers.h; sourceTree = ""; }; + 98F28C97D4A3EC0E6491BA78 /* OIDFakeAuthorizationService.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OIDFakeAuthorizationService.m; sourceTree = ""; }; A5EEF1FD20CF07760044F470 /* OIDTokenUtilitiesTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OIDTokenUtilitiesTests.m; sourceTree = ""; }; A6CEB1172007E384009D492A /* OIDEndSessionRequestTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OIDEndSessionRequestTests.h; sourceTree = ""; }; A6CEB1182007E384009D492A /* OIDEndSessionRequestTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OIDEndSessionRequestTests.m; sourceTree = ""; }; @@ -1172,6 +1187,7 @@ 3417420C1C5D82D3000EF209 /* OIDServiceDiscoveryTests.m */, 0A987C0100000001000A0987 /* OIDAuthorizationServiceTests.m */, 459EB273F7CD3FCE6BEA1EA9 /* OIDAuthorizationServiceInstanceTests.m */, + 606F68661B550F6F822BE4C8 /* OIDFakeAuthorizationServiceTests.m */, 006AFE509B9AA12E7203154D /* OIDFakeExternalUserAgentSessionTests.m */, 3417420D1C5D82D3000EF209 /* OIDTokenRequestTests.h */, 3417420E1C5D82D3000EF209 /* OIDTokenRequestTests.m */, @@ -1329,6 +1345,8 @@ isa = PBXGroup; children = ( 988AF8BA66200AFC0A60FB14 /* AppAuthTestHelpers.h */, + 6314127B4C217751880C08C6 /* OIDFakeAuthorizationService.h */, + 98F28C97D4A3EC0E6491BA78 /* OIDFakeAuthorizationService.m */, EAB1B3CDF2B7C7405D39FD8F /* OIDFakeExternalUserAgentSession.h */, B5FB594568F5DAA341E261F5 /* OIDFakeExternalUserAgentSession.m */, ); @@ -2272,6 +2290,8 @@ F1A717E418CCA5400B300540 /* OIDAuthorizationServiceInstanceTests.m in Sources */, 7F1EA0AC51A93928019E09BF /* OIDFakeExternalUserAgentSession.m in Sources */, B794C1C6F75082B099F84438 /* OIDFakeExternalUserAgentSessionTests.m in Sources */, + 987F98D95DC498D36CEBA89B /* OIDFakeAuthorizationService.m in Sources */, + B7DAD3185B79D5D8FE503603 /* OIDFakeAuthorizationServiceTests.m in Sources */, 3417421F1C5D82D3000EF209 /* OIDTokenRequestTests.m in Sources */, 341742181C5D82D3000EF209 /* OIDAuthorizationResponseTests.m in Sources */, 34A6638B1E8865090060B664 /* OIDRPProfileCode.m in Sources */, @@ -2303,6 +2323,8 @@ DD05E93BBBA3AB6BF88CAB8D /* OIDAuthorizationServiceInstanceTests.m in Sources */, F7DA76425730ACDA2D3107BF /* OIDFakeExternalUserAgentSession.m in Sources */, C278E4687E3AD74270EF88DA /* OIDFakeExternalUserAgentSessionTests.m in Sources */, + 7F9FD7EBFBC828904F80547A /* OIDFakeAuthorizationService.m in Sources */, + C0CC1373332B72C28D75D56E /* OIDFakeAuthorizationServiceTests.m in Sources */, 341AA5071E7F3A9B00FCA5C6 /* OIDAuthStateTests.m in Sources */, 341AA50E1E7F3A9B00FCA5C6 /* OIDTokenResponseTests.m in Sources */, 341AA50D1E7F3A9B00FCA5C6 /* OIDTokenRequestTests.m in Sources */, @@ -2330,6 +2352,8 @@ 5DEEE663EDB0D4A1C1118284 /* OIDAuthorizationServiceInstanceTests.m in Sources */, D07958F60AC2A47A79500914 /* OIDFakeExternalUserAgentSession.m in Sources */, 7C8FC04BF7D3FA45950EEDC3 /* OIDFakeExternalUserAgentSessionTests.m in Sources */, + B99F22B7DECC1FEDBD38FFBC /* OIDFakeAuthorizationService.m in Sources */, + AA05B11331E4CEE5BFCC6046 /* OIDFakeAuthorizationServiceTests.m in Sources */, 341AA4FA1E7F3A9400FCA5C6 /* OIDAuthStateTests.m in Sources */, 341AA5011E7F3A9400FCA5C6 /* OIDTokenResponseTests.m in Sources */, 341AA5001E7F3A9400FCA5C6 /* OIDTokenRequestTests.m in Sources */, @@ -2460,6 +2484,8 @@ 4042060AFEB6D5DE8A86B483 /* OIDAuthorizationServiceInstanceTests.m in Sources */, ABC445C387A0FBA5E0F2ED72 /* OIDFakeExternalUserAgentSession.m in Sources */, 1F3A45649A64B5C1937E5920 /* OIDFakeExternalUserAgentSessionTests.m in Sources */, + 6EC35A668CCAE107D5C4F983 /* OIDFakeAuthorizationService.m in Sources */, + 869B3B05A87137E1D0085826 /* OIDFakeAuthorizationServiceTests.m in Sources */, 343AAA751E8346B400F9D36E /* OIDAuthStateTests.m in Sources */, 343AAA7C1E8346B400F9D36E /* OIDTokenResponseTests.m in Sources */, 343AAA7B1E8346B400F9D36E /* OIDTokenRequestTests.m in Sources */, @@ -2551,6 +2577,8 @@ 1AB85393A09567E7CBB687AE /* OIDAuthorizationServiceInstanceTests.m in Sources */, 6BAAE1371FA75D57506027DB /* OIDFakeExternalUserAgentSession.m in Sources */, 0C2B4674EA8DD9B5FFCD7FD0 /* OIDFakeExternalUserAgentSessionTests.m in Sources */, + DD8D4B26F435BEF787C63052 /* OIDFakeAuthorizationService.m in Sources */, + CF1C5DEAA01896E9EBBEC074 /* OIDFakeAuthorizationServiceTests.m in Sources */, 343AAB811E8349CE00F9D36E /* OIDAuthStateTests.m in Sources */, 343AAB881E8349CE00F9D36E /* OIDTokenResponseTests.m in Sources */, 343AAB871E8349CE00F9D36E /* OIDTokenRequestTests.m in Sources */, @@ -2615,6 +2643,8 @@ 9BE107A4CCBF0579E2354D3B /* OIDAuthorizationServiceInstanceTests.m in Sources */, 6C9154FEA8F907C759672BD2 /* OIDFakeExternalUserAgentSession.m in Sources */, A592292659F68909AE332653 /* OIDFakeExternalUserAgentSessionTests.m in Sources */, + 3FCB7E7F03D56BFC508468CC /* OIDFakeAuthorizationService.m in Sources */, + EB66273FF8DFEFBB0871BDE6 /* OIDFakeAuthorizationServiceTests.m in Sources */, 343AAB8F1E8349CF00F9D36E /* OIDAuthStateTests.m in Sources */, 343AAB961E8349CF00F9D36E /* OIDTokenResponseTests.m in Sources */, 343AAB951E8349CF00F9D36E /* OIDTokenRequestTests.m in Sources */, From 3cf759d6d36346f3eb68a438a61a91821a5f08ae Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Wed, 11 Nov 2026 13:59:57 -0800 Subject: [PATCH 04/13] g-orchestrated: clear the fake's kept callbacks once invoked --- .../OIDFakeAuthorizationService.h | 8 ++- .../OIDFakeAuthorizationService.m | 62 +++++++++++++++++-- UnitTests/OIDFakeAuthorizationServiceTests.m | 61 ++++++++++++++++++ 3 files changed, 123 insertions(+), 8 deletions(-) diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h index 504146819..bdb9497b5 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h @@ -28,6 +28,8 @@ NS_ASSUME_NONNULL_BEGIN @discussion Inject an instance where production code would otherwise call the class methods of @c OIDAuthorizationService. The class methods of this fake are inherited unchanged and still perform real work; only the instance methods are faked. + A kept callback clears itself once invoked. Callbacks usually capture the caller, and the + caller often holds this fake. Keeping the callback would leak both. */ @interface OIDFakeAuthorizationService : OIDAuthorizationService @@ -43,6 +45,7 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, readonly, nullable) id lastExternalUserAgent; /*! @brief The callback of the most recent authorization request. Invoke it to complete the flow. + Becomes nil once invoked. */ @property(nonatomic, readonly, copy, nullable) OIDAuthorizationCallback lastAuthorizationCallback; @@ -55,7 +58,7 @@ NS_ASSUME_NONNULL_BEGIN */ @property(nonatomic, readonly, nullable) OIDEndSessionRequest *lastEndSessionRequest; -/*! @brief The callback of the most recent end-session request. +/*! @brief The callback of the most recent end-session request. Becomes nil once invoked. */ @property(nonatomic, readonly, copy, nullable) OIDEndSessionCallback lastEndSessionCallback; @@ -74,6 +77,7 @@ NS_ASSUME_NONNULL_BEGIN OIDAuthorizationResponse *lastOriginalAuthorizationResponse; /*! @brief The callback of the most recent token request. Invoke it to complete the request. + Becomes nil once invoked. */ @property(nonatomic, readonly, copy, nullable) OIDTokenCallback lastTokenCallback; @@ -81,7 +85,7 @@ NS_ASSUME_NONNULL_BEGIN */ @property(nonatomic, readonly, nullable) OIDRegistrationRequest *lastRegistrationRequest; -/*! @brief The completion of the most recent registration request. +/*! @brief The completion of the most recent registration request. Becomes nil once invoked. */ @property(nonatomic, readonly, copy, nullable) OIDRegistrationCompletion lastRegistrationCompletion; diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m index 68a443282..258390edf 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m @@ -21,21 +21,46 @@ #import "OIDAuthorizationRequest.h" #import "OIDAuthorizationResponse.h" #import "OIDEndSessionRequest.h" +#import "OIDEndSessionResponse.h" #import "OIDExternalUserAgent.h" #import "OIDRegistrationRequest.h" +#import "OIDRegistrationResponse.h" #import "OIDTokenRequest.h" +#import "OIDTokenResponse.h" NS_ASSUME_NONNULL_BEGIN -@implementation OIDFakeAuthorizationService +@implementation OIDFakeAuthorizationService { + /*! @brief How many authorization requests have been made. A kept callback checks it, so an + older callback doesn't clear a newer one. + */ + NSUInteger _authorizationRequestCount; + + /*! @brief How many end-session requests have been made. Used the same way. + */ + NSUInteger _endSessionRequestCount; + + /*! @brief How many registration requests have been made. Used the same way. + */ + NSUInteger _registrationRequestCount; +} - (id) presentAuthorizationRequest:(OIDAuthorizationRequest *)request externalUserAgent:(id)externalUserAgent callback:(OIDAuthorizationCallback)callback { + NSUInteger requestNumber = ++_authorizationRequestCount; + __weak OIDFakeAuthorizationService *weakSelf = self; _lastAuthorizationRequest = request; _lastExternalUserAgent = externalUserAgent; - _lastAuthorizationCallback = [callback copy]; + _lastAuthorizationCallback = ^(OIDAuthorizationResponse *_Nullable authorizationResponse, + NSError *_Nullable error) { + callback(authorizationResponse, error); + OIDFakeAuthorizationService *strongSelf = weakSelf; + if (strongSelf && strongSelf->_authorizationRequestCount == requestNumber) { + strongSelf->_lastAuthorizationCallback = nil; + } + }; _lastAuthorizationSession = [[OIDFakeExternalUserAgentSession alloc] init]; return _lastAuthorizationSession; } @@ -44,24 +69,49 @@ @implementation OIDFakeAuthorizationService presentEndSessionRequest:(OIDEndSessionRequest *)request externalUserAgent:(id)externalUserAgent callback:(OIDEndSessionCallback)callback { + NSUInteger requestNumber = ++_endSessionRequestCount; + __weak OIDFakeAuthorizationService *weakSelf = self; _lastEndSessionRequest = request; - _lastEndSessionCallback = [callback copy]; + _lastEndSessionCallback = ^(OIDEndSessionResponse *_Nullable endSessionResponse, + NSError *_Nullable error) { + callback(endSessionResponse, error); + OIDFakeAuthorizationService *strongSelf = weakSelf; + if (strongSelf && strongSelf->_endSessionRequestCount == requestNumber) { + strongSelf->_lastEndSessionCallback = nil; + } + }; return [[OIDFakeExternalUserAgentSession alloc] init]; } - (void)performTokenRequest:(OIDTokenRequest *)request originalAuthorizationResponse:(nullable OIDAuthorizationResponse *)authorizationResponse callback:(OIDTokenCallback)callback { - _tokenRequestCount++; + NSUInteger requestNumber = ++_tokenRequestCount; + __weak OIDFakeAuthorizationService *weakSelf = self; _lastTokenRequest = request; _lastOriginalAuthorizationResponse = authorizationResponse; - _lastTokenCallback = [callback copy]; + _lastTokenCallback = ^(OIDTokenResponse *_Nullable tokenResponse, NSError *_Nullable error) { + callback(tokenResponse, error); + OIDFakeAuthorizationService *strongSelf = weakSelf; + if (strongSelf && strongSelf->_tokenRequestCount == requestNumber) { + strongSelf->_lastTokenCallback = nil; + } + }; } - (void)performRegistrationRequest:(OIDRegistrationRequest *)request completion:(OIDRegistrationCompletion)completion { + NSUInteger requestNumber = ++_registrationRequestCount; + __weak OIDFakeAuthorizationService *weakSelf = self; _lastRegistrationRequest = request; - _lastRegistrationCompletion = [completion copy]; + _lastRegistrationCompletion = ^(OIDRegistrationResponse *_Nullable registrationResponse, + NSError *_Nullable error) { + completion(registrationResponse, error); + OIDFakeAuthorizationService *strongSelf = weakSelf; + if (strongSelf && strongSelf->_registrationRequestCount == requestNumber) { + strongSelf->_lastRegistrationCompletion = nil; + } + }; } @end diff --git a/UnitTests/OIDFakeAuthorizationServiceTests.m b/UnitTests/OIDFakeAuthorizationServiceTests.m index 905a5b3e9..d69196435 100644 --- a/UnitTests/OIDFakeAuthorizationServiceTests.m +++ b/UnitTests/OIDFakeAuthorizationServiceTests.m @@ -125,4 +125,65 @@ - (void)testPresentAuthorizationRequestReturnsFakeSession { XCTAssertFalse(callbackInvoked); } +/*! @brief Invoking the kept token callback clears it, and the fake stops holding what it captured. + */ +- (void)testInvokingTokenCallbackClearsIt { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + __weak NSObject *weakCaptured = nil; + @autoreleasepool { + NSObject *captured = [[NSObject alloc] init]; + weakCaptured = captured; + [service performTokenRequest:[OIDTokenRequestTests testInstance] + callback:^(OIDTokenResponse *_Nullable tokenResponse, + NSError *_Nullable error) { + (void)captured; + }]; + service.lastTokenCallback(nil, nil); + } + XCTAssertNil(service.lastTokenCallback); + XCTAssertNil(weakCaptured); +} + +/*! @brief Invoking the kept authorization callback clears it, and the fake stops holding what it + captured. + */ +- (void)testInvokingAuthorizationCallbackClearsIt { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + OIDNoOpExternalUserAgent *userAgent = [[OIDNoOpExternalUserAgent alloc] init]; + __weak NSObject *weakCaptured = nil; + @autoreleasepool { + NSObject *captured = [[NSObject alloc] init]; + weakCaptured = captured; + [service presentAuthorizationRequest:[OIDAuthorizationRequestTests testInstance] + externalUserAgent:userAgent + callback:^(OIDAuthorizationResponse *_Nullable response, + NSError *_Nullable error) { + (void)captured; + }]; + service.lastAuthorizationCallback(nil, nil); + } + XCTAssertNil(service.lastAuthorizationCallback); + XCTAssertNil(weakCaptured); +} + +/*! @brief Invoking an older kept callback leaves the newer one in place. + */ +- (void)testInvokingOlderTokenCallbackKeepsNewerOne { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + OIDTokenRequest *request = [OIDTokenRequestTests testInstance]; + [service performTokenRequest:request + callback:^(OIDTokenResponse *_Nullable tokenResponse, + NSError *_Nullable error) { + }]; + OIDTokenCallback olderCallback = service.lastTokenCallback; + [service performTokenRequest:request + callback:^(OIDTokenResponse *_Nullable tokenResponse, + NSError *_Nullable error) { + }]; + OIDTokenCallback newerCallback = service.lastTokenCallback; + + olderCallback(nil, nil); + XCTAssertEqual(service.lastTokenCallback, newerCallback); +} + @end From dc9df2e9ea9ef16b4c8207a38b5e883837b6921c Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:29:23 -0800 Subject: [PATCH 05/13] g-orchestrated: make the fake service an NSObject that conforms to the protocols --- Package.swift | 2 +- .../OIDFakeAuthorizationService.h | 41 +++++++-- .../OIDFakeAuthorizationService.m | 87 ++++++++++++++++++ UnitTests/OIDFakeAuthorizationServiceTests.m | 89 +++++++++++++++++++ 4 files changed, 212 insertions(+), 7 deletions(-) diff --git a/Package.swift b/Package.swift index a04ffee9e..bd1a6765b 100644 --- a/Package.swift +++ b/Package.swift @@ -72,7 +72,7 @@ let package = Package( ), .target( name: "AppAuthTestHelpers", - dependencies: ["AppAuthCore"], + dependencies: ["AppAuthCore", "AppAuth"], path: "Sources/AppAuthTestHelpers", publicHeadersPath: "" ), diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h index bdb9497b5..116aad7e5 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h @@ -17,21 +17,28 @@ */ #import +#import #import "OIDAuthorizationService.h" #import "OIDFakeExternalUserAgentSession.h" +#if SWIFT_PACKAGE +@import AppAuth; +#else +#import "OIDAuthorizationService+IOS.h" +#import "OIDAuthorizationService+Mac.h" +#endif + NS_ASSUME_NONNULL_BEGIN -/*! @brief An @c OIDAuthorizationService whose instance methods record their arguments and keep the +/*! @brief An @c OIDAuthorizationServiceProtocol whose methods record their arguments and keep the callbacks for the test to invoke, instead of presenting UI or making network requests. - @discussion Inject an instance where production code would otherwise call the class methods of - @c OIDAuthorizationService. The class methods of this fake are inherited unchanged and still - perform real work; only the instance methods are faked. + @discussion Inject an instance where production code takes an + @c id. A kept callback clears itself once invoked. Callbacks usually capture the caller, and the caller often holds this fake. Keeping the callback would leak both. */ -@interface OIDFakeAuthorizationService : OIDAuthorizationService +@interface OIDFakeAuthorizationService : NSObject /*! @brief The request passed to the most recent @c -presentAuthorizationRequest:externalUserAgent:callback:. @@ -39,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, readonly, nullable) OIDAuthorizationRequest *lastAuthorizationRequest; /*! @brief The external user agent passed to the most recent authorization request. For the - platform convenience methods, this is the agent AppAuth built for the caller's view + platform convenience methods, this is the agent AppAuth would build for the caller's view controller or window. */ @property(nonatomic, readonly, nullable) id lastExternalUserAgent; @@ -91,4 +98,26 @@ NS_ASSUME_NONNULL_BEGIN @end +#if TARGET_OS_IOS || TARGET_OS_MACCATALYST + +/*! @brief The iOS convenience methods. Each builds the external user agent AppAuth would build + for the view controller, then records the request like + @c -presentAuthorizationRequest:externalUserAgent:callback:. + */ +@interface OIDFakeAuthorizationService (IOS) +@end + +#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST + +#if TARGET_OS_OSX + +/*! @brief The macOS convenience methods. Each builds the external user agent AppAuth would build + for the window, then records the request like + @c -presentAuthorizationRequest:externalUserAgent:callback:. + */ +@interface OIDFakeAuthorizationService (Mac) +@end + +#endif // TARGET_OS_OSX + NS_ASSUME_NONNULL_END diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m index 258390edf..d3e4348d3 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m @@ -28,6 +28,14 @@ #import "OIDTokenRequest.h" #import "OIDTokenResponse.h" +#if SWIFT_PACKAGE +@import AppAuth; +#else +#import "OIDExternalUserAgentCatalyst.h" +#import "OIDExternalUserAgentIOS.h" +#import "OIDExternalUserAgentMac.h" +#endif + NS_ASSUME_NONNULL_BEGIN @implementation OIDFakeAuthorizationService { @@ -83,6 +91,10 @@ @implementation OIDFakeAuthorizationService { return [[OIDFakeExternalUserAgentSession alloc] init]; } +- (void)performTokenRequest:(OIDTokenRequest *)request callback:(OIDTokenCallback)callback { + [self performTokenRequest:request originalAuthorizationResponse:nil callback:callback]; +} + - (void)performTokenRequest:(OIDTokenRequest *)request originalAuthorizationResponse:(nullable OIDAuthorizationResponse *)authorizationResponse callback:(OIDTokenCallback)callback { @@ -116,4 +128,79 @@ - (void)performRegistrationRequest:(OIDRegistrationRequest *)request @end +#if TARGET_OS_IOS || TARGET_OS_MACCATALYST + +@implementation OIDFakeAuthorizationService (IOS) + +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingViewController:(UIViewController *)presentingViewController + callback:(OIDAuthorizationCallback)callback { +#if TARGET_OS_MACCATALYST + id externalUserAgent = [[OIDExternalUserAgentCatalyst alloc] + initWithPresentingViewController:presentingViewController]; +#else // TARGET_OS_MACCATALYST + id externalUserAgent = [[OIDExternalUserAgentIOS alloc] + initWithPresentingViewController:presentingViewController]; +#endif // TARGET_OS_MACCATALYST + return [self presentAuthorizationRequest:request + externalUserAgent:externalUserAgent + callback:callback]; +} + +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingViewController:(UIViewController *)presentingViewController + prefersEphemeralSession:(BOOL)prefersEphemeralSession + callback:(OIDAuthorizationCallback)callback { +#if TARGET_OS_MACCATALYST + id externalUserAgent = [[OIDExternalUserAgentCatalyst alloc] + initWithPresentingViewController:presentingViewController + prefersEphemeralSession:prefersEphemeralSession]; +#else // TARGET_OS_MACCATALYST + id externalUserAgent = [[OIDExternalUserAgentIOS alloc] + initWithPresentingViewController:presentingViewController + prefersEphemeralSession:prefersEphemeralSession]; +#endif // TARGET_OS_MACCATALYST + return [self presentAuthorizationRequest:request + externalUserAgent:externalUserAgent + callback:callback]; +} + +@end + +#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST + +#if TARGET_OS_OSX + +@implementation OIDFakeAuthorizationService (Mac) + +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingWindow:(NSWindow *)presentingWindow + callback:(OIDAuthorizationCallback)callback { + OIDExternalUserAgentMac *externalUserAgent = + [[OIDExternalUserAgentMac alloc] initWithPresentingWindow:presentingWindow]; + return [self presentAuthorizationRequest:request + externalUserAgent:externalUserAgent + callback:callback]; +} + +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingWindow:(NSWindow *)presentingWindow + prefersEphemeralSession:(BOOL)prefersEphemeralSession + callback:(OIDAuthorizationCallback)callback { + OIDExternalUserAgentMac *externalUserAgent = + [[OIDExternalUserAgentMac alloc] initWithPresentingWindow:presentingWindow + prefersEphemeralSession:prefersEphemeralSession]; + return [self presentAuthorizationRequest:request + externalUserAgent:externalUserAgent + callback:callback]; +} + +@end + +#endif // TARGET_OS_OSX + NS_ASSUME_NONNULL_END diff --git a/UnitTests/OIDFakeAuthorizationServiceTests.m b/UnitTests/OIDFakeAuthorizationServiceTests.m index d69196435..97db9d360 100644 --- a/UnitTests/OIDFakeAuthorizationServiceTests.m +++ b/UnitTests/OIDFakeAuthorizationServiceTests.m @@ -22,6 +22,8 @@ @import AppAuthCore; @import AppAuthTestHelpers; #else +#import "Sources/AppAuth/iOS/OIDExternalUserAgentIOS.h" +#import "Sources/AppAuth/macOS/OIDExternalUserAgentMac.h" #import "Sources/AppAuthCore.h" #import "Sources/AppAuthTestHelpers/AppAuthTestHelpers.h" #endif @@ -186,4 +188,91 @@ - (void)testInvokingOlderTokenCallbackKeepsNewerOne { XCTAssertEqual(service.lastTokenCallback, newerCallback); } +/*! @brief The fake conforms to @c OIDAuthorizationServiceProtocol, and is not an + @c OIDAuthorizationService. + */ +- (void)testFakeConformsToServiceProtocol { + id service = [[OIDFakeAuthorizationService alloc] init]; + XCTAssertTrue([service conformsToProtocol:@protocol(OIDAuthorizationServiceProtocol)]); + XCTAssertFalse([service isKindOfClass:[OIDAuthorizationService class]]); +} + +#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST && !SWIFT_PACKAGE + +/*! @brief The view controller methods record the request with an @c OIDExternalUserAgentIOS for + that view controller. + */ +- (void)testPresentingViewControllerRecordsIOSAgent { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + OIDAuthorizationRequest *request = [OIDAuthorizationRequestTests testInstance]; + UIViewController *viewController = [[UIViewController alloc] init]; + + id session = + [service presentAuthorizationRequest:request + presentingViewController:viewController + callback:^(OIDAuthorizationResponse *_Nullable response, + NSError *_Nullable error) { + }]; + + XCTAssertEqual(service.lastAuthorizationRequest, request); + XCTAssertTrue([service.lastExternalUserAgent isKindOfClass:[OIDExternalUserAgentIOS class]]); + OIDExternalUserAgentIOS *agent = (OIDExternalUserAgentIOS *)service.lastExternalUserAgent; + XCTAssertEqual(agent.presentingViewController, viewController); + XCTAssertNotNil(service.lastAuthorizationCallback); + XCTAssertEqual(session, service.lastAuthorizationSession); + + UIViewController *secondViewController = [[UIViewController alloc] init]; + [service presentAuthorizationRequest:request + presentingViewController:secondViewController + prefersEphemeralSession:YES + callback:^(OIDAuthorizationResponse *_Nullable response, + NSError *_Nullable error) { + }]; + + XCTAssertTrue([service.lastExternalUserAgent isKindOfClass:[OIDExternalUserAgentIOS class]]); + OIDExternalUserAgentIOS *secondAgent = (OIDExternalUserAgentIOS *)service.lastExternalUserAgent; + XCTAssertEqual(secondAgent.presentingViewController, secondViewController); +} + +#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST && !SWIFT_PACKAGE + +#if TARGET_OS_OSX && !SWIFT_PACKAGE + +/*! @brief The window methods record the request with an @c OIDExternalUserAgentMac for that + window. + */ +- (void)testPresentingWindowRecordsMacAgent { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + OIDAuthorizationRequest *request = [OIDAuthorizationRequestTests testInstance]; + NSWindow *window = [[NSWindow alloc] init]; + + id session = + [service presentAuthorizationRequest:request + presentingWindow:window + callback:^(OIDAuthorizationResponse *_Nullable response, + NSError *_Nullable error) { + }]; + + XCTAssertEqual(service.lastAuthorizationRequest, request); + XCTAssertTrue([service.lastExternalUserAgent isKindOfClass:[OIDExternalUserAgentMac class]]); + OIDExternalUserAgentMac *agent = (OIDExternalUserAgentMac *)service.lastExternalUserAgent; + XCTAssertEqual(agent.presentingWindow, window); + XCTAssertNotNil(service.lastAuthorizationCallback); + XCTAssertEqual(session, service.lastAuthorizationSession); + + NSWindow *secondWindow = [[NSWindow alloc] init]; + [service presentAuthorizationRequest:request + presentingWindow:secondWindow + prefersEphemeralSession:YES + callback:^(OIDAuthorizationResponse *_Nullable response, + NSError *_Nullable error) { + }]; + + XCTAssertTrue([service.lastExternalUserAgent isKindOfClass:[OIDExternalUserAgentMac class]]); + OIDExternalUserAgentMac *secondAgent = (OIDExternalUserAgentMac *)service.lastExternalUserAgent; + XCTAssertEqual(secondAgent.presentingWindow, secondWindow); +} + +#endif // TARGET_OS_OSX && !SWIFT_PACKAGE + @end From e64a595669fdba8946fb5334749d03a7cb737193 Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:30:01 -0800 Subject: [PATCH 06/13] g-orchestrated: let app targets import AppAuthTestHelpers --- Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h index 116aad7e5..2117e3a15 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h @@ -22,11 +22,14 @@ #import "OIDAuthorizationService.h" #import "OIDFakeExternalUserAgentSession.h" -#if SWIFT_PACKAGE -@import AppAuth; -#else +// Apps that use the Swift package don't define SWIFT_PACKAGE. Check for the header instead. +// AppAuth.xcodeproj finds these headers by name, and the package finds them by directory. +#if __has_include("OIDAuthorizationService+IOS.h") #import "OIDAuthorizationService+IOS.h" #import "OIDAuthorizationService+Mac.h" +#else +#import "iOS/OIDAuthorizationService+IOS.h" +#import "macOS/OIDAuthorizationService+Mac.h" #endif NS_ASSUME_NONNULL_BEGIN From 8ff4bdf19821514a9cc185b4ed1ab008b865dcdc Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:30:01 -0800 Subject: [PATCH 07/13] g-orchestrated: keep the end-session user agent and session in the fake --- Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h | 8 ++++++++ Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h index 2117e3a15..ac5920da4 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h @@ -68,10 +68,18 @@ NS_ASSUME_NONNULL_BEGIN */ @property(nonatomic, readonly, nullable) OIDEndSessionRequest *lastEndSessionRequest; +/*! @brief The external user agent passed to the most recent end-session request. + */ +@property(nonatomic, readonly, nullable) id lastEndSessionExternalUserAgent; + /*! @brief The callback of the most recent end-session request. Becomes nil once invoked. */ @property(nonatomic, readonly, copy, nullable) OIDEndSessionCallback lastEndSessionCallback; +/*! @brief The session returned from the most recent end-session request. + */ +@property(nonatomic, readonly, nullable) OIDFakeExternalUserAgentSession *lastEndSessionSession; + /*! @brief How many token requests have been performed. */ @property(nonatomic, readonly) NSUInteger tokenRequestCount; diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m index d3e4348d3..c649d2a8c 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m @@ -80,6 +80,7 @@ @implementation OIDFakeAuthorizationService { NSUInteger requestNumber = ++_endSessionRequestCount; __weak OIDFakeAuthorizationService *weakSelf = self; _lastEndSessionRequest = request; + _lastEndSessionExternalUserAgent = externalUserAgent; _lastEndSessionCallback = ^(OIDEndSessionResponse *_Nullable endSessionResponse, NSError *_Nullable error) { callback(endSessionResponse, error); @@ -88,7 +89,8 @@ @implementation OIDFakeAuthorizationService { strongSelf->_lastEndSessionCallback = nil; } }; - return [[OIDFakeExternalUserAgentSession alloc] init]; + _lastEndSessionSession = [[OIDFakeExternalUserAgentSession alloc] init]; + return _lastEndSessionSession; } - (void)performTokenRequest:(OIDTokenRequest *)request callback:(OIDTokenCallback)callback { From 7390e76756b3075bf0833f534b6dfa7d321971ac Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:30:01 -0800 Subject: [PATCH 08/13] g-orchestrated: test the fake's end-session and registration methods --- UnitTests/OIDFakeAuthorizationServiceTests.m | 144 +++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/UnitTests/OIDFakeAuthorizationServiceTests.m b/UnitTests/OIDFakeAuthorizationServiceTests.m index 97db9d360..43d1cc3d4 100644 --- a/UnitTests/OIDFakeAuthorizationServiceTests.m +++ b/UnitTests/OIDFakeAuthorizationServiceTests.m @@ -29,6 +29,8 @@ #endif #import "OIDAuthorizationRequestTests.h" #import "OIDAuthorizationResponseTests.h" +#import "OIDEndSessionRequestTests.h" +#import "OIDRegistrationRequestTests.h" #import "OIDTokenRequestTests.h" /*! @brief An external user agent that never presents anything. @@ -188,6 +190,148 @@ - (void)testInvokingOlderTokenCallbackKeepsNewerOne { XCTAssertEqual(service.lastTokenCallback, newerCallback); } +/*! @brief An end-session request is recorded and returns a fake session, and invoking the kept + callback reaches the caller. + */ +- (void)testPresentEndSessionRequestIsRecordedAndCallbackIsReturned { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + OIDEndSessionRequest *request = [OIDEndSessionRequestTests testInstance]; + OIDNoOpExternalUserAgent *userAgent = [[OIDNoOpExternalUserAgent alloc] init]; + __block OIDEndSessionResponse *receivedResponse = nil; + __block NSError *receivedError = nil; + + id session = + [service presentEndSessionRequest:request + externalUserAgent:userAgent + callback:^(OIDEndSessionResponse *_Nullable response, + NSError *_Nullable error) { + receivedResponse = response; + receivedError = error; + }]; + + XCTAssertEqual(session, service.lastEndSessionSession); + XCTAssertTrue([session isKindOfClass:[OIDFakeExternalUserAgentSession class]]); + XCTAssertEqual(service.lastEndSessionRequest, request); + XCTAssertEqual(service.lastEndSessionExternalUserAgent, userAgent); + XCTAssertNil(service.lastAuthorizationSession); + XCTAssertNil(service.lastExternalUserAgent); + XCTAssertNotNil(service.lastEndSessionCallback); + + NSError *someError = [NSError errorWithDomain:@"com.example" code:42 userInfo:nil]; + service.lastEndSessionCallback(nil, someError); + XCTAssertNil(receivedResponse); + XCTAssertEqual(receivedError, someError); +} + +/*! @brief Invoking the kept end-session callback clears it, and the fake stops holding what it + captured. + */ +- (void)testInvokingEndSessionCallbackClearsIt { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + OIDNoOpExternalUserAgent *userAgent = [[OIDNoOpExternalUserAgent alloc] init]; + __weak NSObject *weakCaptured = nil; + @autoreleasepool { + NSObject *captured = [[NSObject alloc] init]; + weakCaptured = captured; + [service presentEndSessionRequest:[OIDEndSessionRequestTests testInstance] + externalUserAgent:userAgent + callback:^(OIDEndSessionResponse *_Nullable response, + NSError *_Nullable error) { + (void)captured; + }]; + service.lastEndSessionCallback(nil, nil); + } + XCTAssertNil(service.lastEndSessionCallback); + XCTAssertNil(weakCaptured); +} + +/*! @brief Invoking an older kept end-session callback leaves the newer one in place. + */ +- (void)testInvokingOlderEndSessionCallbackKeepsNewerOne { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + OIDEndSessionRequest *request = [OIDEndSessionRequestTests testInstance]; + OIDNoOpExternalUserAgent *userAgent = [[OIDNoOpExternalUserAgent alloc] init]; + [service presentEndSessionRequest:request + externalUserAgent:userAgent + callback:^(OIDEndSessionResponse *_Nullable response, + NSError *_Nullable error) { + }]; + OIDEndSessionCallback olderCallback = service.lastEndSessionCallback; + [service presentEndSessionRequest:request + externalUserAgent:userAgent + callback:^(OIDEndSessionResponse *_Nullable response, + NSError *_Nullable error) { + }]; + OIDEndSessionCallback newerCallback = service.lastEndSessionCallback; + + olderCallback(nil, nil); + XCTAssertEqual(service.lastEndSessionCallback, newerCallback); +} + +/*! @brief A registration request is recorded, and invoking the kept completion reaches the caller. + */ +- (void)testPerformRegistrationRequestIsRecordedAndCompletionIsReturned { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + OIDRegistrationRequest *request = [OIDRegistrationRequestTests testInstance]; + __block OIDRegistrationResponse *receivedResponse = nil; + __block NSError *receivedError = nil; + + [service performRegistrationRequest:request + completion:^(OIDRegistrationResponse *_Nullable response, + NSError *_Nullable error) { + receivedResponse = response; + receivedError = error; + }]; + + XCTAssertEqual(service.lastRegistrationRequest, request); + XCTAssertNotNil(service.lastRegistrationCompletion); + + NSError *someError = [NSError errorWithDomain:@"com.example" code:42 userInfo:nil]; + service.lastRegistrationCompletion(nil, someError); + XCTAssertNil(receivedResponse); + XCTAssertEqual(receivedError, someError); +} + +/*! @brief Invoking the kept registration completion clears it, and the fake stops holding what it + captured. + */ +- (void)testInvokingRegistrationCompletionClearsIt { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + __weak NSObject *weakCaptured = nil; + @autoreleasepool { + NSObject *captured = [[NSObject alloc] init]; + weakCaptured = captured; + [service performRegistrationRequest:[OIDRegistrationRequestTests testInstance] + completion:^(OIDRegistrationResponse *_Nullable response, + NSError *_Nullable error) { + (void)captured; + }]; + service.lastRegistrationCompletion(nil, nil); + } + XCTAssertNil(service.lastRegistrationCompletion); + XCTAssertNil(weakCaptured); +} + +/*! @brief Invoking an older kept registration completion leaves the newer one in place. + */ +- (void)testInvokingOlderRegistrationCompletionKeepsNewerOne { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + OIDRegistrationRequest *request = [OIDRegistrationRequestTests testInstance]; + [service performRegistrationRequest:request + completion:^(OIDRegistrationResponse *_Nullable response, + NSError *_Nullable error) { + }]; + OIDRegistrationCompletion olderCompletion = service.lastRegistrationCompletion; + [service performRegistrationRequest:request + completion:^(OIDRegistrationResponse *_Nullable response, + NSError *_Nullable error) { + }]; + OIDRegistrationCompletion newerCompletion = service.lastRegistrationCompletion; + + olderCompletion(nil, nil); + XCTAssertEqual(service.lastRegistrationCompletion, newerCompletion); +} + /*! @brief The fake conforms to @c OIDAuthorizationServiceProtocol, and is not an @c OIDAuthorizationService. */ From 5c6d0729771cdd2df030cb7f1b549a05895930e1 Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:45:35 -0800 Subject: [PATCH 09/13] g-orchestrated: rename the fake's lastExternalUserAgent property --- .../OIDFakeAuthorizationService.h | 3 +- .../OIDFakeAuthorizationService.m | 2 +- UnitTests/OIDFakeAuthorizationServiceTests.m | 28 ++++++++++++------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h index ac5920da4..da4d09758 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h @@ -52,7 +52,8 @@ NS_ASSUME_NONNULL_BEGIN platform convenience methods, this is the agent AppAuth would build for the caller's view controller or window. */ -@property(nonatomic, readonly, nullable) id lastExternalUserAgent; +@property(nonatomic, readonly, nullable) + id lastAuthorizationExternalUserAgent; /*! @brief The callback of the most recent authorization request. Invoke it to complete the flow. Becomes nil once invoked. diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m index c649d2a8c..d24267da1 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m @@ -60,7 +60,7 @@ @implementation OIDFakeAuthorizationService { NSUInteger requestNumber = ++_authorizationRequestCount; __weak OIDFakeAuthorizationService *weakSelf = self; _lastAuthorizationRequest = request; - _lastExternalUserAgent = externalUserAgent; + _lastAuthorizationExternalUserAgent = externalUserAgent; _lastAuthorizationCallback = ^(OIDAuthorizationResponse *_Nullable authorizationResponse, NSError *_Nullable error) { callback(authorizationResponse, error); diff --git a/UnitTests/OIDFakeAuthorizationServiceTests.m b/UnitTests/OIDFakeAuthorizationServiceTests.m index 43d1cc3d4..8c18946e4 100644 --- a/UnitTests/OIDFakeAuthorizationServiceTests.m +++ b/UnitTests/OIDFakeAuthorizationServiceTests.m @@ -122,7 +122,7 @@ - (void)testPresentAuthorizationRequestReturnsFakeSession { XCTAssertEqual(session, service.lastAuthorizationSession); XCTAssertTrue([session isKindOfClass:[OIDFakeExternalUserAgentSession class]]); XCTAssertEqual(service.lastAuthorizationRequest, request); - XCTAssertEqual(service.lastExternalUserAgent, userAgent); + XCTAssertEqual(service.lastAuthorizationExternalUserAgent, userAgent); [session cancel]; XCTAssertEqual(service.lastAuthorizationSession.cancelCount, 1u); @@ -214,7 +214,7 @@ - (void)testPresentEndSessionRequestIsRecordedAndCallbackIsReturned { XCTAssertEqual(service.lastEndSessionRequest, request); XCTAssertEqual(service.lastEndSessionExternalUserAgent, userAgent); XCTAssertNil(service.lastAuthorizationSession); - XCTAssertNil(service.lastExternalUserAgent); + XCTAssertNil(service.lastAuthorizationExternalUserAgent); XCTAssertNotNil(service.lastEndSessionCallback); NSError *someError = [NSError errorWithDomain:@"com.example" code:42 userInfo:nil]; @@ -359,8 +359,10 @@ - (void)testPresentingViewControllerRecordsIOSAgent { }]; XCTAssertEqual(service.lastAuthorizationRequest, request); - XCTAssertTrue([service.lastExternalUserAgent isKindOfClass:[OIDExternalUserAgentIOS class]]); - OIDExternalUserAgentIOS *agent = (OIDExternalUserAgentIOS *)service.lastExternalUserAgent; + XCTAssertTrue( + [service.lastAuthorizationExternalUserAgent isKindOfClass:[OIDExternalUserAgentIOS class]]); + OIDExternalUserAgentIOS *agent = + (OIDExternalUserAgentIOS *)service.lastAuthorizationExternalUserAgent; XCTAssertEqual(agent.presentingViewController, viewController); XCTAssertNotNil(service.lastAuthorizationCallback); XCTAssertEqual(session, service.lastAuthorizationSession); @@ -373,8 +375,10 @@ - (void)testPresentingViewControllerRecordsIOSAgent { NSError *_Nullable error) { }]; - XCTAssertTrue([service.lastExternalUserAgent isKindOfClass:[OIDExternalUserAgentIOS class]]); - OIDExternalUserAgentIOS *secondAgent = (OIDExternalUserAgentIOS *)service.lastExternalUserAgent; + XCTAssertTrue( + [service.lastAuthorizationExternalUserAgent isKindOfClass:[OIDExternalUserAgentIOS class]]); + OIDExternalUserAgentIOS *secondAgent = + (OIDExternalUserAgentIOS *)service.lastAuthorizationExternalUserAgent; XCTAssertEqual(secondAgent.presentingViewController, secondViewController); } @@ -398,8 +402,10 @@ - (void)testPresentingWindowRecordsMacAgent { }]; XCTAssertEqual(service.lastAuthorizationRequest, request); - XCTAssertTrue([service.lastExternalUserAgent isKindOfClass:[OIDExternalUserAgentMac class]]); - OIDExternalUserAgentMac *agent = (OIDExternalUserAgentMac *)service.lastExternalUserAgent; + XCTAssertTrue( + [service.lastAuthorizationExternalUserAgent isKindOfClass:[OIDExternalUserAgentMac class]]); + OIDExternalUserAgentMac *agent = + (OIDExternalUserAgentMac *)service.lastAuthorizationExternalUserAgent; XCTAssertEqual(agent.presentingWindow, window); XCTAssertNotNil(service.lastAuthorizationCallback); XCTAssertEqual(session, service.lastAuthorizationSession); @@ -412,8 +418,10 @@ - (void)testPresentingWindowRecordsMacAgent { NSError *_Nullable error) { }]; - XCTAssertTrue([service.lastExternalUserAgent isKindOfClass:[OIDExternalUserAgentMac class]]); - OIDExternalUserAgentMac *secondAgent = (OIDExternalUserAgentMac *)service.lastExternalUserAgent; + XCTAssertTrue( + [service.lastAuthorizationExternalUserAgent isKindOfClass:[OIDExternalUserAgentMac class]]); + OIDExternalUserAgentMac *secondAgent = + (OIDExternalUserAgentMac *)service.lastAuthorizationExternalUserAgent; XCTAssertEqual(secondAgent.presentingWindow, secondWindow); } From 1c046166c84f66e545be43020e6caf3de12a56f2 Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:46:51 -0800 Subject: [PATCH 10/13] g-orchestrated: note in the fake's header what it keeps between requests --- Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h index da4d09758..58f96e2bb 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h @@ -40,6 +40,9 @@ NS_ASSUME_NONNULL_BEGIN @c id. A kept callback clears itself once invoked. Callbacks usually capture the caller, and the caller often holds this fake. Keeping the callback would leak both. + The requests, external user agents and sessions are kept until the next request of that + kind. An agent built by a platform convenience method holds its view controller or window, + so the fake holds it too. Use a new fake for each test. */ @interface OIDFakeAuthorizationService : NSObject From 5bac3e01ed731a8adbbed8b00c1139dbae2bce2b Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:46:51 -0800 Subject: [PATCH 11/13] g-orchestrated: type the fake's Mac user agent local as the protocol --- Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m index d24267da1..772f48551 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m @@ -181,7 +181,7 @@ @implementation OIDFakeAuthorizationService (Mac) presentAuthorizationRequest:(OIDAuthorizationRequest *)request presentingWindow:(NSWindow *)presentingWindow callback:(OIDAuthorizationCallback)callback { - OIDExternalUserAgentMac *externalUserAgent = + id externalUserAgent = [[OIDExternalUserAgentMac alloc] initWithPresentingWindow:presentingWindow]; return [self presentAuthorizationRequest:request externalUserAgent:externalUserAgent @@ -193,7 +193,7 @@ @implementation OIDFakeAuthorizationService (Mac) presentingWindow:(NSWindow *)presentingWindow prefersEphemeralSession:(BOOL)prefersEphemeralSession callback:(OIDAuthorizationCallback)callback { - OIDExternalUserAgentMac *externalUserAgent = + id externalUserAgent = [[OIDExternalUserAgentMac alloc] initWithPresentingWindow:presentingWindow prefersEphemeralSession:prefersEphemeralSession]; return [self presentAuthorizationRequest:request From c7d46b47303921386579a7cdf7cf80fd041d0cd1 Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:46:51 -0800 Subject: [PATCH 12/13] g-orchestrated: test that an older authorization callback keeps the newer one --- UnitTests/OIDFakeAuthorizationServiceTests.m | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/UnitTests/OIDFakeAuthorizationServiceTests.m b/UnitTests/OIDFakeAuthorizationServiceTests.m index 8c18946e4..d4c3d4827 100644 --- a/UnitTests/OIDFakeAuthorizationServiceTests.m +++ b/UnitTests/OIDFakeAuthorizationServiceTests.m @@ -170,6 +170,29 @@ - (void)testInvokingAuthorizationCallbackClearsIt { XCTAssertNil(weakCaptured); } +/*! @brief Invoking an older kept authorization callback leaves the newer one in place. + */ +- (void)testInvokingOlderAuthorizationCallbackKeepsNewerOne { + OIDFakeAuthorizationService *service = [[OIDFakeAuthorizationService alloc] init]; + OIDAuthorizationRequest *request = [OIDAuthorizationRequestTests testInstance]; + OIDNoOpExternalUserAgent *userAgent = [[OIDNoOpExternalUserAgent alloc] init]; + [service presentAuthorizationRequest:request + externalUserAgent:userAgent + callback:^(OIDAuthorizationResponse *_Nullable response, + NSError *_Nullable error) { + }]; + OIDAuthorizationCallback olderCallback = service.lastAuthorizationCallback; + [service presentAuthorizationRequest:request + externalUserAgent:userAgent + callback:^(OIDAuthorizationResponse *_Nullable response, + NSError *_Nullable error) { + }]; + OIDAuthorizationCallback newerCallback = service.lastAuthorizationCallback; + + olderCallback(nil, nil); + XCTAssertEqual(service.lastAuthorizationCallback, newerCallback); +} + /*! @brief Invoking an older kept callback leaves the newer one in place. */ - (void)testInvokingOlderTokenCallbackKeepsNewerOne { From a2dc20e4f78e44ed576fcb91cba9ef86de23a1a9 Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Tue, 24 Nov 2026 21:42:40 -0800 Subject: [PATCH 13/13] g-orchestrated: make the fake's other request counts readable --- .../OIDFakeAuthorizationService.h | 12 ++++++++++++ .../OIDFakeAuthorizationService.m | 15 +-------------- UnitTests/OIDFakeAuthorizationServiceTests.m | 3 +++ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h index 58f96e2bb..e8452c973 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.h @@ -46,6 +46,10 @@ NS_ASSUME_NONNULL_BEGIN */ @interface OIDFakeAuthorizationService : NSObject +/*! @brief How many authorization requests have been presented. + */ +@property(nonatomic, readonly) NSUInteger authorizationRequestCount; + /*! @brief The request passed to the most recent @c -presentAuthorizationRequest:externalUserAgent:callback:. */ @@ -67,6 +71,10 @@ NS_ASSUME_NONNULL_BEGIN */ @property(nonatomic, readonly, nullable) OIDFakeExternalUserAgentSession *lastAuthorizationSession; +/*! @brief How many end-session requests have been presented. + */ +@property(nonatomic, readonly) NSUInteger endSessionRequestCount; + /*! @brief The request passed to the most recent @c -presentEndSessionRequest:externalUserAgent:callback:. */ @@ -103,6 +111,10 @@ NS_ASSUME_NONNULL_BEGIN */ @property(nonatomic, readonly, copy, nullable) OIDTokenCallback lastTokenCallback; +/*! @brief How many registration requests have been performed. + */ +@property(nonatomic, readonly) NSUInteger registrationRequestCount; + /*! @brief The request passed to the most recent @c -performRegistrationRequest:completion:. */ @property(nonatomic, readonly, nullable) OIDRegistrationRequest *lastRegistrationRequest; diff --git a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m index 772f48551..b991f8cad 100644 --- a/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m +++ b/Sources/AppAuthTestHelpers/OIDFakeAuthorizationService.m @@ -38,20 +38,7 @@ NS_ASSUME_NONNULL_BEGIN -@implementation OIDFakeAuthorizationService { - /*! @brief How many authorization requests have been made. A kept callback checks it, so an - older callback doesn't clear a newer one. - */ - NSUInteger _authorizationRequestCount; - - /*! @brief How many end-session requests have been made. Used the same way. - */ - NSUInteger _endSessionRequestCount; - - /*! @brief How many registration requests have been made. Used the same way. - */ - NSUInteger _registrationRequestCount; -} +@implementation OIDFakeAuthorizationService - (id) presentAuthorizationRequest:(OIDAuthorizationRequest *)request diff --git a/UnitTests/OIDFakeAuthorizationServiceTests.m b/UnitTests/OIDFakeAuthorizationServiceTests.m index d4c3d4827..28fd23980 100644 --- a/UnitTests/OIDFakeAuthorizationServiceTests.m +++ b/UnitTests/OIDFakeAuthorizationServiceTests.m @@ -120,6 +120,7 @@ - (void)testPresentAuthorizationRequestReturnsFakeSession { }]; XCTAssertEqual(session, service.lastAuthorizationSession); + XCTAssertEqual(service.authorizationRequestCount, 1u); XCTAssertTrue([session isKindOfClass:[OIDFakeExternalUserAgentSession class]]); XCTAssertEqual(service.lastAuthorizationRequest, request); XCTAssertEqual(service.lastAuthorizationExternalUserAgent, userAgent); @@ -233,6 +234,7 @@ - (void)testPresentEndSessionRequestIsRecordedAndCallbackIsReturned { }]; XCTAssertEqual(session, service.lastEndSessionSession); + XCTAssertEqual(service.endSessionRequestCount, 1u); XCTAssertTrue([session isKindOfClass:[OIDFakeExternalUserAgentSession class]]); XCTAssertEqual(service.lastEndSessionRequest, request); XCTAssertEqual(service.lastEndSessionExternalUserAgent, userAgent); @@ -306,6 +308,7 @@ - (void)testPerformRegistrationRequestIsRecordedAndCompletionIsReturned { receivedError = error; }]; + XCTAssertEqual(service.registrationRequestCount, 1u); XCTAssertEqual(service.lastRegistrationRequest, request); XCTAssertNotNil(service.lastRegistrationCompletion);