Apache2-Controller

 view release on metacpan or  search on metacpan

t/openid.t  view on Meta::CPAN


use strict;
use warnings FATAL => 'all';
use English '-no_match_vars';

use FindBin;

use lib "$FindBin::Bin/lib";

use Test::More tests => 1;
SKIP: {
    skip 'skip all-- openid does not work for this bugfix release', 1;
    ok( 1 == 1, 'foo' );
    exit;
}

__END__

use Apache2::Controller::Test::Funk qw( diag od qs );
use YAML::Syck;
use URI::Escape;
use Carp qw(croak longmess);
use Log::Log4perl qw(:easy);

# start a separate server.
# because it can't process requests for the openid url
# while it is processing the request that tries to get it.

use Apache2::Controller::Test::OpenIDServer;

# start up the openid test server
my $openid_server = Apache2::Controller::Test::OpenIDServer->new();
my $openid_port = $openid_server->port;
my $openid_url_base = "http://localhost:$openid_port";
diag("openid_url_base: $openid_url_base");

my $openid_url = "$openid_url_base/a2ctest";
my $esc_openid_url = uri_escape($openid_url);

# set the server running in the background
my $openid_server_pid = $openid_server->background;
diag("openid server backgrounded, pid is '$openid_server_pid'");

# use the test libs after forking... although it doesn't seem to matter
use Apache::Test;
use Apache::TestUtil;
use Apache::TestRequest qw( GET_HEAD GET_BODY GET_STR );
plan tests => 25, need_module qw(
    LWP
    Net::OpenID::Server
    HTTP::Server::Simple
);
Apache::TestRequest::user_agent(cookie_jar => {}, requests_redirectable => 0);

my $at_config = Apache::Test::config();
#diag(Dump($at_config));

my $test_server_url = $at_config->{vars}{scheme}.'://'.$at_config->{server}{name};

my $protected_url = "/openid/protected";
my $user_area = "$protected_url/access_user_area";
my $login_url = "$protected_url/login";

# eval everything to make sure we kill the server on an error
eval {

# test the openid server first to make sure it's working
my $openid_working = GET_BODY "$openid_url_base/working";
ok t_cmp(
    $openid_working,
    'WORKING',
    'check temporary openid server is working',
);

my $setup_db = GET_BODY "/openid/unprotected/setup/create_db";
ok t_cmp(
    $setup_db, 
    'Created Database Tables.', 
    'create database tables'
);

sleep 5;

diag("get login page: GET_STR('$user_area')");
my $login_first = GET_STR($user_area);
#diag($login_first);

ok t_cmp(
    $login_first,
    qr{ ^ This \s is \s the \s login \s page\. }mxs,
    'first try redirects internally to login page',
);   

# try the protected page with the param.  it should redirect to registration.
my $protected_page_with_unk_openid_url = "$user_area?openid_url=$esc_openid_url";
diag("trying a protected page with unknown openid_url param: '$protected_page_with_unk_openid_url'");
my $register_when_unknown_protected 
    = GET_BODY($protected_page_with_unk_openid_url);



( run in 1.602 second using v1.01-cache-2.11-cpan-39bf76dae61 )