OpenID test
Errietta Kostala [Fri, 23 Jan 2015 11:18:36 +0000 (11:18 +0000)]
t/06openid.t [new file with mode: 0644]

diff --git a/t/06openid.t b/t/06openid.t
new file mode 100644 (file)
index 0000000..61fe985
--- /dev/null
@@ -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;