Bug 34478: Fix xt/find-missing-csrf.t

It was reporting false positives.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2024-02-06 11:26:05 +01:00
parent 93e3fed043
commit fad58b08ba
No known key found for this signature in database
GPG Key ID: A085E712BEF0E0F0
1 changed files with 7 additions and 6 deletions

View File

@ -66,16 +66,17 @@ sub check_csrf_in_forms {
my @errors;
return @errors unless grep { $_ =~ m|<form| } @lines;
my ( $open, $found ) = ( 0, 0 );
my $line = 0 ;
for my $l (@lines) {
$line++;
$open = $line if ( $l =~ m{<form} && !( $l =~ m{method=('|")get('|")} ) );
$found++ if ( $l =~ m|csrf\-token\.inc| && $open );
if ( $open && $l =~ m|</form| ) {
my $line_number = 0 ;
for my $line (@lines) {
$line_number++;
$open = $line_number if $line =~ m{<form.*method=('|")post('|")}i;
$found++ if $open && $line =~ m{csrf-token\.inc};
if ( $open && $line =~ m{</form} ) {
push @errors,
"The <form> starting on line $open is missing it's corresponding csrf_token include (see bug 22990)"
if !$found;
$found = 0;
undef $open;
}
}
return @errors;