Bug 24879: Use perl shebang to list the exec
[koha.git] / xt / find-missing-auth_checks.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19 use Test::More;
20
21 use File::Slurp qw(read_file);
22
23 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 );
24 push @excluded_paths, 'opac'; # We cannot test the OPAC scripts, some can be accessed without authentication
25
26 my $grep_cmd      = q{git grep -l '#!/usr/bin/perl' -- } . join( ' ', map { qq{':!$_'} } @excluded_paths );
27 my @files         = `$grep_cmd`;
28
29 my @missing_auth_check;
30 FILE: foreach my $file (@files) {
31     chomp $file;
32     my @lines = read_file($file);
33     for my $line ( @lines ) {
34         for my $routine ( qw( get_template_and_user check_cookie_auth checkauth check_api_auth C4::Service->init ) ) {
35             next FILE if $line =~ m|^[^#]*$routine|;
36         }
37     }
38     push @missing_auth_check, $file;
39 }
40 is( scalar @missing_auth_check, 0 ) or diag "No auth check in the following files:\n" . join "\n", @missing_auth_check;
41 done_testing;