migrate to git \o/
[catagits/Catalyst-Authentication-Credential-OpenID.git] / t / live-app.t
index 6d080ed..38f6fe8 100644 (file)
@@ -1,18 +1,42 @@
-#!/usr/bin/env perl
 use strict;
 use warnings;
 
 use FindBin;
 use IO::Socket;
 use Test::More;
-use Test::WWW::Mechanize;
 
-plan skip_all => 'set TEST_HTTP to enable this test' unless $ENV{TEST_HTTP};
-eval "use Catalyst::Devel 1.0";
-plan skip_all => 'Catalyst::Devel required' if $@;
+eval <<_DEPS_;
+   use Test::WWW::Mechanize;
+   use Catalyst::Runtime;
+   use Catalyst::Devel;
+   use Cache::FastMmap;
+   use Catalyst::Authentication::User::Hash;
+   use Catalyst::Plugin::Session::State::Cookie;
+   use Catalyst::Plugin::Session::Store::FastMmap;
+   use Class::Accessor::Fast;
+   use Crypt::DH;
+   use ExtUtils::MakeMaker;
+   use HTML::Parser 3;
+   use LWP::UserAgent;
+   use Net::OpenID::Consumer;
+   use Net::OpenID::Server;
+   use Test::WWW::Mechanize;
+   use Net::DNS;
+   use IO::Socket::INET;
+_DEPS_
 
-plan "no_plan";
-# plan tests => 17;
+if ( $@ )
+{
+    plan skip_all => 'Test application dependencies not satisfied ' . $@;
+}
+elsif ( not $ENV{TEST_HTTP} )
+{
+    plan skip_all => 'Set TEST_HTTP to enable this test';
+}
+else
+{
+    plan tests => 21;
+}
 
 # One port for consumer app, one for provider.
 my $consumer_port = 10000 + int rand(1 + 10000);
@@ -36,7 +60,6 @@ diag("Started Consumer with pid $consumer_pid");
 # How long to wait for test server to start and timeout for UA.
 my $seconds = 15;
 
-
 diag("Waiting (up to $seconds seconds) for application servers to start...");
 
 eval {
@@ -53,7 +76,7 @@ if ( $@ )
     die "Could not run test: $@";
 }
 
-my $root = $ENV{CATALYST_SERVER} = "http://localhost:$consumer_port";
+my $openid_consumer = $ENV{CATALYST_SERVER} = "http://localhost:$consumer_port";
 my $openid_server = "http://localhost:$provider_port";
 
 # Tests start --------------------------------------------
@@ -61,10 +84,64 @@ diag("Started...") if $ENV{TEST_VERBOSE};
 
 my $mech = Test::WWW::Mechanize->new(timeout => $seconds);
 
-$mech->get_ok($root, "GET $root");
-$mech->content_contains("not signed in", "Content looks right");
+$mech->get_ok($openid_consumer, "GET $openid_consumer");
+
+$mech->content_contains("You are not signed in.", "Content looks right");
+
+$mech->get_ok("$openid_consumer/signin_openid", "GET $openid_consumer/signin_openid");
+
+{
+    my $claimed_uri = "$openid_server/provider/paco";
+
+    $mech->submit_form_ok({ form_name => "openid",
+                            fields => { openid_identifier => $claimed_uri,
+                            },
+                          },
+                          "Trying OpenID login, 'openid' realm");
+
+    $mech->content_contains("You're not signed in so you can't be verified",
+                            "Can't use OpenID, not signed in at provider");
+}
+
+# Bad claimed URI.
+{
+    my $claimed_uri = "gopher://localhost:443/what?";
+    $mech->back();
+    $mech->submit_form( form_name => "openid",
+                         fields => { openid_identifier => $claimed_uri,
+                                   },
+                       );
+
+    diag("Trying OpenID with ridiculous URI")
+        if $ENV{TEST_VERBOSE};
+
+    # no_identity_server: The provided URL doesn't declare its OpenID identity server.
+
+    is( $mech->status, 500,
+        "Can't use OpenID: bogus_url" );
+}
+
+# Bad claimed URI.
+{
+    my $claimed_uri = "localhost/some/path";
+    $mech->back();
+    $mech->submit_form( form_name => "openid",
+                         fields => { openid_identifier => $claimed_uri,
+                                   },
+                       );
+
+    diag("Trying OpenID with phony URI")
+        if $ENV{TEST_VERBOSE};
+
+    # no_identity_server: The provided URL doesn't declare its OpenID identity server.
+    is( $mech->status, 500,
+        "Can't use OpenID: no_identity_server");
+}
+
+
 
-$mech->get_ok("$openid_server/login", "GET $root/login");
+#
+$mech->get_ok("$openid_server/login", "GET $openid_consumer/login");
 
 # diag($mech->content);
 
@@ -77,7 +154,7 @@ $mech->submit_form_ok({ form_name => "login",
 
 $mech->content_contains("signed in", "Signed in successfully");
 
-$mech->get_ok("$root/signin_openid", "GET $root/signin_openid");
+$mech->get_ok("$openid_consumer/signin_openid", "GET $openid_consumer/signin_openid");
 
 $mech->content_contains("Sign in with OpenID", "Content looks right");
 
@@ -92,15 +169,15 @@ $mech->submit_form_ok({ form_name => "openid",
 $mech->content_contains("You did it with OpenID!",
                         "Successfully signed in with OpenID");
 
-$mech->get_ok($root, "GET $root");
+$mech->get_ok($openid_consumer, "GET $openid_consumer");
 
 $mech->content_contains("provider/paco", "OpenID info is in the user");
 
 # can't be verified
 
-$mech->get_ok("$root/logout", "GET $root/logout");
+$mech->get_ok("$openid_consumer/logout", "GET $openid_consumer/logout");
 
-$mech->get_ok("$root/signin_openid", "GET $root/signin_openid");
+$mech->get_ok("$openid_consumer/signin_openid", "GET $openid_consumer/signin_openid");
 
 $mech->content_contains("Sign in with OpenID", "Content looks right");