| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package OAuth::Lite2::Agent::PSGIMock; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
21
|
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use Params::Validate qw(CODEREF); |
|
|
1
|
|
|
|
|
0
|
|
|
|
1
|
|
|
|
|
52
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use HTTP::Response; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
20
|
|
|
8
|
1
|
|
|
1
|
|
432
|
use HTTP::Message::PSGI; |
|
|
1
|
|
|
|
|
9221
|
|
|
|
1
|
|
|
|
|
50
|
|
|
9
|
1
|
|
|
1
|
|
8
|
use Try::Tiny; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
181
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
OAuth::Lite2::Agent::PSGIMock - Agent class for test which use PSGI App |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head2 SYNOPSIS |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Test::More; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $endpoint = OAuth::Lite2::Server::Endpoint::Token->new( |
|
20
|
|
|
|
|
|
|
data_handler => 'YourApp::DataHandler', |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $agent = OAuth::Lite2::Agent::PSGIMock->new( app => $endpoint ); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $client = OAuth::Lite2::Client::UsernameAndPassword->new( |
|
26
|
|
|
|
|
|
|
client_id => q{foo}, |
|
27
|
|
|
|
|
|
|
client_secret => q{bar}, |
|
28
|
|
|
|
|
|
|
agent => $agent, |
|
29
|
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $res = $client->get_access_token( |
|
32
|
|
|
|
|
|
|
username => q{buz}, |
|
33
|
|
|
|
|
|
|
password => q{huga}, |
|
34
|
|
|
|
|
|
|
scope => q{email}, |
|
35
|
|
|
|
|
|
|
); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
is($res->access_token, ...); |
|
38
|
|
|
|
|
|
|
is($res->refresh_token, ...); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
This class is useful for test to check if your PSGI based |
|
44
|
|
|
|
|
|
|
server application acts as expected. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 METHODS |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 new (%args) |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
parameters |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=over 4 |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item app (PSGI application) |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=back |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub new { |
|
61
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my %args = Params::Validate::validate(@_, { |
|
64
|
|
|
|
|
|
|
app => 1, |
|
65
|
|
|
|
|
|
|
}); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $self = bless { |
|
68
|
|
|
|
|
|
|
app => $args{app}, |
|
69
|
0
|
|
|
|
|
|
}, $class; |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return $self; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 request ($req) |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
handle request with PSIG application you set at constructor |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub request { |
|
81
|
0
|
|
|
0
|
1
|
|
my ($self, $req) = @_; |
|
82
|
|
|
|
|
|
|
my $res = try { |
|
83
|
0
|
|
|
0
|
|
|
HTTP::Response->from_psgi($self->{app}->($req->to_psgi)); |
|
84
|
|
|
|
|
|
|
} catch { |
|
85
|
0
|
|
|
0
|
|
|
HTTP::Response->from_psgi([500, [ "Content-Type" => "text/plain" ], [ $_ ] ]); |
|
86
|
0
|
|
|
|
|
|
}; |
|
87
|
0
|
|
|
|
|
|
return $res; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
L, |
|
95
|
|
|
|
|
|
|
L |
|
96
|
|
|
|
|
|
|
L |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 AUTHOR |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Lyo Kato, C |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
105
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
|
106
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |