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