Skip to content

Commit

Permalink
fix(Pinpoint): Fixing error decoding AWSPinpointEndpointProfile when …
Browse files Browse the repository at this point in the history
…user attributes are set (#5431)
  • Loading branch information
ruisebas authored Sep 4, 2024
1 parent e5b425c commit f9f4a25
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 39 deletions.
3 changes: 2 additions & 1 deletion AWSPinpoint/AWSPinpointEndpointProfile.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
47 changes: 10 additions & 37 deletions AWSPinpointUnitTests/AWSPinpointNSSecureCodingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f9f4a25

Please sign in to comment.