line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::PlugAuth; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
5
|
1
|
|
|
1
|
|
20
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
6
|
1
|
|
|
1
|
|
4
|
use PlugAuth::Lite; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
7
|
1
|
|
|
1
|
|
25
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
6
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: minimum PlugAuth server to test Clustericious apps against |
10
|
|
|
|
|
|
|
our $VERSION = '0.36_01'; # TRIAL VERSION |
11
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new |
15
|
|
|
|
|
|
|
{ |
16
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
17
|
0
|
0
|
|
|
|
|
my $config = ref $_[0] ? $_[0] : {@_}; |
18
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
$self->{app} = PlugAuth::Lite->new($config); |
21
|
0
|
|
|
|
|
|
$self->{ua} = Mojo::UserAgent->new; |
22
|
0
|
|
0
|
|
|
|
eval { $self->ua->server->app($self->app) } // $self->ua->app($self->app); |
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
0
|
|
0
|
|
|
|
$self->{url} = eval { $self->ua->server->url->to_string } // $self->ua->app_url->to_string; |
|
0
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
$self->{url} =~ s{/$}{}; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
1
|
|
sub ua { shift->{ua} } |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
1
|
|
sub app { shift->{app} } |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
0
|
1
|
|
sub url { shift->{url} } |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub apply_to_client_app |
41
|
|
|
|
|
|
|
{ |
42
|
0
|
|
|
0
|
1
|
|
my($self, $client_app) = @_; |
43
|
0
|
|
|
0
|
|
|
$client_app->helper(auth_ua => sub { $self->ua }); |
|
0
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
return; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=pod |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=encoding UTF-8 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Test::PlugAuth - minimum PlugAuth server to test Clustericious apps against |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 VERSION |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
version 0.36_01 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 SYNOPSIS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
assuming you have a Clustericious app MyApp with authentication/authorization |
66
|
|
|
|
|
|
|
directives that you need to test: |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
use Test::Clustericious::Config; |
69
|
|
|
|
|
|
|
use Test::Clustericious; |
70
|
|
|
|
|
|
|
use Test::PlugAuth; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $auth = Test::PlugAuth->new(auth => { |
73
|
|
|
|
|
|
|
my($user,$pass) = @_; |
74
|
|
|
|
|
|
|
return $user eq 'gooduser' && $pass eq 'goodpass'; |
75
|
|
|
|
|
|
|
}); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
create_config_ok 'MyApp', { plug_auth => { url => $auth->url } }; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$t = Test::Clustericious->new('MyApp'); |
80
|
|
|
|
|
|
|
$auth->apply_to_client_app($t->app); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $port = $t->ua->app_url->port; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$t->get_ok("http://baduser:badpass\@localhost:$port/private") |
85
|
|
|
|
|
|
|
->status_is(401); |
86
|
|
|
|
|
|
|
$t->get_ok("http://gooduser:goodpass\@localhost:$port/private") |
87
|
|
|
|
|
|
|
->status_is(200); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 DESCRIPTION |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Provides a way to test a Clustericious application with a fake PlugAuth server |
92
|
|
|
|
|
|
|
with reduced boilerplate |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 Test::PlugAuth->new( $config ) |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Creates a new instance of Test::PlugAuth. The $config is passed |
99
|
|
|
|
|
|
|
directly into L<PlugAuth::Lite>. See L<Mojolicious::Plugin::PlugAuthLite> |
100
|
|
|
|
|
|
|
for details. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 ua |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
The L<Mojo::UserAgent> used to connect to the PlugAuth (lite) server. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 app |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
The L<PlugAuth::Lite> instance of the PlugAuth server. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 url |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
The (fake) url used to connect to the PlugAuth server with. You MUST |
115
|
|
|
|
|
|
|
connect to through the L<Mojo::UserAgent> above. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 METHODS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 $test_auth->apply_to_client_app( $client_app ) |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Given a Clustericious application C<$client_app>, this method will |
122
|
|
|
|
|
|
|
rewire our L<Mojo::UserAgent> for authentication requests to PlugAuth. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 AUTHOR |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Graham Ollis <plicease@cpan.org> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Graham Ollis. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
133
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |