From b6c416fef318e63189acf9995025573e9b77dc21 Mon Sep 17 00:00:00 2001 From: Akshat Gandhi <54901287+AkshatG6@users.noreply.github.com> Date: Tue, 7 Oct 2025 15:10:31 -0700 Subject: [PATCH 01/11] Fixing refresh parameters mismatch bug --- GoogleSignIn/Sources/GIDEMMSupport.m | 57 +++++++- GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m | 137 ++++++++++++++++++++ 2 files changed, 191 insertions(+), 3 deletions(-) diff --git a/GoogleSignIn/Sources/GIDEMMSupport.m b/GoogleSignIn/Sources/GIDEMMSupport.m index 0e7b0369..1637f476 100644 --- a/GoogleSignIn/Sources/GIDEMMSupport.m +++ b/GoogleSignIn/Sources/GIDEMMSupport.m @@ -58,6 +58,13 @@ typedef NS_ENUM(NSInteger, ErrorCode) { ErrorCodeAppVerificationRequired, }; +@interface GIDEMMSupport () + ++ (NSDictionary *) + dictionaryWithStringValuesFromDictionary:(NSDictionary *)originalDictionary; + +@end + @implementation GIDEMMSupport - (instancetype)init { @@ -115,9 +122,11 @@ + (NSDictionary *)parametersWithParameters:(NSDictionary *)parameters #pragma mark - GTMAuthSessionDelegate - (nullable NSDictionary *) -additionalTokenRefreshParametersForAuthSession:(GTMAuthSession *)authSession { - return [GIDEMMSupport updatedEMMParametersWithParameters: - authSession.authState.lastTokenResponse.additionalParameters]; + additionalTokenRefreshParametersForAuthSession:(GTMAuthSession *)authSession { + NSDictionary *additionalParameters = authSession.authState.lastTokenResponse.additionalParameters; + NSDictionary *updatedAdditionalParameters = + [GIDEMMSupport updatedEMMParametersWithParameters:additionalParameters]; + return [GIDEMMSupport dictionaryWithStringValuesFromDictionary:updatedAdditionalParameters]; } - (void)updateErrorForAuthSession:(GTMAuthSession *)authSession @@ -128,6 +137,48 @@ - (void)updateErrorForAuthSession:(GTMAuthSession *)authSession }]; } +#pragma mark - Private Helpers + ++ (NSDictionary *) + dictionaryWithStringValuesFromDictionary:(NSDictionary *)originalDictionary { + NSMutableDictionary *stringifiedDictionary = + [NSMutableDictionary dictionaryWithCapacity:originalDictionary.count]; + + [originalDictionary enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) { + // Case 1: The value is already of `NSString` type. + if ([value isKindOfClass:[NSString class]]) { + stringifiedDictionary[key] = value; + return; + } + + // Case 2: The value is of `NSNumber` type (which includes `BOOL` type). + if ([value isKindOfClass:[NSNumber class]]) { + if (CFGetTypeID((__bridge CFTypeRef)value) == CFBooleanGetTypeID()) { + stringifiedDictionary[key] = [value boolValue] ? @"true" : @"false"; + } else { + stringifiedDictionary[key] = [value stringValue]; + } + return; + } + + // Case 3: The value is of NSArray or NSDictionary type. + // To satisfy `GTMAppAuth`'s requirement for [String: String] parameters, the entire + // object is serialized into a single JSON string. + if ([NSJSONSerialization isValidJSONObject:value]) { + NSError *error = nil; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:value options:0 error:&error]; + + if (jsonData && !error) { + stringifiedDictionary[key] = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + } else { + stringifiedDictionary[key] = [value description]; + } + return; + } + }]; + return stringifiedDictionary; +} + @end NS_ASSUME_NONNULL_END diff --git a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m index 990aa733..663c77f6 100644 --- a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m +++ b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m @@ -59,6 +59,11 @@ static NSString *const kDeviceOSKey = @"device_os"; static NSString *const kEMMPasscodeInfoKey = @"emm_passcode_info"; +@interface GIDEMMSupport (Private) ++ (NSDictionary *) + dictionaryWithStringValuesFromDictionary:(NSDictionary *)originalDictionary; +@end + @interface GIDEMMSupportTest : XCTestCase // The view controller that has been presented, if any. @property(nonatomic, strong, nullable) UIViewController *presentedViewController; @@ -274,6 +279,138 @@ - (void)testHandleTokenFetchEMMError_errorIsNotEMM { [self waitForExpectations:@[ called ] timeout:1]; } +# pragma mark - String Conversion Tests + +- (void)testStringConversion_withAnyNumber_isConvertedToString { + NSDictionary *inputDictionary = @{ @"number_key": @12345 }; + + NSDictionary *resultDictionary = [GIDEMMSupport + dictionaryWithStringValuesFromDictionary:inputDictionary]; + + XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]]); + XCTAssertEqualObjects(resultDictionary[@"number_key"], @"12345", + @"The NSNumber should be converted to a string."); +} + +- (void)testStringConversion_withNumberOne_isConvertedToString { + NSDictionary *inputDictionary = @{ @"number_key": @1 }; + + NSDictionary *resultDictionary = [GIDEMMSupport + dictionaryWithStringValuesFromDictionary:inputDictionary]; + + XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]]); + XCTAssertEqualObjects(resultDictionary[@"number_key"], @"1", + @"The NSNumber should be converted to a string."); +} + +- (void)testStringConversion_withNumberZero_isConvertedToString { + NSDictionary *inputDictionary = @{ @"number_key": @0}; + + NSDictionary *resultDictionary = [GIDEMMSupport + dictionaryWithStringValuesFromDictionary:inputDictionary]; + + XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]]); + XCTAssertEqualObjects(resultDictionary[@"number_key"], @"0", + @"The NSNumber should be converted to a string."); +} + +- (void)testStringConversion_withBooleanYes_isConvertedToTrueString { + NSDictionary *inputDictionary = @{ @"bool_key": @YES }; + + NSDictionary *resultDictionary = [GIDEMMSupport + dictionaryWithStringValuesFromDictionary:inputDictionary]; + + XCTAssertTrue([resultDictionary[@"bool_key"] isKindOfClass:[NSString class]], + @"The value should be an NSString."); + XCTAssertEqualObjects(resultDictionary[@"bool_key"], @"true", + @"The boolean YES should be converted to the string 'true'."); +} + +- (void)testStringConversion_withBooleanNo_isConvertedToFalseString { + NSDictionary *inputDictionary = @{ @"bool_key": @NO }; + + NSDictionary *resultDictionary = [GIDEMMSupport + dictionaryWithStringValuesFromDictionary:inputDictionary]; + + XCTAssertTrue([resultDictionary[@"bool_key"] isKindOfClass:[NSString class]], + @"The value should be an NSString."); + XCTAssertEqualObjects(resultDictionary[@"bool_key"], @"false", + @"The boolean NO should be converted to the string 'false'."); +} + +- (void)testStringConversion_withString_remainsUnchanged { + NSDictionary *inputDictionary = @{ @"string_key": @"hello" }; + + NSDictionary *resultDictionary = [GIDEMMSupport + dictionaryWithStringValuesFromDictionary:inputDictionary]; + + XCTAssertTrue([resultDictionary[@"string_key"] isKindOfClass:[NSString class]], + @"The value should still be an NSString."); + XCTAssertEqualObjects(resultDictionary[@"string_key"], @"hello", + @"The original string value should be preserved."); +} + +- (void)testStringConversion_withArray_isConvertedToJSONString { + NSDictionary *inputDictionary = @{ + @"array_key": @[ @1, @"two", @YES ] + }; + + NSDictionary *resultDictionary = [GIDEMMSupport + dictionaryWithStringValuesFromDictionary:inputDictionary]; + + XCTAssertTrue([resultDictionary[@"array_key"] isKindOfClass:[NSString class]], + @"The value should be an NSString."); + XCTAssertEqualObjects(resultDictionary[@"array_key"], @"[1,\"two\",true]", + @"The array should be serialized into a JSON string."); +} + +- (void)testStringConversion_withDictionary_isConvertedToJSONString { + NSDictionary *valueAsDictionary = @{ @"nested_key": @"nested_value" }; + NSDictionary *inputDictionary = @{ + @"dict_key": @{ + @"nested_key": @"nested_value" + } + }; + + NSDictionary *resultDictionary = [GIDEMMSupport + dictionaryWithStringValuesFromDictionary:inputDictionary]; + + XCTAssertTrue([resultDictionary[@"dict_key"] isKindOfClass:[NSString class]], + @"The value should be an NSString."); + XCTAssertEqualObjects(resultDictionary[@"dict_key"], @"{\"nested_key\":\"nested_value\"}", + @"The dictionary should be serialized into a JSON string."); +} + +- (void)testStringConversion_withMixedTypes_allAreConverted { + NSDictionary *inputDictionary = @{ + @"string_key": @"hello", + @"number_key": @987, + @"bool_key": @YES, + @"array_key": @[ @"a", @NO ], + }; + + NSDictionary *resultDictionary = [GIDEMMSupport + dictionaryWithStringValuesFromDictionary:inputDictionary]; + + XCTAssertTrue([resultDictionary[@"string_key"] isKindOfClass:[NSString class]]); + XCTAssertEqualObjects(resultDictionary[@"string_key"], @"hello"); + + XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]]); + XCTAssertEqualObjects(resultDictionary[@"number_key"], @"987"); + + XCTAssertTrue([resultDictionary[@"bool_key"] isKindOfClass:[NSString class]]); + XCTAssertEqualObjects(resultDictionary[@"bool_key"], @"true"); + + XCTAssertTrue([resultDictionary[@"array_key"] isKindOfClass:[NSString class]]); + XCTAssertEqualObjects(resultDictionary[@"array_key"], @"[\"a\",false]"); +} + +- (void)testStringConversion_withEmptyDictionary_returnsEmptyDictionary { + NSDictionary *resultDictionary = [GIDEMMSupport dictionaryWithStringValuesFromDictionary:@{}]; + + XCTAssertEqual(resultDictionary.count, 0, @"The resulting dictionary should be empty."); +} + # pragma mark - Helpers - (NSString *)systemVersion { From cfb1d71e60073c9944a15c1fe6eafca78c3fbff3 Mon Sep 17 00:00:00 2001 From: Akshat Gandhi <54901287+AkshatG6@users.noreply.github.com> Date: Tue, 7 Oct 2025 15:42:26 -0700 Subject: [PATCH 02/11] Fixed styling --- GoogleSignIn/Sources/GIDEMMSupport.m | 6 ++-- GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m | 34 +++++++++++++-------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/GoogleSignIn/Sources/GIDEMMSupport.m b/GoogleSignIn/Sources/GIDEMMSupport.m index 1637f476..8b118dd7 100644 --- a/GoogleSignIn/Sources/GIDEMMSupport.m +++ b/GoogleSignIn/Sources/GIDEMMSupport.m @@ -161,9 +161,9 @@ - (void)updateErrorForAuthSession:(GTMAuthSession *)authSession return; } - // Case 3: The value is of NSArray or NSDictionary type. - // To satisfy `GTMAppAuth`'s requirement for [String: String] parameters, the entire - // object is serialized into a single JSON string. + // Case 3: The value is of `NSArray` or `NSDictionary` type. + // To satisfy `GTMAppAuth`'s requirement for `NSDictionary` parameter, + // the entire value object is serialized into a single `JSON` string. if ([NSJSONSerialization isValidJSONObject:value]) { NSError *error = nil; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:value options:0 error:&error]; diff --git a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m index 663c77f6..40194614 100644 --- a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m +++ b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m @@ -287,7 +287,8 @@ - (void)testStringConversion_withAnyNumber_isConvertedToString { NSDictionary *resultDictionary = [GIDEMMSupport dictionaryWithStringValuesFromDictionary:inputDictionary]; - XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]]); + XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]], + @"The value should be an NSString."); XCTAssertEqualObjects(resultDictionary[@"number_key"], @"12345", @"The NSNumber should be converted to a string."); } @@ -298,7 +299,8 @@ - (void)testStringConversion_withNumberOne_isConvertedToString { NSDictionary *resultDictionary = [GIDEMMSupport dictionaryWithStringValuesFromDictionary:inputDictionary]; - XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]]); + XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]], + @"The value should be an NSString."); XCTAssertEqualObjects(resultDictionary[@"number_key"], @"1", @"The NSNumber should be converted to a string."); } @@ -309,7 +311,8 @@ - (void)testStringConversion_withNumberZero_isConvertedToString { NSDictionary *resultDictionary = [GIDEMMSupport dictionaryWithStringValuesFromDictionary:inputDictionary]; - XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]]); + XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]], + @"The value should be an NSString."); XCTAssertEqualObjects(resultDictionary[@"number_key"], @"0", @"The NSNumber should be converted to a string."); } @@ -365,7 +368,6 @@ - (void)testStringConversion_withArray_isConvertedToJSONString { } - (void)testStringConversion_withDictionary_isConvertedToJSONString { - NSDictionary *valueAsDictionary = @{ @"nested_key": @"nested_value" }; NSDictionary *inputDictionary = @{ @"dict_key": @{ @"nested_key": @"nested_value" @@ -392,17 +394,25 @@ - (void)testStringConversion_withMixedTypes_allAreConverted { NSDictionary *resultDictionary = [GIDEMMSupport dictionaryWithStringValuesFromDictionary:inputDictionary]; - XCTAssertTrue([resultDictionary[@"string_key"] isKindOfClass:[NSString class]]); - XCTAssertEqualObjects(resultDictionary[@"string_key"], @"hello"); + XCTAssertTrue([resultDictionary[@"string_key"] isKindOfClass:[NSString class]], + @"The value should be an NSString."); + XCTAssertEqualObjects(resultDictionary[@"string_key"], @"hello", + @"The original string value should be preserved"); - XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]]); - XCTAssertEqualObjects(resultDictionary[@"number_key"], @"987"); + XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]], + @"The value should be an NSString."); + XCTAssertEqualObjects(resultDictionary[@"number_key"], @"987", + @"The NSNumber should be converted to a string."); - XCTAssertTrue([resultDictionary[@"bool_key"] isKindOfClass:[NSString class]]); - XCTAssertEqualObjects(resultDictionary[@"bool_key"], @"true"); + XCTAssertTrue([resultDictionary[@"bool_key"] isKindOfClass:[NSString class]], + @"The value should be an NSString."); + XCTAssertEqualObjects(resultDictionary[@"bool_key"], @"true", + @"The boolean YES should be converted to the string 'true'."); - XCTAssertTrue([resultDictionary[@"array_key"] isKindOfClass:[NSString class]]); - XCTAssertEqualObjects(resultDictionary[@"array_key"], @"[\"a\",false]"); + XCTAssertTrue([resultDictionary[@"array_key"] isKindOfClass:[NSString class]], + @"The value should be an NSString."); + XCTAssertEqualObjects(resultDictionary[@"array_key"], @"[\"a\",false]", + @"The array should be serialized into a JSON string."); } - (void)testStringConversion_withEmptyDictionary_returnsEmptyDictionary { From d7cbecb21de8708f9ee23a60ed34db3f88f77e02 Mon Sep 17 00:00:00 2001 From: Akshat Gandhi <54901287+AkshatG6@users.noreply.github.com> Date: Tue, 7 Oct 2025 17:59:06 -0700 Subject: [PATCH 03/11] Removed the support for handling nested containers in GIDEMMSupport.m --- GoogleSignIn/Sources/GIDEMMSupport.m | 18 ++---- GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m | 68 --------------------- 2 files changed, 4 insertions(+), 82 deletions(-) diff --git a/GoogleSignIn/Sources/GIDEMMSupport.m b/GoogleSignIn/Sources/GIDEMMSupport.m index 8b118dd7..c1c57a8d 100644 --- a/GoogleSignIn/Sources/GIDEMMSupport.m +++ b/GoogleSignIn/Sources/GIDEMMSupport.m @@ -161,20 +161,10 @@ - (void)updateErrorForAuthSession:(GTMAuthSession *)authSession return; } - // Case 3: The value is of `NSArray` or `NSDictionary` type. - // To satisfy `GTMAppAuth`'s requirement for `NSDictionary` parameter, - // the entire value object is serialized into a single `JSON` string. - if ([NSJSONSerialization isValidJSONObject:value]) { - NSError *error = nil; - NSData *jsonData = [NSJSONSerialization dataWithJSONObject:value options:0 error:&error]; - - if (jsonData && !error) { - stringifiedDictionary[key] = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; - } else { - stringifiedDictionary[key] = [value description]; - } - return; - } + // NOTE: Nested container objects (e.g., NSArray, NSDictionary) are intentionally ignored. + // The underlying AppAuth API expects a flat `NSDictionary` and is + // not designed for serialized, nested objects. A proper fix for nested objects + // would require a larger refactoring of the AppAuth and GTMAppAuth libraries. }]; return stringifiedDictionary; } diff --git a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m index 40194614..a7edbabb 100644 --- a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m +++ b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m @@ -353,74 +353,6 @@ - (void)testStringConversion_withString_remainsUnchanged { @"The original string value should be preserved."); } -- (void)testStringConversion_withArray_isConvertedToJSONString { - NSDictionary *inputDictionary = @{ - @"array_key": @[ @1, @"two", @YES ] - }; - - NSDictionary *resultDictionary = [GIDEMMSupport - dictionaryWithStringValuesFromDictionary:inputDictionary]; - - XCTAssertTrue([resultDictionary[@"array_key"] isKindOfClass:[NSString class]], - @"The value should be an NSString."); - XCTAssertEqualObjects(resultDictionary[@"array_key"], @"[1,\"two\",true]", - @"The array should be serialized into a JSON string."); -} - -- (void)testStringConversion_withDictionary_isConvertedToJSONString { - NSDictionary *inputDictionary = @{ - @"dict_key": @{ - @"nested_key": @"nested_value" - } - }; - - NSDictionary *resultDictionary = [GIDEMMSupport - dictionaryWithStringValuesFromDictionary:inputDictionary]; - - XCTAssertTrue([resultDictionary[@"dict_key"] isKindOfClass:[NSString class]], - @"The value should be an NSString."); - XCTAssertEqualObjects(resultDictionary[@"dict_key"], @"{\"nested_key\":\"nested_value\"}", - @"The dictionary should be serialized into a JSON string."); -} - -- (void)testStringConversion_withMixedTypes_allAreConverted { - NSDictionary *inputDictionary = @{ - @"string_key": @"hello", - @"number_key": @987, - @"bool_key": @YES, - @"array_key": @[ @"a", @NO ], - }; - - NSDictionary *resultDictionary = [GIDEMMSupport - dictionaryWithStringValuesFromDictionary:inputDictionary]; - - XCTAssertTrue([resultDictionary[@"string_key"] isKindOfClass:[NSString class]], - @"The value should be an NSString."); - XCTAssertEqualObjects(resultDictionary[@"string_key"], @"hello", - @"The original string value should be preserved"); - - XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]], - @"The value should be an NSString."); - XCTAssertEqualObjects(resultDictionary[@"number_key"], @"987", - @"The NSNumber should be converted to a string."); - - XCTAssertTrue([resultDictionary[@"bool_key"] isKindOfClass:[NSString class]], - @"The value should be an NSString."); - XCTAssertEqualObjects(resultDictionary[@"bool_key"], @"true", - @"The boolean YES should be converted to the string 'true'."); - - XCTAssertTrue([resultDictionary[@"array_key"] isKindOfClass:[NSString class]], - @"The value should be an NSString."); - XCTAssertEqualObjects(resultDictionary[@"array_key"], @"[\"a\",false]", - @"The array should be serialized into a JSON string."); -} - -- (void)testStringConversion_withEmptyDictionary_returnsEmptyDictionary { - NSDictionary *resultDictionary = [GIDEMMSupport dictionaryWithStringValuesFromDictionary:@{}]; - - XCTAssertEqual(resultDictionary.count, 0, @"The resulting dictionary should be empty."); -} - # pragma mark - Helpers - (NSString *)systemVersion { From 55aa271d62e91431def43f586ddb5719ce2a4f84 Mon Sep 17 00:00:00 2001 From: Akshat Gandhi <54901287+AkshatG6@users.noreply.github.com> Date: Wed, 8 Oct 2025 10:59:49 -0700 Subject: [PATCH 04/11] Updated comments in GIDEMMSupport.m --- GoogleSignIn/Sources/GIDEMMSupport.m | 8 -------- 1 file changed, 8 deletions(-) diff --git a/GoogleSignIn/Sources/GIDEMMSupport.m b/GoogleSignIn/Sources/GIDEMMSupport.m index c1c57a8d..a09a48ce 100644 --- a/GoogleSignIn/Sources/GIDEMMSupport.m +++ b/GoogleSignIn/Sources/GIDEMMSupport.m @@ -145,13 +145,10 @@ - (void)updateErrorForAuthSession:(GTMAuthSession *)authSession [NSMutableDictionary dictionaryWithCapacity:originalDictionary.count]; [originalDictionary enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) { - // Case 1: The value is already of `NSString` type. if ([value isKindOfClass:[NSString class]]) { stringifiedDictionary[key] = value; return; } - - // Case 2: The value is of `NSNumber` type (which includes `BOOL` type). if ([value isKindOfClass:[NSNumber class]]) { if (CFGetTypeID((__bridge CFTypeRef)value) == CFBooleanGetTypeID()) { stringifiedDictionary[key] = [value boolValue] ? @"true" : @"false"; @@ -160,11 +157,6 @@ - (void)updateErrorForAuthSession:(GTMAuthSession *)authSession } return; } - - // NOTE: Nested container objects (e.g., NSArray, NSDictionary) are intentionally ignored. - // The underlying AppAuth API expects a flat `NSDictionary` and is - // not designed for serialized, nested objects. A proper fix for nested objects - // would require a larger refactoring of the AppAuth and GTMAppAuth libraries. }]; return stringifiedDictionary; } From 4177aed7264f2ea03ba0cff692ebb6f07da6ca67 Mon Sep 17 00:00:00 2001 From: Akshat Gandhi <54901287+AkshatG6@users.noreply.github.com> Date: Thu, 9 Oct 2025 08:52:15 -0700 Subject: [PATCH 05/11] Updated tests. --- GoogleSignIn/Sources/GIDEMMSupport.m | 17 +--- GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m | 95 +++++++++++++-------- 2 files changed, 63 insertions(+), 49 deletions(-) diff --git a/GoogleSignIn/Sources/GIDEMMSupport.m b/GoogleSignIn/Sources/GIDEMMSupport.m index a09a48ce..b54e7907 100644 --- a/GoogleSignIn/Sources/GIDEMMSupport.m +++ b/GoogleSignIn/Sources/GIDEMMSupport.m @@ -58,13 +58,6 @@ typedef NS_ENUM(NSInteger, ErrorCode) { ErrorCodeAppVerificationRequired, }; -@interface GIDEMMSupport () - -+ (NSDictionary *) - dictionaryWithStringValuesFromDictionary:(NSDictionary *)originalDictionary; - -@end - @implementation GIDEMMSupport - (instancetype)init { @@ -116,17 +109,15 @@ + (NSDictionary *)parametersWithParameters:(NSDictionary *)parameters if (isPasscodeInfoRequired) { allParameters[kEMMPasscodeInfoParameterName] = [GIDMDMPasscodeState passcodeState].info; } - return allParameters; + return [GIDEMMSupport dictionaryWithStringValuesFromDictionary:allParameters]; } #pragma mark - GTMAuthSessionDelegate - (nullable NSDictionary *) - additionalTokenRefreshParametersForAuthSession:(GTMAuthSession *)authSession { - NSDictionary *additionalParameters = authSession.authState.lastTokenResponse.additionalParameters; - NSDictionary *updatedAdditionalParameters = - [GIDEMMSupport updatedEMMParametersWithParameters:additionalParameters]; - return [GIDEMMSupport dictionaryWithStringValuesFromDictionary:updatedAdditionalParameters]; +additionalTokenRefreshParametersForAuthSession:(GTMAuthSession *)authSession { + return [GIDEMMSupport updatedEMMParametersWithParameters: + authSession.authState.lastTokenResponse.additionalParameters]; } - (void)updateErrorForAuthSession:(GTMAuthSession *)authSession diff --git a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m index a7edbabb..ea405f3b 100644 --- a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m +++ b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m @@ -281,76 +281,89 @@ - (void)testHandleTokenFetchEMMError_errorIsNotEMM { # pragma mark - String Conversion Tests -- (void)testStringConversion_withAnyNumber_isConvertedToString { - NSDictionary *inputDictionary = @{ @"number_key": @12345 }; +- (void)testParametersWithParameters_withAnyNumber_isConvertedToString { + NSDictionary *inputParameters = @{ @"number_key": @12345 }; - NSDictionary *resultDictionary = [GIDEMMSupport - dictionaryWithStringValuesFromDictionary:inputDictionary]; + NSDictionary *stringifiedParameters = [GIDEMMSupport parametersWithParameters:inputParameters + emmSupport:@"1" + isPasscodeInfoRequired:NO]; - XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]], + XCTAssertTrue([stringifiedParameters[@"number_key"] isKindOfClass:[NSString class]], @"The value should be an NSString."); - XCTAssertEqualObjects(resultDictionary[@"number_key"], @"12345", + XCTAssertEqualObjects(stringifiedParameters[@"number_key"], @"12345", @"The NSNumber should be converted to a string."); + [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; } -- (void)testStringConversion_withNumberOne_isConvertedToString { - NSDictionary *inputDictionary = @{ @"number_key": @1 }; - NSDictionary *resultDictionary = [GIDEMMSupport - dictionaryWithStringValuesFromDictionary:inputDictionary]; +- (void)testParametersWithParameters_withNumberOne_isConvertedToString { + NSDictionary *inputParameters = @{ @"number_key": @1 }; - XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]], + NSDictionary *stringifiedParameters = [GIDEMMSupport parametersWithParameters:inputParameters + emmSupport:@"1" + isPasscodeInfoRequired:NO]; + + XCTAssertTrue([stringifiedParameters[@"number_key"] isKindOfClass:[NSString class]], @"The value should be an NSString."); - XCTAssertEqualObjects(resultDictionary[@"number_key"], @"1", + XCTAssertEqualObjects(stringifiedParameters[@"number_key"], @"1", @"The NSNumber should be converted to a string."); + [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; } -- (void)testStringConversion_withNumberZero_isConvertedToString { - NSDictionary *inputDictionary = @{ @"number_key": @0}; +- (void)testParametersWithParameters_withNumberZero_isConvertedToString { + NSDictionary *inputParameters = @{ @"number_key": @0}; - NSDictionary *resultDictionary = [GIDEMMSupport - dictionaryWithStringValuesFromDictionary:inputDictionary]; + NSDictionary *stringifiedParameters = [GIDEMMSupport parametersWithParameters:inputParameters + emmSupport:@"1" + isPasscodeInfoRequired:NO]; - XCTAssertTrue([resultDictionary[@"number_key"] isKindOfClass:[NSString class]], + XCTAssertTrue([stringifiedParameters[@"number_key"] isKindOfClass:[NSString class]], @"The value should be an NSString."); - XCTAssertEqualObjects(resultDictionary[@"number_key"], @"0", + XCTAssertEqualObjects(stringifiedParameters[@"number_key"], @"0", @"The NSNumber should be converted to a string."); + [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; } -- (void)testStringConversion_withBooleanYes_isConvertedToTrueString { - NSDictionary *inputDictionary = @{ @"bool_key": @YES }; +- (void)testParametersWithParameters_withBooleanYes_isConvertedToTrueString { + NSDictionary *inputParameters = @{ @"bool_key": @YES }; - NSDictionary *resultDictionary = [GIDEMMSupport - dictionaryWithStringValuesFromDictionary:inputDictionary]; + NSDictionary *stringifiedParameters = [GIDEMMSupport parametersWithParameters:inputParameters + emmSupport:@"1" + isPasscodeInfoRequired:NO]; - XCTAssertTrue([resultDictionary[@"bool_key"] isKindOfClass:[NSString class]], + XCTAssertTrue([stringifiedParameters[@"bool_key"] isKindOfClass:[NSString class]], @"The value should be an NSString."); - XCTAssertEqualObjects(resultDictionary[@"bool_key"], @"true", + XCTAssertEqualObjects(stringifiedParameters[@"bool_key"], @"true", @"The boolean YES should be converted to the string 'true'."); + [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; } -- (void)testStringConversion_withBooleanNo_isConvertedToFalseString { - NSDictionary *inputDictionary = @{ @"bool_key": @NO }; +- (void)testParametersWithParameters_withBooleanNo_isConvertedToFalseString { + NSDictionary *inputParameters = @{ @"bool_key": @NO }; - NSDictionary *resultDictionary = [GIDEMMSupport - dictionaryWithStringValuesFromDictionary:inputDictionary]; + NSDictionary *stringifiedParameters = [GIDEMMSupport parametersWithParameters:inputParameters + emmSupport:@"1" + isPasscodeInfoRequired:NO]; - XCTAssertTrue([resultDictionary[@"bool_key"] isKindOfClass:[NSString class]], + XCTAssertTrue([stringifiedParameters[@"bool_key"] isKindOfClass:[NSString class]], @"The value should be an NSString."); - XCTAssertEqualObjects(resultDictionary[@"bool_key"], @"false", + XCTAssertEqualObjects(stringifiedParameters[@"bool_key"], @"false", @"The boolean NO should be converted to the string 'false'."); + [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; } -- (void)testStringConversion_withString_remainsUnchanged { - NSDictionary *inputDictionary = @{ @"string_key": @"hello" }; +- (void)testParametersWithParameters_withString_remainsUnchanged { + NSDictionary *inputParameters = @{ @"string_key": @"hello" }; - NSDictionary *resultDictionary = [GIDEMMSupport - dictionaryWithStringValuesFromDictionary:inputDictionary]; + NSDictionary *stringifiedParameters = [GIDEMMSupport parametersWithParameters:inputParameters + emmSupport:@"1" + isPasscodeInfoRequired:NO]; - XCTAssertTrue([resultDictionary[@"string_key"] isKindOfClass:[NSString class]], + XCTAssertTrue([stringifiedParameters[@"string_key"] isKindOfClass:[NSString class]], @"The value should still be an NSString."); - XCTAssertEqualObjects(resultDictionary[@"string_key"], @"hello", + XCTAssertEqualObjects(stringifiedParameters[@"string_key"], @"hello", @"The original string value should be preserved."); + [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; } # pragma mark - Helpers @@ -381,6 +394,16 @@ - (void)unswizzle { self.presentedViewController = nil; } +- (void)assertAllKeysAndValuesAreStringsInDictionary:(NSDictionary *)dictionary { + [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + XCTAssertTrue([key isKindOfClass:[NSString class]], + @"All keys must be NSStrings. Found a key of type '%@'.", [key class]); + XCTAssertTrue([obj isKindOfClass:[NSString class]], + @"All values must be NSStrings. Found a value of type '%@' for key '%@'.", + [obj class], key); + }]; +} + @end NS_ASSUME_NONNULL_END From 02bed528636f494af79f8c06cabfcc50378d7334 Mon Sep 17 00:00:00 2001 From: Akshat Gandhi <54901287+AkshatG6@users.noreply.github.com> Date: Thu, 9 Oct 2025 08:55:34 -0700 Subject: [PATCH 06/11] Updated tests. --- GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m | 5 ----- 1 file changed, 5 deletions(-) diff --git a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m index ea405f3b..f5b97362 100644 --- a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m +++ b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m @@ -59,11 +59,6 @@ static NSString *const kDeviceOSKey = @"device_os"; static NSString *const kEMMPasscodeInfoKey = @"emm_passcode_info"; -@interface GIDEMMSupport (Private) -+ (NSDictionary *) - dictionaryWithStringValuesFromDictionary:(NSDictionary *)originalDictionary; -@end - @interface GIDEMMSupportTest : XCTestCase // The view controller that has been presented, if any. @property(nonatomic, strong, nullable) UIViewController *presentedViewController; From cd35b3d23d84b455494b7df536f99dfdcbaf1a89 Mon Sep 17 00:00:00 2001 From: Akshat Gandhi <54901287+AkshatG6@users.noreply.github.com> Date: Thu, 9 Oct 2025 09:04:31 -0700 Subject: [PATCH 07/11] Updated tests. --- GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m | 24 ++++++--------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m index f5b97362..9925178b 100644 --- a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m +++ b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m @@ -283,11 +283,9 @@ - (void)testParametersWithParameters_withAnyNumber_isConvertedToString { emmSupport:@"1" isPasscodeInfoRequired:NO]; - XCTAssertTrue([stringifiedParameters[@"number_key"] isKindOfClass:[NSString class]], - @"The value should be an NSString."); + [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; XCTAssertEqualObjects(stringifiedParameters[@"number_key"], @"12345", @"The NSNumber should be converted to a string."); - [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; } @@ -298,11 +296,9 @@ - (void)testParametersWithParameters_withNumberOne_isConvertedToString { emmSupport:@"1" isPasscodeInfoRequired:NO]; - XCTAssertTrue([stringifiedParameters[@"number_key"] isKindOfClass:[NSString class]], - @"The value should be an NSString."); + [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; XCTAssertEqualObjects(stringifiedParameters[@"number_key"], @"1", @"The NSNumber should be converted to a string."); - [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; } - (void)testParametersWithParameters_withNumberZero_isConvertedToString { @@ -312,11 +308,9 @@ - (void)testParametersWithParameters_withNumberZero_isConvertedToString { emmSupport:@"1" isPasscodeInfoRequired:NO]; - XCTAssertTrue([stringifiedParameters[@"number_key"] isKindOfClass:[NSString class]], - @"The value should be an NSString."); + [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; XCTAssertEqualObjects(stringifiedParameters[@"number_key"], @"0", @"The NSNumber should be converted to a string."); - [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; } - (void)testParametersWithParameters_withBooleanYes_isConvertedToTrueString { @@ -326,11 +320,9 @@ - (void)testParametersWithParameters_withBooleanYes_isConvertedToTrueString { emmSupport:@"1" isPasscodeInfoRequired:NO]; - XCTAssertTrue([stringifiedParameters[@"bool_key"] isKindOfClass:[NSString class]], - @"The value should be an NSString."); + [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; XCTAssertEqualObjects(stringifiedParameters[@"bool_key"], @"true", @"The boolean YES should be converted to the string 'true'."); - [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; } - (void)testParametersWithParameters_withBooleanNo_isConvertedToFalseString { @@ -340,11 +332,9 @@ - (void)testParametersWithParameters_withBooleanNo_isConvertedToFalseString { emmSupport:@"1" isPasscodeInfoRequired:NO]; - XCTAssertTrue([stringifiedParameters[@"bool_key"] isKindOfClass:[NSString class]], - @"The value should be an NSString."); + [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; XCTAssertEqualObjects(stringifiedParameters[@"bool_key"], @"false", @"The boolean NO should be converted to the string 'false'."); - [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; } - (void)testParametersWithParameters_withString_remainsUnchanged { @@ -354,11 +344,9 @@ - (void)testParametersWithParameters_withString_remainsUnchanged { emmSupport:@"1" isPasscodeInfoRequired:NO]; - XCTAssertTrue([stringifiedParameters[@"string_key"] isKindOfClass:[NSString class]], - @"The value should still be an NSString."); + [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; XCTAssertEqualObjects(stringifiedParameters[@"string_key"], @"hello", @"The original string value should be preserved."); - [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; } # pragma mark - Helpers From 984f68746c7de628d747d9f03a8fe727c99d24aa Mon Sep 17 00:00:00 2001 From: Akshat Gandhi <54901287+AkshatG6@users.noreply.github.com> Date: Thu, 9 Oct 2025 09:48:16 -0700 Subject: [PATCH 08/11] Updated tests. --- GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m | 1 - 1 file changed, 1 deletion(-) diff --git a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m index 9925178b..fd48c70f 100644 --- a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m +++ b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m @@ -288,7 +288,6 @@ - (void)testParametersWithParameters_withAnyNumber_isConvertedToString { @"The NSNumber should be converted to a string."); } - - (void)testParametersWithParameters_withNumberOne_isConvertedToString { NSDictionary *inputParameters = @{ @"number_key": @1 }; From e09d59bc906bb6df2508dde35c966973a861e024 Mon Sep 17 00:00:00 2001 From: Akshat Gandhi <54901287+AkshatG6@users.noreply.github.com> Date: Thu, 9 Oct 2025 11:45:58 -0700 Subject: [PATCH 09/11] Updated method return type in GIDEMMSupport --- GoogleSignIn/Sources/GIDEMMSupport.h | 9 +++++---- GoogleSignIn/Sources/GIDEMMSupport.m | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/GoogleSignIn/Sources/GIDEMMSupport.h b/GoogleSignIn/Sources/GIDEMMSupport.h index f57a6af7..61f445a4 100644 --- a/GoogleSignIn/Sources/GIDEMMSupport.h +++ b/GoogleSignIn/Sources/GIDEMMSupport.h @@ -34,12 +34,13 @@ NS_ASSUME_NONNULL_BEGIN completion:(void (^)(NSError *_Nullable))completion; /// Gets a new set of URL parameters that contains updated EMM-related URL parameters if needed. -+ (NSDictionary *)updatedEMMParametersWithParameters:(NSDictionary *)parameters; ++ (NSDictionary *)updatedEMMParametersWithParameters: + (NSDictionary *)parameters; /// Gets a new set of URL parameters that also contains EMM-related URL parameters if needed. -+ (NSDictionary *)parametersWithParameters:(NSDictionary *)parameters - emmSupport:(nullable NSString *)emmSupport - isPasscodeInfoRequired:(BOOL)isPasscodeInfoRequired; ++ (NSDictionary *)parametersWithParameters:(NSDictionary *)parameters + emmSupport:(nullable NSString *)emmSupport + isPasscodeInfoRequired:(BOOL)isPasscodeInfoRequired; @end diff --git a/GoogleSignIn/Sources/GIDEMMSupport.m b/GoogleSignIn/Sources/GIDEMMSupport.m index b54e7907..0914d841 100644 --- a/GoogleSignIn/Sources/GIDEMMSupport.m +++ b/GoogleSignIn/Sources/GIDEMMSupport.m @@ -84,16 +84,16 @@ + (void)handleTokenFetchEMMError:(nullable NSError *)error } } -+ (NSDictionary *)updatedEMMParametersWithParameters:(NSDictionary *)parameters { ++ (NSDictionary *)updatedEMMParametersWithParameters: + (NSDictionary *)parameters { return [self parametersWithParameters:parameters emmSupport:parameters[kEMMSupportParameterName] isPasscodeInfoRequired:parameters[kEMMPasscodeInfoParameterName] != nil]; } - -+ (NSDictionary *)parametersWithParameters:(NSDictionary *)parameters - emmSupport:(nullable NSString *)emmSupport - isPasscodeInfoRequired:(BOOL)isPasscodeInfoRequired { ++ (NSDictionary *)parametersWithParameters:(NSDictionary *)parameters + emmSupport:(nullable NSString *)emmSupport + isPasscodeInfoRequired:(BOOL)isPasscodeInfoRequired { if (!emmSupport) { return parameters; } From 16ac0bb73894eb03fb8f6e4d86ec05138c2cae00 Mon Sep 17 00:00:00 2001 From: Akshat Gandhi <54901287+AkshatG6@users.noreply.github.com> Date: Thu, 16 Oct 2025 11:12:25 -0700 Subject: [PATCH 10/11] Updated tests in GIDEMMSupportTest --- GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m | 58 +++++++++++++++------ 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m index fd48c70f..08eb150f 100644 --- a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m +++ b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m @@ -283,9 +283,15 @@ - (void)testParametersWithParameters_withAnyNumber_isConvertedToString { emmSupport:@"1" isPasscodeInfoRequired:NO]; - [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; XCTAssertEqualObjects(stringifiedParameters[@"number_key"], @"12345", @"The NSNumber should be converted to a string."); + [stringifiedParameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + XCTAssertTrue([key isKindOfClass:[NSString class]], + @"All keys must be NSStrings. Found a key of type '%@'.", [key class]); + XCTAssertTrue([obj isKindOfClass:[NSString class]], + @"All values must be NSStrings. Found a value of type '%@' for key '%@'.", + [obj class], key); + }]; } - (void)testParametersWithParameters_withNumberOne_isConvertedToString { @@ -295,9 +301,15 @@ - (void)testParametersWithParameters_withNumberOne_isConvertedToString { emmSupport:@"1" isPasscodeInfoRequired:NO]; - [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; XCTAssertEqualObjects(stringifiedParameters[@"number_key"], @"1", @"The NSNumber should be converted to a string."); + [stringifiedParameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + XCTAssertTrue([key isKindOfClass:[NSString class]], + @"All keys must be NSStrings. Found a key of type '%@'.", [key class]); + XCTAssertTrue([obj isKindOfClass:[NSString class]], + @"All values must be NSStrings. Found a value of type '%@' for key '%@'.", + [obj class], key); + }]; } - (void)testParametersWithParameters_withNumberZero_isConvertedToString { @@ -307,9 +319,15 @@ - (void)testParametersWithParameters_withNumberZero_isConvertedToString { emmSupport:@"1" isPasscodeInfoRequired:NO]; - [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; XCTAssertEqualObjects(stringifiedParameters[@"number_key"], @"0", @"The NSNumber should be converted to a string."); + [stringifiedParameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + XCTAssertTrue([key isKindOfClass:[NSString class]], + @"All keys must be NSStrings. Found a key of type '%@'.", [key class]); + XCTAssertTrue([obj isKindOfClass:[NSString class]], + @"All values must be NSStrings. Found a value of type '%@' for key '%@'.", + [obj class], key); + }]; } - (void)testParametersWithParameters_withBooleanYes_isConvertedToTrueString { @@ -319,9 +337,15 @@ - (void)testParametersWithParameters_withBooleanYes_isConvertedToTrueString { emmSupport:@"1" isPasscodeInfoRequired:NO]; - [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; XCTAssertEqualObjects(stringifiedParameters[@"bool_key"], @"true", @"The boolean YES should be converted to the string 'true'."); + [stringifiedParameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + XCTAssertTrue([key isKindOfClass:[NSString class]], + @"All keys must be NSStrings. Found a key of type '%@'.", [key class]); + XCTAssertTrue([obj isKindOfClass:[NSString class]], + @"All values must be NSStrings. Found a value of type '%@' for key '%@'.", + [obj class], key); + }]; } - (void)testParametersWithParameters_withBooleanNo_isConvertedToFalseString { @@ -331,9 +355,15 @@ - (void)testParametersWithParameters_withBooleanNo_isConvertedToFalseString { emmSupport:@"1" isPasscodeInfoRequired:NO]; - [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; XCTAssertEqualObjects(stringifiedParameters[@"bool_key"], @"false", @"The boolean NO should be converted to the string 'false'."); + [stringifiedParameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + XCTAssertTrue([key isKindOfClass:[NSString class]], + @"All keys must be NSStrings. Found a key of type '%@'.", [key class]); + XCTAssertTrue([obj isKindOfClass:[NSString class]], + @"All values must be NSStrings. Found a value of type '%@' for key '%@'.", + [obj class], key); + }]; } - (void)testParametersWithParameters_withString_remainsUnchanged { @@ -343,9 +373,15 @@ - (void)testParametersWithParameters_withString_remainsUnchanged { emmSupport:@"1" isPasscodeInfoRequired:NO]; - [self assertAllKeysAndValuesAreStringsInDictionary:stringifiedParameters]; XCTAssertEqualObjects(stringifiedParameters[@"string_key"], @"hello", @"The original string value should be preserved."); + [stringifiedParameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + XCTAssertTrue([key isKindOfClass:[NSString class]], + @"All keys must be NSStrings. Found a key of type '%@'.", [key class]); + XCTAssertTrue([obj isKindOfClass:[NSString class]], + @"All values must be NSStrings. Found a value of type '%@' for key '%@'.", + [obj class], key); + }]; } # pragma mark - Helpers @@ -376,16 +412,6 @@ - (void)unswizzle { self.presentedViewController = nil; } -- (void)assertAllKeysAndValuesAreStringsInDictionary:(NSDictionary *)dictionary { - [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - XCTAssertTrue([key isKindOfClass:[NSString class]], - @"All keys must be NSStrings. Found a key of type '%@'.", [key class]); - XCTAssertTrue([obj isKindOfClass:[NSString class]], - @"All values must be NSStrings. Found a value of type '%@' for key '%@'.", - [obj class], key); - }]; -} - @end NS_ASSUME_NONNULL_END From 5885c132a592bc60b44f5a0a9686a1d1f10c5c7f Mon Sep 17 00:00:00 2001 From: Akshat Gandhi <54901287+AkshatG6@users.noreply.github.com> Date: Thu, 16 Oct 2025 11:35:12 -0700 Subject: [PATCH 11/11] Updated tests in GIDEMMSupportTest --- GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m | 54 +++++---------------- 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m index 08eb150f..9aece13b 100644 --- a/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m +++ b/GoogleSignIn/Tests/Unit/GIDEMMSupportTest.m @@ -285,13 +285,8 @@ - (void)testParametersWithParameters_withAnyNumber_isConvertedToString { XCTAssertEqualObjects(stringifiedParameters[@"number_key"], @"12345", @"The NSNumber should be converted to a string."); - [stringifiedParameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - XCTAssertTrue([key isKindOfClass:[NSString class]], - @"All keys must be NSStrings. Found a key of type '%@'.", [key class]); - XCTAssertTrue([obj isKindOfClass:[NSString class]], - @"All values must be NSStrings. Found a value of type '%@' for key '%@'.", - [obj class], key); - }]; + XCTAssertTrue([stringifiedParameters[@"number_key"] isKindOfClass:[NSString class]], + @"The final value should be of a NSString type."); } - (void)testParametersWithParameters_withNumberOne_isConvertedToString { @@ -303,13 +298,8 @@ - (void)testParametersWithParameters_withNumberOne_isConvertedToString { XCTAssertEqualObjects(stringifiedParameters[@"number_key"], @"1", @"The NSNumber should be converted to a string."); - [stringifiedParameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - XCTAssertTrue([key isKindOfClass:[NSString class]], - @"All keys must be NSStrings. Found a key of type '%@'.", [key class]); - XCTAssertTrue([obj isKindOfClass:[NSString class]], - @"All values must be NSStrings. Found a value of type '%@' for key '%@'.", - [obj class], key); - }]; + XCTAssertTrue([stringifiedParameters[@"number_key"] isKindOfClass:[NSString class]], + @"The final value should be of a NSString type."); } - (void)testParametersWithParameters_withNumberZero_isConvertedToString { @@ -321,13 +311,8 @@ - (void)testParametersWithParameters_withNumberZero_isConvertedToString { XCTAssertEqualObjects(stringifiedParameters[@"number_key"], @"0", @"The NSNumber should be converted to a string."); - [stringifiedParameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - XCTAssertTrue([key isKindOfClass:[NSString class]], - @"All keys must be NSStrings. Found a key of type '%@'.", [key class]); - XCTAssertTrue([obj isKindOfClass:[NSString class]], - @"All values must be NSStrings. Found a value of type '%@' for key '%@'.", - [obj class], key); - }]; + XCTAssertTrue([stringifiedParameters[@"number_key"] isKindOfClass:[NSString class]], + @"The final value should be of a NSString type."); } - (void)testParametersWithParameters_withBooleanYes_isConvertedToTrueString { @@ -339,13 +324,8 @@ - (void)testParametersWithParameters_withBooleanYes_isConvertedToTrueString { XCTAssertEqualObjects(stringifiedParameters[@"bool_key"], @"true", @"The boolean YES should be converted to the string 'true'."); - [stringifiedParameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - XCTAssertTrue([key isKindOfClass:[NSString class]], - @"All keys must be NSStrings. Found a key of type '%@'.", [key class]); - XCTAssertTrue([obj isKindOfClass:[NSString class]], - @"All values must be NSStrings. Found a value of type '%@' for key '%@'.", - [obj class], key); - }]; + XCTAssertTrue([stringifiedParameters[@"bool_key"] isKindOfClass:[NSString class]], + @"The final value should be of a NSString type."); } - (void)testParametersWithParameters_withBooleanNo_isConvertedToFalseString { @@ -357,13 +337,8 @@ - (void)testParametersWithParameters_withBooleanNo_isConvertedToFalseString { XCTAssertEqualObjects(stringifiedParameters[@"bool_key"], @"false", @"The boolean NO should be converted to the string 'false'."); - [stringifiedParameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - XCTAssertTrue([key isKindOfClass:[NSString class]], - @"All keys must be NSStrings. Found a key of type '%@'.", [key class]); - XCTAssertTrue([obj isKindOfClass:[NSString class]], - @"All values must be NSStrings. Found a value of type '%@' for key '%@'.", - [obj class], key); - }]; + XCTAssertTrue([stringifiedParameters[@"bool_key"] isKindOfClass:[NSString class]], + @"The final value should be of a NSString type."); } - (void)testParametersWithParameters_withString_remainsUnchanged { @@ -375,13 +350,8 @@ - (void)testParametersWithParameters_withString_remainsUnchanged { XCTAssertEqualObjects(stringifiedParameters[@"string_key"], @"hello", @"The original string value should be preserved."); - [stringifiedParameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - XCTAssertTrue([key isKindOfClass:[NSString class]], - @"All keys must be NSStrings. Found a key of type '%@'.", [key class]); - XCTAssertTrue([obj isKindOfClass:[NSString class]], - @"All values must be NSStrings. Found a value of type '%@' for key '%@'.", - [obj class], key); - }]; + XCTAssertTrue([stringifiedParameters[@"string_key"] isKindOfClass:[NSString class]], + @"The final value should be of a NSString type."); } # pragma mark - Helpers