Skip to content

Commit

Permalink
Resolve localhost in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
und3f committed May 2, 2012
1 parent ef3d37a commit 669e431
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 8 additions & 4 deletions t/basic.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use Test::TCP;
use Plack::Loader; use Plack::Loader;
use LWP::UserAgent; use LWP::UserAgent;
use FindBin '$Bin'; use FindBin '$Bin';
use Socket;


my $host = "localhost";
my $ca_cert = "$Bin/ca.pem"; my $ca_cert = "$Bin/ca.pem";
my $server_pem = "$Bin/server.pem"; my $server_pem = "$Bin/server.pem";


Expand All @@ -25,16 +27,16 @@ subtest 'tls connection' => sub {
my $ua = my $ua =
LWP::UserAgent->new( LWP::UserAgent->new(
ssl_opts => {verify_hostname => 1, SSL_ca_file => $ca_cert}); ssl_opts => {verify_hostname => 1, SSL_ca_file => $ca_cert});
my $res = $ua->get("https://localhost:$port"); my $res = $ua->get("https://$host:$port");
$success = $res->is_success or die $res->status_line; $success = $res->is_success or die $res->status_line;
$content = $res->decoded_content; $content = $res->decoded_content;
}, },
server => sub { server => sub {
my $port = shift; my $port = shift;
my $server = Plack::Loader->load( my $server = Plack::Loader->load(
'Twiggy::TLS', 'Twiggy::TLS',
host => inet_ntoa(inet_aton($host)),
port => $port, port => $port,
host => '127.0.0.1',
tls_key => $server_pem, tls_key => $server_pem,
tls_cert => $server_pem, tls_cert => $server_pem,
); );
Expand All @@ -48,8 +50,10 @@ subtest 'tls connection' => sub {
['Content-Type' => 'text/plain'], ['Content-Type' => 'text/plain'],
[$env->{"psgi.url_scheme"}] [$env->{"psgi.url_scheme"}]
]; ];
}); }
}); );
}
);


ok $success, "https connection success"; ok $success, "https connection success";
is $content, "https", "returned content is right"; is $content, "https", "returned content is right";
Expand Down
8 changes: 5 additions & 3 deletions t/client-auth.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use Test::TCP;
use Plack::Loader; use Plack::Loader;
use LWP::UserAgent; use LWP::UserAgent;
use FindBin '$Bin'; use FindBin '$Bin';
use Socket;


my $host = "localhost";
my $ca_cert = "$Bin/ca.pem"; my $ca_cert = "$Bin/ca.pem";
my $server_pem = "$Bin/server.pem"; my $server_pem = "$Bin/server.pem";
my $client_pem = "$Bin/client.pem"; my $client_pem = "$Bin/client.pem";
Expand All @@ -28,11 +30,11 @@ subtest 'tls connection' => sub {
verify_hostname => 1, verify_hostname => 1,
SSL_ca_file => $ca_cert, SSL_ca_file => $ca_cert,


SSL_key_file => $client_pem, SSL_key_file => $client_pem,
SSL_cert_file => $client_pem, SSL_cert_file => $client_pem,
} }
); );
my $res = $ua->get("https://localhost:$port"); my $res = $ua->get("https://$host:$port");
$success = $res->is_success or die $res->status_line; $success = $res->is_success or die $res->status_line;


$content = $res->decoded_content; $content = $res->decoded_content;
Expand All @@ -41,8 +43,8 @@ subtest 'tls connection' => sub {
my $port = shift; my $port = shift;
my $server = Plack::Loader->load( my $server = Plack::Loader->load(
'Twiggy::TLS', 'Twiggy::TLS',
host => inet_ntoa(inet_aton($host)),
port => $port, port => $port,
host => '127.0.0.1',
tls_key => $server_pem, tls_key => $server_pem,
tls_cert => $server_pem, tls_cert => $server_pem,
tls_ca => $ca_cert, tls_ca => $ca_cert,
Expand Down

0 comments on commit 669e431

Please sign in to comment.