File: 03-path_info_link.t

package info (click to toggle)
libcgi-application-plugin-linkintegrity-perl 0.06-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 308 kB
  • sloc: perl: 269; sh: 7; makefile: 2
file content (110 lines) | stat: -rw-r--r-- 3,779 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

use Test::More 'no_plan';
use strict;
$ENV{CGI_APP_RETURN_ONLY} = 1;

{
    package WebApp;
    use CGI::Application;
    use vars qw(@ISA);
    use URI;
    @ISA = ('CGI::Application');

    use Test::More;
    use CGI::Application::Plugin::LinkIntegrity;

    sub setup {
        my $self = shift;
        $self->run_modes([qw/start/]);
        $self->link_integrity_config(
            'secret'           => 'foo',
            'disable'          => 1,
        );
    }

    sub start {
        my $self = shift;

        my $self_url             = URI->new($self->query->url);
        my $self_url_w_path_info = URI->new($self->query->url(-path_info => 1));


        $self->link_integrity_config(
            secret        => 'foo',
        );

        # Bare path_link - should remove the path_info
        my $link = $self->path_link;

        my $uri = URI->new($link);
        my %params = $uri->query_form;

        is($uri->path, $self_url->path,  '[plain checksum] URI path');
        ok(keys %params == 1,            '[plain checksum] URI params');
        ok(length $params{'_checksum'},  '[plain checksum] URI checksum');

        # Test explicitly passing url params (w/o path_info (empty_string))
        $link = $self->path_link('', wubba => 'woo', 'foo' => 'bar', bar=> 'baz');

        $uri = URI->new($link);
        %params = $uri->query_form;

        is($uri->path, $self_url->path,      '[params path_info=""] URI path');
        ok(keys %params == 4,                '[params path_info=""] URI params');
        ok(length $params{'_checksum'},      '[params path_info=""] URI checksum');
        is($params{'foo'}, 'bar',            '[params path_info=""] URI param:foo');
        is($params{'bar'}, 'baz',            '[params path_info=""] URI param:bar');
        is($params{'wubba'}, 'woo',          '[params path_info=""] URI param:wubba');

        # Test explicitly passing url params (w/o path_info (undef)
        $link = $self->path_link(undef, wubba => 'woo', 'foo' => 'bar', bar=> 'baz');

        $uri = URI->new($link);
        %params = $uri->query_form;

        is($uri->path, $self_url->path,      '[params path_info=undef] URI path');
        ok(keys %params == 4,                '[params path_info=undef] URI params');
        ok(length $params{'_checksum'},      '[params path_info=undef] URI checksum');
        is($params{'foo'}, 'bar',            '[params path_info=undef] URI param:foo');
        is($params{'bar'}, 'baz',            '[params path_info=undef] URI param:bar');
        is($params{'wubba'}, 'woo',          '[params path_info=undef] URI param:wubba');


        # Test with new path_info
        $link = $self->path_link('/sic/transit/gloria/mundi',
            wubba => 'woo','foo' => 'bar', bar=> 'baz'
        );

        $uri = URI->new($link);
        %params = $uri->query_form;

        my $u = $self_url->clone;
        $u->path_segments($u->path_segments, qw(sic transit gloria mundi));

        is($uri->path, $u->path,             '[new path_info] URI path');
        ok(keys %params == 4,                '[new path_info] URI params');
        ok(length $params{'_checksum'},      '[new path_info] URI checksum');
        is($params{'foo'}, 'bar',            '[new path_info] URI param:foo');
        is($params{'bar'}, 'baz',            '[new path_info] URI param:bar');
        is($params{'wubba'}, 'woo',          '[new path_info] URI param:wubba');

    }
}

local *STDIN;
open(STDIN, '<', '/dev/null');

$ENV{'REQUEST_METHOD'} = 'POST';
$ENV{'SERVER_PORT'}    = '80';
$ENV{'SCRIPT_NAME'}    = '/cgi-bin/app.cgi';
$ENV{'SERVER_NAME'}    = 'www.example.com';
$ENV{'PATH_INFO'}      = '/my/happy/pathy/info';
$ENV{'QUERY_STRING'}   = 'zap=zoom&zap=zub&guff=gubbins&zap=zuzzu';


WebApp->new->run;