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

Update OIDEndSessionRequest method signature to match nullability on type #753

Closed
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
4 changes: 2 additions & 2 deletions Source/AppAuthCore/OIDEndSessionRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (instancetype)
initWithConfiguration:(OIDServiceConfiguration *)configuration
idTokenHint:(NSString *)idTokenHint
idTokenHint:(nullable NSString *)idTokenHint
postLogoutRedirectURL:(NSURL *)postLogoutRedirectURL
additionalParameters:(nullable NSDictionary<NSString *, NSString *> *)additionalParameters;

Expand All @@ -89,7 +89,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (instancetype)
initWithConfiguration:(OIDServiceConfiguration *)configuration
idTokenHint:(NSString *)idTokenHint
idTokenHint:(nullable NSString *)idTokenHint
postLogoutRedirectURL:(NSURL *)postLogoutRedirectURL
state:(NSString *)state
additionalParameters:(nullable NSDictionary<NSString *, NSString *> *)additionalParameters
Expand Down
4 changes: 2 additions & 2 deletions Source/AppAuthCore/OIDEndSessionRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ - (instancetype)init
)

- (instancetype)initWithConfiguration:(OIDServiceConfiguration *)configuration
idTokenHint:(NSString *)idTokenHint
idTokenHint:(nullable NSString *)idTokenHint
postLogoutRedirectURL:(NSURL *)postLogoutRedirectURL
state:(NSString *)state
additionalParameters:(NSDictionary<NSString *,NSString *> *)additionalParameters
Expand All @@ -82,7 +82,7 @@ - (instancetype)initWithConfiguration:(OIDServiceConfiguration *)configuration
}

- (instancetype)initWithConfiguration:(OIDServiceConfiguration *)configuration
idTokenHint:(NSString *)idTokenHint
idTokenHint:(nullable NSString *)idTokenHint
postLogoutRedirectURL:(NSURL *)postLogoutRedirectURL
additionalParameters:(NSDictionary<NSString *,NSString *> *)additionalParameters
{
Expand Down
84 changes: 80 additions & 4 deletions UnitTests/OIDEndSessionRequestTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,24 @@ + (OIDEndSessionRequest *)testInstance {
OIDServiceConfiguration *configuration = [[OIDServiceConfiguration alloc] initWithDiscoveryDocument:discoveryDocument];

return [[OIDEndSessionRequest alloc] initWithConfiguration:configuration
idTokenHint:kTestIdTokenHint
postLogoutRedirectURL:[NSURL URLWithString:kTestRedirectURL]
state:kTestState
additionalParameters:additionalParameters];
idTokenHint:kTestIdTokenHint
postLogoutRedirectURL:[NSURL URLWithString:kTestRedirectURL]
state:kTestState
additionalParameters:additionalParameters];
}

+ (OIDEndSessionRequest *)testInstanceWithNilIdToken {
NSDictionary *additionalParameters =
@{ kTestAdditionalParameterKey : kTestAdditionalParameterValue };

OIDServiceDiscovery *discoveryDocument = [[OIDServiceDiscovery alloc] initWithDictionary:[OIDServiceDiscoveryTests completeServiceDiscoveryDictionary] error:nil];
OIDServiceConfiguration *configuration = [[OIDServiceConfiguration alloc] initWithDiscoveryDocument:discoveryDocument];

return [[OIDEndSessionRequest alloc] initWithConfiguration:configuration
idTokenHint:nil
postLogoutRedirectURL:[NSURL URLWithString:kTestRedirectURL]
state:kTestState
additionalParameters:additionalParameters];
}

/*! @brief Tests the @c NSCopying implementation by round-tripping an instance through the copying
Expand Down Expand Up @@ -126,4 +140,66 @@ - (void)testLogoutRequestURL {
XCTAssertEqualObjects(query[@"post_logout_redirect_uri"], kTestRedirectURL);
}

/*! @brief Tests the @c NSCopying implementation by round-tripping an instance with no ID token hint through the copying
process and checking to make sure the source and destination instances are equivalent.
*/
- (void)testCopying_withNilIdToken {
OIDEndSessionRequest *request = [[self class] testInstanceWithNilIdToken];

XCTAssertNil(request.idTokenHint);
XCTAssertEqualObjects(request.postLogoutRedirectURL, [NSURL URLWithString:kTestRedirectURL]);
XCTAssertEqualObjects(request.state, kTestState);
XCTAssertEqualObjects(request.additionalParameters[kTestAdditionalParameterKey],
kTestAdditionalParameterValue);

OIDEndSessionRequest *requestCopy = [request copy];

XCTAssertNotNil(requestCopy.configuration);
XCTAssertEqualObjects(requestCopy.configuration, request.configuration);
XCTAssertEqualObjects(requestCopy.postLogoutRedirectURL, request.postLogoutRedirectURL);
XCTAssertEqualObjects(requestCopy.state, request.state);
XCTAssertEqualObjects(requestCopy.idTokenHint, request.idTokenHint);
}

/*! @brief Tests the @c NSSecureCoding by round-tripping an instance with no ID token hint through the coding process and
checking to make sure the source and destination instances are equivalent.
*/
- (void)testSecureCoding_WithNilIdToken {
OIDEndSessionRequest *request = [[self class] testInstanceWithNilIdToken];

XCTAssertNil(request.idTokenHint);
XCTAssertEqualObjects(request.postLogoutRedirectURL, [NSURL URLWithString:kTestRedirectURL]);
XCTAssertEqualObjects(request.state, kTestState);
XCTAssertEqualObjects(request.additionalParameters[kTestAdditionalParameterKey],
kTestAdditionalParameterValue);

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:request];
OIDEndSessionRequest *requestCopy = [NSKeyedUnarchiver unarchiveObjectWithData:data];

XCTAssertNotNil(requestCopy.configuration);
XCTAssertEqualObjects(requestCopy.configuration.authorizationEndpoint,
request.configuration.authorizationEndpoint);
XCTAssertEqualObjects(requestCopy.postLogoutRedirectURL, request.postLogoutRedirectURL);
XCTAssertEqualObjects(requestCopy.state, request.state);
XCTAssertEqualObjects(requestCopy.idTokenHint, request.idTokenHint);
}

- (void)testLogoutRequestURL_withNilIdToken {
OIDEndSessionRequest *request = [[self class] testInstanceWithNilIdToken];
NSURL *endSessionRequestURL = request.endSessionRequestURL;

NSURLComponents *components = [NSURLComponents componentsWithString:endSessionRequestURL.absoluteString];

XCTAssertTrue([endSessionRequestURL.absoluteString hasPrefix:@"https://www.example.com/logout"]);

NSMutableDictionary<NSString *, NSString*> *query = [[NSMutableDictionary alloc] init];
for (NSURLQueryItem *queryItem in components.queryItems) {
query[queryItem.name] = queryItem.value;
}

XCTAssertEqualObjects(query[@"state"], kTestState);
XCTAssertNil(query[@"id_token_hint"]);
XCTAssertEqualObjects(query[@"post_logout_redirect_uri"], kTestRedirectURL);
}

@end