Skip to content

Commit f9f4a25

Browse files
authored
fix(Pinpoint): Fixing error decoding AWSPinpointEndpointProfile when user attributes are set (#5431)
1 parent e5b425c commit f9f4a25

File tree

3 files changed

+16
-39
lines changed

3 files changed

+16
-39
lines changed

AWSPinpoint/AWSPinpointEndpointProfile.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@ + (BOOL)supportsSecureCoding {
578578
- (id)initWithCoder:(NSCoder *)decoder {
579579
if (self = [super init]) {
580580
_userId = [decoder decodeObjectOfClass:[NSString class] forKey:@"userId"];
581-
_userAttributes = [decoder decodeObjectOfClass:[NSDictionary class] forKey:@"userAttributes"];
581+
NSSet * attributesClasses = [NSSet setWithObjects:[NSDictionary class], [NSArray class], [NSString class], nil];
582+
_userAttributes = [decoder decodeObjectOfClasses:attributesClasses forKey:@"userAttributes"];
582583
}
583584
return self;
584585
}

AWSPinpointUnitTests/AWSPinpointNSSecureCodingTests.m

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ @interface AWSPinpointNSSecureCodingTests : XCTestCase
4040

4141
@property (nonatomic, strong) NSURL *archiveURL;
4242

43-
// Specifically declare these methods in the interface so we can set availability
44-
// to iOS 11. Tests that don't use newer APIs don't need to be declared here.
45-
- (void)testProfileArchivesAndUnarchivesUsingSecureCoding API_AVAILABLE(ios(11));
46-
- (void)testProfileArchivesAndUnarchivesWithLegacyAPI API_AVAILABLE(ios(11));
47-
48-
- (void)testSessionArchivesAndUnarchivesSecurely API_AVAILABLE(ios(11));
49-
- (void)testSessionArchivesAndUnarchivesWithLegacyAPI API_AVAILABLE(ios(11));
50-
5143
@end
5244

5345
@implementation AWSPinpointNSSecureCodingTests
@@ -60,6 +52,16 @@ - (void)testProfileArchivesAndUnarchivesUsingSecureCoding {
6052
debug:YES
6153
userDefaults:[NSUserDefaults standardUserDefaults] keychain:[AWSUICKeyChainStore keyChainStoreWithService: @"com.amazonaws.AWSPinpointContext"]];
6254

55+
[profile addAttribute:@[@"Attribute1", @"Attribute2"]
56+
forKey:@"profileAttributeKey"];
57+
[profile addMetric:[NSNumber numberWithInt:10] forKey:@"profileMetricKey"];
58+
59+
AWSPinpointEndpointProfileUser *user = [AWSPinpointEndpointProfileUser new];
60+
user.userId = @"UserId";
61+
[user addUserAttribute:@[@"Attribute1", @"Attribute2"]
62+
forKey:@"userAttributeKey"];
63+
profile.user = user;
64+
6365
NSError *error;
6466
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profile
6567
requiringSecureCoding:YES
@@ -80,21 +82,6 @@ - (void)testProfileSupportsSecureCoding {
8082
XCTAssert([AWSPinpointEndpointProfile supportsSecureCoding]);
8183
}
8284

83-
- (void)testProfileArchivesAndUnarchivesWithLegacyAPI {
84-
AWSPinpointEndpointProfile *profile = [[AWSPinpointEndpointProfile alloc] initWithApplicationId:@"app-id-123"
85-
endpointId:@"endpoint-id-123"
86-
applicationLevelOptOut:YES
87-
isRegisteredForRemoteNotifications:YES
88-
debug:YES
89-
userDefaults:[NSUserDefaults standardUserDefaults] keychain:[AWSUICKeyChainStore keyChainStoreWithService: @"com.amazonaws.AWSPinpointContext"]];
90-
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profile];
91-
92-
AWSPinpointEndpointProfile *unarchivedProfile = (AWSPinpointEndpointProfile *)[NSKeyedUnarchiver unarchiveObjectWithData:data];
93-
94-
// The class doesn't support `isEqual` so we'll compare string descriptions
95-
XCTAssertEqualObjects([unarchivedProfile description], [profile description]);
96-
}
97-
9885
- (void)testSessionArchivesAndUnarchivesSecurely {
9986
AWSPinpointSession *session = [[AWSPinpointSession alloc] initWithSessionId:@"session-123"
10087
withStartTime:[NSDate new]
@@ -121,18 +108,4 @@ - (void)testSessionSupportsSecureCoding {
121108
XCTAssert([AWSPinpointSession supportsSecureCoding]);
122109
}
123110

124-
- (void)testSessionArchivesAndUnarchivesWithLegacyAPI {
125-
AWSPinpointSession *session = [[AWSPinpointSession alloc] initWithSessionId:@"session-123"
126-
withStartTime:[NSDate new]
127-
withStopTime:nil];
128-
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:session];
129-
130-
AWSPinpointSession *unarchivedSession = (AWSPinpointSession *)[NSKeyedUnarchiver unarchiveObjectWithData:data];
131-
132-
// The class doesn't support `isEqual` or `description` so we'll compare property-by-property
133-
XCTAssertEqualObjects(unarchivedSession.sessionId, session.sessionId);
134-
XCTAssertEqualObjects(unarchivedSession.startTime, session.startTime);
135-
XCTAssertEqualObjects(unarchivedSession.stopTime, session.stopTime);
136-
}
137-
138111
@end

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
## Unreleased
44

5-
-Features for next release
5+
### Bug Fixes
6+
7+
- **AWSPinpoint**
8+
- Fixing error decoding `AWSPinpointEndpointProfile` when user attributes are set. (#5431)
69

710
## 2.37.0
811

0 commit comments

Comments
 (0)