5 use lib ("$FindBin::Bin/lib");
7 use stemmaweb::Test::Common;
10 use LWP::Protocol::PSGI;
11 use Test::WWW::Mechanize;
14 use HTML::TreeBuilder;
17 use stemmaweb::Test::DB;
19 my $dir = stemmaweb::Test::DB->new_db;
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...
25 LWP::Protocol::PSGI->register(stemmaweb->psgi_app);
27 my $ua = Test::WWW::Mechanize->new;
30 my $scope = $dir->new_scope;
32 $ua->get_ok('http://localhost/login');
34 local *Catalyst::Authentication::Credential::OpenID::authenticate = sub {
35 my ( $self, $c, $realm, $authinfo ) = @_;
37 return $realm->find_user({ url => 'https://www.google.com/accounts/o8/id' }, $c);
40 ok !$dir->find_user({ url => 'https://www.google.com/accounts/o8/id' }), 'No such user, yet.';
45 openid_identifier => 'https://www.google.com/accounts/o8/id',
49 $ua->content_contains('You have logged in.', 'Openid login works');
53 $ua->content_contains('Hello! https://www.google.com/accounts/o8/id!', 'We are logged in.');
55 ok $dir->find_user({ url => 'https://www.google.com/accounts/o8/id' }), 'The user is now there.';
58 # Converting to Google ID.
60 local *stemmaweb::Authentication::Credential::Google::authenticate = sub {
61 my ( $self, $c, $realm, $authinfo ) = @_;
63 return $realm->find_user({
64 openid_id => 'https://www.google.com/accounts/o8/id',
68 $ua->get_ok('http://localhost/login');
73 id_token => 'something',
74 email => 'email@example.org',
78 $ua->content_contains('You have logged in.', 'G+ login works');
82 $ua->content_contains('Hello! 42!', 'We are logged in.');
86 my $scope = $dir->new_scope;
88 ok !$dir->find_user({ url => 'https://www.google.com/accounts/o8/id' }), 'Old google-openid is gone.';
90 ok $dir->find_user({ sub => 42, openid_id => 'https://www.google.com/accounts/o8/id' }), 'The G+ user is there.';
94 $ua->get_ok('http://localhost/login');
96 local *stemmaweb::Authentication::Credential::Google::authenticate = sub {
97 my ( $self, $c, $realm, $authinfo ) = @_;
99 return $realm->find_user({
100 openid_id => 'https://www.google.com/accounts/o8/id',
108 id_token => 'something',
109 email => 'email@example.org',
113 $ua->content_contains('You have logged in.', 'We can now log in to our created user');
117 $ua->content_contains('Hello! 42!', 'We are logged in.');
120 # Brand new user just from open id.
123 my $scope = $dir->new_scope;
126 ok !$dir->find_user({ sub => 2, openid_id => 'https://www.google.com/accounts/o8/id2' }), 'The G+ user is not yet there.';
130 $ua->get_ok('http://localhost/login');
132 local *stemmaweb::Authentication::Credential::Google::authenticate = sub {
133 my ( $self, $c, $realm, $authinfo ) = @_;
135 return $realm->find_user({
136 openid_id => 'https://www.google.com/accounts/o8/id2',
144 id_token => 'something',
145 email => 'email@example.org',
149 $ua->content_contains('You have logged in.', 'We can now log in to our created user');
153 $ua->content_contains('Hello! 2!', 'We are logged in.');
155 ok $dir->find_user({ sub => 2, openid_id => 'https://www.google.com/accounts/o8/id2' }), 'The G+ user is there.';
159 $ua->get_ok('http://localhost/login');
164 id_token => 'something',
165 email => 'email@example.org',
169 $ua->content_contains('You have logged in.', 'We can login again');
173 $ua->content_contains('Hello! 2!', 'We are logged in.');