Skip to content

Commit 69aa820

Browse files
committed
Blocked by another PR to create and test OIDAuthorizationRequest.
1 parent 25b266a commit 69aa820

File tree

4 files changed

+62
-51
lines changed

4 files changed

+62
-51
lines changed

GoogleSignIn/Sources/GIDAuthorizationFlowProcessor/Implementations/Fakes/GIDFakeAuthorizationFlowProcessor.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,22 @@
1818

1919
#import "GoogleSignIn/Sources/GIDAuthorizationFlowProcessor/API/GIDAuthorizationFlowProcessor.h"
2020

21+
#ifdef SWIFT_PACKAGE
22+
@import AppAuth;
23+
#else
24+
#import <AppAuth/AppAuth.h>
25+
#endif
26+
2127
NS_ASSUME_NONNULL_BEGIN
2228

2329
/// The block which provides the response for the method `startWithOptions:emmSupport:completion:`.
2430
///
25-
/// @param data The OIDAuthorizationResponse object returned if succeed,
31+
/// @param authorizationResponse The OIDAuthorizationResponse object returned if succeeded.
2632
/// @param error The error returned if failed.
2733
typedef void(^GIDAuthorizationFlowProcessorFakeResponseProviderBlock)
2834
(OIDAuthorizationResponse *_Nullable authorizationResponse, NSError *_Nullable error);
2935

30-
/// The block to set up data based on the input request for the method
36+
/// The block to set up response value for the method
3137
/// `startWithOptions:emmSupport:completion:`.
3238
///
3339
/// @param responseProvider The block which provides the response.
@@ -36,8 +42,9 @@ typedef void (^GIDAuthorizationFlowProcessorTestBlock)
3642

3743
@interface GIDFakeAuthorizationFlowProcessor : NSObject <GIDAuthorizationFlowProcessor>
3844

39-
/// Set the test block which provides the response value.
40-
- (void)setTestBlock:(GIDAuthorizationFlowProcessorTestBlock)block;
45+
/// The test block which provides the response value.
46+
@property(nonatomic) GIDAuthorizationFlowProcessorTestBlock testBlock;
47+
4148

4249
@end
4350

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
#import "GoogleSignIn/Sources/GIDAuthorizationFlowProcessor/Implementations/Fakes/GIDFakeAuthorizationFlowProcessor.h"
22

3-
@interface GIDFakeAuthorizationFlowProcessor ()
4-
5-
@property(nonatomic) GIDAuthorizationFlowProcessorTestBlock testBlock;
6-
7-
@end
8-
93
@implementation GIDFakeAuthorizationFlowProcessor
104

115
- (void)startWithOptions:(GIDSignInInternalOptions *)options
126
emmSupport:(nullable NSString *)emmSupport
137
completion:(void (^)(OIDAuthorizationResponse *_Nullable authorizationResponse,
148
NSError *_Nullable error))completion {
159
NSAssert(self.testBlock != nil, @"Set the test block before invoking this method.");
10+
11+
1612
self.testBlock(^(OIDAuthorizationResponse *authorizationResponse, NSError *error) {
1713
completion(authorizationResponse, error);
1814
});
1915
}
2016

21-
/// Not used in test for now.
2217
- (BOOL)isStarted {
18+
NSAssert(NO, @"Not implemented.");
2319
return YES;
2420
}
2521

26-
/// Not used in test for now.
2722
- (BOOL)resumeExternalUserAgentFlowWithURL:(NSURL *)url {
23+
NSAssert(NO, @"Not implemented.");
2824
return YES;
2925
}
3026

31-
/// Not used in test for now.
32-
- (void)cancelAuthenticationFlow {}
27+
- (void)cancelAuthenticationFlow {
28+
NSAssert(NO, @"Not implemented.");
29+
}
3330

3431
@end

GoogleSignIn/Tests/Unit/GIDAuthorizationFlowProcessorTest.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ - (void)testStartAndResumeAuthorizationFlow_success {
9292
emmSupport:nil
9393
completion:^(OIDAuthorizationResponse *authorizationResponse,
9494
NSError *error) {
95-
<
9695
XCTAssertEqualObjects(authorizationResponse.accessToken,
9796
self->_fakeResponse.accessToken);
9897
XCTAssertEqualObjects(authorizationResponse.authorizationCode,

GoogleSignIn/Tests/Unit/GIDSignInTest.m

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// Test module imports
2727
@import GoogleSignIn;
2828

29-
#import "GoogleSignIn/Sources/GIDAuthorizationFlowProcessor/Implementations/GIDAuthorizationFlowProcessor.h"
29+
#import "GoogleSignIn/Sources/GIDAuthorizationFlowProcessor/Implementations/Fakes/GIDFakeAuthorizationFlowProcessor.h"
3030
#import "GoogleSignIn/Sources/GIDEMMSupport.h"
3131
#import "GoogleSignIn/Sources/GIDGoogleUser_Private.h"
3232
#import "GoogleSignIn/Sources/GIDSignIn_Private.h"
@@ -36,7 +36,6 @@
3636
#import "GoogleSignIn/Sources/GIDHTTPFetcher/Implementations/GIDHTTPFetcher.h"
3737
#import "GoogleSignIn/Sources/GIDProfileDataFetcher/Implementations/GIDProfileDataFetcher.h"
3838

39-
4039
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
4140
#import "GoogleSignIn/Sources/GIDEMMErrorHandler.h"
4241
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
@@ -203,6 +202,9 @@ @interface GIDSignInTest : XCTestCase {
203202
// Fake for |GIDHTTPFetcher|.
204203
GIDFakeHTTPFetcher *_httpFetcher;
205204

205+
// Fake for |GIDAuthorizationFlowProcessor|
206+
GIDFakeAuthorizationFlowProcessor *_authorizationFlowProcessor;
207+
206208
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
207209
// Mock |UIViewController|.
208210
id _presentingViewController;
@@ -289,14 +291,14 @@ - (void)setUp {
289291
OCMStub([_authorization initWithAuthState:OCMOCK_ANY]).andReturn(_authorization);
290292
_user = OCMStrictClassMock([GIDGoogleUser class]);
291293
_oidAuthorizationService = OCMStrictClassMock([OIDAuthorizationService class]);
292-
OCMStub([_oidAuthorizationService
293-
presentAuthorizationRequest:SAVE_TO_ARG_BLOCK(self->_savedAuthorizationRequest)
294-
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
295-
presentingViewController:SAVE_TO_ARG_BLOCK(self->_savedPresentingViewController)
296-
#elif TARGET_OS_OSX
297-
presentingWindow:SAVE_TO_ARG_BLOCK(self->_savedPresentingWindow)
298-
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
299-
callback:COPY_TO_ARG_BLOCK(self->_savedAuthorizationCallback)]);
294+
// OCMStub([_oidAuthorizationService
295+
// presentAuthorizationRequest:SAVE_TO_ARG_BLOCK(self->_savedAuthorizationRequest)
296+
//#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
297+
// presentingViewController:SAVE_TO_ARG_BLOCK(self->_savedPresentingViewController)
298+
//#elif TARGET_OS_OSX
299+
// presentingWindow:SAVE_TO_ARG_BLOCK(self->_savedPresentingWindow)
300+
//#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
301+
// callback:COPY_TO_ARG_BLOCK(self->_savedAuthorizationCallback)]);
300302
OCMStub([self->_oidAuthorizationService
301303
performTokenRequest:SAVE_TO_ARG_BLOCK(self->_savedTokenRequest)
302304
callback:COPY_TO_ARG_BLOCK(self->_savedTokenCallback)]);
@@ -314,15 +316,14 @@ - (void)setUp {
314316

315317
_httpFetcher = [[GIDFakeHTTPFetcher alloc] init];
316318

317-
GIDAuthorizationFlowProcessor * authorizationFlowProcessor =
318-
[[GIDAuthorizationFlowProcessor alloc] init];
319+
_authorizationFlowProcessor = [[GIDFakeAuthorizationFlowProcessor alloc] init];
319320

320321
id<GIDProfileDataFetcher> profileDataFetcher = [[GIDProfileDataFetcher alloc] init];
321322

322323
_signIn = [[GIDSignIn alloc] initWithKeychainHandler:_keychainHandler
323324
httpFetcher:_httpFetcher
324325
profileDataFetcher:profileDataFetcher
325-
authorizationFlowProcessor:authorizationFlowProcessor];
326+
authorizationFlowProcessor:_authorizationFlowProcessor];
326327

327328
_hint = nil;
328329

@@ -343,7 +344,7 @@ - (void)tearDown {
343344
OCMVerifyAll(_tokenResponse);
344345
OCMVerifyAll(_tokenRequest);
345346
OCMVerifyAll(_user);
346-
OCMVerifyAll(_oidAuthorizationService);
347+
// OCMVerifyAll(_oidAuthorizationService);
347348

348349
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
349350
OCMVerifyAll(_presentingViewController);
@@ -1215,6 +1216,34 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow
12151216
refreshToken:kRefreshToken
12161217
codeVerifier:nil
12171218
additionalParameters:tokenResponse.request.additionalParameters];
1219+
1220+
// Simulate auth endpoint response
1221+
GIDAuthorizationFlowProcessorTestBlock testBlock;
1222+
if (modalCancel) {
1223+
NSError *error = [NSError errorWithDomain:OIDGeneralErrorDomain
1224+
code:OIDErrorCodeUserCanceledAuthorizationFlow
1225+
userInfo:nil];
1226+
testBlock = ^(GIDAuthorizationFlowProcessorFakeResponseProviderBlock responseProvider) {
1227+
responseProvider(nil, error);
1228+
};
1229+
} else {
1230+
testBlock = ^(GIDAuthorizationFlowProcessorFakeResponseProviderBlock responseProvider) {
1231+
responseProvider(authResponse, nil);
1232+
};
1233+
}
1234+
_authorizationFlowProcessor.testBlock = testBlock;
1235+
1236+
// maybeFetchToken
1237+
if (!(authError || modalCancel)) {
1238+
[[[_authState expect] andReturn:nil] lastTokenResponse];
1239+
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
1240+
// Corresponds to EMM support
1241+
[[[_authState expect] andReturn:authResponse] lastAuthorizationResponse];
1242+
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
1243+
[[[_authState expect] andReturn:nil] lastTokenResponse];
1244+
[[[_authState expect] andReturn:authResponse] lastAuthorizationResponse];
1245+
[[[_authState expect] andReturn:authResponse] lastAuthorizationResponse];
1246+
}
12181247

12191248
if (restoredSignIn) {
12201249
// maybeFetchToken
@@ -1280,34 +1309,13 @@ - (void)OAuthLoginWithAddScopesFlow:(BOOL)addScopesFlow
12801309
XCTAssertEqualObjects(params[@"include_granted_scopes"], @"true");
12811310
XCTAssertEqualObjects(params[kSDKVersionLoggingParameter], GIDVersion());
12821311
XCTAssertEqualObjects(params[kEnvironmentLoggingParameter], GIDEnvironment());
1283-
XCTAssertNotNil(_savedAuthorizationCallback);
1312+
// XCTAssertNotNil(_savedAuthorizationCallback);
12841313
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
12851314
XCTAssertEqual(_savedPresentingViewController, _presentingViewController);
12861315
#elif TARGET_OS_OSX
12871316
XCTAssertEqual(_savedPresentingWindow, _presentingWindow);
12881317
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
12891318

1290-
// maybeFetchToken
1291-
if (!(authError || modalCancel)) {
1292-
[[[_authState expect] andReturn:nil] lastTokenResponse];
1293-
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
1294-
// Corresponds to EMM support
1295-
[[[_authState expect] andReturn:authResponse] lastAuthorizationResponse];
1296-
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
1297-
[[[_authState expect] andReturn:nil] lastTokenResponse];
1298-
[[[_authState expect] andReturn:authResponse] lastAuthorizationResponse];
1299-
[[[_authState expect] andReturn:authResponse] lastAuthorizationResponse];
1300-
}
1301-
1302-
// Simulate auth endpoint response
1303-
if (modalCancel) {
1304-
NSError *error = [NSError errorWithDomain:OIDGeneralErrorDomain
1305-
code:OIDErrorCodeUserCanceledAuthorizationFlow
1306-
userInfo:nil];
1307-
_savedAuthorizationCallback(nil, error);
1308-
} else {
1309-
_savedAuthorizationCallback(authResponse, nil);
1310-
}
13111319

13121320
if (authError || modalCancel) {
13131321
return;

0 commit comments

Comments
 (0)