Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
54df794
Create method verifyAccountDetailsInteractivelyWithOptions.
brnnmrls Apr 17, 2024
5896985
Move configuration creation methods to GIDConfiguration from GIDSignIn.
brnnmrls Apr 18, 2024
94a4175
Implement default options creation methods.
brnnmrls Apr 18, 2024
4c2a643
Options validation.
brnnmrls Apr 18, 2024
78e175d
Add config initializers.
brnnmrls Apr 25, 2024
731d3a8
Merge branch 'briannamorales/vwg-flow' into briannamorales/optionsVal…
brnnmrls Apr 25, 2024
a5b9a61
Fix spacing.
brnnmrls Apr 25, 2024
d70400a
Add import to use GIDAccountDetailTypeAgeOver18.
brnnmrls Apr 25, 2024
f858d20
Import GIDConfiguration to test file.
brnnmrls Apr 25, 2024
e04a1ea
Add in initializer with config tests.
brnnmrls May 1, 2024
93fb453
Make used variables properties.
brnnmrls May 2, 2024
8bfd659
Add tests for config initializer and current user exception.
brnnmrls May 7, 2024
9376a4b
Create fake main bundle initializer and modify tests.
brnnmrls May 8, 2024
51c5a36
Unblock testing in GIDVerifyAccountDetailTest by changing GIDSignInTe…
brnnmrls May 8, 2024
6ce9f10
Address formatting and indicate designated initializer in GIDFakeMain…
brnnmrls May 9, 2024
4d981eb
Add stopFaking calls in appropriate tests.
brnnmrls May 9, 2024
89b92d3
Let parameter-less `init` be nullable and require `initWithConfig` to…
brnnmrls May 10, 2024
7112ce5
Fix method description and make `initWithConfig` nullable.
brnnmrls May 10, 2024
af1ee12
Remove nullability annotations and update doc comments.
brnnmrls May 13, 2024
3e21d6d
Update doc comment.
brnnmrls May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@

@implementation GIDVerifyAccountDetail

- (instancetype)initWithConfig:(GIDConfiguration *)configuration {
Comment thread
brnnmrls marked this conversation as resolved.
Resolved
Comment thread
mdmathias marked this conversation as resolved.
Resolved
self = [super init];
if (self) {
_configuration = configuration;
}
return self;
}

- (instancetype)init {
GIDConfiguration *configuration;
NSBundle *bundle = NSBundle.mainBundle;
if (bundle) {
configuration = [GIDConfiguration configurationFromBundle:bundle];
}

if (!configuration) {
return nil;
}

return [self initWithConfig:configuration];
}

#pragma mark - Public methods

- (void)verifyAccountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDetails
presentingViewController:(UIViewController *)presentingViewController
completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult,
Expand All @@ -42,11 +66,6 @@ - (void)verifyAccountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDet
hint:(nullable NSString *)hint
completion:(nullable void (^)(GIDVerifiedAccountDetailResult *_Nullable verifyResult,
NSError *_Nullable error))completion {
NSBundle *bundle = NSBundle.mainBundle;
if (bundle) {
_configuration = [GIDConfiguration configurationFromBundle:bundle];
}

GIDSignInInternalOptions *options =
[GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
presentingViewController:presentingViewController
Expand All @@ -58,8 +77,69 @@ - (void)verifyAccountDetails:(NSArray<GIDVerifiableAccountDetail *> *)accountDet
[self verifyAccountDetailsInteractivelyWithOptions:options];
}

#pragma mark - Authentication flow

- (void)verifyAccountDetailsInteractivelyWithOptions:(GIDSignInInternalOptions *)options {
// TODO(#397): Sanity checks and start the incremental authorization flow.
if (!options.interactive) {
return;
}

// Ensure that a configuration is set.
if (!_configuration) {
// NOLINTNEXTLINE(google-objc-avoid-throwing-exception)
[NSException raise:NSInvalidArgumentException
format:@"No active configuration. Make sure GIDClientID is set in Info.plist."];
return;
}

[self assertValidCurrentUser];

// Explicitly throw exception for missing client ID here. This must come before
// scheme check because schemes rely on reverse client IDs.
[self assertValidParameters:options];

[self assertValidPresentingViewController:options];

// If the application does not support the required URL schemes tell the developer so.
GIDSignInCallbackSchemes *schemes =
[[GIDSignInCallbackSchemes alloc] initWithClientIdentifier:options.configuration.clientID];
NSArray<NSString *> *unsupportedSchemes = [schemes unsupportedSchemes];
if (unsupportedSchemes.count != 0) {
// NOLINTNEXTLINE(google-objc-avoid-throwing-exception)
[NSException raise:NSInvalidArgumentException
format:@"Your app is missing support for the following URL schemes: %@",
[unsupportedSchemes componentsJoinedByString:@", "]];
}
// TODO(#397): Start the incremental authorization flow.
Comment thread
brnnmrls marked this conversation as resolved.
Resolved
}

#pragma mark - Helpers

// Assert that a current user exists.
- (void)assertValidCurrentUser {
if (!GIDSignIn.sharedInstance.currentUser) {
// NOLINTNEXTLINE(google-objc-avoid-throwing-exception)
[NSException raise:NSInvalidArgumentException
format:@"|currentUser| must be set to verify."];
}
}

// Asserts the parameters being valid.
- (void)assertValidParameters:(GIDSignInInternalOptions *)options {
if (![options.configuration.clientID length]) {
// NOLINTNEXTLINE(google-objc-avoid-throwing-exception)
[NSException raise:NSInvalidArgumentException
format:@"You must specify |clientID| in |GIDConfiguration|"];
}
}

// Assert that the presenting view controller has been set.
- (void)assertValidPresentingViewController:(GIDSignInInternalOptions *)options {
if (!options.presentingViewController) {
// NOLINTNEXTLINE(google-objc-avoid-throwing-exception)
[NSException raise:NSInvalidArgumentException
format:@"|presentingViewController| must be set."];
}
}

@end
Expand Down
15 changes: 15 additions & 0 deletions GoogleSignIn/Sources/Public/GoogleSignIn/GIDVerifyAccountDetail.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ typedef void (^GIDVerifyCompletion)(GIDVerifiedAccountDetailResult *_Nullable ve
/// The active configuration for this instance of `GIDVerifyAccountDetail`.
@property(nonatomic, nullable) GIDConfiguration *configuration;

/// Initialize a `GIDVerifyAccountDetail` object by specifying all available properties.
///
/// @param config The configuration to be used.
/// @return An initialized `GIDVerifyAccountDetail` instance.
Comment thread
brnnmrls marked this conversation as resolved.
Resolved
- (instancetype)initWithConfig:(GIDConfiguration *)config
Comment thread
brnnmrls marked this conversation as resolved.
Resolved
Comment thread
brnnmrls marked this conversation as resolved.
Resolved
NS_DESIGNATED_INITIALIZER;


/// Initialize a `GIDVerifyAccountDetail` object by calling the designated initializer
/// with the default configuration from the bundle's Info.plist.
///
/// @return An initialized `GIDVerifyAccountDetail` instance.
/// Otherwise, `nil` if the configuration cannot be automatically generated from your app's Info.plist.
- (instancetype)init;

/// Starts an interactive verification flow.
///
/// The completion will be called at the end of this process. Any saved verification
Expand Down
39 changes: 34 additions & 5 deletions GoogleSignIn/Tests/Unit/GIDFakeMainBundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,45 @@

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/**
* @class GIDFakeMainBundle
* @brief Helps fake [NSBundle mainBundle]
*/
@interface GIDFakeMainBundle : NSObject

/**
* @fn initWithClientID:serverClientID:hostedDomain:openIDRealm:
* @brief Initializes a GIDFakeMainBundle object.
* @param clientID The fake client idenfitier for the app.
* @param serverClientID The fake server client idenfitier for the app.
* @param hostedDomain The fake hosted domain for the app.
* @param openIDRealm The fake OpenID realm for the app.
*/
- (instancetype)initWithClientID:(nullable id)clientID
serverClientID:(nullable id)serverClientID
hostedDomain:(nullable id)hostedDomain
openIDRealm:(nullable id)openIDRealm
NS_DESIGNATED_INITIALIZER;

/**
* @fn init:
* @brief Initializes a GIDFakeMainBundle object with `nil` to all of the designated initializer's parameters.
*/
- (instancetype)init;
/**
* @fn startFaking:
* @brief Starts faking [NSBundle mainBundle]
*/
- (void)startFaking;

/**
* @fn startFakingWithClientID:
* @brief Starts faking [NSBundle mainBundle]
* @param clientID The fake client idenfitier for the app.
*/
- (void)startFakingWithClientID:(NSString *)clientID;
- (void)startFakingWithClientID:(nullable NSString *)clientID;

/**
* @fn stopFaking
Expand Down Expand Up @@ -87,9 +114,11 @@
* @param hostedDomain The fake hosted domain for the app.
* @param openIDRealm The fake OpenID realm for the app.
*/
- (void)fakeWithClientID:(id)clientID
serverClientID:(id)serverClientID
hostedDomain:(id)hostedDomain
openIDRealm:(id)openIDRealm;
- (void)fakeWithClientID:(nullable id)clientID
serverClientID:(nullable id)serverClientID
hostedDomain:(nullable id)hostedDomain
openIDRealm:(nullable id)openIDRealm;

@end

NS_ASSUME_NONNULL_END
38 changes: 34 additions & 4 deletions GoogleSignIn/Tests/Unit/GIDFakeMainBundle.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,38 @@ @implementation GIDFakeMainBundle {
NSMutableDictionary *_fakeConfig;
}

- (void)startFakingWithClientID:(NSString *)clientId {
_clientId = clientId;
- (instancetype)initWithClientID:(nullable id)clientID
serverClientID:(nullable id)serverClientID
hostedDomain:(nullable id)hostedDomain
openIDRealm:(nullable id)openIDRealm {
self = [super init];

if (self) {
_clientId = clientID;

_fakeConfig = clientID ? [@{ @"GIDClientID" : clientID } mutableCopy] : [@{} mutableCopy];

[self fakeWithClientID:clientID
serverClientID:serverClientID
hostedDomain:hostedDomain
openIDRealm:openIDRealm];
}
return self;
}

- (instancetype)init {
Comment thread
brnnmrls marked this conversation as resolved.
Resolved
return [self initWithClientID:nil
serverClientID:nil
hostedDomain:nil
openIDRealm:nil];
}

- (void)startFaking {
_fakedKeys = @[ kCFBundleURLTypesKey,
kConfigClientIDKey,
kConfigServerClientIDKey,
kConfigHostedDomainKey,
kConfigOpenIDRealmKey ];

_fakeConfig = [@{ @"GIDClientID" : clientId } mutableCopy];

[GULSwizzler swizzleClass:[NSBundle class]
selector:@selector(objectForInfoDictionaryKey:)
Expand All @@ -62,6 +84,14 @@ - (void)startFakingWithClientID:(NSString *)clientId {
}];
}

- (void)startFakingWithClientID:(nullable NSString *)clientId {
_clientId = clientId;

_fakeConfig = clientId ? [@{ @"GIDClientID" : clientId } mutableCopy] : [@{} mutableCopy];

[self startFaking];
}

- (void)stopFaking {
[GULSwizzler unswizzleClass:[NSBundle class]
selector:@selector(objectForInfoDictionaryKey:)
Expand Down
6 changes: 4 additions & 2 deletions GoogleSignIn/Tests/Unit/GIDSignInTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,14 @@ - (void)setUp {
#elif TARGET_OS_OSX
_presentingWindow = OCMStrictClassMock([NSWindow class]);
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
_authState = OCMStrictClassMock([OIDAuthState class]);

// TODO: Fix strict mocks from carrying forward to subsequent tests. (#410)
_authState = OCMClassMock([OIDAuthState class]);
Comment thread
brnnmrls marked this conversation as resolved.
Resolved
OCMStub([_authState alloc]).andReturn(_authState);
OCMStub([_authState initWithAuthorizationResponse:OCMOCK_ANY]).andReturn(_authState);
_tokenResponse = OCMStrictClassMock([OIDTokenResponse class]);
_tokenRequest = OCMStrictClassMock([OIDTokenRequest class]);
_authorization = OCMStrictClassMock([GTMAuthSession class]);
_authorization = OCMClassMock([GTMAuthSession class]);
_keychainStore = OCMStrictClassMock([GTMKeychainStore class]);
OCMStub(
[_keychainStore retrieveAuthSessionWithItemName:OCMOCK_ANY error:OCMArg.anyObjectRef]
Expand Down
Loading