Skip to content
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
7 changes: 7 additions & 0 deletions Source/OIDServiceDiscovery.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ - (nullable instancetype)initWithJSONData:(NSData *)serviceDiscoveryJSONData
description:jsonError.localizedDescription];
return nil;
}
if (![json isKindOfClass:[NSDictionary class]]) {
*error = [OIDErrorUtilities errorWithCode:OIDErrorCodeInvalidDiscoveryDocument
underlyingError:nil
description:@"Discovery document isn't a dictionary"];
return nil;
}

return [self initWithDictionary:json error:error];
}

Expand Down
16 changes: 16 additions & 0 deletions UnitTests/OIDServiceDiscoveryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ + (NSURL *)googleDiscoveryAuthorizationEndpoint {
"ail_verified\",\"exp\",\"family_name\",\"given_name\",\"iat\",\"iss\",\"locale\",\"name\",\""
"picture\",\"sub\"]}";

static NSString *const kDiscoveryDocumentNotDictionary =
@"[\"code\",\"token\",\"id_token\",\"code token\",\"code id_token\",\"token id_token\",\"code to"
"ken id_token\",\"none\"]";

/*! @brief Tests that URLs are handled properly when converted from the dictionary's string
representation.
*/
Expand Down Expand Up @@ -222,6 +226,18 @@ - (void)testErrorWhenBadFormat {
XCTAssertEqual(error.code, OIDErrorCodeJSONDeserializationError, @"");
}

/*! @brief Tests that we get an error when the root JSON object isn't a dictionary.
*/
- (void)testErrorWhenRootObjectNotNSDictionary {
NSError *error;
OIDServiceDiscovery *discovery = [[OIDServiceDiscovery alloc] initWithJSON:kDiscoveryDocumentNotDictionary error:&error];
XCTAssertNil(discovery, @"When initializing a discovery document, it should not return an "
"instance if the root JSON object is not a NSDictionary.");
XCTAssertNotNil(error, @"There should be an error indicating we received bad JSON.");
XCTAssertEqualObjects(error.domain, OIDGeneralErrorDomain, @"");
XCTAssertEqual(error.code, OIDErrorCodeInvalidDiscoveryDocument, @"");
}

/*! @brief Tests that we get an error when the required fields aren't in the source dictionary.
*/
- (void)testErrorWhenMissingFields {
Expand Down