|
30 | 30 | #pragma GCC diagnostic push
|
31 | 31 | #pragma GCC diagnostic ignored "-Wgnu"
|
32 | 32 |
|
| 33 | +// Define a subclass of @c OIDServiceDiscovery that provides the old NSCoding decoding |
| 34 | +// implementation. |
| 35 | +@interface OIDServiceDiscoveryOldDecoding : OIDServiceDiscovery |
| 36 | +@end |
| 37 | + |
| 38 | +@implementation OIDServiceDiscoveryOldDecoding |
| 39 | + |
| 40 | ++ (BOOL)supportsSecureCoding { |
| 41 | + return YES; |
| 42 | +} |
| 43 | + |
| 44 | +- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { |
| 45 | + NSError *error; |
| 46 | + NSDictionary *dictionary = [[NSDictionary alloc] initWithCoder:aDecoder]; |
| 47 | + self = [self initWithDictionary:dictionary error:&error]; |
| 48 | + if (error) { |
| 49 | + return nil; |
| 50 | + } |
| 51 | + return self; |
| 52 | +} |
| 53 | + |
| 54 | +@end |
| 55 | + |
| 56 | +// Define a subclass of @c OIDServiceDiscovery that provides the old NSCoding encoding |
| 57 | +// implementation. |
| 58 | +@interface OIDServiceDiscoveryOldEncoding : OIDServiceDiscovery |
| 59 | +@end |
| 60 | + |
| 61 | +@implementation OIDServiceDiscoveryOldEncoding |
| 62 | + |
| 63 | +- (void)encodeWithCoder:(NSCoder *)coder { |
| 64 | + [self.discoveryDictionary encodeWithCoder:coder]; |
| 65 | +} |
| 66 | + |
| 67 | +@end |
| 68 | + |
33 | 69 | /*! Testing URL used when testing URL conversions. */
|
34 | 70 | static NSString *const kTestURL = @"http://www.google.com/";
|
35 | 71 |
|
@@ -110,7 +146,7 @@ + (NSDictionary *)completeServiceDiscoveryDictionary {
|
110 | 146 | kJWKSURLKey : @"http://www.example.com/jwks",
|
111 | 147 | kRegistrationEndpointKey : @"Registration Endpoint",
|
112 | 148 | kEndSessionEndpointKey : @"https://www.example.com/logout",
|
113 |
| - kScopesSupportedKey : @"Scopes Supported", |
| 149 | + kScopesSupportedKey : @[ @"scope1", @"scope2" ], |
114 | 150 | kResponseTypesSupportedKey : @"Response Types Supported",
|
115 | 151 | kResponseModesSupportedKey : @"Response Modes Supported",
|
116 | 152 | kGrantTypesSupportedKey : @"Grant Types Supported",
|
@@ -411,10 +447,97 @@ - (void)testSecureCoding {
|
411 | 447 | OIDServiceDiscovery *discovery =
|
412 | 448 | [[OIDServiceDiscovery alloc] initWithDictionary:serviceDiscoveryDictionary
|
413 | 449 | error:&error];
|
414 |
| - NSData *data = [NSKeyedArchiver archivedDataWithRootObject:discovery]; |
415 |
| - OIDServiceDiscovery *unarchived = [NSKeyedUnarchiver unarchiveObjectWithData:data]; |
| 450 | + NSData *data; |
| 451 | + if (@available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *)) { |
| 452 | + data = [NSKeyedArchiver archivedDataWithRootObject:discovery |
| 453 | + requiringSecureCoding:YES |
| 454 | + error:&error]; |
| 455 | + } else { |
| 456 | + data = [NSKeyedArchiver archivedDataWithRootObject:discovery]; |
| 457 | + } |
| 458 | + |
| 459 | + OIDServiceDiscovery *unarchived; |
| 460 | + if (@available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *)) { |
| 461 | + unarchived = [NSKeyedUnarchiver unarchivedObjectOfClass:[OIDServiceDiscovery class] |
| 462 | + fromData:data |
| 463 | + error:&error]; |
| 464 | + } else { |
| 465 | + unarchived = [NSKeyedUnarchiver unarchiveObjectWithData:data]; |
| 466 | + } |
| 467 | + |
| 468 | + XCTAssertEqualObjects(discovery.discoveryDictionary, unarchived.discoveryDictionary); |
| 469 | +} |
416 | 470 |
|
417 |
| - XCTAssertEqualObjects(discovery.discoveryDictionary, unarchived.discoveryDictionary, @""); |
| 471 | +/*! @brief To ensure backward compatibility, test our ability to decode the old encoding of |
| 472 | + @c OIDServiceDiscovery. |
| 473 | + */ |
| 474 | +- (void)testSecureCodingDecodeOld { |
| 475 | + NSError *error; |
| 476 | + NSDictionary *serviceDiscoveryDictionary = [[self class] completeServiceDiscoveryDictionary]; |
| 477 | + OIDServiceDiscoveryOldEncoding *discovery = |
| 478 | + [[OIDServiceDiscoveryOldEncoding alloc] initWithDictionary:serviceDiscoveryDictionary |
| 479 | + error:&error]; |
| 480 | + NSData *data; |
| 481 | + if (@available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *)) { |
| 482 | + data = [NSKeyedArchiver archivedDataWithRootObject:discovery |
| 483 | + requiringSecureCoding:YES |
| 484 | + error:&error]; |
| 485 | + } else { |
| 486 | + data = [NSKeyedArchiver archivedDataWithRootObject:discovery]; |
| 487 | + } |
| 488 | + |
| 489 | + OIDServiceDiscovery *unarchived; |
| 490 | + if (@available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *)) { |
| 491 | + NSSet<Class> *allowedClasses = [NSSet setWithArray:@[[OIDServiceDiscovery class], |
| 492 | + [NSDictionary class], |
| 493 | + [NSArray class], |
| 494 | + [NSString class], |
| 495 | + [NSNumber class], |
| 496 | + [NSNull class]]]; |
| 497 | + unarchived = [NSKeyedUnarchiver unarchivedObjectOfClasses:allowedClasses |
| 498 | + fromData:data |
| 499 | + error:&error]; |
| 500 | + } else { |
| 501 | + unarchived = [NSKeyedUnarchiver unarchiveObjectWithData:data]; |
| 502 | + } |
| 503 | + |
| 504 | + XCTAssertEqualObjects(discovery.discoveryDictionary, unarchived.discoveryDictionary); |
| 505 | +} |
| 506 | + |
| 507 | +/*! @brief To ensure forward compatibility, test the ability of the old implementation to decode |
| 508 | + the new encoding of @c OIDServiceDiscovery. |
| 509 | + */ |
| 510 | +- (void)testSecureCodingOldDecodeNew { |
| 511 | + NSError *error; |
| 512 | + NSDictionary *serviceDiscoveryDictionary = [[self class] completeServiceDiscoveryDictionary]; |
| 513 | + OIDServiceDiscoveryOldDecoding *discovery = |
| 514 | + [[OIDServiceDiscoveryOldDecoding alloc] initWithDictionary:serviceDiscoveryDictionary |
| 515 | + error:&error]; |
| 516 | + NSData *data; |
| 517 | + if (@available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *)) { |
| 518 | + data = [NSKeyedArchiver archivedDataWithRootObject:discovery |
| 519 | + requiringSecureCoding:YES |
| 520 | + error:&error]; |
| 521 | + } else { |
| 522 | + data = [NSKeyedArchiver archivedDataWithRootObject:discovery]; |
| 523 | + } |
| 524 | + |
| 525 | + OIDServiceDiscovery *unarchived; |
| 526 | + if (@available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *)) { |
| 527 | + NSSet<Class> *allowedClasses = [NSSet setWithArray:@[[OIDServiceDiscoveryOldDecoding class], |
| 528 | + [NSDictionary class], |
| 529 | + [NSArray class], |
| 530 | + [NSString class], |
| 531 | + [NSNumber class], |
| 532 | + [NSNull class]]]; |
| 533 | + unarchived = [NSKeyedUnarchiver unarchivedObjectOfClasses:allowedClasses |
| 534 | + fromData:data |
| 535 | + error:&error]; |
| 536 | + } else { |
| 537 | + unarchived = [NSKeyedUnarchiver unarchiveObjectWithData:data]; |
| 538 | + } |
| 539 | + XCTAssertNil(error); |
| 540 | + XCTAssertEqualObjects(discovery.discoveryDictionary, unarchived.discoveryDictionary); |
418 | 541 | }
|
419 | 542 |
|
420 | 543 | /*! @brief Tests the NSCopying implementation by round-tripping an instance through the copying
|
|
0 commit comments