|
|
@@ -22,6 +22,7 @@
|
|
|
|
|
|
#import "GoogleSignIn/Sources/GIDSignInInternalOptions.h"
|
|
|
#import "GoogleSignIn/Sources/GIDSignInPreferences.h"
|
|
|
+#import "GoogleSignIn/Tests/Unit/OIDAuthorizationResponse+Testing.h"
|
|
|
#import "GoogleSignIn/Tests/Unit/OIDTokenResponse+Testing.h"
|
|
|
|
|
|
#ifdef SWIFT_PACKAGE
|
|
|
@@ -35,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
static NSString * const kClientId = @"FakeClientID";
|
|
|
static NSString * const kUserEmail = @"FakeUserEmail";
|
|
|
static NSString * const kServerClientId = @"FakeServerClientID";
|
|
|
+static NSString * const kOpenIDRealm = @"FakeRealm";
|
|
|
|
|
|
static NSString * const kScopeBirthday = @"birthday";
|
|
|
static NSString * const kScopeEmail = @"email";
|
|
|
@@ -46,6 +48,7 @@ static NSString * const kScopeProfile = @"profile";
|
|
|
|
|
|
@implementation GIDAuthorizationUtilTest {
|
|
|
GIDConfiguration *_configuration;
|
|
|
+ BOOL _isEligibleForEMM;
|
|
|
}
|
|
|
|
|
|
- (void)setUp {
|
|
|
@@ -54,8 +57,14 @@ static NSString * const kScopeProfile = @"profile";
|
|
|
serverClientID:kServerClientId
|
|
|
hostedDomain:kHostedDomain
|
|
|
openIDRealm:nil];
|
|
|
+
|
|
|
+#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
|
|
|
+ _isEligibleForEMM = [UIDevice currentDevice].systemVersion.integerValue >= 9;
|
|
|
+#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
|
|
|
}
|
|
|
|
|
|
+# pragma mark - test `authorizationRequestWithOptions:emmSupport:`.
|
|
|
+
|
|
|
- (void)testCreateAuthorizationRequest_signInFlow {
|
|
|
GIDSignInInternalOptions *options =
|
|
|
[GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
|
|
|
@@ -134,11 +143,7 @@ static NSString * const kScopeProfile = @"profile";
|
|
|
- (void)testCreateAuthorizationRequest_signInFlow_EMM {
|
|
|
GIDSignInInternalOptions *options =
|
|
|
[GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
|
|
|
-#if TARGET_OS_IOS || TARGET_OS_MACCATALYST
|
|
|
presentingViewController:nil
|
|
|
-#elif TARGET_OS_OSX
|
|
|
- presentingWindow:nil
|
|
|
-#endif // TARGET_OS_OSX
|
|
|
loginHint:kUserEmail
|
|
|
addScopesFlow:NO
|
|
|
completion:nil];
|
|
|
@@ -154,8 +159,7 @@ static NSString * const kScopeProfile = @"profile";
|
|
|
systemName, [UIDevice currentDevice].systemVersion];
|
|
|
NSDictionary<NSString *, NSObject *> *authParams = request.additionalParameters;
|
|
|
|
|
|
- BOOL isEligibleForEMM = [UIDevice currentDevice].systemVersion.integerValue >= 9;
|
|
|
- if (isEligibleForEMM) {
|
|
|
+ if (_isEligibleForEMM) {
|
|
|
XCTAssertEqualObjects(authParams[@"emm_support"], kEMMVersion,
|
|
|
@"EMM support should match in auth request");
|
|
|
XCTAssertEqualObjects(authParams[@"device_os"], expectedOSVersion,
|
|
|
@@ -170,13 +174,85 @@ static NSString * const kScopeProfile = @"profile";
|
|
|
|
|
|
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
|
|
|
|
|
|
+#pragma mark - test `accessTokenRequestWithAuthState:serverClientID:openIDRealm:emmSupport:`.
|
|
|
+
|
|
|
+- (void)testCreateAccessTokenRequest_NoAccessToken_hasAuthorizationCode {
|
|
|
+ OIDAuthorizationResponse *authResponse =
|
|
|
+ [OIDAuthorizationResponse testInstanceWithAdditionalParameters:nil
|
|
|
+ errorString:nil];
|
|
|
+
|
|
|
+ OIDAuthState *authState = [[OIDAuthState alloc] initWithAuthorizationResponse:authResponse
|
|
|
+ tokenResponse:nil];
|
|
|
+
|
|
|
+ OIDTokenRequest *tokenRequest =
|
|
|
+ [GIDAuthorizationUtil accessTokenRequestWithAuthState:authState
|
|
|
+ serverClientID:kServerClientId
|
|
|
+ openIDRealm:kOpenIDRealm
|
|
|
+ emmSupport:nil];
|
|
|
+
|
|
|
+ NSDictionary<NSString *, NSString *> *params = tokenRequest.additionalParameters;
|
|
|
+ XCTAssertEqual(params[kOpenIDRealmParameter], kOpenIDRealm, @"OpenID Realm should match.");
|
|
|
+ XCTAssertEqual(params[kAudienceParameter], kServerClientId, @"Server Client ID should match.");
|
|
|
+}
|
|
|
+
|
|
|
+#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
|
|
|
+
|
|
|
+- (void)testCreateAccessTokenRequest_EMMFlow {
|
|
|
+ NSDictionary<NSString *, NSString *> *additionalParameters =
|
|
|
+ @{ @"emm_passcode_info_required" : @"1" };
|
|
|
+
|
|
|
+ OIDAuthorizationResponse *authResponse =
|
|
|
+ [OIDAuthorizationResponse testInstanceWithAdditionalParameters:additionalParameters
|
|
|
+ errorString:nil];
|
|
|
+
|
|
|
+ OIDAuthState *authState = [[OIDAuthState alloc] initWithAuthorizationResponse:authResponse
|
|
|
+ tokenResponse:nil];
|
|
|
+
|
|
|
+ OIDTokenRequest *tokenRequest =
|
|
|
+ [GIDAuthorizationUtil accessTokenRequestWithAuthState:authState
|
|
|
+ serverClientID:nil
|
|
|
+ openIDRealm:nil
|
|
|
+ emmSupport:kEMMVersion];
|
|
|
+ NSString *systemName = [UIDevice currentDevice].systemName;
|
|
|
+ if ([systemName isEqualToString:@"iPhone OS"]) {
|
|
|
+ systemName = @"iOS";
|
|
|
+ }
|
|
|
+ NSString *expectedOSVersion = [NSString stringWithFormat:@"%@ %@",
|
|
|
+ systemName, [UIDevice currentDevice].systemVersion];
|
|
|
+
|
|
|
+ NSDictionary<NSString *, NSString *> *tokenParams = tokenRequest.additionalParameters;
|
|
|
+
|
|
|
+ if (_isEligibleForEMM) {
|
|
|
+ XCTAssertEqualObjects(tokenParams[@"emm_support"], kEMMVersion,
|
|
|
+ @"EMM support should match in token request");
|
|
|
+ XCTAssertEqualObjects(tokenParams[@"device_os"],
|
|
|
+ expectedOSVersion,
|
|
|
+ @"OS version should match in token request");
|
|
|
+ XCTAssertNotNil(tokenParams[@"emm_passcode_info"],
|
|
|
+ @"passcode info should be in token request");
|
|
|
+ } else {
|
|
|
+ XCTAssertNil(tokenParams[@"emm_support"],
|
|
|
+ @"EMM support should not be in token request for unsupported OS");
|
|
|
+ XCTAssertNil(tokenParams[@"device_os"],
|
|
|
+ @"OS version should not be in token request for unsupported OS");
|
|
|
+ XCTAssertNil(tokenParams[@"emm_passcode_info"],
|
|
|
+ @"passcode info should not be in token request for unsupported OS");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
|
|
|
+
|
|
|
+#pragma mark - test `resolvedScopesFromGrantedScopes:ithNewScopes:error:`.
|
|
|
+
|
|
|
- (void)testUnionScopes_success {
|
|
|
NSArray<NSString *> *scopes = @[kScopeEmail, kScopeProfile];
|
|
|
NSArray<NSString *> *newScopes = @[kScopeBirthday];
|
|
|
|
|
|
NSError *error;
|
|
|
NSArray<NSString *> *allScopes =
|
|
|
- [GIDAuthorizationUtil resolvedScopesFromGrantedScoped:scopes
|
|
|
+ [GIDAuthorizationUtil resolvedScopesFromGrantedScopes:scopes
|
|
|
withNewScopes:newScopes
|
|
|
error:&error];
|
|
|
|
|
|
@@ -191,7 +267,7 @@ static NSString * const kScopeProfile = @"profile";
|
|
|
|
|
|
NSError *error;
|
|
|
NSArray<NSString *> *allScopes =
|
|
|
- [GIDAuthorizationUtil resolvedScopesFromGrantedScoped:scopes
|
|
|
+ [GIDAuthorizationUtil resolvedScopesFromGrantedScopes:scopes
|
|
|
withNewScopes:newScopes
|
|
|
error:&error];
|
|
|
|