Commit | Line | Data |
fbb4eba9 |
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 | |
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 | |
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 | # Creating an openID user. |
34 | |
35 | local *Catalyst::Authentication::Credential::OpenID::authenticate = sub { |
36 | my ( $self, $c, $realm, $authinfo ) = @_; |
37 | |
38 | return $realm->find_user({ url => 'https://www.google.com/accounts/o8/id' }, $c); |
39 | }; |
40 | |
41 | ok !$dir->find_user({ url => 'https://www.google.com/accounts/o8/id' }), 'No such user, yet.'; |
42 | |
43 | $ua->submit_form( |
44 | form_number => 2, |
45 | fields => { |
46 | openid_identifier => 'https://www.google.com/accounts/o8/id', |
47 | }, |
48 | ); |
49 | |
50 | $ua->content_contains('You have logged in.', 'Openid login works'); |
51 | |
52 | $ua->get('/'); |
53 | |
54 | $ua->content_contains('Hello! https://www.google.com/accounts/o8/id!', 'We are logged in.'); |
55 | |
56 | ok $dir->find_user({ url => 'https://www.google.com/accounts/o8/id' }), 'The user is now there.'; |
57 | $ua->get('/logout'); |
58 | |
59 | # Converting to Google ID. |
60 | |
61 | local *stemmaweb::Authentication::Credential::Google::authenticate = sub { |
62 | my ( $self, $c, $realm, $authinfo ) = @_; |
63 | |
64 | return $realm->find_user({ |
65 | openid_id => 'https://www.google.com/accounts/o8/id', |
66 | sub => 42, |
67 | }, $c); |
68 | }; |
69 | $ua->get_ok('http://localhost/login'); |
70 | |
71 | $ua->submit_form( |
72 | form_number => 1, |
73 | fields => { |
74 | id_token => 'something', |
75 | email => 'email@example.org', |
76 | }, |
77 | ); |
78 | |
79 | $ua->content_contains('You have logged in.', 'G+ login works'); |
80 | |
81 | $ua->get('/'); |
82 | |
83 | $ua->content_contains('Hello! 42!', 'We are logged in.'); |
84 | |
85 | |
86 | my $ouser =$dir->find_user({ url => 'https://www.google.com/accounts/o8/id' }); |
87 | |
88 | diag $ouser->id . "\n\n\n"; |
89 | |
90 | |
91 | ok $dir->find_user({ sub => 42, openid_id => 'https://www.google.com/accounts/o8/id' }), 'The G+ user is there.'; |
92 | |
93 | |
94 | $ua->get('/logout'); |
95 | |
96 | $ua->get_ok('http://localhost/login'); |
97 | |
98 | $ua->submit_form( |
99 | form_number => 1, |
100 | fields => { |
101 | id_token => 'something', |
102 | email => 'email@example.org', |
103 | }, |
104 | ); |
105 | |
106 | $ua->content_contains('You have logged in.', 'We can now log in to our created user'); |
107 | |
108 | $ua->get('/'); |
109 | |
110 | $ua->content_contains('Hello! 42!', 'We are logged in.'); |
111 | |
112 | done_testing; |