9 use Test::WWW::Mechanize;
11 # plan skip_all => 'set TEST_HTTP to enable this test' unless $ENV{TEST_HTTP};
12 eval "use Catalyst::Devel 1.0";
13 plan skip_all => 'Catalyst::Devel required' if $@;
17 # How long to wait for test server to start and timeout for UA.
20 # Spawn the standalone HTTP server.
21 my $port = 30000 + int rand(1 + 10000);
23 my $pipe = "perl -I$FindBin::Bin/../lib -I$FindBin::Bin/TestApp/lib $FindBin::Bin/TestApp/script/testapp_server.pl -fork -port $port |";
25 # my $pipe = "perl -I$FindBin::Bin/../lib -I$FindBin::Bin/TestApp/lib $FindBin::Bin/TestApp/script/testapp_server.pl -f -port $port 2>&1 |";
27 my $pid = open my $server, $pipe
28 or die "Unable to spawn standalone HTTP server: $!";
30 diag("Waiting (up to $seconds seconds) for server to start...");
33 local $SIG{ALRM} = sub { die "Server took too long to start\n" }; # NB: \n required
36 while ( check_port( 'localhost', $port ) != 1 ) {
46 die "Could not run test: $@\n$pipe";
49 my $root = $ENV{CATALYST_SERVER} = "http://localhost:$port";
51 # Tests start --------------------------------------------
55 my $mech = Test::WWW::Mechanize->new(timeout => $seconds);
57 $mech->get_ok($root, "GET $root");
58 $mech->content_contains("not signed in", "Content looks right");
60 $mech->get_ok("$root/login", "GET $root/login");
62 # diag($mech->content);
64 $mech->submit_form_ok({ form_name => "login",
65 fields => { username => "paco",
66 password => "l4s4v3n7ur45",
69 "Trying cleartext login, 'memebers' realm");
71 $mech->content_contains("signed in", "Signed in successfully");
73 $mech->get_ok("$root/signin_openid", "GET $root/signin_openid");
75 $mech->content_contains("Sign in with OpenID", "Content looks right");
77 my $claimed_uri = "$root/provider/paco";
79 $mech->submit_form_ok({ form_name => "openid",
80 fields => { openid_identifier => $claimed_uri,
83 "Trying OpenID login, 'openid' realm");
85 $mech->content_contains("You did it with OpenID!",
86 "Successfully signed in with OpenID");
88 $mech->get_ok($root, "GET $root");
90 $mech->content_contains("provider/paco", "OpenID signed in");
91 #$mech->content_contains("paco", "OpenID signed in as paco");
95 $mech->get_ok("$root/logout", "GET $root/logout");
97 $mech->get_ok("$root/signin_openid", "GET $root/signin_openid");
99 $mech->content_contains("Sign in with OpenID", "Content looks right");
101 $mech->submit_form_ok({ form_name => "openid",
102 fields => { openid_identifier => $claimed_uri,
105 "Trying OpenID login, 'openid' realm");
107 $mech->content_contains("can't be verified",
108 "Proper failure for unauthenticated memember.");
110 # Tests end ----------------------------------------------
119 my ( $host, $port ) = @_;
121 my $remote = IO::Socket::INET->new(