From c961467d412796e66fb925d4b1cba303766a0f0b Mon Sep 17 00:00:00 2001 From: Maxime Besson Date: Thu, 29 Aug 2019 18:37:02 +0200 Subject: [PATCH] tests: make expectReject more flexible --- lemonldap-ng-portal/t/36-Combination-with-token.t | 4 ++-- lemonldap-ng-portal/t/test-lib.pm | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lemonldap-ng-portal/t/36-Combination-with-token.t b/lemonldap-ng-portal/t/36-Combination-with-token.t index 165c3e43a..57b3aa70d 100644 --- a/lemonldap-ng-portal/t/36-Combination-with-token.t +++ b/lemonldap-ng-portal/t/36-Combination-with-token.t @@ -26,7 +26,7 @@ SKIP: { $client = iniCmb('[Dm] and [DB]'); expectCookie( try('rtyler') ); - expectReject( try('dwho'), 5 ); + expectReject( try('dwho'), 401, 5 ); $client = iniCmb('if($env->{HTTP_X} eq "dwho") then [Dm] else [DB]'); expectCookie( try('dwho') ); @@ -37,7 +37,7 @@ SKIP: { ); expectCookie( try('rtyler') ); expectCookie( try('dvador') ); - expectReject( try('dwho'), 5 ); + expectReject( try('dwho'), 401, 5 ); } count($maintests); clean_sessions(); diff --git a/lemonldap-ng-portal/t/test-lib.pm b/lemonldap-ng-portal/t/test-lib.pm index 1f157b5a1..77d556113 100644 --- a/lemonldap-ng-portal/t/test-lib.pm +++ b/lemonldap-ng-portal/t/test-lib.pm @@ -344,14 +344,14 @@ Note that it works only for Ajax request (see below). =cut sub expectReject { - my ( $res, $code ) = @_; - ok( $res->[0] == 401, ' Response is 401' ) or explain( $res->[0], 401 ); + my ( $res, $status, $code ) = @_; + $status ||= 401; + cmp_ok( $res->[0], '==', $status, " Response status is $status" ); 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' ); if ( defined $code ) { - ok( $res->{error} == $code, "Error code is $code" ) - or explain( $res->{error}, $code ); + is( $res->{error}, $code, " Error code is $code" ); } else { pass("Error code is $res->{error}"); @@ -696,9 +696,8 @@ sub _get { $args{remote_user} ? ( 'REMOTE_USER' => $args{remote_user} ) : () ), - 'REQUEST_METHOD' => $args{method} - || 'GET', - 'REQUEST_URI' => $path . ( $args{query} ? "?$args{query}" : '' ), + 'REQUEST_METHOD' => $args{method} || 'GET', + 'REQUEST_URI' => $path . ( $args{query} ? "?$args{query}" : '' ), ( $args{query} ? ( QUERY_STRING => $args{query} ) : () ), 'SCRIPT_NAME' => '', 'SERVER_NAME' => 'auth.example.com',