Add note about using TTD
[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
f9a80a48 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...
24
fd1c80de 25my $scope = $dir->new_scope;
26
27LWP::Protocol::PSGI->register(stemmaweb->psgi_app);
28
29my $ua = Test::WWW::Mechanize->new;
30
31$ua->get_ok('http://localhost/login');
32
33# Trying a user that already exists
34
35local *Catalyst::Authentication::Credential::OpenID::authenticate = sub {
36 my ( $self, $c, $realm, $authinfo ) = @_;
37
38 return $realm->find_user({ url => 'http://localhost/' }, $c);
39};
40
41$ua->submit_form(
42 form_number => 2,
43 fields => {
44 openid_identifier => 'http://localhost',
45 },
46);
47
48$ua->content_contains('You have logged in.', 'Openid login works');
49
50$ua->get('/');
51
52$ua->content_contains('Hello! http://localhost/!', 'We are logged in.');
53
54$ua->get('/logout');
55
56# Trying a user that doesn't already exist
57
58local *Catalyst::Authentication::Credential::OpenID::authenticate = sub {
59 my ( $self, $c, $realm, $authinfo ) = @_;
60
61 return $realm->find_user({ url => 'http://example.org/' }, $c);
62};
63
64
65ok !$dir->find_user({ url => 'http://example.org/' }), 'No such user, yet.';
66
67$ua->get_ok('http://localhost/login');
68
69$ua->submit_form(
70 form_number => 2,
71 fields => {
72 openid_identifier => 'http://example.org',
73 },
74);
75
76$ua->content_contains('You have logged in.', 'Openid login works');
77
78$ua->get('/');
79
80$ua->content_contains('Hello! http://example.org/!', 'We are logged in.');
81
82ok $dir->find_user({ url => 'http://example.org/' }), 'User now exists.';
83
84$ua->get('/logout');
85
86$ua->get_ok('http://localhost/login');
87
88$ua->submit_form(
89 form_number => 2,
90 fields => {
91 openid_identifier => 'http://example.org',
92 },
93);
94
95$ua->content_contains('You have logged in.', 'We can now log in to our created user');
96
97$ua->get('/');
98
99$ua->content_contains('Hello! http://example.org/!', 'We are logged in.');
100
101done_testing;