View | Details | Raw Unified | Return to bug 24879
Collapse All | Expand All

(-)a/xt/find-missing-auth_checks.t (-41 / +10 lines)
Lines 18-71 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
use Test::More;
19
use Test::More;
20
20
21
use File::Spec;
21
use File::Slurp qw(read_file);
22
use File::Find;
23
22
24
my @files;
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 );
25
sub wanted {
24
push @excluded_paths, 'opac'; # We cannot test the OPAC scripts, some can be accessed without authentication
26
    my $name = $File::Find::name;
27
    push @files, $name
28
      if $name =~ m{^\./(
29
           acqui
30
          |admin
31
          |authorities
32
          |basket
33
          |catalogue
34
          |cataloguing
35
          |circ
36
          |clubs
37
          |course_reserves
38
          |labels
39
          |members
40
          |patroncards
41
          |pos
42
          |reports
43
          |reserve
44
          |reviews
45
          |rotating_collections
46
          |serials
47
          |services
48
          |suggestion
49
          |svc
50
          |tags
51
          |tools
52
          |virtualshelves
53
        )}xms
54
      && $name =~ m{\.(pl)$}
55
      && -f $name;
56
}
57
25
58
find({ wanted => \&wanted, no_chdir => 1 }, File::Spec->curdir());
26
my $grep_cmd      = q{git grep -l '#!/usr/bin/perl' -- } . join( ' ', map { qq{':!$_'} } @excluded_paths );
27
my @files         = `$grep_cmd`;
59
28
60
my @missing_auth_check;
29
my @missing_auth_check;
61
FILE: foreach my $name (@files) {
30
FILE: foreach my $file (@files) {
62
    open( FILE, $name ) || die "cannot open file $name $!";
31
    chomp $file;
63
    while ( my $line = <FILE> ) {
32
    my @lines = read_file($file);
33
    for my $line ( @lines ) {
64
        for my $routine ( qw( get_template_and_user check_cookie_auth checkauth check_api_auth C4::Service->init ) ) {
34
        for my $routine ( qw( get_template_and_user check_cookie_auth checkauth check_api_auth C4::Service->init ) ) {
65
            next FILE if $line =~ m|^[^#]*$routine|;
35
            next FILE if $line =~ m|^[^#]*$routine|;
66
        }
36
        }
67
    }
37
    }
68
    push @missing_auth_check, $name;
38
    push @missing_auth_check, $file;
69
}
39
}
70
is( scalar @missing_auth_check, 0 ) or diag "No auth check in the following files:\n" . join "\n", @missing_auth_check;
40
is( scalar @missing_auth_check, 0 ) or diag "No auth check in the following files:\n" . join "\n", @missing_auth_check;
71
done_testing;
41
done_testing;
72
- 

Return to bug 24879