9 use Test::WWW::Mechanize;
12 plan skip_all => 'set TEST_HTTP to enable this test' unless $ENV{TEST_HTTP};
13 eval "use Catalyst::Devel 1.0";
14 plan skip_all => 'Catalyst::Devel required' if $@;
21 # How long to wait for test server to start and timeout for UA.
24 # Spawn the standalone HTTP server.
25 my $port = 30000 + int rand(1 + 10000);
27 my $pipe = "perl -I$FindBin::Bin/../lib -I$FindBin::Bin/TestApp/lib $FindBin::Bin/TestApp/script/testapp_server.pl -f -port $port |";
29 # my $pipe = "perl -I$FindBin::Bin/../lib -I$FindBin::Bin/TestApp/lib $FindBin::Bin/TestApp/script/testapp_server.pl -f -port $port 2>&1 |";
32 my $pid = open my $server, $pipe
33 or die "Unable to spawn standalone HTTP server: $!";
35 diag("Waiting (up to $seconds seconds) for server to start...");
38 local $SIG{ALRM} = sub { die "Server took too long to start\n" }; # NB: \n required
41 while ( check_port( 'localhost', $port ) != 1 ) {
51 die "Could not run test: $@\n$pipe";
54 my $root = $ENV{CATALYST_SERVER} = "http://localhost:$port";
56 # Tests start --------------------------------------------
60 my $mech = Test::WWW::Mechanize->new(timeout => $seconds);
62 $mech->get_ok($root, "GET $root");
63 $mech->content_contains("not signed in", "Content looks right");
65 $mech->get_ok("$root/login", "GET $root/login");
67 # diag($mech->content);
69 $mech->submit_form_ok({ form_name => "login",
70 fields => { username => "paco",
71 password => "l4s4v3n7ur45",
74 "Trying cleartext login, 'memebers' realm");
76 $mech->content_contains("signed in", "Signed in successfully");
78 $mech->get_ok("$root/signin_openid", "GET $root/signin_openid");
80 $mech->content_contains("Sign in with OpenID", "Content looks right");
82 my $claimed_uri = "$root/provider/paco";
84 $mech->submit_form_ok({ form_name => "openid",
85 fields => { openid_identifier => $claimed_uri,
88 "Trying OpenID login, 'openid' realm");
90 $mech->content_contains("You did it with OpenID!",
91 "Successfully signed in with OpenID");
93 $mech->get_ok($root, "GET $root");
95 $mech->content_contains("provider/paco", "OpenID info is in the user");
99 $mech->get_ok("$root/logout", "GET $root/logout");
101 $mech->get_ok("$root/signin_openid", "GET $root/signin_openid");
103 $mech->content_contains("Sign in with OpenID", "Content looks right");
105 $mech->submit_form_ok({ form_name => "openid",
106 fields => { openid_identifier => $claimed_uri,
109 "Trying OpenID login, 'openid' realm");
111 $mech->content_contains("can't be verified",
112 "Proper failure for unauthenticated memember.");
114 # Tests end ----------------------------------------------
123 my ( $host, $port ) = @_;
125 my $remote = IO::Socket::INET->new(