Bug 36792: Limit POSIX imports
[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 =
24     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 koha_perl_deps.pl );
25 push @excluded_paths, 'opac';    # We cannot test the OPAC scripts, some can be accessed without authentication
26
27 my $grep_cmd = q{git grep -l '#!/usr/bin/perl' -- } . join( ' ', map { qq{':!$_'} } @excluded_paths );
28 my @files    = `$grep_cmd`;
29
30 my @missing_auth_check;
31 FILE: foreach my $file (@files) {
32     chomp $file;
33     my @lines = read_file($file);
34     for my $line (@lines) {
35         for my $routine (qw( get_template_and_user check_cookie_auth checkauth check_api_auth C4::Service->init )) {
36             next FILE if $line =~ m|^[^#]*$routine|;
37         }
38     }
39     push @missing_auth_check, $file;
40 }
41 is( scalar @missing_auth_check, 0 ) or diag "No auth check in the following files:\n" . join "\n", @missing_auth_check;
42 done_testing;