[Rt-commit] rt branch, 4.0/external-auth-tests, created. rt-4.0.1rc1-13-g4716929

Alex Vandiver alexmv at bestpractical.com
Wed Jun 1 16:37:25 EDT 2011


The branch, 4.0/external-auth-tests has been created
        at  4716929adc66843b4542a9ace4f0e022a7c98ed5 (commit)

- Log -----------------------------------------------------------------
commit d464e8e10351ab8c87c38c8e62238e9655da6f53
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Jun 1 15:21:31 2011 -0400

    Refactor "the PSGI app under testing" into a method

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index b468aae..96fae31 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1259,6 +1259,18 @@ sub started_ok {
     return $self->$function( $variant, @_ );
 }
 
+sub test_app {
+    my $self = shift;
+
+    require RT::Interface::Web::Handler;
+    my $app = RT::Interface::Web::Handler->PSGIApp;
+
+    require Plack::Middleware::Test::StashWarnings;
+    $app = Plack::Middleware::Test::StashWarnings->wrap($app);
+
+    return $app;
+}
+
 sub start_plack_server {
     my $self = shift;
 
@@ -1301,18 +1313,13 @@ sub start_plack_server {
     # stick this in a scope so that when $app is garbage collected,
     # StashWarnings can complain about unhandled warnings
     do {
-        require RT::Interface::Web::Handler;
-        my $app = RT::Interface::Web::Handler->PSGIApp;
-
-        require Plack::Middleware::Test::StashWarnings;
-        $app = Plack::Middleware::Test::StashWarnings->wrap($app);
-
-        $plack_server->run($app);
+        $plack_server->run($self->test_app);
     };
 
     exit;
 }
 
+our $TEST_APP;
 sub start_inline_server {
     my $self = shift;
 
@@ -1324,6 +1331,7 @@ sub start_inline_server {
     RT::Interface::Web->ClearSquished;
 
     Test::More::ok(1, "psgi test server ok");
+    $TEST_APP = $self->test_app;
     return ("http://localhost:$port", RT::Test::Web->new);
 }
 
diff --git a/lib/RT/Test/Web.pm b/lib/RT/Test/Web.pm
index 3be1b85..aaad882 100644
--- a/lib/RT/Test/Web.pm
+++ b/lib/RT/Test/Web.pm
@@ -59,15 +59,7 @@ require Test::More;
 sub new {
     my ($class, @args) = @_;
 
-    if ($class->isa('Test::WWW::Mechanize::PSGI')) {
-        require RT::Interface::Web::Handler;
-        my $app = RT::Interface::Web::Handler->PSGIApp;
-        require Plack::Middleware::Test::StashWarnings;
-        $app = Plack::Middleware::Test::StashWarnings->wrap($app);
-
-        push @args, app => $app;
-    }
-
+    push @args, app => $RT::Test::TEST_APP if $RT::Test::TEST_APP;
     my $self = $class->SUPER::new(@args);
     $self->cookie_jar(HTTP::Cookies->new);
 

commit f98897ff14ec016668cf5ee350974e35bc54317d
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Jun 1 15:27:25 2011 -0400

    Push arguments to ->start_server down into other functions as key/value pairs

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 96fae31..554ae85 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1256,11 +1256,12 @@ sub started_ok {
     unless ( $self->can($function) ) {
         die "Don't know how to start server '$server'";
     }
-    return $self->$function( $variant, @_ );
+    return $self->$function( variant => $variant, @_ );
 }
 
 sub test_app {
     my $self = shift;
+    my %server_opt = @_;
 
     require RT::Interface::Web::Handler;
     my $app = RT::Interface::Web::Handler->PSGIApp;
@@ -1298,7 +1299,7 @@ sub start_plack_server {
             unless $handled;
         push @SERVERS, $pid;
         my $Tester = Test::Builder->new;
-        $Tester->ok(1, @_);
+        $Tester->ok(1, "started plack server ok");
 
         __reconnect_rt();
         return ("http://localhost:$port", RT::Test::Web->new);
@@ -1313,7 +1314,7 @@ sub start_plack_server {
     # stick this in a scope so that when $app is garbage collected,
     # StashWarnings can complain about unhandled warnings
     do {
-        $plack_server->run($self->test_app);
+        $plack_server->run($self->test_app(@_));
     };
 
     exit;
@@ -1331,17 +1332,22 @@ sub start_inline_server {
     RT::Interface::Web->ClearSquished;
 
     Test::More::ok(1, "psgi test server ok");
-    $TEST_APP = $self->test_app;
+    $TEST_APP = $self->test_app(@_);
     return ("http://localhost:$port", RT::Test::Web->new);
 }
 
 sub start_apache_server {
     my $self = shift;
-    my $variant = shift || 'mod_perl';
-    $ENV{RT_TEST_WEB_HANDLER} = "apache+$variant";
+    my %server_opt = @_;
+    $server_opt{variant} ||= 'mod_perl';
+    $ENV{RT_TEST_WEB_HANDLER} = "apache+$server_opt{variant}";
 
     require RT::Test::Apache;
-    my $pid = RT::Test::Apache->start_server($variant || 'mod_perl', $port, \%tmp);
+    my $pid = RT::Test::Apache->start_server(
+        %server_opt,
+        port => $port,
+        tmp => \%tmp
+    );
     push @SERVERS, $pid;
 
     my $url = RT->Config->Get('WebURL');
diff --git a/lib/RT/Test/Apache.pm b/lib/RT/Test/Apache.pm
index 6a4acd9..7904a04 100644
--- a/lib/RT/Test/Apache.pm
+++ b/lib/RT/Test/Apache.pm
@@ -71,9 +71,9 @@ if ($apxs and not $apache_module_prefix) {
 $apache_module_prefix ||= 'modules';
 
 sub start_server {
-    my ($self, $variant, $port, $tmp) = @_;
-    my %tmp = %$tmp;
-    my %info = $self->apache_server_info( variant => $variant );
+    my ($self, %config) = @_;
+    my %tmp = %{$config{tmp}};
+    my %info = $self->apache_server_info( %config );
 
     RT::Test::diag(do {
         open( my $fh, '<', $tmp{'config'}{'RT'} ) or die $!;
@@ -83,10 +83,10 @@ sub start_server {
 
     my $tmpl = File::Spec->rel2abs( File::Spec->catfile(
         't', 'data', 'configs',
-        'apache'. $info{'version'} .'+'. $variant .'.conf'
+        'apache'. $info{'version'} .'+'. $config{variant} .'.conf'
     ) );
     my %opt = (
-        listen         => $port,
+        listen         => $config{port},
         server_root    => $info{'HTTPD_ROOT'} || $ENV{'HTTPD_ROOT'}
             || Test::More::BAIL_OUT("Couldn't figure out server root"),
         document_root  => $RT::MasonComponentRoot,

commit 4716929adc66843b4542a9ace4f0e022a7c98ed5
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Jun 1 15:48:32 2011 -0400

    Add basic tests for WebExternalAuth

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 554ae85..c95ebe3 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1269,6 +1269,16 @@ sub test_app {
     require Plack::Middleware::Test::StashWarnings;
     $app = Plack::Middleware::Test::StashWarnings->wrap($app);
 
+    if ($server_opt{basic_auth}) {
+        require Plack::Middleware::Auth::Basic;
+        $app = Plack::Middleware::Auth::Basic->wrap(
+            $app,
+            authenticator => sub {
+                my ($username, $password) = @_;
+                return $username eq 'root' && $password eq 'password';
+            }
+        );
+    }
     return $app;
 }
 
diff --git a/lib/RT/Test/Apache.pm b/lib/RT/Test/Apache.pm
index 7904a04..ae81b89 100644
--- a/lib/RT/Test/Apache.pm
+++ b/lib/RT/Test/Apache.pm
@@ -70,6 +70,19 @@ if ($apxs and not $apache_module_prefix) {
 
 $apache_module_prefix ||= 'modules';
 
+sub basic_auth {
+    my $self = shift;
+    my $passwd = File::Spec->rel2abs( File::Spec->catfile(
+        't', 'data', 'configs', 'passwords' ) );
+
+    return <<"EOT";
+    AuthType Basic
+    AuthName "restricted area"
+    AuthUserFile $passwd
+    Require user root
+EOT
+}
+
 sub start_server {
     my ($self, %config) = @_;
     my %tmp = %{$config{tmp}};
@@ -95,6 +108,7 @@ sub start_server {
         rt_sbin_path   => $RT::SbinPath,
         rt_site_config => $ENV{'RT_SITE_CONFIG'},
         load_modules   => $info{load_modules},
+        basic_auth     => $config{basic_auth} ? $self->basic_auth : "",
     );
     foreach (qw(log pid lock)) {
         $opt{$_ .'_file'} = File::Spec->catfile(
@@ -179,6 +193,7 @@ sub apache_server_info {
     ) unless exists $MODULES{$res{version}}{$res{variant}};
 
     my @mlist = @{$MODULES{$res{version}}{$res{variant}}};
+    push @mlist, "authn_file", "auth_basic", "authz_user" if $res{basic_auth};
 
     $res{'load_modules'} = '';
     foreach my $mod ( @mlist ) {
diff --git a/t/data/configs/apache2.2+fastcgi.conf.in b/t/data/configs/apache2.2+fastcgi.conf.in
index dc045e9..efb1ee8 100644
--- a/t/data/configs/apache2.2+fastcgi.conf.in
+++ b/t/data/configs/apache2.2+fastcgi.conf.in
@@ -38,6 +38,8 @@ DocumentRoot "%%DOCUMENT_ROOT%%"
     Order allow,deny
     Allow from all
 
+%%BASIC_AUTH%%
+
     Options +ExecCGI
     AddHandler fastcgi-script fcgi
 </Location>
diff --git a/t/data/configs/apache2.2+mod_perl.conf.in b/t/data/configs/apache2.2+mod_perl.conf.in
index aad8bf5..2cb71af 100644
--- a/t/data/configs/apache2.2+mod_perl.conf.in
+++ b/t/data/configs/apache2.2+mod_perl.conf.in
@@ -50,6 +50,8 @@ DocumentRoot "%%DOCUMENT_ROOT%%"
     Order allow,deny
     Allow from all
 
+%%BASIC_AUTH%%
+
     SetHandler perl-script
     PerlResponseHandler Plack::Handler::Apache2
     PerlSetVar psgi_app %%RT_SBIN_PATH%%/rt-server
diff --git a/t/data/configs/passwords b/t/data/configs/passwords
new file mode 100644
index 0000000..2ea72d1
--- /dev/null
+++ b/t/data/configs/passwords
@@ -0,0 +1,2 @@
+# root / password
+root:8NbrT44Shvnco
diff --git a/t/web/remote_user.t b/t/web/remote_user.t
new file mode 100644
index 0000000..8e2c1f5
--- /dev/null
+++ b/t/web/remote_user.t
@@ -0,0 +1,35 @@
+use strict;
+use warnings;
+use RT;
+use RT::Test tests => 8;
+
+RT->Config->Set( DevelMode => 0 );
+RT->Config->Set( WebExternalAuth => 1 );
+
+my ( $url, $m ) = RT::Test->started_ok( basic_auth => 1 );
+$m->get($url);
+is($m->status, 401, "Initial request wuth no creds gets 401");
+
+my $authority = URI->new($url)->authority;
+
+$m->credentials(
+    $authority,
+    "restricted area",
+    root => "wrong",
+);
+$m->get($url);
+is($m->status, 401, "Request with wrong creds gets 401");
+
+$m->credentials(
+    $authority,
+    "restricted area",
+    root => "password",
+);
+$m->get($url);
+is($m->status, 200, "Request with right creds gets 200");
+
+$m->content_like(
+    qr{<span class="current-user">\Qroot\E</span>}i,
+    "Has user on the page"
+);
+$m->content_unlike(qr/Logout/i, "Has no logout button, no WebFallbackToInternalAuth");

-----------------------------------------------------------------------


More information about the Rt-commit mailing list