[Rt-commit] [rtir] 01/02: Test redirecting to /RTIR/ on login

Kevin Falcone falcone at bestpractical.com
Wed Oct 29 16:39:26 EDT 2014


This is an automated email from the git hooks/post-receive script.

falcone pushed a commit to branch 3.2/rtir-login-redirect-rest
in repository rtir.

commit f75969b93b182c5b8d8809b44f7cfcb1cdf4566e
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Wed Oct 29 15:24:58 2014 -0400

    Test redirecting to /RTIR/ on login
    
    Steals liberally from core's t/web/redirect-after-login.t
    The thing we care about is that an RTIR user goes to /RTIR/ but REST or
    other direct links are left alone.
    
    The login() function doesn't test the login page, so it isn't helpful
    for our use case and I'm glad I was able to steal the repetitive code
    from core.
    
    Doesn't test everything it could, you still need to manually deal with
    WebPath and checking Rt-Authen-ExternalAuth but it's a great help for
    the basics.
---
 MANIFEST                  |   1 +
 t/030-redirect-on-login.t | 115 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 116 insertions(+)

diff --git a/MANIFEST b/MANIFEST
index adc9f05..46ebe8d 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -216,6 +216,7 @@ t/011-merge.t
 t/015-make-clicky.t
 t/019-watchers-on-create.t
 t/020-incident-and-investigation.t
+t/030-redirect-on-login.t
 t/articles/basics.t
 t/articles/on-create.t
 t/articles/on-update.t
diff --git a/t/030-redirect-on-login.t b/t/030-redirect-on-login.t
new file mode 100644
index 0000000..58eb47d
--- /dev/null
+++ b/t/030-redirect-on-login.t
@@ -0,0 +1,115 @@
+use strict;
+use warnings;
+
+use RT::IR::Test tests => undef;
+
+RT::Test->started_ok;
+my $agent = default_agent();
+$agent->logout;
+
+# $agent->login() doesn't actually test /NoAuth/Login.html
+# It requests $rt_web_url/?user=root;pass=password which is
+# a different flow than our users use.
+my $url = $agent->rt_base_url;
+diag $url if $ENV{TEST_VERBOSE};
+$agent->get($url);
+
+# test a login from the main page
+{
+    $agent->get_ok($url);
+    is($agent->{'status'}, 200, "Loaded a page");
+    is($agent->uri, $url, "didn't redirect to /NoAuth/Login.html for base URL");
+    ok($agent->current_form->find_input('user'));
+    ok($agent->current_form->find_input('pass'));
+    like($agent->current_form->action, qr{/NoAuth/Login\.html$}, "login form action is correct");
+
+    ok($agent->content =~ /username:/i);
+    $agent->field( 'user' => 'rtir_test_user' );
+    $agent->field( 'pass' => 'rtir_test_pass' );
+
+    # the field isn't named, so we have to click link 0
+    $agent->click(0);
+    is( $agent->status, 200, "Fetched the page ok");
+    ok( $agent->content =~ /Logout/i, "Found a logout link");
+    is( $agent->uri, $url.'RTIR/', "right URL" );
+    like( $agent->{redirected_uri}, qr{/NoAuth/Login\.html$}, "We redirected from login");
+    $agent->logout();
+}
+
+
+# test a login from a non-front page, both with a double leading slash and without
+for my $path (qw(Prefs/Other.html /Prefs/Other.html)) {
+    my $requested = $url.$path;
+    $agent->get_ok($requested);
+    is($agent->status, 200, "Loaded a page");
+    like($agent->uri, qr'/NoAuth/Login\.html\?next=[a-z0-9]{32}', "on login page, with next page hash");
+    is($agent->{redirected_uri}, $requested, "redirected from our requested page");
+
+    ok($agent->current_form->find_input('user'));
+    ok($agent->current_form->find_input('pass'));
+    ok($agent->current_form->find_input('next'));
+    like($agent->value('next'), qr/^[a-z0-9]{32}$/i, "next page argument is a hash");
+    like($agent->current_form->action, qr{/NoAuth/Login\.html$}, "login form action is correct");
+
+    ok($agent->content =~ /username:/i);
+    $agent->field( 'user' => 'rtir_test_user' );
+    $agent->field( 'pass' => 'rtir_test_pass' );
+
+    # the field isn't named, so we have to click link 0
+    $agent->click(0);
+    is( $agent->status, 200, "Fetched the page ok");
+    ok( $agent->content =~ /Logout/i, "Found a logout link");
+
+    if ($path =~ m{/}) {
+        (my $collapsed = $path) =~ s{^/}{};
+        is( $agent->uri, $url.$collapsed, "right URL, with leading slashes in path collapsed" );
+    } else {
+        is( $agent->uri, $requested, "right URL" );
+    }
+
+    like( $agent->{redirected_uri}, qr{/NoAuth/Login\.html}, "We redirected from login");
+    $agent->logout();
+}
+
+# test a login from the main page as somebody not in the duty team
+{
+    $agent->get_ok($url);
+    is($agent->{'status'}, 200, "Loaded a page");
+    is($agent->uri, $url, "didn't redirect to /NoAuth/Login.html for base URL");
+    ok($agent->current_form->find_input('user'));
+    ok($agent->current_form->find_input('pass'));
+    like($agent->current_form->action, qr{/NoAuth/Login\.html$}, "login form action is correct");
+
+    ok($agent->content =~ /username:/i);
+    $agent->field( 'user' => 'root' );
+    $agent->field( 'pass' => 'password' );
+
+    # the field isn't named, so we have to click link 0
+    $agent->click(0);
+    is( $agent->status, 200, "Fetched the page ok");
+    ok( $agent->content =~ /Logout/i, "Found a logout link");
+    is( $agent->uri, $url, "right URL" );
+    like( $agent->{redirected_uri}, qr{/NoAuth/Login\.html$}, "We redirected from login");
+    $agent->logout();
+}
+
+# test REST login response
+{
+    $agent = RT::Test::Web->new;
+    my $requested = $url."REST/1.0/?user=rtir_test_user;pass=rtir_test_pass";
+    $agent->get($requested);
+    is($agent->status, 200, "Loaded a page");
+    is($agent->uri, $requested, "didn't redirect to /NoAuth/Login.html for REST");
+    $agent->get_ok($url."REST/1.0");
+}
+
+
+
+
+done_testing;
+
+#TODO
+#Test with WebPath (needs apache)
+#Test with config off
+
+1;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the rt-commit mailing list