Skip to content

Commit 7b64c26

Browse files
committed
Issue #444: switch to using Test2::Tools::HTTP
1 parent e3e2a2a commit 7b64c26

File tree

4 files changed

+44
-30
lines changed

4 files changed

+44
-30
lines changed

bin/otobo.CheckModules.pl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
# --
1717

18-
use 5.024;
18+
use strict;
1919
use warnings;
20+
use 5.024;
2021

2122
use File::Basename;
2223
use FindBin qw($RealBin);
@@ -982,6 +983,18 @@
982983
ports => undef,
983984
},
984985
},
986+
{
987+
Module => 'Test2::Tools::HTTP',
988+
Required => 0,
989+
Features => ['devel:test'],
990+
Comment => 'testing PSGI apps and URLs',
991+
InstTypes => {
992+
aptget => undef,
993+
emerge => undef,
994+
zypper => undef,
995+
ports => undef,
996+
},
997+
},
985998
{
986999
Module => 'Mojolicious',
9871000
Required => 0,

cpanfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ feature 'devel:test', 'Suppport for devel:test' => sub {
116116
# basic test functions
117117
requires 'Test2::Suite';
118118

119+
# testing PSGI apps and URLs
120+
requires 'Test2::Tools::HTTP';
121+
119122
};
120123

121124
feature 'div:bcrypt', 'Suppport for div:bcrypt' => sub {
@@ -317,6 +320,9 @@ feature 'optional', 'Suppport for optional' => sub {
317320
# basic test functions
318321
requires 'Test2::Suite';
319322

323+
# testing PSGI apps and URLs
324+
requires 'Test2::Tools::HTTP';
325+
320326
# a web framework that makes web development fun again
321327
requires 'Mojolicious';
322328

cpanfile.docker

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ requires 'Unicode::Collate';
104104
# basic test functions
105105
requires 'Test2::Suite';
106106

107+
# testing PSGI apps and URLs
108+
requires 'Test2::Tools::HTTP';
109+
107110
# };
108111

109112
# feature 'div:bcrypt', 'Suppport for div:bcrypt' => sub {

scripts/test/PSGI/DbViewer.t

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ use LWP::UserAgent;
2727

2828
# CPAN modules
2929
use Test2::V0;
30+
use Test2::Tools::HTTP;
31+
use HTTP::Request::Common;
3032

3133
# OTOBO modules
3234
use Kernel::System::ObjectManager;
@@ -72,28 +74,22 @@ my $AdminLoginURL = $BaseURL . "index.pl?Action=Login;User=$TestAdminUserLogin;P
7274
my $HelloURL = $BaseURL . '../hello';
7375
my $DbViewerURL = $BaseURL . 'dbviewer';
7476

75-
my $UserAgent = LWP::UserAgent->new(
76-
Timeout => 60,
77-
);
78-
$UserAgent->cookie_jar( {} ); # keep cookies
79-
8077
# TODO: check HelloURL access allowed without login
8178
# TODO: check HelloURL content
8279
# TODO: check DbViewerURL access denied without login
8380

8481
# Login as admin
8582
{
86-
my $Response = $UserAgent->get( $AdminLoginURL );
87-
ok( $Response->is_success(), "login to agent interface as admin user" );
88-
89-
if ( !$Response->is_success() ) {
90-
# TODO: maybe bail out
91-
done_testing();
92-
93-
exit;
94-
}
83+
http_request(
84+
[ GET($AdminLoginURL), follow_redirects => 1 ],
85+
http_response {
86+
http_is_success();
87+
},
88+
'login to agent interface as admin user'
89+
);
9590

9691
# Get session info from cookie
92+
my $UserAgent = http_ua();
9793
my $AdminSessionValid;
9894
$UserAgent->cookie_jar()->scan(
9995
sub {
@@ -104,26 +100,22 @@ $UserAgent->cookie_jar( {} ); # keep cookies
104100
);
105101

106102
ok( $AdminSessionValid, 'valid session for admin user' );
107-
108-
if ( !$AdminSessionValid ) {
109-
done_testing();
110-
111-
exit;
112-
}
113103
}
114104

115105
# check /dbviewer
116106
{
117-
my $Response = $UserAgent->get($DbViewerURL);
118-
my $Status = $Response->code();
119-
120-
is( $Status, 200, "status of $DbViewerURL" );
121-
122-
ok( scalar $Response->header('Content-type'), "content type $DbViewerURL" );
123-
124-
ok( ! scalar $Response->header('X-OTOBO-Login'), "$DbViewerURL is no OTOBO login screen" );
107+
http_request(
108+
[ GET($DbViewerURL), follow_redirects => 1 ],
109+
http_response {
110+
http_is_success();
111+
http_content_type( 'text/html' );
112+
# TODO: check response contents
113+
},
114+
'testing /dbviewer URL',
115+
);
125116

126-
# TODO: check response contents
117+
# TODO: how can Test2::Tools::HTTP used for that test
118+
#ok( ! scalar $Response->header('X-OTOBO-Login'), "$DbViewerURL is no OTOBO login screen" );
127119
}
128120

129121
# cleanup cache

0 commit comments

Comments
 (0)