-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathAdminGenericInterfaceTransportHTTPREST.t
339 lines (290 loc) · 12.2 KB
/
AdminGenericInterfaceTransportHTTPREST.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# --
# OTOBO is a web-based ticketing system for service organisations.
# --
# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/
# Copyright (C) 2019-2025 Rother OSS GmbH, https://otobo.io/
# --
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# --
use strict;
use warnings;
use utf8;
# Set up the test driver $Self when we are running as a standalone script.
use Kernel::System::UnitTest::RegisterDriver;
our $Self;
# OTOBO modules
use Kernel::System::UnitTest::Selenium;
my $Selenium = Kernel::System::UnitTest::Selenium->new( LogExecuteCommandActive => 1 );
$Selenium->RunTest(
sub {
my $Helper = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
my $WebserviceObject = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice');
my $RandomID = $Helper->GetRandomID();
# Create test web service.
my $WebserviceID = $WebserviceObject->WebserviceAdd(
Config => {
Debugger => {
DebugThreshold => 'debug',
TestMode => 1,
},
Provider => {
Transport => {
Type => '',
},
},
},
Name => "Selenium $RandomID web service",
ValidID => 1,
UserID => 1,
);
$Self->True(
$WebserviceID,
"Web service ID $WebserviceID is created"
);
# Create test user and login.
my $TestUserLogin = $Helper->TestUserCreate(
Groups => ['admin'],
) || die "Did not get test user";
$Selenium->Login(
Type => 'Agent',
User => $TestUserLogin,
Password => $TestUserLogin,
);
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
my $ScriptAlias = $ConfigObject->Get('ScriptAlias');
my $Home = $ConfigObject->Get('Home');
# Navigate to AdminGenericInterfaceWebservice screen.
$Selenium->VerifiedGet("${ScriptAlias}index.pl?Action=AdminGenericInterfaceWebservice");
# Click on created web service.
$Selenium->find_element("//a[contains(\@href, 'WebserviceID=$WebserviceID')]")->VerifiedClick();
# Select 'HTTP::REST' as provider network transport.
$Selenium->InputFieldValueSet(
Element => '#ProviderTransportList',
Value => 'HTTP::REST',
);
# Select 'HTTP::REST' as requester network transport.
$Selenium->InputFieldValueSet(
Element => '#RequesterTransportList',
Value => 'HTTP::REST',
);
# Click on 'Save'.
$Selenium->find_element( "#SubmitAndContinue", 'css' )->VerifiedClick();
# Click to configure provider network transport.
$Selenium->find_element("//button[\@id='ProviderTransportProperties']")->VerifiedClick();
# Verify screen.
for my $ID (
qw(MaxLength KeepAlive)
)
{
$Selenium->find_element( "#$ID", 'css' )->is_enabled();
}
# Verify URL.
$Self->True(
$Selenium->get_current_url()
=~ /CommunicationType=Provider;Action=AdminGenericInterfaceTransportHTTPREST;Subaction=Add/,
"Current URL on Add action is correct"
);
$Selenium->find_element( "#MaxLength", 'css' )->send_keys('1000');
$Selenium->InputFieldValueSet(
Element => '#KeepAlive',
Value => 1,
);
# Add one additional response header line.
$Selenium->find_element( "#AddValue", 'css' )->click();
# Click on 'Save' without entering anything to trigger client-side validation.
$Selenium->find_element( "#SubmitAndContinue", 'css' )->click();
$Selenium->WaitFor(
JavaScript => "return \$('.DefaultValueKeyItem.Error').length && \$('.DefaultValueItem.Error').length"
);
# Check if errors are shown.
$Self->True(
$Selenium->execute_script(
"return \$('.DefaultValueKeyItem.Error').length;"
),
'Default key field highlighted as an error'
);
$Self->True(
$Selenium->execute_script(
"return \$('.DefaultValueItem.Error').length;"
),
'Default key field highlighted as an error'
);
# Input key and value for additional response headers.
$Selenium->find_element( '.DefaultValueKeyItem', 'css' )->send_keys('Key1');
$Selenium->find_element( '.DefaultValueItem', 'css' )->send_keys('Value1');
# Click on 'Save'.
$Selenium->find_element( "#SubmitAndContinue", 'css' )->VerifiedClick();
# Verify URL is changed while we are on the same screen.
$Self->True(
$Selenium->get_current_url() =~ /Action=AdminGenericInterfaceTransportHTTPREST;Subaction=Change/,
"Current URL after 'Save' button click is correct"
);
# Verify saved fields.
$Self->Is(
$Selenium->find_element( "#MaxLength", 'css' )->get_value(),
'1000',
"Inputed value for MaxLength field is correct"
);
$Self->Is(
$Selenium->find_element( "#KeepAlive", 'css' )->get_value(),
1,
"Selected value for KeepAlive field is correct"
);
$Self->Is(
$Selenium->find_element( '.DefaultValueKeyItem', 'css' )->get_value(),
'Key1',
'Inputed value for DefaultValueKeyItem field is correct'
);
$Self->Is(
$Selenium->find_element( '.DefaultValueItem', 'css' )->get_value(),
'Value1',
'Inputed value for DefaultValueItem field is correct'
);
# Click on 'Save and finish' verify JS redirection.
$Selenium->find_element( "#Submit", 'css' )->VerifiedClick();
$Self->True(
$Selenium->get_current_url() =~ /Action=AdminGenericInterfaceWebservice/,
"Click on 'Save and finish' button - JS is successful"
);
# Click to configure requester network transport.
$Selenium->find_element("//button[\@id='RequesterTransportProperties']")->VerifiedClick();
# Verify screen.
for my $ID (
qw(
Host DefaultCommand Timeout
AuthType BasicAuthUser BasicAuthPassword
UseSSL SSLCertificate SSLKey SSLPassword SSLCAFile SSLCADir
UseProxy ProxyHost ProxyUser ProxyPassword ProxyExclude
)
)
{
$Selenium->find_element( "#$ID", 'css' )->is_enabled();
}
# Verify URL.
$Self->True(
$Selenium->get_current_url()
=~ /CommunicationType=Requester;Action=AdminGenericInterfaceTransportHTTPREST;Subaction=Add/,
"Current URL on Add action is correct"
);
# Click to 'Save' and verify client side validation for missing fields.
$Selenium->find_element( "#SubmitAndContinue", 'css' )->click();
for my $ValidationField (qw( Host )) {
$Selenium->WaitFor(
JavaScript => "return typeof(\$) === 'function' && \$('#$ValidationField.Error').length"
);
$Self->Is(
$Selenium->execute_script(
"return \$('#$ValidationField').hasClass('Error')"
),
1,
"Client side validation for missing field $ValidationField is successful",
);
}
# Verify certain fields are Hidden with default options,
# select appropriate option to trigger JS to remove Hidden class.
my @RequesterJSFields = (
{
CheckField => 'BasicAuthField',
OptionField => 'AuthType',
OptionValue => 'BasicAuth',
},
{
CheckField => 'SSLField',
OptionField => 'UseSSL',
OptionValue => 'Yes',
},
{
CheckField => 'ProxyField',
OptionField => 'UseProxy',
OptionValue => 'Yes',
},
);
for my $Field (@RequesterJSFields) {
# Change field to trigger JS (if necessary).
if ( $Field->{OptionValuePre} ) {
$Selenium->InputFieldValueSet(
Element => "#$Field->{OptionField}",
Value => $Field->{OptionValuePre},
);
}
# Verify field is hidden.
$Self->Is(
$Selenium->execute_script(
"return \$('.$Field->{CheckField}').hasClass('Hidden')"
),
1,
"$Field->{CheckField} field is hidden",
);
# Change field to trigger JS.
$Selenium->InputFieldValueSet(
Element => "#$Field->{OptionField}",
Value => $Field->{OptionValue},
);
# Verify JS removed Hidden class, fields are shown.
$Self->Is(
$Selenium->execute_script(
"return \$('.$Field->{CheckField}').hasClass('Hidden')"
),
0,
"$Field->{CheckField} field is shown",
);
}
# Input fields.
my %RequesterInputData = (
Host => 'TransportHost-' . $RandomID,
BasicAuthUser => 'User' . $RandomID,
BasicAuthPassword => 'Pass' . $RandomID,
ProxyHost => 'http://proxy_hostname:8080',
ProxyUser => 'SSLUser' . $RandomID,
ProxyPassword => 'SSLPass' . $RandomID,
SSLCertificate => $Home . '/scripts/test/sample/SSL/certificate.pem',
SSLKey => $Home . '/scripts/test/sample/SSL/certificate.key.pem',
SSLPassword => 'SSLPass' . $RandomID,
SSLCAFile => $Home . '/scripts/test/sample/SSL/ca-certificate.pem',
SSLCADir => $Home . '/scripts/test/sample/SSL/',
);
for my $InputField ( sort keys %RequesterInputData ) {
$Selenium->find_element( "#$InputField", 'css' )->send_keys( $RequesterInputData{$InputField} );
}
# Click on 'Save'.
$Selenium->find_element( "#SubmitAndContinue", 'css' )->VerifiedClick();
# Verify URL is changed while we are on the same screen.
$Self->True(
$Selenium->get_current_url() =~ /Action=AdminGenericInterfaceTransportHTTPREST;Subaction=Change/,
"Current URL after 'Save' button click is correct"
);
# Verify saved fields.
for my $VerifyField ( sort keys %RequesterInputData ) {
$Self->Is(
$Selenium->find_element( "#$VerifyField", 'css' )->get_value(),
$RequesterInputData{$VerifyField},
"Inputed value for $VerifyField field is correct"
);
}
# Click on 'Save and finish' verify JS redirection.
$Selenium->find_element( "#Submit", 'css' )->VerifiedClick();
$Self->True(
$Selenium->get_current_url() =~ /Action=AdminGenericInterfaceWebservice/,
"Click on 'Save and finish' button - JS is successful"
);
# Delete test created web service.
my $Success = $WebserviceObject->WebserviceDelete(
ID => $WebserviceID,
UserID => 1,
);
$Self->True(
$Success,
"Web service ID $WebserviceID is deleted"
);
# Make sure cache is correct.
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp( Type => 'Webservice' );
}
);
$Self->DoneTesting();