[Jifty-commit] r5168 - in jifty/trunk: . lib/Jifty/Plugin/OAuth t/TestApp-Plugin-OAuth/lib/TestApp/Plugin/OAuth

Jifty commits jifty-commit at lists.jifty.org
Tue Feb 26 03:36:17 EST 2008


Author: sartak
Date: Tue Feb 26 03:36:17 2008
New Revision: 5168

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Plugin/OAuth/Dispatcher.pm
   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/01-basic.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
   jifty/trunk/t/TestApp-Plugin-OAuth/t/05-protected-resource.t
   jifty/trunk/t/TestApp-Plugin-OAuth/t/06-read-only.t
   jifty/trunk/t/TestApp-Plugin-OAuth/t/07-read-write.t

Log:
 r52029 at onn:  sartak | 2008-02-26 03:31:10 -0500
 Make Crypt::OpenSSL::RSA optional for OAuth, and fix the tests to not require it


Modified: jifty/trunk/lib/Jifty/Plugin/OAuth/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/OAuth/Dispatcher.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/OAuth/Dispatcher.pm	Tue Feb 26 03:36:17 2008
@@ -7,7 +7,6 @@
 use Net::OAuth::RequestTokenRequest;
 use Net::OAuth::AccessTokenRequest;
 use Net::OAuth::ProtectedResourceRequest;
-use Crypt::OpenSSL::RSA;
 use URI::Escape 'uri_unescape';
 
 on     POST '/oauth/request_token' => \&request_token;
@@ -312,7 +311,15 @@
 
 {
     my %valid_signature_methods = map { $_ => 1 }
-                                  qw/PLAINTEXT HMAC-SHA1 RSA-SHA1/;
+                                  qw/PLAINTEXT HMAC-SHA1 /;
+
+    if (eval { require Crypt::OpenSSL::RSA; 1 }) {
+        $valid_signature_methods{"RSA-SHA1"} = 1;
+    }
+    else {
+        Jifty->log->debug("RSA-SHA1 support for OAuth unavailable: Crypt::OpenSSL::RSA is not installed.");
+    }
+
     my %key_field = ('RSA-SHA1' => 'rsa_key');
 
     sub get_signature_key {

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	Tue Feb 26 03:36:17 2008
@@ -5,14 +5,13 @@
 use base qw/Jifty::Test/;
 
 use MIME::Base64;
-use Crypt::OpenSSL::RSA;
 use Digest::HMAC_SHA1 'hmac_sha1';
 use Jifty::Test::WWW::Mechanize;
 
 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);
+                 get_access_token has_rsa rsa_skip);
 
 our $timestamp = 0;
 our $url;
@@ -172,6 +171,7 @@
     my $signature;
 
     if ($sig_method eq 'RSA-SHA1') {
+        require Crypt::OpenSSL::RSA;
         my $pubkey = Crypt::OpenSSL::RSA->new_private_key($key);
         $signature = encode_base64($pubkey->sign($signature_base_string), "");
     }
@@ -191,6 +191,15 @@
 
 }
 
+sub has_rsa {
+    eval { require Crypt::OpenSSL::RSA; 1 }
+}
+
+sub rsa_skip {
+    my $count = shift || Carp::carp "You must specify a number of tests to skip.";
+    ::skip 'Crypt::OpenSSL::RSA is required for these tests', $count unless has_rsa;
+}
+
 sub slurp {
     no warnings 'once';
     my $file = shift;

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	Tue Feb 26 03:36:17 2008
@@ -4,14 +4,11 @@
 
 use Test::More;
 BEGIN {
-    if (eval { require Net::OAuth::Request; require Crypt::OpenSSL::RSA; 1 }) {
-        unless (eval { Net::OAuth::Request->VERSION('0.05') }) {
-            diag "You might see some test failures if your Net-OAuth isn't 0.05. Please upgrade.";
-        }
+    if (eval { require Net::OAuth::Request; 1 } && eval { Net::OAuth::Request->VERSION('0.05') }) {
         plan tests => 10;
     }
     else {
-        plan skip_all => "Net::OAuth or Crypt::OpenSSL::RSA isn't installed";
+        plan skip_all => "Net::OAuth 0.05 isn't installed";
     }
 }
 
@@ -50,23 +47,27 @@
 is($sig, 'tR3+Ty81lMeYAr/Fid0kMTYa/WM=', 'HMAC-SHA1 signature correct');
 # }}}
 # sign RSA-SHA1 {{{
-($sig, $sbs, $nrp) = sign(
-    'GET',
-    'pfkkdhi9sl3r4s00',
-    'kd94hf93k423kf44',
-    sign_url => 'http://photos.example.net/photos',
-    signature_key => $seckey,
-    oauth_consumer_key => 'dpf43f3p2l4k3l03',
-    oauth_signature_method => 'RSA-SHA1',
-    oauth_timestamp => '1191242096',
-    oauth_nonce => 'kllo9940pd9333jh',
-    oauth_token => 'nnch734d00sl2jdk',
-    file => 'vacation.jpg',
-    size => 'original',
-    oauth_version => '1.0');
+SKIP: {
+    rsa_skip(3);
 
-is($nrp, 'file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=RSA-SHA1&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original', 'RSA-SHA1 normalized request paramaters correct');
-is($sbs, 'GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DRSA-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal', 'RSA-SHA1 signature-base-string correct');
-is($sig, 'NA2rGBEAnHta9amI/lwEHmuJzkDF2CtfzPNc+jbQIvsFKi0AyRQFi1etC+yxmHLn6bHKSHmn/pR4GOhN+2AP5fi0Aw9mr9n/k7LybUCUwRK/OjJH7b8ESXhkluss+UXCZoLOeaO9Pxskdi1DzWMOhY8si9hfYsCGrHrVbdcqwcw=', 'RSA-SHA1 signature correct');
+    ($sig, $sbs, $nrp) = sign(
+        'GET',
+        'pfkkdhi9sl3r4s00',
+        'kd94hf93k423kf44',
+        sign_url => 'http://photos.example.net/photos',
+        signature_key => $seckey,
+        oauth_consumer_key => 'dpf43f3p2l4k3l03',
+        oauth_signature_method => 'RSA-SHA1',
+        oauth_timestamp => '1191242096',
+        oauth_nonce => 'kllo9940pd9333jh',
+        oauth_token => 'nnch734d00sl2jdk',
+        file => 'vacation.jpg',
+        size => 'original',
+        oauth_version => '1.0');
+
+    is($nrp, 'file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=RSA-SHA1&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original', 'RSA-SHA1 normalized request paramaters correct');
+    is($sbs, 'GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DRSA-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal', 'RSA-SHA1 signature-base-string correct');
+    is($sig, 'NA2rGBEAnHta9amI/lwEHmuJzkDF2CtfzPNc+jbQIvsFKi0AyRQFi1etC+yxmHLn6bHKSHmn/pR4GOhN+2AP5fi0Aw9mr9n/k7LybUCUwRK/OjJH7b8ESXhkluss+UXCZoLOeaO9Pxskdi1DzWMOhY8si9hfYsCGrHrVbdcqwcw=', 'RSA-SHA1 signature correct');
+}
 # }}}
 

Modified: jifty/trunk/t/TestApp-Plugin-OAuth/t/01-basic.t
==============================================================================
--- jifty/trunk/t/TestApp-Plugin-OAuth/t/01-basic.t	(original)
+++ jifty/trunk/t/TestApp-Plugin-OAuth/t/01-basic.t	Tue Feb 26 03:36:17 2008
@@ -4,11 +4,11 @@
 
 use Test::More;
 BEGIN {
-    if (eval { require Net::OAuth::Request; require Crypt::OpenSSL::RSA; 1 }) {
+    if (eval { require Net::OAuth::Request; 1 } && eval { Net::OAuth::Request->VERSION('0.05') }) {
         plan tests => 9;
     }
     else {
-        plan skip_all => "Net::OAuth or Crypt::OpenSSL::RSA isn't installed";
+        plan skip_all => "Net::OAuth 0.05 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	Tue Feb 26 03:36:17 2008
@@ -4,11 +4,11 @@
 
 use Test::More;
 BEGIN {
-    if (eval { require Net::OAuth::Request; require Crypt::OpenSSL::RSA; 1 }) {
+    if (eval { require Net::OAuth::Request; 1 } && eval { Net::OAuth::Request->VERSION('0.05') }) {
         plan tests => 61;
     }
     else {
-        plan skip_all => "Net::OAuth or Crypt::OpenSSL::RSA isn't installed";
+        plan skip_all => "Net::OAuth 0.05 isn't installed";
     }
 }
 
@@ -60,14 +60,18 @@
 );
 # }}}
 # get a request token as a known consumer (RSA-SHA1) {{{
-response_is(
-    code                   => 200,
-    testname               => "200 - RSA-SHA1 signature",
-    consumer_secret        => 'bar',
-    oauth_consumer_key     => 'foo',
-    signature_key          => $seckey,
-    oauth_signature_method => 'RSA-SHA1',
-);
+SKIP: {
+    rsa_skip(3);
+
+    response_is(
+        code                   => 200,
+        testname               => "200 - RSA-SHA1 signature",
+        consumer_secret        => 'bar',
+        oauth_consumer_key     => 'foo',
+        signature_key          => $seckey,
+        oauth_signature_method => 'RSA-SHA1',
+    );
+};
 # }}}
 # get a request token using authorization header {{{
 response_is(
@@ -83,23 +87,21 @@
 --$timestamp;
 response_is(
     code                   => 200,
-    testname               => "200 - RSA-SHA1 signature",
+    testname               => "200 - same timestamp, different nonce",
     consumer_secret        => 'bar',
     oauth_consumer_key     => 'foo',
     oauth_nonce            => 'kjfh',
-    signature_key          => $seckey,
-    oauth_signature_method => 'RSA-SHA1',
+    oauth_signature_method => 'HMAC-SHA1',
 );
 # }}}
 # same nonce, different timestamp {{{
 response_is(
     code                   => 200,
-    testname               => "200 - RSA-SHA1 signature",
+    testname               => "200 - same nonce, different timestamp",
     consumer_secret        => 'bar',
     oauth_consumer_key     => 'foo',
     oauth_nonce            => 'kjfh',
-    signature_key          => $seckey,
-    oauth_signature_method => 'RSA-SHA1',
+    oauth_signature_method => 'HMAC-SHA1',
 );
 # }}}}
 
@@ -131,14 +133,18 @@
 # failure modes
 
 # request a request token as an RSA-less consumer (RSA-SHA1) {{{
-response_is(
-    code                   => 400,
-    testname               => "400 - RSA-SHA1 signature, without registering RSA key!",
-    consumer_secret        => 'bar2',
-    oauth_consumer_key     => 'foo2',
-    signature_key          => $seckey,
-    oauth_signature_method => 'RSA-SHA1',
-);
+SKIP: {
+    rsa_skip(2);
+
+    response_is(
+        code                   => 400,
+        testname               => "400 - RSA-SHA1 signature, without registering RSA key!",
+        consumer_secret        => 'bar2',
+        oauth_consumer_key     => 'foo2',
+        signature_key          => $seckey,
+        oauth_signature_method => 'RSA-SHA1',
+    );
+};
 # }}}
 # unknown consumer {{{
 # we're back to the first consumer, so we need a locally larger timestamp

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	Tue Feb 26 03:36:17 2008
@@ -4,11 +4,11 @@
 
 use Test::More;
 BEGIN {
-    if (eval { require Net::OAuth::Request; require Crypt::OpenSSL::RSA; 1 }) {
+    if (eval { require Net::OAuth::Request; 1 } && eval { Net::OAuth::Request->VERSION('0.05') }) {
         plan tests => 85;
     }
     else {
-        plan skip_all => "Net::OAuth or Crypt::OpenSSL::RSA isn't installed";
+        plan skip_all => "Net::OAuth 0.05 isn't installed";
     }
 }
 

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	Tue Feb 26 03:36:17 2008
@@ -4,11 +4,11 @@
 
 use Test::More;
 BEGIN {
-    if (eval { require Net::OAuth::Request; require Crypt::OpenSSL::RSA; 1 }) {
+    if (eval { require Net::OAuth::Request; 1 } && eval { Net::OAuth::Request->VERSION('0.05') }) {
         plan tests => 70;
     }
     else {
-        plan skip_all => "Net::OAuth or Crypt::OpenSSL::RSA isn't installed";
+        plan skip_all => "Net::OAuth 0.05 isn't installed";
     }
 }
 

Modified: jifty/trunk/t/TestApp-Plugin-OAuth/t/05-protected-resource.t
==============================================================================
--- jifty/trunk/t/TestApp-Plugin-OAuth/t/05-protected-resource.t	(original)
+++ jifty/trunk/t/TestApp-Plugin-OAuth/t/05-protected-resource.t	Tue Feb 26 03:36:17 2008
@@ -4,11 +4,11 @@
 
 use Test::More;
 BEGIN {
-    if (eval { require Net::OAuth::Request; require Crypt::OpenSSL::RSA; 1 }) {
+    if (eval { require Net::OAuth::Request; 1 } && eval { Net::OAuth::Request->VERSION('0.05') }) {
         plan tests => 58;
     }
     else {
-        plan skip_all => "Net::OAuth or Crypt::OpenSSL::RSA isn't installed";
+        plan skip_all => "Net::OAuth 0.05 isn't installed";
     }
 }
 

Modified: jifty/trunk/t/TestApp-Plugin-OAuth/t/06-read-only.t
==============================================================================
--- jifty/trunk/t/TestApp-Plugin-OAuth/t/06-read-only.t	(original)
+++ jifty/trunk/t/TestApp-Plugin-OAuth/t/06-read-only.t	Tue Feb 26 03:36:17 2008
@@ -4,11 +4,11 @@
 
 use Test::More;
 BEGIN {
-    if (eval { require Net::OAuth::Request; require Crypt::OpenSSL::RSA; 1 }) {
+    if (eval { require Net::OAuth::Request; 1 } && eval { Net::OAuth::Request->VERSION('0.05') }) {
         plan tests => 28;
     }
     else {
-        plan skip_all => "Net::OAuth or Crypt::OpenSSL::RSA isn't installed";
+        plan skip_all => "Net::OAuth 0.05 isn't installed";
     }
 }
 

Modified: jifty/trunk/t/TestApp-Plugin-OAuth/t/07-read-write.t
==============================================================================
--- jifty/trunk/t/TestApp-Plugin-OAuth/t/07-read-write.t	(original)
+++ jifty/trunk/t/TestApp-Plugin-OAuth/t/07-read-write.t	Tue Feb 26 03:36:17 2008
@@ -4,11 +4,11 @@
 
 use Test::More;
 BEGIN {
-    if (eval { require Net::OAuth::Request; require Crypt::OpenSSL::RSA; 1 }) {
+    if (eval { require Net::OAuth::Request; 1 } && eval { Net::OAuth::Request->VERSION('0.05') }) {
         plan tests => 28;
     }
     else {
-        plan skip_all => "Net::OAuth or Crypt::OpenSSL::RSA isn't installed";
+        plan skip_all => "Net::OAuth 0.05 isn't installed";
     }
 }
 


More information about the Jifty-commit mailing list