line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::PlugAuth::Plugin::Auth; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
375580
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
55
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
52
|
|
5
|
2
|
|
|
2
|
|
748
|
use Test::PlugAuth::Plugin; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
40
|
|
6
|
2
|
|
|
2
|
|
35
|
use 5.010001; |
|
2
|
|
|
|
|
6
|
|
7
|
2
|
|
|
2
|
|
9
|
use Test::Builder; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
40
|
|
8
|
2
|
|
|
2
|
|
898
|
use Role::Tiny (); |
|
2
|
|
|
|
|
6109
|
|
|
2
|
|
|
|
|
42
|
|
9
|
2
|
|
|
2
|
|
730
|
use PlugAuth; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
27
|
|
10
|
2
|
|
|
2
|
|
73
|
use base qw( Exporter ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1413
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw( run_tests ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# ABSTRACT: Test a PlugAuth Auth plugin for correctness |
15
|
|
|
|
|
|
|
our $VERSION = '0.38'; # VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub run_tests |
21
|
|
|
|
|
|
|
{ |
22
|
2
|
|
|
2
|
1
|
210
|
my($class, $global_config, $plugin_config) = @_; |
23
|
2
|
50
|
|
|
|
15
|
$class = "PlugAuth::Plugin::$class" unless $class =~ /::/; |
24
|
2
|
|
|
2
|
|
836
|
eval qq{ use $class }; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
49
|
|
|
2
|
|
|
|
|
125
|
|
25
|
2
|
50
|
|
|
|
14
|
die $@ if $@; |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
50
|
|
|
19
|
$global_config //= {}; |
28
|
|
|
|
|
|
|
$global_config = Clustericious::Config->new($global_config) |
29
|
2
|
50
|
|
|
|
5
|
unless eval { $global_config->isa('Clustericious::Config') }; |
|
2
|
|
|
|
|
41
|
|
30
|
2
|
|
50
|
|
|
1467
|
$plugin_config //= {}; |
31
|
|
|
|
|
|
|
$plugin_config = Clustericious::Config->new($plugin_config) |
32
|
2
|
50
|
|
|
|
5
|
unless eval { $plugin_config->isa('Clustericious::Config') }; |
|
2
|
|
|
|
|
21
|
|
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
680
|
$Test->plan( tests => 14); |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
1959
|
my $object = eval { $class->new($global_config, $plugin_config, PlugAuth->new()) }; |
|
2
|
|
|
|
|
41
|
|
37
|
2
|
|
|
|
|
11
|
my $error = $@; |
38
|
2
|
50
|
|
|
|
13
|
if(ref $object) |
39
|
|
|
|
|
|
|
{ |
40
|
2
|
|
|
|
|
22
|
$Test->ok(1, "New returns a reference"); |
41
|
2
|
|
|
|
|
1387
|
eval { |
42
|
2
|
|
|
|
|
83
|
foreach my $user ($object->all_users) |
43
|
|
|
|
|
|
|
{ |
44
|
0
|
|
|
|
|
0
|
$object->delete_user($user); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
|
|
0
|
$Test->ok(0, "New returns a reference"); |
51
|
0
|
|
|
|
|
0
|
$Test->diag("ERROR: $error"); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
91
|
$Test->ok( Role::Tiny::does_role($object, 'PlugAuth::Role::Plugin'), 'does Plugin'); |
55
|
2
|
|
|
|
|
1203
|
$Test->ok( Role::Tiny::does_role($object, 'PlugAuth::Role::Auth'), 'does Auth'); |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
1058
|
$Test->ok( eval { $object->check_credentials( 'foo', 'bar') } == 0, "check_credentials (foo:bar) == 0"); |
|
2
|
|
|
|
|
17
|
|
58
|
2
|
50
|
|
|
|
1129
|
$Test->diag($@) if $@; |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
8
|
$Test->ok( eval { $object->create_user( 'foo', 'bar' ) } == 1, "create_user returns 1"); |
|
2
|
|
|
|
|
16
|
|
61
|
2
|
50
|
|
|
|
1115
|
$Test->diag($@) if $@; |
62
|
|
|
|
|
|
|
|
63
|
2
|
|
|
|
|
16
|
my $refresh = Role::Tiny::does_role($object, 'PlugAuth::Role::Refresh'); |
64
|
2
|
50
|
|
|
|
69
|
if($refresh) |
65
|
|
|
|
|
|
|
{ |
66
|
2
|
|
|
|
|
7
|
eval { $object->refresh }; |
|
2
|
|
|
|
|
15
|
|
67
|
2
|
50
|
|
|
|
10
|
$Test->diag("refresh died: $@") if $@; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
7
|
$Test->ok( eval { $object->check_credentials( 'foo', 'bar') } == 1, "check_credentials (foo:bar) == 1"); |
|
2
|
|
|
|
|
13
|
|
71
|
2
|
50
|
|
|
|
54770
|
$Test->diag($@) if $@; |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
11
|
$Test->ok( eval { $object->change_password( 'foo', 'baz') } == 1, "change_password returns 1"); |
|
2
|
|
|
|
|
21
|
|
74
|
2
|
50
|
|
|
|
1026
|
$Test->diag($@) if $@; |
75
|
|
|
|
|
|
|
|
76
|
2
|
50
|
|
|
|
9
|
if($refresh) |
77
|
|
|
|
|
|
|
{ |
78
|
2
|
|
|
|
|
9
|
eval { $object->refresh }; |
|
2
|
|
|
|
|
14
|
|
79
|
2
|
50
|
|
|
|
10
|
$Test->diag("refresh died: $@") if $@; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
|
|
7
|
$Test->ok( eval { $object->check_credentials( 'foo', 'bar') } == 0, "check_credentials (foo:bar) == 0"); |
|
2
|
|
|
|
|
14
|
|
83
|
2
|
50
|
|
|
|
1661
|
$Test->diag($@) if $@; |
84
|
|
|
|
|
|
|
|
85
|
2
|
|
|
|
|
8
|
$Test->ok( eval { $object->check_credentials( 'foo', 'baz') } == 1, "check_credentials (foo:baz) == 1"); |
|
2
|
|
|
|
|
16
|
|
86
|
2
|
50
|
|
|
|
47002
|
$Test->diag($@) if $@; |
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
9
|
do { |
89
|
2
|
|
|
|
|
112
|
my @users = $object->all_users; |
90
|
2
|
50
|
|
|
|
15
|
if(@users > 0) |
91
|
|
|
|
|
|
|
{ |
92
|
2
|
|
33
|
|
|
25
|
my $pass = $#users == 0 && $users[0] eq 'foo'; |
93
|
2
|
|
|
|
|
14
|
$Test->ok($pass, "all_users == [ foo ]"); |
94
|
2
|
50
|
|
|
|
1239
|
$Test->diag("all_users actually == [ " . join(', ', @users) . " ]") unless $pass; |
95
|
|
|
|
|
|
|
|
96
|
2
|
|
|
|
|
7
|
eval { $object->create_user( 'fop', 'bar' ) }; |
|
2
|
|
|
|
|
17
|
|
97
|
2
|
50
|
|
|
|
20
|
$Test->diag($@) if $@; |
98
|
|
|
|
|
|
|
|
99
|
2
|
50
|
|
|
|
12
|
if($refresh) |
100
|
|
|
|
|
|
|
{ |
101
|
2
|
|
|
|
|
7
|
eval { $object->refresh }; |
|
2
|
|
|
|
|
20
|
|
102
|
2
|
50
|
|
|
|
13
|
$Test->diag("refresh died: $@") if $@; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
2
|
|
|
|
|
68
|
@users = $object->all_users; |
106
|
|
|
|
|
|
|
|
107
|
2
|
|
33
|
|
|
41
|
$pass = $#users == 1 && (($users[0] eq 'foo' && $users[1] eq 'fop') || ($users[0] eq 'fop' && $users[1] eq 'foo')); |
108
|
2
|
|
|
|
|
23
|
$Test->ok($pass, "all_users == [ foo, fop ]"); |
109
|
2
|
50
|
|
|
|
1913
|
$Test->diag("all_users actually == [ " . join(', ', @users) . " ]") unless $pass; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else |
112
|
|
|
|
|
|
|
{ |
113
|
0
|
|
|
|
|
0
|
$Test->skip("all_users returns ()"); |
114
|
0
|
|
|
|
|
0
|
$Test->skip("all_users returns ()"); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
}; |
117
|
|
|
|
|
|
|
|
118
|
2
|
|
|
|
|
11
|
$Test->ok( eval { $object->delete_user( 'foo') } == 1, "delete_user returns 1"); |
|
2
|
|
|
|
|
16
|
|
119
|
2
|
50
|
|
|
|
1034
|
$Test->diag($@) if $@; |
120
|
|
|
|
|
|
|
|
121
|
2
|
50
|
|
|
|
12
|
if($refresh) |
122
|
|
|
|
|
|
|
{ |
123
|
2
|
|
|
|
|
7
|
eval { $object->refresh }; |
|
2
|
|
|
|
|
15
|
|
124
|
2
|
50
|
|
|
|
11
|
$Test->diag("refresh died: $@") if $@; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
2
|
|
|
|
|
8
|
$Test->ok( eval { $object->check_credentials( 'foo', 'bar') } == 0, "check_credentials (foo:bar) == 0"); |
|
2
|
|
|
|
|
12
|
|
128
|
2
|
50
|
|
|
|
1107
|
$Test->diag($@) if $@; |
129
|
|
|
|
|
|
|
|
130
|
2
|
|
|
|
|
9
|
$Test->ok( eval { $object->check_credentials( 'foo', 'baz') } == 0, "check_credentials (foo:baz) == 0"); |
|
2
|
|
|
|
|
14
|
|
131
|
2
|
50
|
|
|
|
951
|
$Test->diag($@) if $@; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=pod |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=encoding UTF-8 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 NAME |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Test::PlugAuth::Plugin::Auth - Test a PlugAuth Auth plugin for correctness |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 VERSION |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
version 0.38 |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 SYNOPSIS |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
use Test::PlugAuth::Plugin::Auth; |
153
|
|
|
|
|
|
|
run_tests 'MyPlugin'; # runs tests against PlugAuth::Plugin::MyPlugin |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 FUNCTIONS |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 run_tests $plugin_name, [ $global_config, [ $plugin_config ] ] |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Run the specification tests against the given plugin. The configuration |
160
|
|
|
|
|
|
|
arguments are optional. The first is the hash which is usually found in |
161
|
|
|
|
|
|
|
~/etc/PlugAuth.conf and the second is the plugin config. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 SEE ALSO |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
L<PlugAuth>, |
166
|
|
|
|
|
|
|
L<PlugAuth::Guide::Plugin> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 AUTHOR |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Graham Ollis <gollis@sesda3.com> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
This software is copyright (c) 2012 by NASA GSFC. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
177
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |