[snowy] Fix tests for OAuth 1.0a
- From: Sanford Armstrong <sharm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [snowy] Fix tests for OAuth 1.0a
- Date: Wed, 16 Jun 2010 14:28:43 +0000 (UTC)
commit a0ae268e5c39bcafd1b8c4d5931c2e558c73f49e
Author: Leon Handreke <leon handreke gmail com>
Date: Wed Jun 16 14:11:22 2010 +0200
Fix tests for OAuth 1.0a
https://bugzilla.gnome.org/show_bug.cgi?id=620126
api/tests.py | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/api/tests.py b/api/tests.py
index 2d82804..2cccdc7 100644
--- a/api/tests.py
+++ b/api/tests.py
@@ -15,7 +15,7 @@ from django.contrib.auth.models import User
from django.utils.functional import curry
from piston import oauth
-from piston.models import Consumer, Token
+from piston.models import Consumer, Token, generate_random, VERIFIER_SIZE
from piston.forms import OAuthAuthenticationForm
from snowy import settings
@@ -34,10 +34,14 @@ class OAuthRequester:
oaconsumer = oauth.OAuthConsumer(self.consumer.key,
self.consumer.secret)
+ # Callback URL
+ c_url = 'http://printer.example.com/request_token_ready'
+
# Get a request key...
url = 'http://' + self.SERVER_NAME + '/oauth/request_token/'
request = oauth.OAuthRequest.from_consumer_and_token(oaconsumer,
- http_url=url)
+ http_url=url,
+ parameters={"oauth_callback" : c_url})
request.sign_request(self.signature_method, oaconsumer, None)
response = test_case.client.get('/oauth/request_token/',
@@ -51,21 +55,27 @@ class OAuthRequester:
test_case.failUnless(test_case.client.login(username=username,
password=password))
url = 'http://' + self.SERVER_NAME + '/oauth/authenticate/'
- c_url = 'http://printer.example.com/request_token_ready'
request = oauth.OAuthRequest.from_token_and_callback(token=oatoken,
- callback=c_url,
http_url=url)
request.sign_request(self.signature_method, oaconsumer, oatoken)
# Faking form submission seems to not work, so approve token manually
+ # This normally happens in piston.store.authorize_request_token
token.is_approved = True
+ token.verifier = generate_random(VERIFIER_SIZE)
token.user = User.objects.get(username=username)
token.save()
+ # Normally the oauth_verifier is transmitted with the callback to the
+ # consumer, which does not happen here. Get the verifier directly from
+ # the database instead.
+ oaverifier = token.verifier
+
# Obtain access token...
url = 'http://' + self.SERVER_NAME + '/oauth/access_token/'
request = oauth.OAuthRequest.from_consumer_and_token(oaconsumer,
token=oatoken,
+ verifier=oaverifier,
http_url=url)
request.sign_request(self.signature_method, oaconsumer, oatoken)
response = test_case.client.get('/oauth/access_token/',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]