tests: make expectReject more flexible
This commit is contained in:
parent
667757a1a8
commit
c961467d41
|
@ -26,7 +26,7 @@ SKIP: {
|
||||||
|
|
||||||
$client = iniCmb('[Dm] and [DB]');
|
$client = iniCmb('[Dm] and [DB]');
|
||||||
expectCookie( try('rtyler') );
|
expectCookie( try('rtyler') );
|
||||||
expectReject( try('dwho'), 5 );
|
expectReject( try('dwho'), 401, 5 );
|
||||||
|
|
||||||
$client = iniCmb('if($env->{HTTP_X} eq "dwho") then [Dm] else [DB]');
|
$client = iniCmb('if($env->{HTTP_X} eq "dwho") then [Dm] else [DB]');
|
||||||
expectCookie( try('dwho') );
|
expectCookie( try('dwho') );
|
||||||
|
@ -37,7 +37,7 @@ SKIP: {
|
||||||
);
|
);
|
||||||
expectCookie( try('rtyler') );
|
expectCookie( try('rtyler') );
|
||||||
expectCookie( try('dvador') );
|
expectCookie( try('dvador') );
|
||||||
expectReject( try('dwho'), 5 );
|
expectReject( try('dwho'), 401, 5 );
|
||||||
}
|
}
|
||||||
count($maintests);
|
count($maintests);
|
||||||
clean_sessions();
|
clean_sessions();
|
||||||
|
|
|
@ -344,14 +344,14 @@ Note that it works only for Ajax request (see below).
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub expectReject {
|
sub expectReject {
|
||||||
my ( $res, $code ) = @_;
|
my ( $res, $status, $code ) = @_;
|
||||||
ok( $res->[0] == 401, ' Response is 401' ) or explain( $res->[0], 401 );
|
$status ||= 401;
|
||||||
|
cmp_ok( $res->[0], '==', $status, " Response status is $status" );
|
||||||
eval { $res = JSON::from_json( $res->[2]->[0] ) };
|
eval { $res = JSON::from_json( $res->[2]->[0] ) };
|
||||||
ok( not($@), 'Content is JSON' )
|
ok( not($@), ' Content is JSON' )
|
||||||
or explain( $res->[2]->[0], 'JSON content' );
|
or explain( $res->[2]->[0], 'JSON content' );
|
||||||
if ( defined $code ) {
|
if ( defined $code ) {
|
||||||
ok( $res->{error} == $code, "Error code is $code" )
|
is( $res->{error}, $code, " Error code is $code" );
|
||||||
or explain( $res->{error}, $code );
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pass("Error code is $res->{error}");
|
pass("Error code is $res->{error}");
|
||||||
|
@ -696,9 +696,8 @@ sub _get {
|
||||||
$args{remote_user} ? ( 'REMOTE_USER' => $args{remote_user} )
|
$args{remote_user} ? ( 'REMOTE_USER' => $args{remote_user} )
|
||||||
: ()
|
: ()
|
||||||
),
|
),
|
||||||
'REQUEST_METHOD' => $args{method}
|
'REQUEST_METHOD' => $args{method} || 'GET',
|
||||||
|| 'GET',
|
'REQUEST_URI' => $path . ( $args{query} ? "?$args{query}" : '' ),
|
||||||
'REQUEST_URI' => $path . ( $args{query} ? "?$args{query}" : '' ),
|
|
||||||
( $args{query} ? ( QUERY_STRING => $args{query} ) : () ),
|
( $args{query} ? ( QUERY_STRING => $args{query} ) : () ),
|
||||||
'SCRIPT_NAME' => '',
|
'SCRIPT_NAME' => '',
|
||||||
'SERVER_NAME' => 'auth.example.com',
|
'SERVER_NAME' => 'auth.example.com',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user