File: 22_timeout_guest_fallback.t

package info (click to toggle)
libapache2-mod-auth-tkt 2.3.99~b1-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 856 kB
  • sloc: ansic: 2,213; perl: 1,756; sh: 128; makefile: 94; php: 88; ruby: 59; tcl: 55; python: 48
file content (82 lines) | stat: -rw-r--r-- 2,451 bytes parent folder | download
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env perl
#
# Test auth ticket timeouts with Guest Fallback on (TKTAuthTimeoutMin set to 1)
#

use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestUtil;
use Apache::TestRequest qw(GET POST);
use HTTP::Cookies;
use lib "cgi";
use Apache::AuthTkt;
use File::Basename;

plan tests => 9, need 'LWP',
  { "env variable MAT_TEST_TIMEOUTS not set" => $ENV{MAT_TEST_TIMEOUTS} };

# Turn off automatic redirection following
Apache::TestRequest::user_agent(
  requests_redirectable => 0,
  reset => 1,
);

ok 1;   # simple load test

my $url = '/secret_timeout_guest_fallback/index.cgi';
my $res = GET $url;

# No cookie - should be redirected
#ok t_cmp($res->code, 307, 'redirected');
#ok t_cmp($res->content, qr/redirect.*login/is, 'no ticket: redirect to login');

# Generate ticket and cookie jar
my $at = Apache::AuthTkt->new(conf => 't/conf/extra.conf');
my $ticket = $at->ticket(uid => 'testuser', ip_addr => '127.0.0.1');
my $jar = HTTP::Cookies->new;
$jar->set_cookie(1, 'auth_tkt', $ticket, '/', '.localdomain');
# print $jar->as_string;

# Reset the TestRequest user_agent to use our cookie jar
Apache::TestRequest::user_agent(
  cookie_jar => $jar,
  requests_redirectable => 0,
  reset => 1,
);

# Retest with our cookie - should NOT redirect
$res = GET $url;
ok t_cmp($res->code, 200, 'not redirected with ticket take 1');
ok t_cmp($res->content, qr/^This is secret_timeout_guest_fallback, you are testuser/, 'user is testuser');

sub nap
{
  my ($t) = @_;
  print "(sleeping for $t seconds ...)\n";
  sleep $t;
}

# Sleep for 20 seconds and retry (timeout is 1 minute) - should be accepted
nap 20;
$res = GET $url;
ok t_cmp($res->code, 200, 'not redirected with ticket take 2');
ok t_cmp($res->content, qr/^This is secret_timeout_guest_fallback, you are testuser/, 'user is testuser');

# Sleep for another 20 seconds and retry (timeout is 1 minute) - should be accepted
nap 20;
$res = GET $url;
ok t_cmp($res->code, 200, 'not redirected with ticket take 3');
ok t_cmp($res->content, qr/^This is secret_timeout_guest_fallback, you are testuser/, 'user is testuser');

# Sleep for another 25 seconds and retry (timeout is 1 minute) - should
#   timeout, not be directed, and be reauthenticated as guest
nap 25;
$res = GET $url;
ok t_cmp($res->code, 200);
ok t_cmp($res->content, qr/^This is secret_timeout_guest_fallback, you are guest/, "timed out, user is now 'guest'");


# vim:sw=2:et:sm:smartindent:ft=perl