OpenID test
[scpubgit/stemmaweb.git] / t / 06openid.t
CommitLineData
fd1c80de 1use warnings;
2use strict;
3
4use FindBin;
5use lib ("$FindBin::Bin/lib");
6
7use stemmaweb::Test::Common;
8
9use stemmaweb;
10use LWP::Protocol::PSGI;
11use Test::WWW::Mechanize;
12
13use Test::More;
14use HTML::TreeBuilder;
15use Data::Dumper;
16
17use stemmaweb::Test::DB;
18
19my $dir = stemmaweb::Test::DB->new_db;
20
21my $scope = $dir->new_scope;
22
23LWP::Protocol::PSGI->register(stemmaweb->psgi_app);
24
25my $ua = Test::WWW::Mechanize->new;
26
27$ua->get_ok('http://localhost/login');
28
29# Trying a user that already exists
30
31local *Catalyst::Authentication::Credential::OpenID::authenticate = sub {
32 my ( $self, $c, $realm, $authinfo ) = @_;
33
34 return $realm->find_user({ url => 'http://localhost/' }, $c);
35};
36
37$ua->submit_form(
38 form_number => 2,
39 fields => {
40 openid_identifier => 'http://localhost',
41 },
42);
43
44$ua->content_contains('You have logged in.', 'Openid login works');
45
46$ua->get('/');
47
48$ua->content_contains('Hello! http://localhost/!', 'We are logged in.');
49
50$ua->get('/logout');
51
52# Trying a user that doesn't already exist
53
54local *Catalyst::Authentication::Credential::OpenID::authenticate = sub {
55 my ( $self, $c, $realm, $authinfo ) = @_;
56
57 return $realm->find_user({ url => 'http://example.org/' }, $c);
58};
59
60
61ok !$dir->find_user({ url => 'http://example.org/' }), 'No such user, yet.';
62
63$ua->get_ok('http://localhost/login');
64
65$ua->submit_form(
66 form_number => 2,
67 fields => {
68 openid_identifier => 'http://example.org',
69 },
70);
71
72$ua->content_contains('You have logged in.', 'Openid login works');
73
74$ua->get('/');
75
76$ua->content_contains('Hello! http://example.org/!', 'We are logged in.');
77
78ok $dir->find_user({ url => 'http://example.org/' }), 'User now exists.';
79
80$ua->get('/logout');
81
82$ua->get_ok('http://localhost/login');
83
84$ua->submit_form(
85 form_number => 2,
86 fields => {
87 openid_identifier => 'http://example.org',
88 },
89);
90
91$ua->content_contains('You have logged in.', 'We can now log in to our created user');
92
93$ua->get('/');
94
95$ua->content_contains('Hello! http://example.org/!', 'We are logged in.');
96
97done_testing;