-
Notifications
You must be signed in to change notification settings - Fork 282
Carry nonce and claimsAsJSON through Device Policy flows
#637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
w-goog
wants to merge
4
commits into
main
Choose a base branch
from
feature/continuation-options-carry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−50
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a310d68
g-orchestrated: Carry nonce and claims JSON into continuation options
w-goog c8a90b8
g-orchestrated: Changelog: carry nonce and claims across continuation
w-goog 91e52fd
g-orchestrated: Test continuation options preserve nonce and claims
w-goog 73e34c6
g-orchestrated: Share test setup and rename the continuation test
w-goog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,92 +25,139 @@ | |
| #import <OCMock/OCMock.h> | ||
| #endif | ||
|
|
||
| @interface GIDSignInInternalOptionsTest : XCTestCase | ||
| @end | ||
| static NSString *const kLoginHint = @"login_hint"; | ||
| static NSString *const kScope1 = @"scope1"; | ||
| static NSString *const kScope2 = @"scope2"; | ||
| static NSString *const kNonce = @"test_nonce"; | ||
| static NSString *const kClaimsAsJSON = @"{\"claim\":\"value\"}"; | ||
|
|
||
| @implementation GIDSignInInternalOptionsTest | ||
| @interface GIDSignInInternalOptionsTest : XCTestCase { | ||
| // Mock for the configuration passed to the option factories. | ||
| id _configuration; | ||
|
|
||
| - (void)testDefaultOptions { | ||
| id configuration = OCMStrictClassMock([GIDConfiguration class]); | ||
| #if TARGET_OS_IOS || TARGET_OS_MACCATALYST | ||
| id presentingViewController = OCMStrictClassMock([UIViewController class]); | ||
| // Mock for the presenting view controller passed to the option factories. | ||
| id _presentingViewController; | ||
| #elif TARGET_OS_OSX | ||
| id presentingWindow = OCMStrictClassMock([NSWindow class]); | ||
| // Mock for the presenting window passed to the option factories. | ||
| id _presentingWindow; | ||
| #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST | ||
| NSString *loginHint = @"login_hint"; | ||
| } | ||
| @end | ||
|
|
||
| GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult, | ||
| NSError * _Nullable error) {}; | ||
| GIDSignInInternalOptions *options = | ||
| [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration | ||
| @implementation GIDSignInInternalOptionsTest | ||
|
|
||
| #pragma mark - Lifecycle | ||
|
|
||
| - (void)setUp { | ||
| [super setUp]; | ||
| _configuration = OCMStrictClassMock([GIDConfiguration class]); | ||
| #if TARGET_OS_IOS || TARGET_OS_MACCATALYST | ||
| presentingViewController:presentingViewController | ||
| _presentingViewController = OCMStrictClassMock([UIViewController class]); | ||
| #elif TARGET_OS_OSX | ||
| presentingWindow:presentingWindow | ||
| _presentingWindow = OCMStrictClassMock([NSWindow class]); | ||
| #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST | ||
| loginHint:loginHint | ||
| addScopesFlow:NO | ||
| completion:completion]; | ||
| XCTAssertTrue(options.interactive); | ||
| XCTAssertFalse(options.continuation); | ||
| XCTAssertFalse(options.addScopesFlow); | ||
| XCTAssertNil(options.extraParams); | ||
| } | ||
|
|
||
| #pragma mark - Helpers | ||
|
|
||
| // The claim set requested by `-optionsWithAllParameters`. `GIDClaim` implements | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use doc comments instead. |
||
| // `-isEqual:` by name and essentiality, so a freshly built set compares equal. | ||
| - (NSSet<GIDClaim *> *)expectedClaims { | ||
| return [NSSet setWithObject:[GIDClaim authTimeClaim]]; | ||
| } | ||
|
|
||
| OCMVerifyAll(configuration); | ||
| - (GIDSignInInternalOptions *)optionsWithAllParameters { | ||
| GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult, | ||
| NSError *_Nullable error) {}; | ||
| return [GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration | ||
| #if TARGET_OS_IOS || TARGET_OS_MACCATALYST | ||
| OCMVerifyAll(presentingViewController); | ||
| presentingViewController:_presentingViewController | ||
| #elif TARGET_OS_OSX | ||
| OCMVerifyAll(presentingWindow); | ||
| presentingWindow:_presentingWindow | ||
| #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST | ||
| loginHint:kLoginHint | ||
| addScopesFlow:NO | ||
| scopes:@[kScope1, kScope2] | ||
| nonce:kNonce | ||
| claims:[self expectedClaims] | ||
| completion:completion]; | ||
| } | ||
|
|
||
| - (void)testDefaultOptions_withAllParameters_initializesPropertiesCorrectly { | ||
| id configuration = OCMStrictClassMock([GIDConfiguration class]); | ||
| // Verifies the mocks created in `-setUp` have no unfulfilled expectations. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| - (void)verifyConfigurationAndPresentationMocks { | ||
| OCMVerifyAll(_configuration); | ||
| #if TARGET_OS_IOS || TARGET_OS_MACCATALYST | ||
| id presentingViewController = OCMStrictClassMock([UIViewController class]); | ||
| OCMVerifyAll(_presentingViewController); | ||
| #elif TARGET_OS_OSX | ||
| id presentingWindow = OCMStrictClassMock([NSWindow class]); | ||
| OCMVerifyAll(_presentingWindow); | ||
| #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST | ||
| NSString *loginHint = @"login_hint"; | ||
| NSArray<NSString *> *scopes = @[@"scope1", @"scope2"]; | ||
| NSString *nonce = @"test_nonce"; | ||
| NSSet<GIDClaim *> *claims = [NSSet setWithObject:[GIDClaim authTimeClaim]]; | ||
| NSArray<NSString *> *expectedScopes = @[@"scope1", @"scope2", @"email", @"profile"]; | ||
| } | ||
|
|
||
| #pragma mark - Tests | ||
|
|
||
| - (void)testDefaultOptions { | ||
| GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult, | ||
| NSError * _Nullable error) {}; | ||
| NSError *_Nullable error) {}; | ||
| GIDSignInInternalOptions *options = | ||
| [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration | ||
| [GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration | ||
| #if TARGET_OS_IOS || TARGET_OS_MACCATALYST | ||
| presentingViewController:presentingViewController | ||
| presentingViewController:_presentingViewController | ||
| #elif TARGET_OS_OSX | ||
| presentingWindow:presentingWindow | ||
| presentingWindow:_presentingWindow | ||
| #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST | ||
| loginHint:loginHint | ||
| loginHint:kLoginHint | ||
| addScopesFlow:NO | ||
| scopes:scopes | ||
| nonce:nonce | ||
| claims:claims | ||
| completion:completion]; | ||
| XCTAssertTrue(options.interactive); | ||
| XCTAssertFalse(options.continuation); | ||
| XCTAssertFalse(options.addScopesFlow); | ||
| XCTAssertNil(options.extraParams); | ||
|
|
||
| [self verifyConfigurationAndPresentationMocks]; | ||
| } | ||
|
|
||
| - (void)testDefaultOptions_withAllParameters_initializesPropertiesCorrectly { | ||
| NSArray<NSString *> *expectedScopes = @[kScope1, kScope2, @"email", @"profile"]; | ||
|
|
||
| GIDSignInInternalOptions *options = [self optionsWithAllParameters]; | ||
|
|
||
| XCTAssertTrue(options.interactive); | ||
| XCTAssertFalse(options.continuation); | ||
| XCTAssertFalse(options.addScopesFlow); | ||
| XCTAssertNil(options.extraParams); | ||
|
|
||
| // Convert arrays to sets for comparison to make the test order-independent. | ||
| XCTAssertEqualObjects([NSSet setWithArray:options.scopes], [NSSet setWithArray:expectedScopes]); | ||
| XCTAssertEqualObjects(options.nonce, nonce); | ||
| XCTAssertEqualObjects(options.claims, claims); | ||
| XCTAssertEqualObjects([NSSet setWithArray:options.scopes], | ||
| [NSSet setWithArray:expectedScopes]); | ||
| XCTAssertEqualObjects(options.nonce, kNonce); | ||
| XCTAssertEqualObjects(options.claims, [self expectedClaims]); | ||
| XCTAssertNil(options.claimsAsJSON); | ||
|
|
||
| OCMVerifyAll(configuration); | ||
| #if TARGET_OS_IOS || TARGET_OS_MACCATALYST | ||
| OCMVerifyAll(presentingViewController); | ||
| #elif TARGET_OS_OSX | ||
| OCMVerifyAll(presentingWindow); | ||
| #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST | ||
| [self verifyConfigurationAndPresentationMocks]; | ||
| } | ||
|
|
||
| - (void)testOptionsWithExtraParameters_forContinuation_preservesAllPropertiesAndSetsContinuation { | ||
| GIDSignInInternalOptions *options = [self optionsWithAllParameters]; | ||
| options.claimsAsJSON = kClaimsAsJSON; | ||
| NSDictionary *extraParams = @{@"extra_key" : @"extra_value"}; | ||
|
|
||
| GIDSignInInternalOptions *continuationOptions = | ||
| [options optionsWithExtraParameters:extraParams forContinuation:YES]; | ||
|
|
||
| XCTAssertEqualObjects(continuationOptions.nonce, kNonce); | ||
| XCTAssertEqualObjects(continuationOptions.claims, [self expectedClaims]); | ||
| XCTAssertEqualObjects(continuationOptions.claimsAsJSON, kClaimsAsJSON); | ||
| XCTAssertTrue(continuationOptions.continuation); | ||
| XCTAssertEqualObjects(continuationOptions.extraParams, extraParams); | ||
| XCTAssertEqualObjects(continuationOptions.loginHint, kLoginHint); | ||
| XCTAssertEqualObjects([NSSet setWithArray:continuationOptions.scopes], | ||
| [NSSet setWithArray:options.scopes]); | ||
| XCTAssertFalse(continuationOptions.addScopesFlow); | ||
| XCTAssertTrue(continuationOptions.interactive); | ||
|
|
||
| [self verifyConfigurationAndPresentationMocks]; | ||
| } | ||
|
|
||
| - (void)testSilentOptions { | ||
| GIDSignInCompletion completion = ^(GIDSignInResult *_Nullable signInResult, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use
///so that comment is visible throughout the file.