7 use Test::WWW::Mechanize;
9 # plan skip_all => 'set TEST_HTTP to enable this test' unless $ENV{TEST_HTTP};
10 eval "use Catalyst::Devel";
11 plan skip_all => 'Catalyst::Devel required' if $@;
15 # How long to wait for test server to start and timeout for UA.
18 # Spawn the standalone HTTP server.
19 my $port = 3000 + int rand(1 + 1000);
21 my $pipe = "perl -I$FindBin::Bin/../lib -I$FindBin::Bin/TestApp/lib $FindBin::Bin/TestApp/script/testapp_server.pl -f -p $port |";
23 # my $pipe = "perl -I$FindBin::Bin/../lib -I$FindBin::Bin/TestApp/lib $FindBin::Bin/TestApp/script/testapp_server.pl -f -port $port 2>&1 |";
25 my $pid = open my $server, $pipe
26 or die "Unable to spawn standalone HTTP server: $!";
28 diag("Waiting (up to $seconds seconds) for server to start...");
31 local $SIG{ALRM} = sub { die "Server took too long to start\n" }; # NB: \n required
34 while ( check_port( 'localhost', $port ) != 1 ) {
44 die "Could not run test: $@\n$pipe";
47 my $root = $ENV{CATALYST_SERVER} = "http://localhost:$port";
49 # Tests start --------------------------------------------
53 my $mech = Test::WWW::Mechanize->new(timeout => $seconds);
55 $mech->get_ok($root, "GET $root");
56 $mech->content_contains("not signed in", "Content looks right");
58 $mech->get_ok("$root/login", "GET $root/login");
60 # diag($mech->content);
62 $mech->submit_form_ok({ form_name => "login",
63 fields => { username => "paco",
64 password => "l4s4v3n7ur45",
67 "Trying cleartext login, 'memebers' realm");
69 $mech->content_contains("signed in", "Signed in successfully");
70 $mech->get_ok("$root/signin_openid", "GET $root/signin_openid");
71 $mech->content_contains("Sign in with OpenID", "Content looks right");
73 my $claimed_uri = "$root/provider/paco";
75 $mech->submit_form_ok({ form_name => "openid",
76 fields => { openid_identifier => $claimed_uri,
79 "Trying OpenID login, 'openid' realm");
81 $mech->content_contains("You did it with OpenID!",
82 "Successfully signed in with OpenID");
84 $mech->get_ok($root, "GET $root");
86 $mech->content_contains("provider/paco", "OpenID signed in");
89 $mech->get_ok("$root/signin_openid", "GET $root/signin_openid");
90 my $non_openid_uri = "$root/not_a_valid_openid_uri";
91 $mech->submit_form_ok({ form_name => "openid",
92 fields => { openid_identifier => $non_openid_uri,
98 $mech->get_ok("$root/logout", "GET $root/logout");
99 $mech->content_contains("You are not signed in", "Content looks right");
100 $mech->get_ok("$root/signin_openid", "GET $root/signin_openid");
101 $mech->content_contains("Sign in with OpenID", "Content looks right");
103 $mech->submit_form_ok({ form_name => "openid",
104 fields => { openid_identifier => $claimed_uri,
107 "Trying OpenID login, 'openid' realm");
109 $mech->content_contains("can't be verified",
110 "Proper failure for unauthenticated memember.")
111 or diag($mech->content);
115 # Tests end ----------------------------------------------
126 my ( $host, $port ) = @_;
128 my $remote = IO::Socket::INET->new(
152 use Test::WWW::Mechanize;
154 # plan skip_all => 'set TEST_HTTP to enable this test' unless $ENV{TEST_HTTP};
155 eval "use Catalyst::Devel 1.0";
156 plan skip_all => 'Catalyst::Devel required' if $@;
160 # How long to wait for test server to start and timeout for UA.
163 # Spawn the standalone HTTP server.
164 my $port = 30000 + int rand(1 + 10000);
166 my $pipe = "perl -I$FindBin::Bin/../lib -I$FindBin::Bin/TestApp/lib $FindBin::Bin/TestApp/script/testapp_server.pl -fork -port $port |";
168 # my $pipe = "perl -I$FindBin::Bin/../lib -I$FindBin::Bin/TestApp/lib $FindBin::Bin/TestApp/script/testapp_server.pl -f -port $port 2>&1 |";
170 my $pid = open my $server, $pipe
171 or die "Unable to spawn standalone HTTP server: $!";
173 diag("Waiting (up to $seconds seconds) for server to start...");
176 local $SIG{ALRM} = sub { die "Server took too long to start\n" }; # NB: \n required
179 while ( check_port( 'localhost', $port ) != 1 ) {
189 die "Could not run test: $@\n$pipe";
192 my $root = $ENV{CATALYST_SERVER} = "http://localhost:$port";
194 # Tests start --------------------------------------------
198 my $mech = Test::WWW::Mechanize->new(timeout => $seconds);
200 $mech->get_ok($root, "GET $root");
201 $mech->content_contains("not signed in", "Content looks right");
203 $mech->get_ok("$root/login", "GET $root/login");
205 # diag($mech->content);
207 $mech->submit_form_ok({ form_name => "login",
208 fields => { username => "paco",
209 password => "l4s4v3n7ur45",
212 "Trying cleartext login, 'memebers' realm");
214 $mech->content_contains("signed in", "Signed in successfully");
216 $mech->get_ok("$root/signin_openid", "GET $root/signin_openid");
218 $mech->content_contains("Sign in with OpenID", "Content looks right");
220 my $claimed_uri = "$root/provider/paco";
222 $mech->submit_form_ok({ form_name => "openid",
223 fields => { openid_identifier => $claimed_uri,
226 "Trying OpenID login, 'openid' realm");
228 $mech->content_contains("You did it with OpenID!",
229 "Successfully signed in with OpenID");
231 $mech->get_ok($root, "GET $root");
233 $mech->content_contains("provider/paco", "OpenID signed in");
234 #$mech->content_contains("paco", "OpenID signed in as paco");
238 $mech->get_ok("$root/logout", "GET $root/logout");
240 $mech->get_ok("$root/signin_openid", "GET $root/signin_openid");
242 $mech->content_contains("Sign in with OpenID", "Content looks right");
244 $mech->submit_form_ok({ form_name => "openid",
245 fields => { openid_identifier => $claimed_uri,
248 "Trying OpenID login, 'openid' realm");
250 $mech->content_contains("can't be verified",
251 "Proper failure for unauthenticated memember.");
253 # Tests end ----------------------------------------------
262 my ( $host, $port ) = @_;
264 my $remote = IO::Socket::INET->new(