Skip to content

Commit

Permalink
Fix unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihai Sardarescu committed Jul 11, 2016
1 parent 4abc9cb commit f606de9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
35 changes: 34 additions & 1 deletion UnitTests/OIDAuthorizationRequestTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
*/
static NSString *const kTestClientID = @"ClientID";

/*! @var kTestClientID
@brief Test value for the @c clientID property.
*/
static NSString *const kTestClientSecret = @"ClientSecret";

/*! @var kTestScope
@brief Test value for the @c scope property.
*/
Expand Down Expand Up @@ -155,6 +160,7 @@ + (OIDAuthorizationRequest *)testInstance {
OIDAuthorizationRequest *request =
[[OIDAuthorizationRequest alloc] initWithConfiguration:configuration
clientId:kTestClientID
clientSecret:kTestClientSecret
scope:[OIDScopeUtilities scopesWithArray:@[ kTestScope, kTestScopeA ]]
redirectURL:[NSURL URLWithString:kTestRedirectURL]
responseType:kTestResponseType
Expand All @@ -171,6 +177,7 @@ + (OIDAuthorizationRequest *)testInstanceCodeFlow {
OIDAuthorizationRequest *request =
[[OIDAuthorizationRequest alloc] initWithConfiguration:configuration
clientId:kTestClientID
clientSecret:kTestClientSecret
scope:[OIDScopeUtilities scopesWithArray:@[ kTestScope, kTestScopeA ]]
redirectURL:[NSURL URLWithString:kTestRedirectURL]
responseType:OIDResponseTypeCode
Expand All @@ -185,13 +192,35 @@ + (OIDAuthorizationRequest *)testInstanceCodeFlow {
/*! @fn testScopeInitializerWithManyScopes
@brief Tests the initializer which takes an array of scopes.
*/
- (void)testScopeInitializerWithManyScopes {
- (void)testScopeInitializerWithManyScopesAndNoClientSecret {
NSDictionary *additionalParameters =
@{ kTestAdditionalParameterKey : kTestAdditionalParameterValue };
OIDServiceConfiguration *configuration = [OIDServiceConfigurationTests testInstance];
OIDAuthorizationRequest *request =
[[OIDAuthorizationRequest alloc] initWithConfiguration:configuration
clientId:kTestClientID
scopes:@[ kTestScope, kTestScopeA ]
redirectURL:[NSURL URLWithString:kTestRedirectURL]
responseType:OIDResponseTypeCode
additionalParameters:additionalParameters];

XCTAssertEqualObjects(request.responseType, @"code");
XCTAssertEqualObjects(request.scope, kTestScopesMerged);
XCTAssertEqualObjects(request.clientID, kTestClientID);
XCTAssertEqualObjects(request.clientSecret, nil);
XCTAssertEqualObjects(request.redirectURL, [NSURL URLWithString:kTestRedirectURL]);
XCTAssertEqualObjects(request.additionalParameters[kTestAdditionalParameterKey],
kTestAdditionalParameterValue);
}

- (void)testScopeInitializerWithManyScopesAndClientSecret {
NSDictionary *additionalParameters =
@{ kTestAdditionalParameterKey : kTestAdditionalParameterValue };
OIDServiceConfiguration *configuration = [OIDServiceConfigurationTests testInstance];
OIDAuthorizationRequest *request =
[[OIDAuthorizationRequest alloc] initWithConfiguration:configuration
clientId:kTestClientID
clientSecret:kTestClientSecret
scopes:@[ kTestScope, kTestScopeA ]
redirectURL:[NSURL URLWithString:kTestRedirectURL]
responseType:OIDResponseTypeCode
Expand All @@ -200,6 +229,7 @@ - (void)testScopeInitializerWithManyScopes {
XCTAssertEqualObjects(request.responseType, @"code");
XCTAssertEqualObjects(request.scope, kTestScopesMerged);
XCTAssertEqualObjects(request.clientID, kTestClientID);
XCTAssertEqualObjects(request.clientSecret, kTestClientSecret);
XCTAssertEqualObjects(request.redirectURL, [NSURL URLWithString:kTestRedirectURL]);
XCTAssertEqualObjects(request.additionalParameters[kTestAdditionalParameterKey],
kTestAdditionalParameterValue);
Expand All @@ -215,6 +245,7 @@ - (void)testCopying {
XCTAssertEqualObjects(request.responseType, kTestResponseType);
XCTAssertEqualObjects(request.scope, kTestScopesMerged);
XCTAssertEqualObjects(request.clientID, kTestClientID);
XCTAssertEqualObjects(request.clientSecret, kTestClientSecret);
XCTAssertEqualObjects(request.redirectURL, [NSURL URLWithString:kTestRedirectURL]);
XCTAssertEqualObjects(request.state, kTestState);
XCTAssertEqualObjects(request.codeVerifier, kTestCodeVerifier);
Expand All @@ -230,6 +261,7 @@ - (void)testCopying {
XCTAssertEqualObjects(requestCopy.responseType, request.responseType);
XCTAssertEqualObjects(requestCopy.scope, request.scope);
XCTAssertEqualObjects(requestCopy.clientID, request.clientID);
XCTAssertEqualObjects(requestCopy.clientSecret, request.clientSecret);
XCTAssertEqualObjects(requestCopy.redirectURL, request.redirectURL);
XCTAssertEqualObjects(requestCopy.state, request.state);
XCTAssertEqualObjects(requestCopy.codeVerifier, request.codeVerifier);
Expand All @@ -249,6 +281,7 @@ - (void)testSecureCoding {
XCTAssertEqualObjects(request.responseType, kTestResponseType);
XCTAssertEqualObjects(request.scope, kTestScopesMerged);
XCTAssertEqualObjects(request.clientID, kTestClientID);
XCTAssertEqualObjects(request.clientSecret, kTestClientSecret);
XCTAssertEqualObjects(request.redirectURL, [NSURL URLWithString:kTestRedirectURL]);
XCTAssertEqualObjects(request.state, kTestState);
XCTAssertEqualObjects(request.codeVerifier, kTestCodeVerifier);
Expand Down
7 changes: 7 additions & 0 deletions UnitTests/OIDTokenRequestTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ + (OIDTokenRequest *)testInstance {
authorizationCode:authResponse.authorizationCode
redirectURL:authResponse.request.redirectURL
clientID:authResponse.request.clientID
clientSecret:authResponse.request.clientSecret
scopes:scopesArray
refreshToken:kRefreshTokenTestValue
codeVerifier:authResponse.request.codeVerifier
Expand All @@ -74,6 +75,7 @@ + (OIDTokenRequest *)testInstanceCodeExchange {
authorizationCode:authResponse.authorizationCode
redirectURL:authResponse.request.redirectURL
clientID:authResponse.request.clientID
clientSecret:authResponse.request.clientSecret
scopes:scopesArray
refreshToken:kRefreshTokenTestValue
codeVerifier:authResponse.request.codeVerifier
Expand All @@ -93,6 +95,7 @@ + (OIDTokenRequest *)testInstanceRefresh {
authorizationCode:authResponse.authorizationCode
redirectURL:authResponse.request.redirectURL
clientID:authResponse.request.clientID
clientSecret:authResponse.request.clientSecret
scopes:scopesArray
refreshToken:kRefreshTokenTestValue
codeVerifier:authResponse.request.codeVerifier
Expand All @@ -114,6 +117,7 @@ - (void)testCopying {
XCTAssertEqualObjects(request.authorizationCode, authResponse.authorizationCode);
XCTAssertEqualObjects(request.redirectURL, authResponse.request.redirectURL);
XCTAssertEqualObjects(request.clientID, authResponse.request.clientID);
XCTAssertEqualObjects(request.clientSecret, authResponse.request.clientSecret);
XCTAssertEqualObjects(request.scope, authResponse.request.scope);
XCTAssertEqualObjects(request.refreshToken, kRefreshTokenTestValue);
XCTAssertEqualObjects(request.codeVerifier, authResponse.request.codeVerifier);
Expand All @@ -132,6 +136,7 @@ - (void)testCopying {
XCTAssertEqualObjects(requestCopy.authorizationCode, request.authorizationCode);
XCTAssertEqualObjects(requestCopy.redirectURL, request.redirectURL);
XCTAssertEqualObjects(requestCopy.clientID, request.clientID);
XCTAssertEqualObjects(requestCopy.clientSecret, request.clientSecret);
XCTAssertEqualObjects(requestCopy.scope, authResponse.request.scope);
XCTAssertEqualObjects(requestCopy.refreshToken, kRefreshTokenTestValue);
XCTAssertEqualObjects(requestCopy.codeVerifier, authResponse.request.codeVerifier);
Expand All @@ -154,6 +159,7 @@ - (void)testSecureCoding {
XCTAssertEqualObjects(request.authorizationCode, authResponse.authorizationCode);
XCTAssertEqualObjects(request.redirectURL, authResponse.request.redirectURL);
XCTAssertEqualObjects(request.clientID, authResponse.request.clientID);
XCTAssertEqualObjects(request.clientSecret, authResponse.request.clientSecret);
XCTAssertEqualObjects(request.scope, authResponse.request.scope);
XCTAssertEqualObjects(request.refreshToken, kRefreshTokenTestValue);
XCTAssertEqualObjects(request.codeVerifier, authResponse.request.codeVerifier);
Expand All @@ -175,6 +181,7 @@ - (void)testSecureCoding {
XCTAssertEqualObjects(requestCopy.authorizationCode, request.authorizationCode);
XCTAssertEqualObjects(requestCopy.redirectURL, request.redirectURL);
XCTAssertEqualObjects(requestCopy.clientID, request.clientID);
XCTAssertEqualObjects(requestCopy.clientSecret, request.clientSecret);
XCTAssertEqualObjects(requestCopy.scope, authResponse.request.scope);
XCTAssertEqualObjects(requestCopy.refreshToken, kRefreshTokenTestValue);
XCTAssertEqualObjects(requestCopy.codeVerifier, authResponse.request.codeVerifier);
Expand Down

0 comments on commit f606de9

Please sign in to comment.