File: 02-redirect-test.t

package info (click to toggle)
libcatalystx-simplelogin-perl 0.21-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 464 kB
  • sloc: perl: 3,134; makefile: 2
file content (41 lines) | stat: -rwxr-xr-x 1,554 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;
use HTTP::Request::Common;

use FindBin qw($Bin);
use lib "$Bin/lib";

use Catalyst::Test 'TestAppRedirect';

foreach my $path (qw|needslogin needslogin_chained needslogin_chained_subpart|) {
    my ($res, $c) = ctx_request(GET "/$path");
    is($res->code, 302, 'get 302 redirect for /' . $path);
    is($res->header('Location'), 'http://localhost/login', 'Redirect to /login');
    ok(!$res->header('X-Action-Run'), 'Action shouldnt run! ' . ($res->header('X-Action-Run')||''));
}
{
    my ($res, $c) = ctx_request(GET "/needslogin_chained_subpart");
    ok($res->header('X-Start-Chain-Run'), 'Start of chain actions run when needslogin at end of chain');
}

{
    my ($res, $c) = ctx_request('/needslogin');
# FIXME
#    ok($c->session->{redirect_to_after_login}, '$c->session->{redirect_to_after_login} set');
    my $cookie = $res->header('Set-Cookie');
    ok($cookie, 'Have a cookie');
    ($res, $c) = ctx_request(POST '/login', [username => 'bob', password => 's00p3r'], Cookie => $cookie);
    $cookie = $res->header('Set-Cookie');
    ok(!exists($c->session->{redirect_to_after_login}), '$c->session->{redirect_to_after_login} cleared');
    ok($c->user, 'Have a user in $c');
    is($res->code, 302, 'get 302 redirect to needslogin');
    is($res->header('Location'), 'http://localhost/needslogin', 'Redirect to /needslogin');
    ($res, $c) = ctx_request(GET '/needslogin', Cookie => $cookie);
    is($res->code, 200, 'get 200 ok for page which needs login');
}

done_testing;