Skip to content
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

fix(Pinpoint): Fixing error decoding AWSPinpointEndpointProfile when attributes are set. #5431

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading