[Jifty-commit] r4395 - 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:35 EST 2007
Author: sartak
Date: Fri Nov 9 13:31:35 2007
New Revision: 4395
Modified:
jifty/trunk/ (props changed)
jifty/trunk/t/TestApp-Plugin-OAuth/lib/TestApp/Plugin/OAuth/Test.pm
jifty/trunk/t/TestApp-Plugin-OAuth/t/00-test-setup.t
jifty/trunk/t/TestApp-Plugin-OAuth/t/02-request-token.t
jifty/trunk/t/TestApp-Plugin-OAuth/t/03-authorize.t
jifty/trunk/t/TestApp-Plugin-OAuth/t/04-access-token.t
Log:
r44778 at onn: sartak | 2007-11-07 14:41:01 -0500
Refactor the tests
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:35 2007
@@ -7,16 +7,12 @@
use MIME::Base64;
use Crypt::OpenSSL::RSA;
use Digest::HMAC_SHA1 'hmac_sha1';
+use Jifty::Test::WWW::Mechanize;
-our @EXPORT = qw($timestamp $url $mech $pubkey $seckey $token_obj
+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);
-
-sub setup {
- my $class = shift;
- $class->SUPER::setup;
- $class->export_to_level(1);
-}
+ allow_ok deny_ok _authorize_request_token
+ get_request_token get_authorized_token get_access_token);
our $timestamp = 0;
our $url;
@@ -24,6 +20,19 @@
our $pubkey = slurp('t/id_rsa.pub');
our $seckey = slurp('t/id_rsa');
our $token_obj;
+our $server;
+our $URL;
+
+sub setup {
+ my $class = shift;
+ $class->SUPER::setup;
+ $class->export_to_level(1);
+
+ $server = Jifty::Test->make_server;
+ $URL = $server->started_ok;
+ $mech = Jifty::Test::WWW::Mechanize->new();
+ $url = $URL . '/oauth/request_token';
+}
sub response_is {
++$timestamp;
@@ -41,7 +50,8 @@
@_,
);
- local $url = delete $params{url} || $url;
+ local $url = $URL . delete $params{url}
+ if $params{url};
for (grep {!defined $params{$_}} keys %params) {
delete $params{$_};
@@ -54,7 +64,7 @@
my $consumer_secret = delete $params{consumer_secret}
or die "consumer_secret not passed to response_is!";
- if ($url =~ /access_token/) {
+ if ($url !~ /request_token/) {
$token_secret ||= $token_obj->secret;
$params{oauth_token} ||= $token_obj->token;
}
@@ -230,5 +240,40 @@
return;
}
+sub get_request_token {
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+ response_is(
+ url => '/oauth/request_token',
+ code => 200,
+ testname => "200 - plaintext signature",
+ consumer_secret => 'bar',
+ oauth_consumer_key => 'foo',
+ oauth_signature_method => 'PLAINTEXT',
+ @_,
+ );
+ return $token_obj;
+}
+
+sub get_authorized_token {
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ get_request_token(@_);
+ allow_ok();
+ return $token_obj;
+}
+
+sub get_access_token {
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ get_authorized_token();
+ response_is(
+ url => '/oauth/access_token',
+ code => 200,
+ testname => "200 - plaintext signature",
+ consumer_secret => 'bar',
+ oauth_consumer_key => 'foo',
+ oauth_signature_method => 'PLAINTEXT',
+ );
+}
+
1;
Modified: jifty/trunk/t/TestApp-Plugin-OAuth/t/00-test-setup.t
==============================================================================
--- jifty/trunk/t/TestApp-Plugin-OAuth/t/00-test-setup.t (original)
+++ jifty/trunk/t/TestApp-Plugin-OAuth/t/00-test-setup.t Fri Nov 9 13:31:35 2007
@@ -5,7 +5,7 @@
use Test::More;
BEGIN {
if (eval { require Net::OAuth::Request; require Crypt::OpenSSL::RSA; 1 }) {
- plan tests => 9;
+ plan tests => 10;
}
else {
plan skip_all => "Net::OAuth isn't installed";
Modified: jifty/trunk/t/TestApp-Plugin-OAuth/t/02-request-token.t
==============================================================================
--- jifty/trunk/t/TestApp-Plugin-OAuth/t/02-request-token.t (original)
+++ jifty/trunk/t/TestApp-Plugin-OAuth/t/02-request-token.t Fri Nov 9 13:31:35 2007
@@ -5,7 +5,7 @@
use Test::More;
BEGIN {
if (eval { require Net::OAuth::Request; require Crypt::OpenSSL::RSA; 1 }) {
- plan tests => 59;
+ plan tests => 58;
}
else {
plan skip_all => "Net::OAuth isn't installed";
@@ -17,14 +17,6 @@
use TestApp::Plugin::OAuth::Test;
-use Jifty::Test::WWW::Mechanize;
-
-my $server = Jifty::Test->make_server;
-isa_ok($server, 'Jifty::Server');
-my $URL = $server->started_ok;
-$mech = Jifty::Test::WWW::Mechanize->new();
-$url = $URL . '/oauth/request_token';
-
# create some consumers {{{
my $consumer = Jifty::Plugin::OAuth::Model::Consumer->new(current_user => Jifty::CurrentUser->superuser);
my ($ok, $msg) = $consumer->create(
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:35 2007
@@ -5,7 +5,7 @@
use Test::More;
BEGIN {
if (eval { require Net::OAuth::Request; require Crypt::OpenSSL::RSA; 1 }) {
- plan tests => 86;
+ plan tests => 85;
}
else {
plan skip_all => "Net::OAuth isn't installed";
@@ -19,27 +19,6 @@
use Jifty::Test::WWW::Mechanize;
-my $server = Jifty::Test->make_server;
-isa_ok($server, 'Jifty::Server');
-my $URL = $server->started_ok;
-$mech = Jifty::Test::WWW::Mechanize->new();
-$url = $URL . '/oauth/request_token';
-
-# helper functions {{{
-sub get_request_token {
- local $Test::Builder::Level = $Test::Builder::Level + 1;
-
- response_is(
- code => 200,
- testname => "200 - plaintext signature",
- consumer_secret => 'bar',
- oauth_consumer_key => 'foo',
- oauth_signature_method => 'PLAINTEXT',
- @_,
- );
- return $token_obj;
-}
-# }}}
# create some consumers {{{
my $consumer = Jifty::Plugin::OAuth::Model::Consumer->new(current_user => Jifty::CurrentUser->superuser);
my ($ok, $msg) = $consumer->create(
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:35 2007
@@ -5,7 +5,7 @@
use Test::More;
BEGIN {
if (eval { require Net::OAuth::Request; require Crypt::OpenSSL::RSA; 1 }) {
- plan tests => 71;
+ plan tests => 70;
}
else {
plan skip_all => "Net::OAuth isn't installed";
@@ -19,35 +19,6 @@
use Jifty::Test::WWW::Mechanize;
-my $server = Jifty::Test->make_server;
-isa_ok($server, 'Jifty::Server');
-my $URL = $server->started_ok;
-$mech = Jifty::Test::WWW::Mechanize->new();
-$url = $URL . '/oauth/access_token';
-
-# helper functions {{{
-sub get_request_token {
- local $Test::Builder::Level = $Test::Builder::Level + 1;
-
- response_is(
- url => $URL . '/oauth/request_token',
- code => 200,
- testname => "200 - plaintext signature",
- consumer_secret => 'bar',
- oauth_consumer_key => 'foo',
- oauth_signature_method => 'PLAINTEXT',
- @_,
- );
- return $token_obj;
-}
-
-sub get_authorized_token {
- local $Test::Builder::Level = $Test::Builder::Level + 1;
- get_request_token(@_);
- allow_ok();
- return $token_obj;
-}
-# }}}
# setup {{{
# create two consumers {{{
my $consumer = Jifty::Plugin::OAuth::Model::Consumer->new(current_user => Jifty::CurrentUser->superuser);
@@ -84,6 +55,7 @@
get_authorized_token();
my $request_token = $token_obj->token;
response_is(
+ url => '/oauth/access_token',
code => 200,
testname => "200 - plaintext signature",
consumer_secret => 'bar',
@@ -96,6 +68,7 @@
get_request_token();
deny_ok();
response_is(
+ url => '/oauth/access_token',
code => 401,
testname => "401 - denied token",
consumer_secret => 'bar',
@@ -107,6 +80,7 @@
get_authorized_token();
$request_token = $token_obj;
response_is(
+ url => '/oauth/access_token',
code => 401,
testname => "401 - denied token",
consumer_secret => 'bar2',
@@ -117,6 +91,7 @@
# get that same access token as the original consumer {{{
$token_obj = $request_token;
response_is(
+ url => '/oauth/access_token',
code => 200,
testname => "200 - got token",
consumer_secret => 'bar',
@@ -128,6 +103,7 @@
get_authorized_token();
--$timestamp;
response_is(
+ url => '/oauth/access_token',
code => 200,
testname => "200 - plaintext signature",
consumer_secret => 'bar',
@@ -139,6 +115,7 @@
# different timestamp, same nonce {{{
get_authorized_token();
response_is(
+ url => '/oauth/access_token',
code => 200,
testname => "200 - plaintext signature",
consumer_secret => 'bar',
@@ -151,6 +128,7 @@
get_authorized_token();
$timestamp -= 2;
response_is(
+ url => '/oauth/access_token',
code => 401,
testname => "401 - duplicate ts/nonce as previous access",
consumer_secret => 'bar',
@@ -163,6 +141,7 @@
get_authorized_token();
--$timestamp;
response_is(
+ url => '/oauth/access_token',
code => 401,
testname => "401 - duplicate ts/nonce for request token",
consumer_secret => 'bar',
@@ -173,6 +152,7 @@
# same request token {{{
$token_obj = $request_token;
response_is(
+ url => '/oauth/access_token',
code => 401,
testname => "401 - already used",
consumer_secret => 'bar',
@@ -184,6 +164,7 @@
get_authorized_token();
$token_obj->set_valid_until(DateTime->now(time_zone => "GMT")->subtract(days => 1));
response_is(
+ url => '/oauth/access_token',
code => 401,
testname => "401 - expired",
consumer_secret => 'bar',
@@ -194,6 +175,7 @@
# wrong consumer secret {{{
get_authorized_token();
response_is(
+ url => '/oauth/access_token',
code => 401,
testname => "401 - wrong secret",
consumer_secret => 'bah!',
More information about the Jifty-commit
mailing list