From f9f4a252b901b4b04ed1bfad219d8935167a5875 Mon Sep 17 00:00:00 2001 From: Sebastian Villena <97059974+ruisebas@users.noreply.github.com> Date: Wed, 4 Sep 2024 13:42:17 -0400 Subject: [PATCH] fix(Pinpoint): Fixing error decoding AWSPinpointEndpointProfile when user attributes are set (#5431) --- AWSPinpoint/AWSPinpointEndpointProfile.m | 3 +- .../AWSPinpointNSSecureCodingTests.m | 47 ++++--------------- CHANGELOG.md | 5 +- 3 files changed, 16 insertions(+), 39 deletions(-) diff --git a/AWSPinpoint/AWSPinpointEndpointProfile.m b/AWSPinpoint/AWSPinpointEndpointProfile.m index 7bd67b1db89..892bf6b3d5a 100644 --- a/AWSPinpoint/AWSPinpointEndpointProfile.m +++ b/AWSPinpoint/AWSPinpointEndpointProfile.m @@ -578,7 +578,8 @@ + (BOOL)supportsSecureCoding { - (id)initWithCoder:(NSCoder *)decoder { if (self = [super init]) { _userId = [decoder decodeObjectOfClass:[NSString class] forKey:@"userId"]; - _userAttributes = [decoder decodeObjectOfClass:[NSDictionary class] forKey:@"userAttributes"]; + NSSet * attributesClasses = [NSSet setWithObjects:[NSDictionary class], [NSArray class], [NSString class], nil]; + _userAttributes = [decoder decodeObjectOfClasses:attributesClasses forKey:@"userAttributes"]; } return self; } diff --git a/AWSPinpointUnitTests/AWSPinpointNSSecureCodingTests.m b/AWSPinpointUnitTests/AWSPinpointNSSecureCodingTests.m index 0ed2f8d2c5f..edcbf75aafb 100644 --- a/AWSPinpointUnitTests/AWSPinpointNSSecureCodingTests.m +++ b/AWSPinpointUnitTests/AWSPinpointNSSecureCodingTests.m @@ -40,14 +40,6 @@ @interface AWSPinpointNSSecureCodingTests : XCTestCase @property (nonatomic, strong) NSURL *archiveURL; -// Specifically declare these methods in the interface so we can set availability -// to iOS 11. Tests that don't use newer APIs don't need to be declared here. -- (void)testProfileArchivesAndUnarchivesUsingSecureCoding API_AVAILABLE(ios(11)); -- (void)testProfileArchivesAndUnarchivesWithLegacyAPI API_AVAILABLE(ios(11)); - -- (void)testSessionArchivesAndUnarchivesSecurely API_AVAILABLE(ios(11)); -- (void)testSessionArchivesAndUnarchivesWithLegacyAPI API_AVAILABLE(ios(11)); - @end @implementation AWSPinpointNSSecureCodingTests @@ -60,6 +52,16 @@ - (void)testProfileArchivesAndUnarchivesUsingSecureCoding { debug:YES userDefaults:[NSUserDefaults standardUserDefaults] keychain:[AWSUICKeyChainStore keyChainStoreWithService: @"com.amazonaws.AWSPinpointContext"]]; + [profile addAttribute:@[@"Attribute1", @"Attribute2"] + forKey:@"profileAttributeKey"]; + [profile addMetric:[NSNumber numberWithInt:10] forKey:@"profileMetricKey"]; + + AWSPinpointEndpointProfileUser *user = [AWSPinpointEndpointProfileUser new]; + user.userId = @"UserId"; + [user addUserAttribute:@[@"Attribute1", @"Attribute2"] + forKey:@"userAttributeKey"]; + profile.user = user; + NSError *error; NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profile requiringSecureCoding:YES @@ -80,21 +82,6 @@ - (void)testProfileSupportsSecureCoding { XCTAssert([AWSPinpointEndpointProfile supportsSecureCoding]); } -- (void)testProfileArchivesAndUnarchivesWithLegacyAPI { - AWSPinpointEndpointProfile *profile = [[AWSPinpointEndpointProfile alloc] initWithApplicationId:@"app-id-123" - endpointId:@"endpoint-id-123" - applicationLevelOptOut:YES - isRegisteredForRemoteNotifications:YES - debug:YES - userDefaults:[NSUserDefaults standardUserDefaults] keychain:[AWSUICKeyChainStore keyChainStoreWithService: @"com.amazonaws.AWSPinpointContext"]]; - NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profile]; - - AWSPinpointEndpointProfile *unarchivedProfile = (AWSPinpointEndpointProfile *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; - - // The class doesn't support `isEqual` so we'll compare string descriptions - XCTAssertEqualObjects([unarchivedProfile description], [profile description]); -} - - (void)testSessionArchivesAndUnarchivesSecurely { AWSPinpointSession *session = [[AWSPinpointSession alloc] initWithSessionId:@"session-123" withStartTime:[NSDate new] @@ -121,18 +108,4 @@ - (void)testSessionSupportsSecureCoding { XCTAssert([AWSPinpointSession supportsSecureCoding]); } -- (void)testSessionArchivesAndUnarchivesWithLegacyAPI { - AWSPinpointSession *session = [[AWSPinpointSession alloc] initWithSessionId:@"session-123" - withStartTime:[NSDate new] - withStopTime:nil]; - NSData *data = [NSKeyedArchiver archivedDataWithRootObject:session]; - - AWSPinpointSession *unarchivedSession = (AWSPinpointSession *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; - - // The class doesn't support `isEqual` or `description` so we'll compare property-by-property - XCTAssertEqualObjects(unarchivedSession.sessionId, session.sessionId); - XCTAssertEqualObjects(unarchivedSession.startTime, session.startTime); - XCTAssertEqualObjects(unarchivedSession.stopTime, session.stopTime); -} - @end diff --git a/CHANGELOG.md b/CHANGELOG.md index e6976e8ffd2..7c120b736d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,10 @@ ## Unreleased --Features for next release +### Bug Fixes + +- **AWSPinpoint** + - Fixing error decoding `AWSPinpointEndpointProfile` when user attributes are set. (#5431) ## 2.37.0