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 my $scope = $dir->new_scope;
27 LWP::Protocol::PSGI->register(stemmaweb->psgi_app);
29 my $ua = Test::WWW::Mechanize->new;
31 $ua->get_ok('http://localhost/login');
33 # Creating an openID user.
35 local *Catalyst::Authentication::Credential::OpenID::authenticate = sub {
36 my ( $self, $c, $realm, $authinfo ) = @_;
38 return $realm->find_user({ url => 'https://www.google.com/accounts/o8/id' }, $c);
41 ok !$dir->find_user({ url => 'https://www.google.com/accounts/o8/id' }), 'No such user, yet.';
46 openid_identifier => 'https://www.google.com/accounts/o8/id',
50 $ua->content_contains('You have logged in.', 'Openid login works');
54 $ua->content_contains('Hello! https://www.google.com/accounts/o8/id!', 'We are logged in.');
56 ok $dir->find_user({ url => 'https://www.google.com/accounts/o8/id' }), 'The user is now there.';
59 # Converting to Google ID.
61 local *stemmaweb::Authentication::Credential::Google::authenticate = sub {
62 my ( $self, $c, $realm, $authinfo ) = @_;
64 return $realm->find_user({
65 openid_id => 'https://www.google.com/accounts/o8/id',
69 $ua->get_ok('http://localhost/login');
74 id_token => 'something',
75 email => 'email@example.org',
79 $ua->content_contains('You have logged in.', 'G+ login works');
83 $ua->content_contains('Hello! 42!', 'We are logged in.');
86 my $ouser =$dir->find_user({ url => 'https://www.google.com/accounts/o8/id' });
88 diag $ouser->id . "\n\n\n";
91 ok $dir->find_user({ sub => 42, openid_id => 'https://www.google.com/accounts/o8/id' }), 'The G+ user is there.';
96 $ua->get_ok('http://localhost/login');
101 id_token => 'something',
102 email => 'email@example.org',
106 $ua->content_contains('You have logged in.', 'We can now log in to our created user');
110 $ua->content_contains('Hello! 42!', 'We are logged in.');