Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 2 additions & 4 deletions GoogleSignIn/Sources/GIDRestrictedScopesRegistry.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ @implementation GIDRestrictedScopesRegistry
- (instancetype)init {
self = [super init];
if (self) {
_restrictedScopes = [NSSet setWithObjects:kAccountDetailTypeAgeOver18Scope, nil];
_scopeToClassMapping = @{
kAccountDetailTypeAgeOver18Scope: [GIDVerifyAccountDetail class],
};
_restrictedScopes = [NSSet set];
_scopeToClassMapping = @{};
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

NSString *const kAccountDetailTypeAgeOver18Scope = @"https://www.googleapis.com/auth/verified.age.over18.standard";

@implementation GIDVerifiableAccountDetail

- (instancetype)initWithAccountDetailType:(GIDAccountDetailType)accountDetailType {
Expand All @@ -31,12 +29,7 @@ - (instancetype)initWithAccountDetailType:(GIDAccountDetailType)accountDetailTyp
}

- (nullable NSString *)scope {
switch (self.accountDetailType) {
case GIDAccountDetailTypeAgeOver18:
return kAccountDetailTypeAgeOver18Scope;
default:
return nil;
}
return nil;
}

- (BOOL)isEqual:(id)object {
Expand All @@ -51,9 +44,6 @@ - (NSUInteger)hash {
}

+ (GIDAccountDetailType)detailTypeWithString:(NSString *)detailTypeString {
if ([detailTypeString isEqualToString:kAccountDetailTypeAgeOver18Scope]) {
return GIDAccountDetailTypeAgeOver18;
}
return GIDAccountDetailTypeUnknown;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, GIDAccountDetailType) {
/// Used when the account detail type is unspecified or cannot be matched.
GIDAccountDetailTypeUnknown,
/// User account detail for age over 18.
GIDAccountDetailTypeAgeOver18,
};

/// String scope representing the account detail type for age over 18.
extern NSString *const kAccountDetailTypeAgeOver18Scope;

/// Helper object used to hold the enumeration representing a list of
/// account details that Google can verify via GSI.
@interface GIDVerifiableAccountDetail : NSObject
Expand Down
10 changes: 4 additions & 6 deletions GoogleSignIn/Tests/Unit/GIDRestrictedScopesRegistryTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,16 @@ @implementation GIDRestrictedScopesRegistryTest

- (void)testIsScopeRestricted {
GIDRestrictedScopesRegistry *registry = [[GIDRestrictedScopesRegistry alloc] init];
BOOL isRestricted = [registry isScopeRestricted:kAccountDetailTypeAgeOver18Scope];
XCTAssertTrue(isRestricted);
BOOL isRestricted = [registry isScopeRestricted:@"some_scope"];
XCTAssertFalse(isRestricted);
}

- (void)testRestrictedScopesToClassMappingInSet {
GIDRestrictedScopesRegistry *registry = [[GIDRestrictedScopesRegistry alloc] init];
NSSet<NSString *> *scopes = [NSSet setWithObjects:kAccountDetailTypeAgeOver18Scope, @"some_other_scope", nil];
NSSet<NSString *> *scopes = [NSSet setWithObjects:@"some_scope", @"some_other_scope", nil];
NSDictionary<NSString *, Class> *mapping = [registry restrictedScopesToClassMappingInSet:scopes];

XCTAssertEqual(mapping.count, 1);
XCTAssertEqualObjects(mapping[kAccountDetailTypeAgeOver18Scope], [GIDVerifyAccountDetail class]);
XCTAssertNil(mapping[@"some_other_scope"]);
XCTAssertEqual(mapping.count, 0);
}

@end
Expand Down
5 changes: 3 additions & 2 deletions GoogleSignIn/Tests/Unit/GIDSignInInternalOptionsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ - (void)testDefaultOptionsForVerificationFlow {
hostedDomain:nil
openIDRealm:kOpenIDRealm];
UIViewController *presentingViewController = [[UIViewController alloc] init];
GIDVerifiableAccountDetail *ageOver18Detail = [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeAgeOver18];
NSArray<GIDVerifiableAccountDetail *> *accountDetailsToVerify = @[ageOver18Detail];
GIDVerifiableAccountDetail *testAccountDetail =
[[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeUnknown];
NSArray<GIDVerifiableAccountDetail *> *accountDetailsToVerify = @[testAccountDetail];
NSString *loginHint = @"login_hint";

GIDSignInInternalOptions *options =
Expand Down
26 changes: 0 additions & 26 deletions GoogleSignIn/Tests/Unit/GIDSignInTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -1341,32 +1341,6 @@ - (void)testTokenEndpointEMMError {
XCTAssertNil(_signIn.currentUser, @"should not have current user");
}

- (void)testValidScopesException {
NSString *requestedScope = @"https://www.googleapis.com/auth/verified.age.over18.standard";
NSString *expectedException =
[NSString stringWithFormat:@"The following scopes are not supported in the 'addScopes' flow. "
"Please use the appropriate classes to handle these:\n%@ -> %@\n",
requestedScope, NSStringFromClass([GIDVerifyAccountDetail class])];
BOOL threw = NO;
@try {
[_signIn addScopes:@[requestedScope]
#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
presentingViewController:_presentingViewController
#elif TARGET_OS_OSX
presentingWindow:_presentingWindow
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
completion:_completion];
} @catch (NSException *exception) {
threw = YES;
XCTAssertEqualObjects(exception.description, expectedException);
} @finally {
}
XCTAssert(threw);

// TODO: Keep mocks from carrying forward to subsequent tests. (#410)
[_authState stopMocking];
}

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#pragma mark - Helpers
Expand Down
13 changes: 8 additions & 5 deletions GoogleSignIn/Tests/Unit/GIDVerifiableAccountDetailTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@ @interface GIDVerifiableAccountDetailTests : XCTestCase
@implementation GIDVerifiableAccountDetailTests

- (void)testDesignatedInitializer {
GIDVerifiableAccountDetail *detail = [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeAgeOver18];
GIDVerifiableAccountDetail *detail =
[[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeUnknown];
XCTAssertNotNil(detail);
XCTAssertEqual(detail.accountDetailType, GIDAccountDetailTypeAgeOver18);
XCTAssertEqual(detail.accountDetailType, GIDAccountDetailTypeUnknown);
}

- (void)testScopeRetrieval {
GIDVerifiableAccountDetail *detail = [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeAgeOver18];
GIDVerifiableAccountDetail *detail =
[[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeUnknown];
NSString *retrievedScope = [detail scope];
XCTAssertEqualObjects(retrievedScope, kAccountDetailTypeAgeOver18Scope);
XCTAssertNil(retrievedScope);
}

- (void)testScopeRetrieval_MissingScope {
NSInteger missingScope = 5;
GIDVerifiableAccountDetail *detail = [[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:missingScope];
GIDVerifiableAccountDetail *detail =
[[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:missingScope];
NSString *retrievedScope = [detail scope];
XCTAssertNil(retrievedScope);
}
Expand Down
23 changes: 7 additions & 16 deletions GoogleSignIn/Tests/Unit/GIDVerifiedAccountDetailResultTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ - (void)testInit {
OIDAuthState *authState = [OIDAuthState testInstance];

GIDVerifiableAccountDetail *verifiedAccountDetail =
[[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeAgeOver18];
[[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeUnknown];

NSArray<GIDVerifiableAccountDetail *> *verifiedList =
@[verifiedAccountDetail, verifiedAccountDetail];
Expand All @@ -52,32 +52,23 @@ - (void)testInit {
XCTAssertEqual(result.refreshToken.tokenString, authState.lastTokenResponse.refreshToken);
}

- (void)testRefreshTokensWithCompletion_success {
GIDVerifiableAccountDetail *verifiedAccountDetail =
[[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeAgeOver18];

NSString *kAccountDetailList = [NSString stringWithFormat:@"%@",
kAccountDetailTypeAgeOver18Scope];
- (void)testRefreshTokensWithCompletion_randomScope {
NSString *kAccountDetailList = [NSString stringWithFormat:@"some_scope"];
OIDTokenResponse *tokenResponse = [OIDTokenResponse testInstanceWithScope:kAccountDetailList];
OIDAuthState *authState = [OIDAuthState testInstanceWithTokenResponse:tokenResponse];
GIDVerifiedAccountDetailHandlingFake *result =
[[GIDVerifiedAccountDetailHandlingFake alloc] initWithTokenResponse:authState.lastTokenResponse
verifiedAuthState:authState
error:nil];

NSArray<GIDVerifiableAccountDetail *> *expectedVerifiedList =
@[verifiedAccountDetail];
GIDVerifiedAccountDetailResult *expectedResult =
[[GIDVerifiedAccountDetailResult alloc] initWithAccountDetails:expectedVerifiedList
authState:authState];

XCTestExpectation *expectation =
[self expectationWithDescription:@"Refreshed verified account details completion called"];
[result refreshTokensWithCompletion:^(GIDVerifiedAccountDetailResult * _Nullable refreshedResult,
NSError * _Nullable error) {
XCTAssertNil(error);
XCTAssertNotNil(refreshedResult);
XCTAssertTrue([refreshedResult isEqual:expectedResult]);
XCTAssertEqual([refreshedResult.verifiedAccountDetails count], 0,
@"verifiedAccountDetails should have a count of 0");
[expectation fulfill];
}];

Expand All @@ -103,8 +94,8 @@ - (void)testRefreshTokensWithCompletion_noTokenResponse {
XCTAssertEqual(error, expectedError);
XCTAssertEqual(error.code, kGIDSignInErrorCodeUnknown);
XCTAssertNotNil(refreshedResult);
XCTAssertTrue([refreshedResult.verifiedAccountDetails count] == 0,
@"verifiedAccountDetails should have a count of 0");
XCTAssertEqual([refreshedResult.verifiedAccountDetails count], 0,
@"verifiedAccountDetails should have a count of 0");
[expectation fulfill];
}];

Expand Down
6 changes: 3 additions & 3 deletions GoogleSignIn/Tests/Unit/GIDVerifyAccountDetailTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ - (void)setUp {

_verifyAccountDetail = [[GIDVerifyAccountDetail alloc] init];

GIDVerifiableAccountDetail *ageOver18Detail =
[[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeAgeOver18];
_verifiableAccountDetails = @[ageOver18Detail];
GIDVerifiableAccountDetail *testAccountDetail =
[[GIDVerifiableAccountDetail alloc] initWithAccountDetailType:GIDAccountDetailTypeUnknown];
_verifiableAccountDetails = @[testAccountDetail];

_fakeMainBundle = [[GIDFakeMainBundle alloc] initWithClientID:kClientId
serverClientID:kServerClientId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
641495132C405D0200C9A613 /* VerifiedAgeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 641495122C405D0200C9A613 /* VerifiedAgeViewModel.swift */; };
641495152C405E1400C9A613 /* VerificationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 641495142C405E1400C9A613 /* VerificationView.swift */; };
641495172C405E3600C9A613 /* VerificationLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 641495162C405E3600C9A613 /* VerificationLoader.swift */; };
6499D22A2C4B2F4200825B30 /* Verification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6499D2292C4B2F4200825B30 /* Verification.swift */; };
6499D22C2C4B3B1500825B30 /* AgeVerificationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6499D22B2C4B3B1500825B30 /* AgeVerificationView.swift */; };
7345AD032703D9470020AFB1 /* DaysUntilBirthday.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7345AD022703D9470020AFB1 /* DaysUntilBirthday.swift */; };
7345AD052703D9470020AFB1 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7345AD042703D9470020AFB1 /* ContentView.swift */; };
7345AD072703D9480020AFB1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7345AD062703D9480020AFB1 /* Assets.xcassets */; };
Expand Down Expand Up @@ -58,11 +53,6 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
641495122C405D0200C9A613 /* VerifiedAgeViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VerifiedAgeViewModel.swift; sourceTree = "<group>"; };
641495142C405E1400C9A613 /* VerificationView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VerificationView.swift; sourceTree = "<group>"; };
641495162C405E3600C9A613 /* VerificationLoader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VerificationLoader.swift; sourceTree = "<group>"; };
6499D2292C4B2F4200825B30 /* Verification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Verification.swift; sourceTree = "<group>"; };
6499D22B2C4B3B1500825B30 /* AgeVerificationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgeVerificationView.swift; sourceTree = "<group>"; };
7345ACFF2703D9470020AFB1 /* DaysUntilBirthday (iOS).app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "DaysUntilBirthday (iOS).app"; sourceTree = BUILT_PRODUCTS_DIR; };
7345AD022703D9470020AFB1 /* DaysUntilBirthday.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DaysUntilBirthday.swift; sourceTree = "<group>"; };
7345AD042703D9470020AFB1 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -213,9 +203,7 @@
children = (
7345AD042703D9470020AFB1 /* ContentView.swift */,
739FCC45270E467600C92042 /* BirthdayView.swift */,
6499D22B2C4B3B1500825B30 /* AgeVerificationView.swift */,
7345AD112703D9C30020AFB1 /* SignInView.swift */,
641495142C405E1400C9A613 /* VerificationView.swift */,
7345AD142703D9C30020AFB1 /* UserProfileImageView.swift */,
);
path = Views;
Expand All @@ -225,7 +213,6 @@
isa = PBXGroup;
children = (
739FCC47270E659A00C92042 /* Birthday.swift */,
6499D2292C4B2F4200825B30 /* Verification.swift */,
);
path = Models;
sourceTree = "<group>";
Expand All @@ -234,7 +221,6 @@
isa = PBXGroup;
children = (
7345AD162703D9C30020AFB1 /* AuthenticationViewModel.swift */,
641495122C405D0200C9A613 /* VerifiedAgeViewModel.swift */,
736F49BB270E102C00580053 /* BirthdayViewModel.swift */,
);
path = ViewModels;
Expand All @@ -245,7 +231,6 @@
children = (
7345AD172703D9C30020AFB1 /* GoogleSignInAuthenticator.swift */,
736F49B9270E05E200580053 /* BirthdayLoader.swift */,
641495162C405E3600C9A613 /* VerificationLoader.swift */,
7345AD192703D9C30020AFB1 /* UserProfileImageLoader.swift */,
);
path = Services;
Expand Down Expand Up @@ -389,9 +374,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6499D22A2C4B2F4200825B30 /* Verification.swift in Sources */,
739FCC48270E659A00C92042 /* Birthday.swift in Sources */,
6499D22C2C4B3B1500825B30 /* AgeVerificationView.swift in Sources */,
739FCC46270E467600C92042 /* BirthdayView.swift in Sources */,
7345AD1B2703D9C30020AFB1 /* SignInView.swift in Sources */,
7345AD212703D9C30020AFB1 /* GoogleSignInAuthenticator.swift in Sources */,
Expand All @@ -400,12 +383,9 @@
736F49BC270E102C00580053 /* BirthdayViewModel.swift in Sources */,
736F49BA270E05E200580053 /* BirthdayLoader.swift in Sources */,
7345AD242703D9C30020AFB1 /* UserProfileView.swift in Sources */,
641495172C405E3600C9A613 /* VerificationLoader.swift in Sources */,
7345AD202703D9C30020AFB1 /* AuthenticationViewModel.swift in Sources */,
641495132C405D0200C9A613 /* VerifiedAgeViewModel.swift in Sources */,
7345AD052703D9470020AFB1 /* ContentView.swift in Sources */,
7345AD032703D9470020AFB1 /* DaysUntilBirthday.swift in Sources */,
641495152C405E1400C9A613 /* VerificationView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Loading
Loading