Skip to content

Commit

Permalink
a few more test examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 31, 2012
1 parent 2bf42a1 commit 9b69e7d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -1776,7 +1776,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Added default TLS cert and key to Mojo::IOLoop to make HTTPS testing
easier, so "mojo daemon --listen https://*:3000" now just works.
- Added request limit support to the daemons.
- Added basic authorization and proxy authorization support to
- Added basic authentication and proxy authentication support to
Mojo::Message::Request. (esskar)
- Added tick callback to Mojo::IOLoop to make mixing multiple event loops
trivial.
Expand Down
2 changes: 0 additions & 2 deletions lib/Mojo/Exception.pm
Expand Up @@ -148,8 +148,6 @@ sub _parse_context {
}
}
}

return $self;
}

1;
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/Message/Request.pm
Expand Up @@ -69,12 +69,12 @@ sub fix_headers {
$headers->host($host) unless $headers->host;
}

# Basic authorization
# Basic authentication
if ((my $u = $url->userinfo) && !$headers->authorization) {
$headers->authorization('Basic ' . b64_encode($u, ''));
}

# Basic proxy authorization
# Basic proxy authentication
if (my $proxy = $self->proxy) {
if ((my $u = $proxy->userinfo) && !$headers->proxy_authorization) {
$headers->proxy_authorization('Basic ' . b64_encode($u, ''));
Expand Down Expand Up @@ -133,14 +133,14 @@ sub parse {
$base->authority($host);
}

# Basic authorization
# Basic authentication
if (my $auth = $headers->authorization) {
if (my $userinfo = $self->_parse_basic_auth($auth)) {
$base->userinfo($userinfo);
}
}

# Basic proxy authorization
# Basic proxy authentication
if (my $auth = $headers->proxy_authorization) {
if (my $userinfo = $self->_parse_basic_auth($auth)) {
$self->proxy(Mojo::URL->new->userinfo($userinfo));
Expand Down
7 changes: 7 additions & 0 deletions lib/Test/Mojo.pm
Expand Up @@ -423,6 +423,10 @@ Current transaction, usually a L<Mojo::Transaction::HTTP> object.
User agent used for testing, defaults to a L<Mojo::UserAgent> object.
# Allow redirects
$t->ua->max_redirects(10);
# Request with Basic authentication
$t->get_ok($t->ua->app_url->userinfo('sri:secr3t')->path('/secrets'));
=head1 METHODS
Expand All @@ -448,6 +452,9 @@ Alias for L<Mojo::UserAgent/"app">.
# Change log level
$t->app->log->level('fatal');
# Test application directly
is $t->app->defaults->{foo}, 'bar', 'right value';
=head2 C<content_is>
$t = $t->content_is('working!');
Expand Down
10 changes: 5 additions & 5 deletions t/mojo/request.t
Expand Up @@ -1044,7 +1044,7 @@ is $req->upload('upload')->filename, '0', 'right filename';
isa_ok $req->upload('upload')->asset, 'Mojo::Asset::Memory', 'right file';
is $req->upload('upload')->asset->size, 69, 'right size';

# Parse full HTTP 1.1 proxy request with basic authorization
# Parse full HTTP 1.1 proxy request with basic authentication
$req = Mojo::Message::Request->new;
$req->parse("GET http://127.0.0.1/foo/bar HTTP/1.1\x0d\x0a");
$req->parse("Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\x0d\x0a");
Expand All @@ -1064,7 +1064,7 @@ is $req->url->base->userinfo, 'Aladdin:open sesame', 'right base userinfo';
is $req->url, 'http://127.0.0.1/foo/bar', 'right URL';
is $req->proxy->userinfo, 'Aladdin:open sesame', 'right proxy userinfo';

# Parse full HTTP 1.1 proxy connect request with basic authorization
# Parse full HTTP 1.1 proxy connect request with basic authentication
$req = Mojo::Message::Request->new;
$req->parse("CONNECT 127.0.0.1:3000 HTTP/1.1\x0d\x0a");
$req->parse("Host: 127.0.0.1\x0d\x0a");
Expand Down Expand Up @@ -1427,7 +1427,7 @@ is $req->headers->host, '127.0.0.1', 'right "Host" value';
is $req->headers->content_length, '13', 'right "Content-Length" value';
is $req->body, "Hello World!\n", 'right content';

# Build full HTTP 1.1 proxy request with basic authorization
# Build full HTTP 1.1 proxy request with basic authentication
$req = Mojo::Message::Request->new;
$req->method('GET');
$req->url->parse('http://Aladdin:open%20sesame@127.0.0.1/foo/bar');
Expand All @@ -1452,7 +1452,7 @@ is $req->headers->proxy_authorization, 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==',
is $req->headers->content_length, '13', 'right "Content-Length" value';
is $req->body, "Hello World!\n", 'right content';

# Build full HTTP 1.1 proxy request with basic authorization (and clone)
# Build full HTTP 1.1 proxy request with basic authentication (and clone)
$req = Mojo::Message::Request->new;
$req->method('GET');
$req->url->parse('http://Aladdin:open%20sesame@127.0.0.1/foo/bar');
Expand Down Expand Up @@ -1495,7 +1495,7 @@ is $clone->headers->proxy_authorization, 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==',
is $clone->headers->content_length, '13', 'right "Content-Length" value';
is $clone->body, "Hello World!\n", 'right content';

# Build full HTTP 1.1 proxy connect request with basic authorization
# Build full HTTP 1.1 proxy connect request with basic authentication
$req = Mojo::Message::Request->new;
$req->method('CONNECT');
$req->url->parse('http://Aladdin:open%20sesame@127.0.0.1:3000/foo/bar');
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/request_cgi.t
Expand Up @@ -103,7 +103,7 @@ is $req->url->to_abs->to_string,
'http://localhost:8080/test/index.cgi/foo/bar?lalala=23&bar=baz',
'right absolute URL';

# Parse Apache like CGI environment variables with basic authorization
# Parse Apache like CGI environment variables with basic authentication
$req = Mojo::Message::Request->new;
$req->parse(
CONTENT_LENGTH => 11,
Expand Down

0 comments on commit 9b69e7d

Please sign in to comment.