/usr/share/otrs/scripts/test/Layout.t is in otrs2 3.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | # --
# scripts/test/Layout.t - layout module testscript
# Copyright (C) 2001-2014 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
use strict;
use warnings;
use utf8;
use vars (qw($Self %Param));
use Kernel::System::AuthSession;
use Kernel::System::Web::Request;
use Kernel::System::Group;
use Kernel::System::Ticket;
use Kernel::System::User;
use Kernel::Output::HTML::Layout;
# create local objects
my $SessionObject = Kernel::System::AuthSession->new( %{$Self} );
my $GroupObject = Kernel::System::Group->new( %{$Self} );
my $TicketObject = Kernel::System::Ticket->new( %{$Self} );
my $UserObject = Kernel::System::User->new( %{$Self} );
my $ParamObject = Kernel::System::Web::Request->new(
%{$Self},
WebRequest => $Param{WebRequest} || 0,
);
my $LayoutObject = Kernel::Output::HTML::Layout->new(
ConfigObject => $Self->{ConfigObject},
LogObject => $Self->{LogObject},
TimeObject => $Self->{TimeObject},
MainObject => $Self->{MainObject},
EncodeObject => $Self->{EncodeObject},
SessionObject => $SessionObject,
DBObject => $Self->{DBObject},
ParamObject => $ParamObject,
TicketObject => $TicketObject,
UserObject => $UserObject,
GroupObject => $GroupObject,
UserChallengeToken => 'TestToken',
UserID => 1,
Lang => 'de',
SessionID => 123,
);
# here everyone can insert example data for the tests
my %Data = (
Created => '2007-11-30 08:58:54',
CreateTime => '2007-11-30 08:58:54',
ChangeTime => '2007-11-30 08:58:54',
TicketFreeTime => '2007-11-30 08:58:54',
TicketFreeTime1 => '2007-11-30 08:58:54',
TicketFreeTime2 => '2007-11-30 08:58:54',
TimeStartMax => '2007-11-30 08:58:54',
TimeStopMax => '2007-11-30 08:58:54',
UpdateTimeDestinationDate => '2007-11-30 08:58:54',
Body => "What do you\n mean with body?"
);
my $StartTime = time();
# --------------------------------------------------------------------#
# Search for $Data{""} etc. because this is the most dangerous bug if you
# modify the Output funciton
# --------------------------------------------------------------------#
# check the header
my $Header = $LayoutObject->Header( Title => 'HeaderTest' );
my $HeaderFlag = 1;
if (
$Header =~ m{ \$ (QData|LQData|Data|Env|QEnv|Config|Include) }msx
|| $Header =~ m{ <dtl \W if }msx
)
{
$HeaderFlag = 0;
}
$Self->True(
$HeaderFlag,
'Header() check the output for not replaced variables',
);
# check the navigation bar
my $NavigationBar = $LayoutObject->NavigationBar();
my $NavigationFlag = 1;
if (
$NavigationBar =~ m{ \$ (QData|LQData|Data|Env|QEnv|Config|Include) }msx
|| $NavigationBar =~ m{ <dtl \W if }msx
)
{
$NavigationFlag = 0;
}
$Self->True(
$NavigationFlag,
'NavigationBar() check the output for not replaced variables',
);
# check the footer
my $Footer = $LayoutObject->Footer();
my $FooterFlag = 1;
if (
$Footer =~ m{ \$ (QData|LQData|Data|Env|QEnv|Config|Include) }msx
|| $Footer =~ m{ <dtl \W if }msx
)
{
$FooterFlag = 0;
}
$Self->True(
$FooterFlag,
'Footer() check the output for not replaced variables',
);
# check all dtl files
my $HomeDirectory = $Self->{ConfigObject}->Get('Home');
my $DTLDirectory = $HomeDirectory . '/Kernel/Output/HTML/Standard/';
my $DIR;
if ( !opendir $DIR, $DTLDirectory ) {
print "Can not open Directory: $DTLDirectory";
return;
}
my @Files = ();
while ( defined( my $Filename = readdir $DIR ) ) {
if ( $Filename =~ m{ \. dtl $}xms ) {
push( @Files, "$DTLDirectory/$Filename" )
}
}
closedir $DIR;
for my $File (@Files) {
if ( $File =~ m{ / ( [^/]+ ) \. dtl}smx ) {
my $DTLName = $1;
# find all blocks auf the dtl files
my $ContentARRAYRef = $Self->{MainObject}->FileRead(
Location => $File,
Result => 'ARRAY'
);
my @Blocks = ();
my %DoubleBlockChecker = ();
for my $Line ( @{$ContentARRAYRef} ) {
if ( $Line =~ m{ <!-- \s{0,1} dtl:block: (.+?) \s{0,1} --> }smx ) {
if ( !$DoubleBlockChecker{$1} ) {
push @Blocks, $1;
}
}
}
# call all blocks
for my $Block (@Blocks) {
# do it three times (its more realistic)
for ( 1 .. 3 ) {
$LayoutObject->Block(
Name => $Block,
Data => \%Data,
);
}
}
# call the output function
my $Output = $LayoutObject->Output(
TemplateFile => $DTLName,
Data => \%Data,
);
my $OutputFlag = 1;
if (
$Output =~ m{ \$ (QData|LQData|Data|Env|QEnv|Config|Include) \{" }msx
|| $Output =~ m{ <dtl \W if }msx
)
{
$OutputFlag = 0;
}
$Self->True(
$OutputFlag,
"Output() check the output for not replaced variables in $DTLName",
);
}
}
# html link quoting of html
my @Tests = (
{
Name => 'HTMLLinkQuote() - simple',
String => 'some Text',
Result => 'some Text',
},
{
Name => 'HTMLLinkQuote() - simple',
String => 'some <a name="top">Text',
Result => 'some <a name="top">Text',
},
{
Name => 'HTMLLinkQuote() - extended',
String => 'some <a href="http://example.com">Text</a>',
Result => 'some <a href="http://example.com" target="_blank">Text</a>',
},
{
Name => 'HTMLLinkQuote() - extended',
String => 'some <a
href="http://example.com">Text</a>',
Result => 'some <a
href="http://example.com" target="_blank">Text</a>',
},
{
Name => 'HTMLLinkQuote() - extended',
String => 'some <a href="http://example.com" target="somewhere">Text</a>',
Result => 'some <a href="http://example.com" target="somewhere">Text</a>',
},
{
Name => 'HTMLLinkQuote() - extended',
String => 'some <a href="http://example.com" target="somewhere">http://example.com</a>',
Result => 'some <a href="http://example.com" target="somewhere">http://example.com</a>',
},
);
for my $Test (@Tests) {
my $HTML = $LayoutObject->HTMLLinkQuote(
String => $Test->{String},
);
$Self->Is(
$HTML || '',
$Test->{Result},
$Test->{Name},
);
}
# this check is only to display how long it had take
$Self->True(
1,
"Layout.t - to handle the whole test file it takes " . ( time() - $StartTime ) . " seconds.",
);
# rich text tests
@Tests = (
{
Name => '_RichTextReplaceLinkOfInlineContent() - generated by outlook',
String =>
'<img alt="" src="/otrs-cvs/otrs-cvs/bin/cgi-bin/index.pl?Action=PictureUpload&FormID=1255961382.1012148.29113074&ContentID=<734083011@19102009-1795>" />',
Result => '<img alt="" src="cid:<734083011@19102009-1795>" />',
},
{
Name => '_RichTextReplaceLinkOfInlineContent() - generated itself',
String =>
'<img width="343" height="563" alt="" src="/otrs-cvs/otrs-cvs/bin/cgi-bin/index.pl?Action=PictureUpload&FormID=1255961382.1012148.29113074&ContentID=inline244217.547683276.1255961382.1012148.29113074@vo7.vo.otrs.com" />',
Result =>
'<img width="343" height="563" alt="" src="cid:inline244217.547683276.1255961382.1012148.29113074@vo7.vo.otrs.com" />',
},
{
Name => '_RichTextReplaceLinkOfInlineContent() - generated itself, with newline',
String =>
"<img width=\"343\" height=\"563\" alt=\"\"\nsrc=\"/otrs-cvs/otrs-cvs/bin/cgi-bin/index.pl?Action=PictureUpload&FormID=1255961382.1012148.29113074&ContentID=inline244217.547683276.1255961382.1012148.29113074\@vo7.vo.otrs.com\" />",
Result =>
"<img width=\"343\" height=\"563\" alt=\"\"\nsrc=\"cid:inline244217.547683276.1255961382.1012148.29113074\@vo7.vo.otrs.com\" />",
},
{
Name =>
'_RichTextReplaceLinkOfInlineContent() - generated itself, with internal and external image',
String =>
'<img width="140" vspace="10" hspace="1" height="38" border="0" alt="AltText" src="http://www.otrs.com/fileadmin/templates/skins/skin_otrs/css/images/logo.gif" /> This text should be displayed <img width="400" height="81" border="0" alt="Description: cid:image001.jpg@01CC3AFE.F81F0B30" src="/otrs/index.pl?Action=PictureUpload&FormID=1311080525.12118416.3676164&ContentID=image001.jpg@01CC4216.1E22E9A0" id="Picture_x0020_1" />',
Result =>
'<img width="140" vspace="10" hspace="1" height="38" border="0" alt="AltText" src="http://www.otrs.com/fileadmin/templates/skins/skin_otrs/css/images/logo.gif" /> This text should be displayed <img width="400" height="81" border="0" alt="Description: cid:image001.jpg@01CC3AFE.F81F0B30" src="cid:image001.jpg@01CC4216.1E22E9A0" id="Picture_x0020_1" />',
},
{
Name =>
'_RichTextReplaceLinkOfInlineContent() - generated itself, with internal and external image, no space before />',
String =>
'<img width="140" vspace="10" hspace="1" height="38" border="0" alt="AltText" src="http://www.otrs.com/fileadmin/templates/skins/skin_otrs/css/images/logo.gif" /> This text should be displayed <img width="400" height="81" border="0" alt="Description: cid:image001.jpg@01CC3AFE.F81F0B30" src="/otrs/index.pl?Action=PictureUpload&FormID=1311080525.12118416.3676164&ContentID=image001.jpg@01CC4216.1E22E9A0" id="Picture_x0020_1"/>',
Result =>
'<img width="140" vspace="10" hspace="1" height="38" border="0" alt="AltText" src="http://www.otrs.com/fileadmin/templates/skins/skin_otrs/css/images/logo.gif" /> This text should be displayed <img width="400" height="81" border="0" alt="Description: cid:image001.jpg@01CC3AFE.F81F0B30" src="cid:image001.jpg@01CC4216.1E22E9A0" id="Picture_x0020_1"/>',
},
);
for my $Test (@Tests) {
my $HTML = $LayoutObject->_RichTextReplaceLinkOfInlineContent(
String => \$Test->{String},
);
$Self->Is(
${$HTML} || '',
$Test->{Result},
$Test->{Name},
);
}
# Tests for _RemoveScriptTags method
@Tests = (
{
Input => '',
Result => '',
Name => '_RemoveScriptTags - empty test',
},
{
Input => '<script type="text/javascript"></script>',
Result => '',
Name => '_RemoveScriptTags - just tags test',
},
{
Input => '
<script type="text/javascript">
123
// 456
789
</script>',
Result => '
123
// 456
789
',
Name => '_RemoveScriptTags - some content test',
},
{
Input => '
<script type="text/javascript">//<![CDATA[
OTRS.UI.Tables.InitTableFilter($(\'#FilterCustomers\'), $(\'#Customers\'));
OTRS.UI.Tables.InitTableFilter($(\'#FilterGroups\'), $(\'#Groups\'));
//]]></script>
',
Result => '
OTRS.UI.Tables.InitTableFilter($(\'#FilterCustomers\'), $(\'#Customers\'));
OTRS.UI.Tables.InitTableFilter($(\'#FilterGroups\'), $(\'#Groups\'));
',
Name => '_RemoveScriptTags - complete content test',
},
{
Input => <<'EOF',
<!--DocumentReadyActionRowAdd-->
<script type="text/javascript"> //<![CDATA[
alert();
//]]></script>
<!--/DocumentReadyActionRowAdd-->
<!--DocumentReadyStart-->
<script type="text/javascript">// <![CDATA[
alert();
//]]></script>
<!--/DocumentReadyStart-->
EOF
Result => <<"EOF",
alert();
\n
alert();
EOF
Name => '_RemoveScriptTags - complete content test with block comments',
},
{
Input => <<'EOF',
<script type="text/javascript"> //<![CDATA[
<!--DocumentReadyActionRowAdd-->
alert();
<!--/DocumentReadyActionRowAdd-->
//]]></script>
EOF
Result => <<"EOF",
alert();
EOF
Name =>
'_RemoveScriptTags - complete content test with block comments inside the script tags',
},
);
for my $Test (@Tests) {
my $LRST = $LayoutObject->_RemoveScriptTags(
Code => $Test->{Input},
);
$Self->Is(
$LRST,
$Test->{Result},
$Test->{Name},
);
}
my @LinkEncodeTests = (
{ Source => '%', Target => '%25', },
{ Source => '&', Target => '%26', },
{ Source => '=', Target => '%3D', },
{ Source => '!', Target => '%21', },
{ Source => '"', Target => '%22', },
{ Source => '#', Target => '%23', },
{ Source => '$', Target => '%24', },
{ Source => '\'', Target => '%27', },
{ Source => ',', Target => '%2C', },
{ Source => '+', Target => '%2B', },
{ Source => '?', Target => '%3F', },
{ Source => '|', Target => '%7C', },
{ Source => '/', Target => '%2F', },
# According to the URL encoding RFC, the path segment of an URL must use %20 for space,
# while in the query string + is used normally. However, IIS does not understand + in the
# path segment, but understands %20 in the query string, like all others do as well.
# Therefore we use %20.
{ Source => ' ', Target => '%20', },
{ Source => ':', Target => '%3A', },
{ Source => ';', Target => '%3B', },
{ Source => '@', Target => '%40', },
# LinkEncode() on reserved characters
{
Source => '!*\'();:@&=+$,/?#[]',
Target => '%21%2A%27%28%29%3B%3A%40%26%3D%2B%24%2C%2F%3F%23%5B%5D',
},
# LinkEncode() on common characters
{
Source => '<>"{}|\`^% ',
Target => '%3C%3E%22%7B%7D%7C%5C%60%5E%25%20',
},
# LinkEncode() on normal characters
{
Source => 'normaltext123',
Target => 'normaltext123',
},
);
for my $LinkEncodeTest (@LinkEncodeTests) {
$Self->Is(
$LayoutObject->LinkEncode( $LinkEncodeTest->{Source} ),
$LinkEncodeTest->{Target},
"LinkEncode from '$LinkEncodeTest->{Source}' to '$LinkEncodeTest->{Target}'",
);
}
1;
|