|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2026 Koha development team |
| 4 |
# |
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <https://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
use Test::More tests => 3; |
| 22 |
use Test::NoWarnings; |
| 23 |
use File::Slurp; |
| 24 |
use Data::Dumper; |
| 25 |
|
| 26 |
use Koha::Devel::Files; |
| 27 |
|
| 28 |
my $dev_files = Koha::Devel::Files->new; |
| 29 |
my @files = $dev_files->ls_tt_files; |
| 30 |
ok( @files > 0, 'We should test something' ); |
| 31 |
|
| 32 |
my @errors; |
| 33 |
for my $file (@files) { |
| 34 |
my @e = catch_missing_nonce($file); |
| 35 |
push @errors, sprintf "%s:%s", $file, join( ",", @e ) if @e; |
| 36 |
} |
| 37 |
|
| 38 |
is( |
| 39 |
@errors, 0, |
| 40 |
"Not all <script> or <style> tags in the following files have 'nonce' attribute (see bug 38365)" |
| 41 |
) or diag( Dumper @errors ); |
| 42 |
|
| 43 |
sub catch_missing_nonce { |
| 44 |
my ($file) = @_; |
| 45 |
|
| 46 |
my @lines = read_file($file); |
| 47 |
my @errors; |
| 48 |
return unless grep { $_ =~ m[<(script|style)] } @lines; |
| 49 |
my $line_number = 0; |
| 50 |
for my $line (@lines) { |
| 51 |
$line_number++; |
| 52 |
if ( $line =~ m{<script} && $line !~ m{<script nonce=} && $line !~ m{src="} ) { |
| 53 |
next if $line =~ m{Babeltheque_url_js}; # Exception |
| 54 |
push @errors, "$line_number: $line"; |
| 55 |
} |
| 56 |
if ( $line =~ m{<style} && $line !~ m{<style nonce=} ) { |
| 57 |
push @errors, "$line_number: $line"; |
| 58 |
} |
| 59 |
|
| 60 |
} |
| 61 |
return @errors; |
| 62 |
} |