Skip to content

Commit ba6ec1f

Browse files
committed
Issue #444: switch to using Test2::Tools::HTTP
1 parent 705ce24 commit ba6ec1f

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);
@@ -994,6 +995,18 @@
994995
ports => undef,
995996
},
996997
},
998+
{
999+
Module => 'Test2::Tools::HTTP',
1000+
Required => 0,
1001+
Features => ['devel:test'],
1002+
Comment => 'testing PSGI apps and URLs',
1003+
InstTypes => {
1004+
aptget => undef,
1005+
emerge => undef,
1006+
zypper => undef,
1007+
ports => undef,
1008+
},
1009+
},
9971010
{
9981011
Module => 'Mojolicious',
9991012
Required => 0,

cpanfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ feature 'devel:test', 'Suppport for devel:test' => sub {
119119
# contains Test2::API which is used in Kernel::System::UnitTest::Driver
120120
requires 'Test::Simple';
121121

122+
# testing PSGI apps and URLs
123+
requires 'Test2::Tools::HTTP';
124+
122125
};
123126

124127
feature 'div:bcrypt', 'Suppport for div:bcrypt' => sub {
@@ -323,6 +326,9 @@ feature 'optional', 'Suppport for optional' => sub {
323326
# contains Test2::API which is used in Kernel::System::UnitTest::Driver
324327
requires 'Test::Simple';
325328

329+
# testing PSGI apps and URLs
330+
requires 'Test2::Tools::HTTP';
331+
326332
# a web framework that makes web development fun again
327333
requires 'Mojolicious';
328334

cpanfile.docker

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ requires 'Unicode::Collate';
107107
# contains Test2::API which is used in Kernel::System::UnitTest::Driver
108108
requires 'Test::Simple';
109109

110+
# testing PSGI apps and URLs
111+
requires 'Test2::Tools::HTTP';
112+
110113
# };
111114

112115
# 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)