From: Errietta Kostala Date: Fri, 23 Jan 2015 11:18:36 +0000 (+0000) Subject: OpenID test X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2Fstemmaweb.git;a=commitdiff_plain;h=fd1c80def1f65d70c7faf705bddf70981c89b796 OpenID test --- diff --git a/t/06openid.t b/t/06openid.t new file mode 100644 index 0000000..61fe985 --- /dev/null +++ b/t/06openid.t @@ -0,0 +1,97 @@ +use warnings; +use strict; + +use FindBin; +use lib ("$FindBin::Bin/lib"); + +use stemmaweb::Test::Common; + +use stemmaweb; +use LWP::Protocol::PSGI; +use Test::WWW::Mechanize; + +use Test::More; +use HTML::TreeBuilder; +use Data::Dumper; + +use stemmaweb::Test::DB; + +my $dir = stemmaweb::Test::DB->new_db; + +my $scope = $dir->new_scope; + +LWP::Protocol::PSGI->register(stemmaweb->psgi_app); + +my $ua = Test::WWW::Mechanize->new; + +$ua->get_ok('http://localhost/login'); + +# Trying a user that already exists + +local *Catalyst::Authentication::Credential::OpenID::authenticate = sub { + my ( $self, $c, $realm, $authinfo ) = @_; + + return $realm->find_user({ url => 'http://localhost/' }, $c); +}; + +$ua->submit_form( + form_number => 2, + fields => { + openid_identifier => 'http://localhost', + }, +); + +$ua->content_contains('You have logged in.', 'Openid login works'); + +$ua->get('/'); + +$ua->content_contains('Hello! http://localhost/!', 'We are logged in.'); + +$ua->get('/logout'); + +# Trying a user that doesn't already exist + +local *Catalyst::Authentication::Credential::OpenID::authenticate = sub { + my ( $self, $c, $realm, $authinfo ) = @_; + + return $realm->find_user({ url => 'http://example.org/' }, $c); +}; + + +ok !$dir->find_user({ url => 'http://example.org/' }), 'No such user, yet.'; + +$ua->get_ok('http://localhost/login'); + +$ua->submit_form( + form_number => 2, + fields => { + openid_identifier => 'http://example.org', + }, +); + +$ua->content_contains('You have logged in.', 'Openid login works'); + +$ua->get('/'); + +$ua->content_contains('Hello! http://example.org/!', 'We are logged in.'); + +ok $dir->find_user({ url => 'http://example.org/' }), 'User now exists.'; + +$ua->get('/logout'); + +$ua->get_ok('http://localhost/login'); + +$ua->submit_form( + form_number => 2, + fields => { + openid_identifier => 'http://example.org', + }, +); + +$ua->content_contains('You have logged in.', 'We can now log in to our created user'); + +$ua->get('/'); + +$ua->content_contains('Hello! http://example.org/!', 'We are logged in.'); + +done_testing;