Skip to content
Closed
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
9 changes: 7 additions & 2 deletions Source/OIDServiceDiscovery.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

NS_ASSUME_NONNULL_BEGIN

/*! @brief Key used to encode the @c discoveryDictionary property for @c NSSecureCoding
*/
static NSString *const kDiscoveryDictionaryKey = @"discovery_dictionary";

/*! Field keys associated with an OpenID Connect Discovery Document. */
static NSString *const kIssuerKey = @"issuer";
static NSString *const kAuthorizationEndpointKey = @"authorization_endpoint";
Expand Down Expand Up @@ -183,7 +187,8 @@ + (BOOL)supportsSecureCoding {

- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
NSError *error;
NSDictionary *dictionary = [[NSDictionary alloc] initWithCoder:aDecoder];
NSDictionary *dictionary = [aDecoder decodeObjectOfClasses:[NSSet setWithObjects:[NSArray class], [NSDictionary class], nil] forKey:kDiscoveryDictionaryKey];

self = [self initWithDictionary:dictionary error:&error];
if (error) {
return nil;
Expand All @@ -192,7 +197,7 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
[_discoveryDictionary encodeWithCoder:aCoder];
[aCoder encodeObject:_discoveryDictionary forKey:kDiscoveryDictionaryKey];
}

#pragma mark - Properties
Expand Down
27 changes: 20 additions & 7 deletions UnitTests/OIDServiceDiscoveryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,26 @@ - (void)testRequestURIParameterSupportedDefaultToYes {
- (void)testSecureCoding {
NSError *error;
NSDictionary *serviceDiscoveryDictionary = [[self class] completeServiceDiscoveryDictionary];
OIDServiceDiscovery *discovery =
[[OIDServiceDiscovery alloc] initWithDictionary:serviceDiscoveryDictionary
error:&error];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:discovery];
OIDServiceDiscovery *unarchived = [NSKeyedUnarchiver unarchiveObjectWithData:data];

XCTAssertEqualObjects(discovery.discoveryDictionary, unarchived.discoveryDictionary, @"");
NSMutableArray<OIDServiceDiscovery *> *discoveries = [[NSMutableArray alloc] init];
[discoveries addObject:[[OIDServiceDiscovery alloc] initWithDictionary:serviceDiscoveryDictionary
error:&error]];
[discoveries addObject:[[OIDServiceDiscovery alloc] initWithJSON:kDiscoveryDocument error:&error]];

for (OIDServiceDiscovery *discovery in discoveries) {
@try {
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:discovery];

NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
unarchiver.requiresSecureCoding = YES;
OIDServiceDiscovery *unarchived = [unarchiver decodeObjectOfClass:[OIDServiceDiscovery class]
forKey:NSKeyedArchiveRootObjectKey];

XCTAssertEqualObjects(discovery.discoveryDictionary, unarchived.discoveryDictionary, @"");
}
@catch (NSException *exception) {
XCTFail("Failed discovery: %@; Exception: %@", discovery.discoveryDictionary, exception);
}
}
}

/*! @brief Tests the NSCopying implementation by round-tripping an instance through the copying
Expand Down