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;
18 use stemmaweb::Test::DB;
20 my $dir = stemmaweb::Test::DB->new_db;
22 # NOTE: this test uses Text::Tradition::Directory
23 # to check user accounts really have been created.
24 # It'll need to be changed once that is replaced...
26 LWP::Protocol::PSGI->register(stemmaweb->psgi_app);
28 my $ua = Test::WWW::Mechanize->new;
30 io("$FindBin::Bin/var")->rmtree if io("$FindBin::Bin/var")->exists;
33 my $scope = $dir->new_scope;
35 $ua->get_ok('http://localhost/login');
37 local *Catalyst::Authentication::Credential::OpenID::authenticate = sub {
38 my ( $self, $c, $realm, $authinfo ) = @_;
40 return $realm->find_user({ url => 'https://www.google.com/accounts/o8/id' }, $c);
43 ok !$dir->find_user({ url => 'https://www.google.com/accounts/o8/id' }), 'No such user, yet.';
48 openid_identifier => 'https://www.google.com/accounts/o8/id',
52 $ua->content_contains('You have logged in.', 'Openid login works');
56 $ua->content_contains('Hello! https://www.google.com/accounts/o8/id!', 'We are logged in.');
58 ok $dir->find_user({ url => 'https://www.google.com/accounts/o8/id' }), 'The user is now there.';
61 # Converting to Google ID.
63 local *stemmaweb::Authentication::Credential::Google::authenticate = sub {
64 my ( $self, $c, $realm, $authinfo ) = @_;
66 return $realm->find_user({
67 openid_id => 'https://www.google.com/accounts/o8/id',
71 $ua->get_ok('http://localhost/login');
76 id_token => 'something',
77 email => 'email@example.org',
81 $ua->content_contains('You have logged in.', 'G+ login works');
85 $ua->content_contains('Hello! 42!', 'We are logged in.');
89 my $scope = $dir->new_scope;
91 # ok !$dir->find_user({ url => 'https://www.google.com/accounts/o8/id' }), 'Old google-openid is gone.';
93 ok $dir->find_user({ sub => 42, openid_id => 'https://www.google.com/accounts/o8/id' }), 'The G+ user is there.';
97 $ua->get_ok('http://localhost/login');
99 local *stemmaweb::Authentication::Credential::Google::authenticate = sub {
100 my ( $self, $c, $realm, $authinfo ) = @_;
102 return $realm->find_user({
103 openid_id => 'https://www.google.com/accounts/o8/id',
111 id_token => 'something',
112 email => 'email@example.org',
116 $ua->content_contains('You have logged in.', 'We can now log in to our created user');
120 $ua->content_contains('Hello! 42!', 'We are logged in.');
123 # Brand new user just from open id.
126 my $scope = $dir->new_scope;
129 ok !$dir->find_user({ sub => 2, openid_id => 'https://www.google.com/accounts/o8/id2' }), 'The G+ user is not yet there.';
133 $ua->get_ok('http://localhost/login');
135 local *stemmaweb::Authentication::Credential::Google::authenticate = sub {
136 my ( $self, $c, $realm, $authinfo ) = @_;
138 return $realm->find_user({
139 openid_id => 'https://www.google.com/accounts/o8/id2',
147 id_token => 'something',
148 email => 'email@example.org',
152 $ua->content_contains('You have logged in.', 'We can now log in to our created user');
156 $ua->content_contains('Hello! 2!', 'We are logged in.');
158 ok $dir->find_user({ sub => 2, openid_id => 'https://www.google.com/accounts/o8/id2' }), 'The G+ user is there.';
162 $ua->get_ok('http://localhost/login');
167 id_token => 'something',
168 email => 'email@example.org',
172 $ua->content_contains('You have logged in.', 'We can login again');
176 $ua->content_contains('Hello! 2!', 'We are logged in.');
182 my $scope = $dir->new_scope;
184 ok !$dir->find_user({ sub => 4242, openid_id => 'https://www.google.com/accounts/o8/id3' }), 'The G+ user is not yet there.';
188 $ua->get_ok('http://localhost/login');
193 id_token => 'eyJraWQiOiJhIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiI0MjQyIiwib3BlbmlkX2lkIjoiaHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS9hY2NvdW50cy9vOC9pZDMifQ.moNERe3UHCY4xGMPxdCqmbg2JKW5feVnYlA8jeB4CdE4c_KL3YHvICQeql-S486HT-AlWBeDJWMr6wWH1kkwz11a2D1oyJ8qCWBssHIkhfv8dm3dphmRbtzYssAOFdGsmnPH1oXolCnl-Qu9WgHkhYYnRJWHr3CkeNA6Yh1xOV3nkaa8REtJckuzh3jyKQgx_rjIFsWBPDmT1rqa_Q0XOGVK34N5tADwpcWmkb3fFnbddzd9L6MnybbFzF_S238Bpr5vNa9doXRBwvJ85AdSn1AWX8R6qVpDbbaiGL2RCahuZYF9XECYm6anee-KTKvxh02KXkG2zniKVvweaMlcbQ',
194 email => 'email@example.org',
198 $ua->content_contains('You have logged in.', 'We can now log in to our created user - the token was decoded');
202 $ua->content_contains('Hello! email@example.org!', 'We are logged in.');
204 ok $dir->find_user({ sub => 4242, openid_id => 'https://www.google.com/accounts/o8/id3' }), 'The G+ user is there.';
208 $ua->get_ok('http://localhost/login');
213 id_token => 'eyJraWQiOiJhIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiI0MjQyIiwib3BlbmlkX2lkIjoiaHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS9hY2NvdW50cy9vOC9pZDMifQ.moNERe3UHCY4xGMPxdCqmbg2JKW5feVnYlA8jeB4CdE4c_KL3YHvICQeql-S486HT-AlWBeDJWMr6wWH1kkwz11a2D1oyJ8qCWBssHIkhfv8dm3dphmRbtzYssAOFdGsmnPH1oXolCnl-Qu9WgHkhYYnRJWHr3CkeNA6Yh1xOV3nkaa8REtJckuzh3jyKQgx_rjIFsWBPDmT1rqa_Q0XOGVK34N5tADwpcWmkb3fFnbddzd9L6MnybbFzF_S238Bpr5vNa9doXRBwvJ85AdSn1AWX8R6qVpDbbaiGL2RCahuZYF9XECYm6anee-KTKvxh02KXkG2zniKVvweaMlcbQ',
214 email => 'email@example.org',
218 $ua->content_contains('You have logged in.', 'We can login again');
222 $ua->content_contains('Hello! email@example.org!', 'We ar logged in.');
225 io("$FindBin::Bin/var")->rmtree if io("$FindBin::Bin/var")->exists;