Commit 15e35924 authored by Yadd's avatar Yadd
Browse files

Update tests (#595)

parent c138514b
......@@ -15,8 +15,11 @@ ok( $res->[0] == 401, 'Response is 401' ) or explain( $res, 401 );
count(2);
# Test "first access" with good url
ok( $res = &client->_get('/?url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw=='),
'Unauth ajax request with good url' );
ok(
$res =
&client->_get( '/', query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==' ),
'Unauth ajax request with good url'
);
ok( $res->[0] == 401, 'Response is 401' ) or explain( $res, 401 );
count(2);
......@@ -24,9 +27,9 @@ count(2);
# -------------------
ok(
$res = &client->_post(
'/', '',
'/',
IO::String->new('user=dwho&password=dwho'),
'application/x-www-form-urlencoded', 23
length => 23
),
'Auth query'
);
......
......@@ -31,10 +31,9 @@ SKIP: {
# -------------------
ok(
$res = &client->_post(
'/', '',
'/',
IO::String->new($postString),
'application/x-www-form-urlencoded',
length($postString)
length => length($postString)
),
'Auth query'
);
......
......@@ -31,10 +31,9 @@ SKIP: {
# -------------------
ok(
$res = &client->_post(
'/', '',
'/',
IO::String->new($postString),
'application/x-www-form-urlencoded',
length($postString)
length => length($postString)
),
'Auth query'
);
......
......@@ -40,9 +40,9 @@ SKIP: {
# -------------------
ok(
$res = &client->_post(
'/', '',
'/',
IO::String->new('user=dwho&password=dwho'),
'application/x-www-form-urlencoded', 23
length => 23
),
'Auth query'
);
......
......@@ -101,9 +101,9 @@ my @tests = (
my $res;
ok(
$res = &client->_post(
'/', '',
'/',
IO::String->new('user=dwho&password=dwho'),
'application/x-www-form-urlencoded', 23
length => 23
),
'Auth query'
);
......@@ -154,9 +154,9 @@ while ( defined( my $url = shift(@tests) ) ) {
or explain( $res->[0], ( $redir ? 302 : 200 ) );
ok(
$res = &client->_post(
'/', '',
'/',
IO::String->new('user=dwho&password=dwho'),
'application/x-www-form-urlencoded', 23
length => 23
),
'Auth query'
);
......
......@@ -140,4 +140,43 @@ sub _get {
);
}
sub _post {
my ( $self, $path, $body, %args ) = @_;
die "$body must be a IO::Handle"
unless ( ref($body) and $body->can('read') );
return $self->app->(
{
'HTTP_ACCEPT' => $args{accept}
|| 'application/json, text/plain, */*',
'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
'HTTP_CACHE_CONTROL' => 'max-age=0',
( $args{cookie} ? ( HTTP_COOKIE => $args{cookie} ) : () ),
'HTTP_HOST' => 'auth.example.com',
'HTTP_USER_AGENT' =>
'Mozilla/5.0 (VAX-4000; rv:36.0) Gecko/20350101 Firefox',
'PATH_INFO' => $path,
( $args{query} ? ( QUERY_STRING => $args{query} ) : () ),
( $args{referer} ? ( REFERER => $args{referer} ) : () ),
'REMOTE_ADDR' => '127.0.0.1',
(
$args{remote_user}
? ( 'REMOTE_USER' => $args{remote_user} )
: ()
),
'REQUEST_METHOD' => 'POST',
'REQUEST_URI' => $path . ( $args{query} ? "?$args{query}" : '' ),
'SCRIPT_NAME' => '',
'SERVER_NAME' => 'auth.example.com',
'SERVER_PORT' => '8002',
'SERVER_PROTOCOL' => 'HTTP/1.1',
( $args{custom} ? %{ $args{custom} } : () ),
'psgix.input.buffered' => 1,
'psgi.input' => $body,
'CONTENT_LENGTH' => $args{length} // scalar( ( stat $body )[7] ),
'CONTENT_TYPE' => $args{type}
|| 'application/x-www-form-urlencoded',
}
);
}
1;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment