Commit | Line | Data |
fd1c80de |
1 | use warnings; |
2 | use strict; |
3 | |
4 | use FindBin; |
5 | use lib ("$FindBin::Bin/lib"); |
6 | |
7 | use stemmaweb::Test::Common; |
8 | |
9 | use stemmaweb; |
10 | use LWP::Protocol::PSGI; |
11 | use Test::WWW::Mechanize; |
12 | |
13 | use Test::More; |
14 | use HTML::TreeBuilder; |
15 | use Data::Dumper; |
16 | |
17 | use stemmaweb::Test::DB; |
18 | |
19 | my $dir = stemmaweb::Test::DB->new_db; |
20 | |
f9a80a48 |
21 | # NOTE: this test uses Text::Tradition::Directory |
22 | # to check user accounts really have been created. |
23 | # It'll need to be changed once that is replaced... |
24 | |
fd1c80de |
25 | my $scope = $dir->new_scope; |
26 | |
27 | LWP::Protocol::PSGI->register(stemmaweb->psgi_app); |
28 | |
29 | my $ua = Test::WWW::Mechanize->new; |
30 | |
31 | $ua->get_ok('http://localhost/login'); |
32 | |
33 | # Trying a user that already exists |
34 | |
35 | local *Catalyst::Authentication::Credential::OpenID::authenticate = sub { |
36 | my ( $self, $c, $realm, $authinfo ) = @_; |
37 | |
38 | return $realm->find_user({ url => 'http://localhost/' }, $c); |
39 | }; |
40 | |
41 | $ua->submit_form( |
42 | form_number => 2, |
43 | fields => { |
44 | openid_identifier => 'http://localhost', |
45 | }, |
46 | ); |
47 | |
48 | $ua->content_contains('You have logged in.', 'Openid login works'); |
49 | |
50 | $ua->get('/'); |
51 | |
52 | $ua->content_contains('Hello! http://localhost/!', 'We are logged in.'); |
53 | |
54 | $ua->get('/logout'); |
55 | |
56 | # Trying a user that doesn't already exist |
57 | |
58 | local *Catalyst::Authentication::Credential::OpenID::authenticate = sub { |
59 | my ( $self, $c, $realm, $authinfo ) = @_; |
60 | |
61 | return $realm->find_user({ url => 'http://example.org/' }, $c); |
62 | }; |
63 | |
64 | |
65 | ok !$dir->find_user({ url => 'http://example.org/' }), 'No such user, yet.'; |
66 | |
67 | $ua->get_ok('http://localhost/login'); |
68 | |
69 | $ua->submit_form( |
70 | form_number => 2, |
71 | fields => { |
72 | openid_identifier => 'http://example.org', |
73 | }, |
74 | ); |
75 | |
76 | $ua->content_contains('You have logged in.', 'Openid login works'); |
77 | |
78 | $ua->get('/'); |
79 | |
80 | $ua->content_contains('Hello! http://example.org/!', 'We are logged in.'); |
81 | |
82 | ok $dir->find_user({ url => 'http://example.org/' }), 'User now exists.'; |
83 | |
84 | $ua->get('/logout'); |
85 | |
86 | $ua->get_ok('http://localhost/login'); |
87 | |
88 | $ua->submit_form( |
89 | form_number => 2, |
90 | fields => { |
91 | openid_identifier => 'http://example.org', |
92 | }, |
93 | ); |
94 | |
95 | $ua->content_contains('You have logged in.', 'We can now log in to our created user'); |
96 | |
97 | $ua->get('/'); |
98 | |
99 | $ua->content_contains('Hello! http://example.org/!', 'We are logged in.'); |
100 | |
101 | done_testing; |