first pass RT4 merge, RT#13852
[freeside.git] / rt / t / web / remote_user.t
1 use strict;
2 use warnings;
3 use RT;
4 use RT::Test tests => 9;
5 use MIME::Base64 qw//;
6
7 RT->Config->Set( DevelMode => 0 );
8 RT->Config->Set( WebExternalAuth => 1 );
9
10 sub auth {
11     return Authorization => "Basic " .
12         MIME::Base64::encode( join(":", @_) );
13 }
14
15 my ( $url, $m ) = RT::Test->started_ok( basic_auth => 1 );
16 $m->get($url);
17 is($m->status, 401, "Initial request with no creds gets 401");
18
19 $m->get($url, auth( root => "wrong" ));
20 is($m->status, 401, "Request with wrong creds gets 401");
21
22 $m->get($url, auth( root => "password" ));
23 is($m->status, 200, "Request with right creds gets 200");
24
25 $m->content_like(
26     qr{<span class="current-user">\Qroot\E</span>}i,
27     "Has user on the page"
28 );
29 $m->content_unlike(qr/Logout/i, "Has no logout button, no WebFallbackToInternalAuth");
30
31 $m->get($url);
32 is($m->status, 401, "Subsequent requests without credentials aren't still logged in");
33
34
35 # Put the credentials back for the warnings check at the end
36 $m->default_header( auth( root => "password" ));