From e4f37ad6a09e97b83bb94642d879dc93ba2dbff6 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 14 Mar 2024 16:53:35 +0100 Subject: [PATCH] Bug 24879: Use perl shebang to list the exec Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- xt/find-missing-auth_checks.t | 50 +++++++---------------------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/xt/find-missing-auth_checks.t b/xt/find-missing-auth_checks.t index 77909bd5c9..d86fab2917 100755 --- a/xt/find-missing-auth_checks.t +++ b/xt/find-missing-auth_checks.t @@ -18,54 +18,24 @@ use Modern::Perl; use Test::More; -use File::Spec; -use File::Find; +use File::Slurp qw(read_file); -my @files; -sub wanted { - my $name = $File::Find::name; - push @files, $name - if $name =~ m{^\./( - acqui - |admin - |authorities - |basket - |catalogue - |cataloguing - |circ - |clubs - |course_reserves - |labels - |members - |patroncards - |pos - |reports - |reserve - |reviews - |rotating_collections - |serials - |services - |suggestion - |svc - |tags - |tools - |virtualshelves - )}xms - && $name =~ m{\.(pl)$} - && -f $name; -} +my @excluded_paths = qw(C4 debian docs etc installer/data install_misc Koha misc selenium t test tmp xt changelanguage.pl build-resources.PL fix-perl-path.PL ); +push @excluded_paths, 'opac'; # We cannot test the OPAC scripts, some can be accessed without authentication -find({ wanted => \&wanted, no_chdir => 1 }, File::Spec->curdir()); +my $grep_cmd = q{git grep -l '#!/usr/bin/perl' -- } . join( ' ', map { qq{':!$_'} } @excluded_paths ); +my @files = `$grep_cmd`; my @missing_auth_check; -FILE: foreach my $name (@files) { - open( FILE, $name ) || die "cannot open file $name $!"; - while ( my $line = ) { +FILE: foreach my $file (@files) { + chomp $file; + my @lines = read_file($file); + for my $line ( @lines ) { for my $routine ( qw( get_template_and_user check_cookie_auth checkauth check_api_auth C4::Service->init ) ) { next FILE if $line =~ m|^[^#]*$routine|; } } - push @missing_auth_check, $name; + push @missing_auth_check, $file; } is( scalar @missing_auth_check, 0 ) or diag "No auth check in the following files:\n" . join "\n", @missing_auth_check; done_testing; -- 2.39.5