Update tests for new ouath testing environment

This commit is contained in:
Christopher Swasey
2012-05-10 12:46:52 -04:00
parent 6351fd428f
commit 02b4bdf75f
3 changed files with 42 additions and 6 deletions

View File

@@ -29,7 +29,7 @@
- (void)testShouldGetAccessToken{
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
RKOAuthClient *client = RKTestNewOAuthClient(loader);
client.authorizationCode = @"1234";
client.authorizationCode = @"4fa8182d7184797dd5000002";
client.callbackURL = @"http://someURL.com";
[client validateAuthorizationCode];
[loader waitForResponse];
@@ -45,13 +45,13 @@
[loader waitForResponse];
assertThatBool(loader.wasSuccessful, is(equalToBool(NO)));
}
- (void)testShouldGetProtectedResource{
//TODO: Encapsulate this code in a correct manner
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
RKOAuthClient *client = RKTestNewOAuthClient(loader);
client.authorizationCode = @"1234";
client.authorizationCode = @"4fa8182d7184797dd5000002";
client.callbackURL = @"http://someURL.com";
[client validateAuthorizationCode];
@@ -59,7 +59,7 @@
RKClient *requestClient = [RKClient clientWithBaseURLString:[client authorizationURL]];
requestClient.OAuth2AccessToken = client.accessToken;
requestClient.authenticationType = RKRequestAuthenticationTypeOAuth2;
RKRequest *request = [requestClient requestWithResourcePath:@"/me"];
RKRequest *request = [requestClient requestWithResourcePath:@"/oauth2/pregen/me"];
request.delegate = resourceLoader;
[request send];
[resourceLoader waitForResponse];

View File

@@ -832,6 +832,42 @@ request.timeoutInterval = 1.0;
assertThat(authorization, isNot(nilValue()));
}
- (void)testShouldBuildAProperAuthorizationHeaderForOAuth1ThatIsAcceptedByServer {
RKRequest *request = [RKRequest requestWithURL:[RKURL URLWithString:[NSString stringWithFormat:@"%@/oauth1/me", [RKTestFactory baseURLString]]]];
request.authenticationType = RKRequestAuthenticationTypeOAuth1;
request.OAuth1AccessToken = @"12345";
request.OAuth1AccessTokenSecret = @"monkey";
request.OAuth1ConsumerKey = @"restkit_key";
request.OAuth1ConsumerSecret = @"restkit_secret";
[request prepareURLRequest];
NSString *authorization = [request.URLRequest valueForHTTPHeaderField:@"Authorization"];
assertThat(authorization, isNot(nilValue()));
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
request.delegate = responseLoader;
[request sendAsynchronously];
[responseLoader waitForResponse];
assertThatBool(responseLoader.successful, is(equalToBool(YES)));
}
- (void)testImproperOAuth1CredentialsShouldFall {
RKRequest *request = [RKRequest requestWithURL:[RKURL URLWithString:[NSString stringWithFormat:@"%@/oauth1/me", [RKTestFactory baseURLString]]]];
request.authenticationType = RKRequestAuthenticationTypeOAuth1;
request.OAuth1AccessToken = @"12345";
request.OAuth1AccessTokenSecret = @"monkey";
request.OAuth1ConsumerKey = @"restkit_key";
request.OAuth1ConsumerSecret = @"restkit_incorrect_secret";
[request prepareURLRequest];
NSString *authorization = [request.URLRequest valueForHTTPHeaderField:@"Authorization"];
assertThat(authorization, isNot(nilValue()));
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
request.delegate = responseLoader;
[request sendAsynchronously];
[responseLoader waitForResponse];
assertThatBool(responseLoader.successful, is(equalToBool(YES)));
}
- (void)testOnDidLoadResponseBlockInvocation {
RKURL *URL = [[RKTestFactory baseURL] URLByAppendingResourcePath:@"/200"];
RKTestResponseLoader* loader = [RKTestResponseLoader responseLoader];

View File

@@ -25,9 +25,9 @@
RKOAuthClient* RKTestNewOAuthClient(RKTestResponseLoader* loader)
{
[loader setTimeout:10];
RKOAuthClient *client = [RKOAuthClient clientWithClientID:@"appID" secret:@"appSecret"];
RKOAuthClient *client = [RKOAuthClient clientWithClientID:@"4fa42a4a7184796662000001" secret:@"restkit_secret"];
client.delegate = loader;
client.authorizationURL = [NSString stringWithFormat:@"%@/oauth/authorize", [RKTestFactory baseURLString]];
client.authorizationURL = [NSString stringWithFormat:@"%@/oauth2/pregen/token", [RKTestFactory baseURLString]];
return client;
}