File: 06_expires.t

package info (click to toggle)
libdancer-perl 1.3521%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,460 kB
  • sloc: perl: 7,436; xml: 2,211; sh: 54; makefile: 32; sql: 5
file content (59 lines) | stat: -rw-r--r-- 1,828 bytes parent folder | download | duplicates (6)
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
use strict;
use warnings;
use Test::More;

BEGIN {
    # Freeze time at Tue, 15-Jun-2010 00:00:00 GMT
    *CORE::GLOBAL::time = sub { return 1276560000 }
}

use Dancer::Cookie;

my $min  = 60;
my $hour = 60 * $min;
my $day  = 24 * $hour;
my $week = 7 * $day;
my $mon  = 30 * $day;
my $year = 365 * $day;

note "expiration times"; {
    my %times = (
        "+2h"                       => "Tue, 15-Jun-2010 02:00:00 GMT",
        "-2h"                       => "Mon, 14-Jun-2010 22:00:00 GMT",
        "1 hour"                    => "Tue, 15-Jun-2010 01:00:00 GMT",
        "3 weeks 4 days 2 hours 99 min 0 secs" => "Sat, 10-Jul-2010 03:39:00 GMT",
        "2 months"                  => "Sat, 14-Aug-2010 00:00:00 GMT",
        "12 years"                  => "Sun, 12-Jun-2022 00:00:00 GMT",

        1288817656 => "Wed, 03-Nov-2010 20:54:16 GMT",
        1288731256 => "Tue, 02-Nov-2010 20:54:16 GMT",
        1288644856 => "Mon, 01-Nov-2010 20:54:16 GMT",
        1288558456 => "Sun, 31-Oct-2010 20:54:16 GMT",
        1288472056 => "Sat, 30-Oct-2010 20:54:16 GMT",
        1288385656 => "Fri, 29-Oct-2010 20:54:16 GMT",
        1288299256 => "Thu, 28-Oct-2010 20:54:16 GMT",
        1288212856 => "Wed, 27-Oct-2010 20:54:16 GMT",

        # Anything not understood is passed through
        "basset hounds got long ears" => "basset hounds got long ears",
    );

    for my $exp (keys %times) {
        my $want = $times{$exp};
        note $want;

        my $cookie = Dancer::Cookie->new(
            name        => "shut.up.and.dance",
            value       => "FMV",
            expires     => $exp
        );

        is($cookie->to_header, 
           "shut.up.and.dance=FMV; path=/; expires=$want; HttpOnly",
           "header with expires");

        is $cookie->expires, $want, "expires";
    }
}

done_testing;