@@ -, +, @@ --- xt/find-missing-auth_checks.t | 50 +++++++---------------------------- 1 file changed, 10 insertions(+), 40 deletions(-) --- a/xt/find-missing-auth_checks.t +++ a/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; --