Skip to content

Commit

Permalink
better connection information tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 3, 2012
1 parent 506214b commit 8357a78
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
15 changes: 14 additions & 1 deletion t/mojo/app.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 55;
use Test::More tests => 63;

# "I was so bored I cut the pony tail off the guy in front of us.
# Look at me, I'm a grad student.
Expand Down Expand Up @@ -90,9 +90,14 @@ $app->routes->post(
);

# POST /upload
my ($local_address, $local_port, $remote_address, $remote_port);
$app->routes->post(
'/upload' => sub {
my $self = shift;
$local_address = $self->tx->local_address;
$local_port = $self->tx->local_port;
$remote_address = $self->tx->remote_address;
$remote_port = $self->tx->remote_port;
$self->render_data($self->req->upload('file')->slurp);
}
);
Expand Down Expand Up @@ -241,6 +246,14 @@ $tx = $ua->post_form(
"http://127.0.0.1:$port/upload" => {file => {content => $result}});
is $tx->res->code, 200, 'right status';
is $tx->res->body, $result, 'right content';
ok $tx->local_address, 'has local address';
ok $tx->local_port > 0, 'has local port';
ok $tx->remote_address, 'has local address';
ok $tx->remote_port > 0, 'has local port';
ok $local_address, 'has local address';
ok $local_port > 0, 'has local port';
ok $remote_address, 'has local address';
ok $remote_port > 0, 'has local port';

# Parallel requests
my $delay = Mojo::IOLoop->delay;
Expand Down
4 changes: 3 additions & 1 deletion t/mojo/user_agent_online.t
Expand Up @@ -14,7 +14,7 @@ plan skip_all => 'IO::Socket::INET6 2.69 required for this test!'
unless Mojo::IOLoop::Server::IPV6;
plan skip_all => 'IO::Socket::SSL 1.37 required for this test!'
unless Mojo::IOLoop::Server::TLS;
plan tests => 86;
plan tests => 88;

# "So then I said to the cop, "No, you're driving under the influence...
# of being a jerk"."
Expand Down Expand Up @@ -267,6 +267,8 @@ is_deeply [$tx->error], ['Bad Request', 400], 'right error';
is_deeply [$tx->res->error], ['Bad Request', 400], 'right error';
ok $tx->local_address, 'has local address';
ok $tx->local_port > 0, 'has local port';
ok $tx->remote_address, 'has local address';
ok $tx->remote_port > 0, 'has local port';

# Connect timeout (non-routable address)
$tx = $ua->connect_timeout(0.5)->get('192.0.2.1');
Expand Down
12 changes: 7 additions & 5 deletions t/mojolicious/lite_app.t
Expand Up @@ -9,7 +9,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 685;
use Test::More tests => 688;

# "Wait you're the only friend I have...
# You really want a robot for a friend?
Expand Down Expand Up @@ -867,13 +867,14 @@ $t->get_ok('/.html')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')
->content_is("/root.html\n/root.html\n/root.html\n/root.html\n/root.html\n");

# GET /0 ("X-Forwarded-For")
my $source = $t->tx->local_address;
$t->get_ok('/0', {'X-Forwarded-For' => '192.168.2.2, 192.168.2.1'})
->status_is(200)->content_like(qr!http\://localhost\:\d+/0-$source-0!);
->status_is(200)->content_like(qr!^http\://localhost\:\d+!)
->content_unlike(qr!/0-192\.168\.2\.1-0$!);

# GET /0 ("X-Forwarded-HTTPS")
$t->get_ok('/0', {'X-Forwarded-HTTPS' => 1})->status_is(200)
->content_like(qr!http\://localhost\:\d+/0-$source-0!);
->content_like(qr!^http\://localhost\:\d+!)
->content_unlike(qr!/0-192\.168\.2\.1-0$!);

# GET /0 (reverse proxy with "X-Forwarded-For")
{
Expand All @@ -887,7 +888,8 @@ $t->get_ok('/0', {'X-Forwarded-HTTPS' => 1})->status_is(200)
{
local $ENV{MOJO_REVERSE_PROXY} = 1;
$t->get_ok('/0', {'X-Forwarded-HTTPS' => 1})->status_is(200)
->content_like(qr!https\://localhost\:\d+/0-$source-0!);
->content_like(qr!^https\://localhost\:\d+!)
->content_unlike(qr!/0-192\.168\.2\.1-0$!);
}

# DELETE /inline/epl
Expand Down

0 comments on commit 8357a78

Please sign in to comment.