]> eyrie.org Git - kerberos/krb5-strength.git/blob - tests/docs/urls-t
Change CrackLib tests for system CrackLib
[kerberos/krb5-strength.git] / tests / docs / urls-t
1 #!/usr/bin/perl
2 #
3 # Check URLs in source files.
4 #
5 # Examine all source files in a distribution for bad URL patterns and report
6 # on files that fail this check.  Currently, this just checks that all the
7 # links to www.eyrie.org are https.
8 #
9 # The canonical version of this file is maintained in the rra-c-util package,
10 # which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
11 #
12 # Copyright 2016 Russ Allbery <eagle@eyrie.org>
13 #
14 # Permission is hereby granted, free of charge, to any person obtaining a
15 # copy of this software and associated documentation files (the "Software"),
16 # to deal in the Software without restriction, including without limitation
17 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 # and/or sell copies of the Software, and to permit persons to whom the
19 # Software is furnished to do so, subject to the following conditions:
20 #
21 # The above copyright notice and this permission notice shall be included in
22 # all copies or substantial portions of the Software.
23 #
24 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
27 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 # DEALINGS IN THE SOFTWARE.
31
32 use 5.006;
33 use strict;
34 use warnings;
35
36 use lib "$ENV{C_TAP_SOURCE}/tap/perl";
37
38 use File::Basename qw(basename);
39 use Test::More;
40 use Test::RRA qw(skip_unless_author);
41 use Test::RRA::Automake qw(all_files automake_setup);
42
43 # Bad patterns to search for.
44 my @BAD_REGEXES = (qr{ http:// \S+ [.]eyrie[.]org }xms);
45 my @BAD_STRINGS = qw(rra@stanford.edu);
46
47 # Only run this test for the package author, since it doesn't indicate any
48 # user-noticable flaw in the package itself.
49 skip_unless_author('Documentation URL tests');
50
51 # Set up Automake testing.
52 automake_setup();
53
54 # Check a single file for one of the bad patterns.
55 #
56 # $path - Path to the file
57 #
58 # Returns: undef
59 sub check_file {
60     my ($path) = @_;
61     my $filename = basename($path);
62
63     # Ignore this check itself (or the Perl version of it) and binary files.
64     return if ($filename eq 'urls.t' || $filename eq 'urls-t');
65     return if !-T $path;
66
67     # Scan the file.
68     open(my $fh, '<', $path) or BAIL_OUT("Cannot open $path");
69     while (defined(my $line = <$fh>)) {
70         for my $regex (@BAD_REGEXES) {
71             if ($line =~ $regex) {
72                 ok(0, "$path contains $regex");
73                 close($fh) or BAIL_OUT("Cannot close $path");
74                 return;
75             }
76         }
77         for my $string (@BAD_STRINGS) {
78             if (index($line, $string) != -1) {
79                 ok(0, "$path contains $string");
80                 close($fh) or BAIL_OUT("Cannot close $path");
81                 return;
82             }
83         }
84     }
85     close($fh) or BAIL_OUT("Cannot close $path");
86     ok(1, $path);
87     return;
88 }
89
90 # Scan every file for any of the bad patterns or strings.  We don't declare a
91 # plan since we skip a lot of files and don't want to precalculate the file
92 # list.
93 my @paths = all_files();
94 for my $path (@paths) {
95     check_file($path);
96 }
97 done_testing();