[Jifty-commit] r4396 - in jifty/trunk: .
t/TestApp-Plugin-OAuth/lib/TestApp/Plugin/OAuth
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Nov 9 13:31:44 EST 2007
Author: sartak
Date: Fri Nov 9 13:31:43 2007
New Revision: 4396
Modified:
jifty/trunk/ (props changed)
jifty/trunk/t/TestApp-Plugin-OAuth/lib/TestApp/Plugin/OAuth/Test.pm
jifty/trunk/t/TestApp-Plugin-OAuth/t/03-authorize.t
jifty/trunk/t/TestApp-Plugin-OAuth/t/04-access-token.t
Log:
r44779 at onn: sartak | 2007-11-07 14:50:59 -0500
Whoops, the consumer and user were using the same mech. But fixing that didn't break anything :)
Modified: jifty/trunk/t/TestApp-Plugin-OAuth/lib/TestApp/Plugin/OAuth/Test.pm
==============================================================================
--- jifty/trunk/t/TestApp-Plugin-OAuth/lib/TestApp/Plugin/OAuth/Test.pm (original)
+++ jifty/trunk/t/TestApp-Plugin-OAuth/lib/TestApp/Plugin/OAuth/Test.pm Fri Nov 9 13:31:43 2007
@@ -9,14 +9,15 @@
use Digest::HMAC_SHA1 'hmac_sha1';
use Jifty::Test::WWW::Mechanize;
-our @EXPORT = qw($timestamp $url $mech $pubkey $seckey $token_obj $server $URL
- response_is sign get_latest_token
- allow_ok deny_ok _authorize_request_token
- get_request_token get_authorized_token get_access_token);
+our @EXPORT = qw($timestamp $url $umech $cmech $pubkey $seckey $token_obj
+ $server $URL response_is sign get_latest_token allow_ok deny_ok
+ _authorize_request_token get_request_token get_authorized_token
+ get_access_token);
our $timestamp = 0;
our $url;
-our $mech;
+our $umech;
+our $cmech;
our $pubkey = slurp('t/id_rsa.pub');
our $seckey = slurp('t/id_rsa');
our $token_obj;
@@ -30,7 +31,8 @@
$server = Jifty::Test->make_server;
$URL = $server->started_ok;
- $mech = Jifty::Test::WWW::Mechanize->new();
+ $umech = Jifty::Test::WWW::Mechanize->new();
+ $cmech = Jifty::Test::WWW::Mechanize->new();
$url = $URL . '/oauth/request_token';
}
@@ -74,13 +76,13 @@
my $r;
if ($method eq 'POST') {
- $r = $mech->post($url, [%params]);
+ $r = $cmech->post($url, [%params]);
}
else {
my $query = join '&',
map { "$_=" . Jifty->web->escape_uri($params{$_}||'') }
keys %params;
- $r = $mech->get("$url?$query");
+ $r = $cmech->get("$url?$query");
}
local $Test::Builder::Level = $Test::Builder::Level + 1;
@@ -88,12 +90,14 @@
undef $token_obj;
get_latest_token();
- if ($code == 200) {
+ if ($code == 200 && $url =~ /oauth/) {
main::ok($token_obj, "Successfully loaded a token object with token ".$token_obj->token.".");
}
else {
main::ok(!$token_obj, "Did not get a token");
}
+
+ return $cmech->content;
}
sub sign {
@@ -161,7 +165,7 @@
}
sub get_latest_token {
- my $content = $mech->content;
+ my $content = $cmech->content;
$content =~ s/\boauth_token=(\w+)//
or return;
@@ -176,14 +180,14 @@
my $package = 'Jifty::Plugin::OAuth::Model::';
- if ($mech->uri =~ /request_token/) {
+ if ($cmech->uri =~ /request_token/) {
$package .= 'RequestToken';
}
- elsif ($mech->uri =~ /access_token/) {
+ elsif ($cmech->uri =~ /access_token/) {
$package .= 'AccessToken';
}
else {
- Jifty->log->error("Called get_latest_token, but I cannot grok the URI " . $mech->uri);
+ Jifty->log->error("Called get_latest_token, but I cannot grok the URI " . $cmech->uri);
return;
}
@@ -205,7 +209,7 @@
ok(0, $error), return if $error;
my $name = $token_obj->consumer->name;
- $mech->content_contains("Allowing $name to access your stuff");
+ $umech->content_contains("Allowing $name to access your stuff");
}
sub deny_ok {
@@ -215,7 +219,7 @@
ok(0, $error), return if $error;
my $name = $token_obj->consumer->name;
- $mech->content_contains("Denying $name the right to access your stuff");
+ $umech->content_contains("Denying $name the right to access your stuff");
}
sub _authorize_request_token {
@@ -227,15 +231,15 @@
my $token = shift || $token_obj->token;
$token = $token->token if ref $token;
- $mech->get('/oauth/authorize')
+ $umech->get('/oauth/authorize')
or return "Unable to navigate to /oauth/authorize";;
- $mech->content =~ /If you trust this application/
+ $umech->content =~ /If you trust this application/
or return "Content did not much qr/If you trust this application/";
- my $moniker = $mech->moniker_for('TestApp::Plugin::OAuth::Action::AuthorizeRequestToken')
+ my $moniker = $umech->moniker_for('TestApp::Plugin::OAuth::Action::AuthorizeRequestToken')
or return "Unable to find moniker for AuthorizeRequestToken";
- $mech->fill_in_action($moniker, token => $token)
+ $umech->fill_in_action($moniker, token => $token)
or return "Unable to fill in the AuthorizeRequestToken action";
- $mech->click_button(value => $which_button)
+ $umech->click_button(value => $which_button)
or return "Unable to click $which_button button";
return;
}
Modified: jifty/trunk/t/TestApp-Plugin-OAuth/t/03-authorize.t
==============================================================================
--- jifty/trunk/t/TestApp-Plugin-OAuth/t/03-authorize.t (original)
+++ jifty/trunk/t/TestApp-Plugin-OAuth/t/03-authorize.t Fri Nov 9 13:31:43 2007
@@ -41,34 +41,34 @@
# }}}
# try to navigate to protected pages while not logged in {{{
-$mech->get_ok($URL . '/oauth/authorize');
-$mech->content_unlike(qr/If you trust this application/);
+$umech->get_ok($URL . '/oauth/authorize');
+$umech->content_unlike(qr/If you trust this application/);
-$mech->get_ok('/oauth/authorized');
-$mech->content_unlike(qr/If you trust this application/);
+$umech->get_ok('/oauth/authorized');
+$umech->content_unlike(qr/If you trust this application/);
-$mech->get_ok('/nuke/the/whales');
-$mech->content_unlike(qr/Press the shiny red button/);
+$umech->get_ok('/nuke/the/whales');
+$umech->content_unlike(qr/Press the shiny red button/);
# }}}
# log in {{{
my $u = TestApp::Plugin::OAuth::Model::User->new(current_user => TestApp::Plugin::OAuth::CurrentUser->superuser);
$u->create( name => 'You Zer', email => 'youzer at example.com', password => 'secret', email_confirmed => 1);
ok($u->id, "New user has valid id set");
-$mech->get_ok('/login');
-$mech->fill_in_action_ok($mech->moniker_for('TestApp::Plugin::OAuth::Action::Login'), email => 'youzer at example.com', password => 'secret');
-$mech->submit;
-$mech->content_contains('Logout');
+$umech->get_ok('/login');
+$umech->fill_in_action_ok($umech->moniker_for('TestApp::Plugin::OAuth::Action::Login'), email => 'youzer at example.com', password => 'secret');
+$umech->submit;
+$umech->content_contains('Logout');
# }}}
# try to navigate to protected pages while logged in {{{
-$mech->get_ok('/oauth/authorize');
-$mech->content_like(qr/If you trust this application/);
+$umech->get_ok('/oauth/authorize');
+$umech->content_like(qr/If you trust this application/);
-$mech->get_ok('/oauth/authorized');
-$mech->content_like(qr/If you trust this application/);
+$umech->get_ok('/oauth/authorized');
+$umech->content_like(qr/If you trust this application/);
-$mech->get_ok('/nuke/the/whales');
-$mech->content_like(qr/Press the shiny red button/);
+$umech->get_ok('/nuke/the/whales');
+$umech->content_like(qr/Press the shiny red button/);
# }}}
# deny an unknown access token {{{
my $error = _authorize_request_token('Deny', 'deadbeef');
@@ -76,7 +76,7 @@
ok(0, $error);
}
else {
- $mech->content_contains("I don't know of that request token.");
+ $umech->content_contains("I don't know of that request token.");
}
# }}}
# allow an unknown access token {{{
@@ -85,7 +85,7 @@
ok(0, $error);
}
else {
- $mech->content_contains("I don't know of that request token.");
+ $umech->content_contains("I don't know of that request token.");
}
# }}}
# deny request token {{{
@@ -98,7 +98,7 @@
ok(0, $error);
}
else {
- $mech->content_contains("I don't know of that request token.");
+ $umech->content_contains("I don't know of that request token.");
}
# }}}
# allow request token {{{
@@ -111,7 +111,7 @@
ok(0, $error);
}
else {
- $mech->content_contains("I don't know of that request token.");
+ $umech->content_contains("I don't know of that request token.");
}
# }}}
# expire a token, try to allow it {{{
@@ -125,7 +125,7 @@
ok(0, $error);
}
else {
- $mech->content_contains("This request token has expired.");
+ $umech->content_contains("This request token has expired.");
}
# }}}
# try again, it should be deleted {{{
@@ -134,69 +134,69 @@
ok(0, $error);
}
else {
- $mech->content_contains("I don't know of that request token.");
+ $umech->content_contains("I don't know of that request token.");
}
# }}}
# deny token with a request parameter {{{
get_request_token();
-$mech->get_ok('/oauth/authorize?oauth_token=' . $token_obj->token);
-$mech->content_like(qr/If you trust this application/);
-$mech->content_unlike(qr/should have provided it/, "token hint doesn't show up if we already have it");
-
-$mech->form_number(1);
-$mech->click_button(value => 'Deny');
-
-$mech->content_contains("Denying FooBar Industries the right to access your stuff");
-$mech->content_contains("click here");
-$mech->content_contains("http://foo.bar.example.com?oauth_token=" . $token_obj->token);
-$mech->content_contains("To return to");
-$mech->content_contains("FooBar Industries");
+$umech->get_ok('/oauth/authorize?oauth_token=' . $token_obj->token);
+$umech->content_like(qr/If you trust this application/);
+$umech->content_unlike(qr/should have provided it/, "token hint doesn't show up if we already have it");
+
+$umech->form_number(1);
+$umech->click_button(value => 'Deny');
+
+$umech->content_contains("Denying FooBar Industries the right to access your stuff");
+$umech->content_contains("click here");
+$umech->content_contains("http://foo.bar.example.com?oauth_token=" . $token_obj->token);
+$umech->content_contains("To return to");
+$umech->content_contains("FooBar Industries");
# }}}
# allow token with a request parameter {{{
get_request_token();
-$mech->get_ok('/oauth/authorize?oauth_token=' . $token_obj->token);
-$mech->content_like(qr/If you trust this application/);
-$mech->content_unlike(qr/should have provided it/, "token hint doesn't show up if we already have it");
-
-$mech->form_number(1);
-$mech->click_button(value => 'Allow');
-
-$mech->content_contains("Allowing FooBar Industries to access your stuff");
-$mech->content_contains("click here");
-$mech->content_contains("http://foo.bar.example.com?oauth_token=" . $token_obj->token);
-$mech->content_contains("To return to");
-$mech->content_contains("FooBar Industries");
+$umech->get_ok('/oauth/authorize?oauth_token=' . $token_obj->token);
+$umech->content_like(qr/If you trust this application/);
+$umech->content_unlike(qr/should have provided it/, "token hint doesn't show up if we already have it");
+
+$umech->form_number(1);
+$umech->click_button(value => 'Allow');
+
+$umech->content_contains("Allowing FooBar Industries to access your stuff");
+$umech->content_contains("click here");
+$umech->content_contains("http://foo.bar.example.com?oauth_token=" . $token_obj->token);
+$umech->content_contains("To return to");
+$umech->content_contains("FooBar Industries");
# }}}
# deny token with a callback {{{
get_request_token();
-$mech->get_ok('/oauth/authorize?oauth_callback=http%3A%2f%2fgoogle.com');
-$mech->content_like(qr/If you trust this application/);
+$umech->get_ok('/oauth/authorize?oauth_callback=http%3A%2f%2fgoogle.com');
+$umech->content_like(qr/If you trust this application/);
-$mech->fill_in_action_ok($mech->moniker_for('TestApp::Plugin::OAuth::Action::AuthorizeRequestToken'), token => $token_obj->token);
-$mech->click_button(value => 'Deny');
+$umech->fill_in_action_ok($umech->moniker_for('TestApp::Plugin::OAuth::Action::AuthorizeRequestToken'), token => $token_obj->token);
+$umech->click_button(value => 'Deny');
-$mech->content_contains("Denying FooBar Industries the right to access your stuff");
-$mech->content_contains("click here");
-$mech->content_contains("http://google.com?oauth_token=" . $token_obj->token);
-$mech->content_contains("To return to");
-$mech->content_contains("FooBar Industries");
+$umech->content_contains("Denying FooBar Industries the right to access your stuff");
+$umech->content_contains("click here");
+$umech->content_contains("http://google.com?oauth_token=" . $token_obj->token);
+$umech->content_contains("To return to");
+$umech->content_contains("FooBar Industries");
# }}}
# deny it with a callback + request params {{{
get_request_token();
-$mech->get_ok('/oauth/authorize?oauth_token='.$token_obj->token.'&oauth_callback=http%3A%2F%2Fgoogle.com%2F%3Ffoo%3Dbar');
-$mech->content_like(qr/If you trust this application/);
-$mech->content_unlike(qr/should have provided it/, "token hint doesn't show up if we already have it");
+$umech->get_ok('/oauth/authorize?oauth_token='.$token_obj->token.'&oauth_callback=http%3A%2F%2Fgoogle.com%2F%3Ffoo%3Dbar');
+$umech->content_like(qr/If you trust this application/);
+$umech->content_unlike(qr/should have provided it/, "token hint doesn't show up if we already have it");
-$mech->form_number(1);
-$mech->click_button(value => 'Deny');
+$umech->form_number(1);
+$umech->click_button(value => 'Deny');
-$mech->content_contains("Denying FooBar Industries the right to access your stuff");
-$mech->content_contains("click here");
+$umech->content_contains("Denying FooBar Industries the right to access your stuff");
+$umech->content_contains("click here");
my $token = $token_obj->token;
-$mech->content_like(qr{http://google\.com/\?foo=bar&(?:amp;|#38;)?oauth_token=$token});
-$mech->content_contains("To return to");
-$mech->content_contains("FooBar Industries");
+$umech->content_like(qr{http://google\.com/\?foo=bar&(?:amp;|#38;)?oauth_token=$token});
+$umech->content_contains("To return to");
+$umech->content_contains("FooBar Industries");
# }}}
# authorizing a token refreshes its valid_until {{{
Modified: jifty/trunk/t/TestApp-Plugin-OAuth/t/04-access-token.t
==============================================================================
--- jifty/trunk/t/TestApp-Plugin-OAuth/t/04-access-token.t (original)
+++ jifty/trunk/t/TestApp-Plugin-OAuth/t/04-access-token.t Fri Nov 9 13:31:43 2007
@@ -45,10 +45,10 @@
$u->create( name => 'You Zer', email => 'youzer at example.com', password => 'secret', email_confirmed => 1);
ok($u->id, "New user has valid id set");
-$mech->get_ok($URL . '/login');
-$mech->fill_in_action_ok($mech->moniker_for('TestApp::Plugin::OAuth::Action::Login'), email => 'youzer at example.com', password => 'secret');
-$mech->submit;
-$mech->content_contains('Logout');
+$umech->get_ok($URL . '/login');
+$umech->fill_in_action_ok($umech->moniker_for('TestApp::Plugin::OAuth::Action::Login'), email => 'youzer at example.com', password => 'secret');
+$umech->submit;
+$umech->content_contains('Logout');
# }}}
# }}}
# basic working access token {{{
More information about the Jifty-commit
mailing list