File: Test-zone11.t

package info (click to toggle)
libzonemaster-perl 7.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,672 kB
  • sloc: perl: 16,806; makefile: 16
file content (241 lines) | stat: -rw-r--r-- 5,498 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
use strict;
use warnings;
use utf8;

use Test::More;
use File::Basename;
use File::Spec::Functions qw( rel2abs );
use lib dirname( rel2abs( $0 ) );

BEGIN {
    use_ok( q{Zonemaster::Engine} );
    use_ok( q{Zonemaster::Engine::Test::Zone} );
    use_ok( q{TestUtil}, qw( perform_testcase_testing ) );
}

my $test_module = q{ZONE};
my $test_case = 'zone11';
my @all_tags = qw(Z11_INCONSISTENT_SPF_POLICIES
                  Z11_DIFFERENT_SPF_POLICIES_FOUND
                  Z11_NO_SPF_FOUND
                  Z11_SPF1_MULTIPLE_RECORDS
                  Z11_SPF1_SYNTAX_ERROR
                  Z11_SPF1_SYNTAX_OK
                  Z11_UNABLE_TO_CHECK_FOR_SPF);

# Root hints
Zonemaster::Engine::Recursor->remove_fake_addresses( '.' );
Zonemaster::Engine::Recursor->add_fake_addresses( '.', {'ibdns.root-servers.net' => ['10.1.72.23']} );

# Test zone scenarios
# - Documentation: L<TestUtil/perform_testcase_testing()>
# - Format: { SCENARIO_NAME => [
#     testable,
#     zone_name,
#     [ MANDATORY_MESSAGE_TAGS ],
#     [ FORBIDDEN_MESSAGE_TAGS ],
#     [ UNDELEGATED_NS ],
#     [ UNDELEGATED_DS ],
#   ] }
#
# - One of MANDATORY_MESSAGE_TAGS and FORBIDDEN_MESSAGE_TAGS may be undefined.
#   See documentation for the meaning of that.

my %subtests = (
    'NO-TXT' => [
        1,
        q(no-txt.zone11.xa),
        [ qw(Z11_NO_SPF_FOUND) ],
        undef,
        [],
        []
    ],
    'NO-SPF-TXT' => [
        1,
        q(no-spf-txt.zone11.xa),
        [ qw(Z11_NO_SPF_FOUND) ],
        undef,
        [],
        []
    ],
    'NON-AUTH-TXT' => [
        1,
        q(non-auth-txt.zone11.xa),
        [ qw(Z11_UNABLE_TO_CHECK_FOR_SPF) ],
        undef,
        [],
        []
    ],
    'NONEXISTENT' => [
        1,
        q(nonexistent.zone11.xa),
        [ qw(Z11_UNABLE_TO_CHECK_FOR_SPF) ],
        undef,
        [],
        []
    ],
    'INCONSISTENT-SPF' => [
        1,
        q(inconsistent-spf.zone11.xa),
        [ qw(Z11_INCONSISTENT_SPF_POLICIES Z11_DIFFERENT_SPF_POLICIES_FOUND) ],
        undef,
        [],
        []
    ],
    'SPF-MISSING-ON-ONE' => [
        1,
        q(spf-missing-on-one.zone11.xa),
        [ qw(Z11_INCONSISTENT_SPF_POLICIES Z11_DIFFERENT_SPF_POLICIES_FOUND) ],
        undef,
        [],
        []
    ],
    'ALL-DIFFERENT-SPF' => [
        1,
        q(all-different-spf.zone11.xa),
        [ qw(Z11_INCONSISTENT_SPF_POLICIES Z11_DIFFERENT_SPF_POLICIES_FOUND) ],
        undef,
        [],
        []
    ],
    'MULTIPLE-SPF-RECORDS' => [
        1,
        q(multiple-spf-records.zone11.xa),
        [ qw(Z11_SPF1_MULTIPLE_RECORDS) ],
        undef,
        [],
        []
    ],
    'INVALID-SYNTAX' => [
        1,
        q(invalid-syntax.zone11.xa),
        [ qw(Z11_SPF1_SYNTAX_ERROR) ],
        undef,
        [],
        []
    ],
    'RANDOM-BYTES' => [
        1,
        q(random-bytes.zone11.xa),
        [ qw(Z11_SPF1_SYNTAX_ERROR) ],
        undef,
        [],
        []
    ],
    'TWO-REDIRECTS' => [
        1,
        q(two-redirects.zone11.xa),
        [ qw(Z11_SPF1_SYNTAX_ERROR) ],
        undef,
        [],
        []
    ],
    'TWO-EXPS' => [
        1,
        q(two-exps.zone11.xa),
        [ qw(Z11_SPF1_SYNTAX_ERROR) ],
        undef,
        [],
        []
    ],
    'TRIVIAL-SPF' => [
        1,
        q(trivial-spf.zone11.xa),
        [ qw(Z11_SPF1_SYNTAX_OK) ],
        undef,
        [],
        []
    ],
    'VALID-SPF' => [
        1,
        q(valid-spf.zone11.xa),
        [ qw(Z11_SPF1_SYNTAX_OK) ],
        undef,
        [],
        []
    ],
    'REDIRECT-NON-FINAL' => [
        1,
        q(redirect-non-final.zone11.xa),
        [ qw(Z11_SPF1_SYNTAX_OK) ],
        undef,
        [],
        []
    ],
    'REDIRECT-AND-ALL' => [
        1,
        q(redirect-and-all.zone11.xa),
        [ qw(Z11_SPF1_SYNTAX_OK) ],
        undef,
        [],
        []
    ],
    'CONTAINS-PTR' => [
        1,
        q(contains-ptr.zone11.xa),
        [ qw(Z11_SPF1_SYNTAX_OK) ],
        undef,
        [],
        []
    ],
    'CONTAINS-P-MACRO' => [
        1,
        q(contains-p-macro.zone11.xa),
        [ qw(Z11_SPF1_SYNTAX_OK) ],
        undef,
        [],
        []
    ],
    'CONTAINS-PR-MACRO' => [
        1,
        q(contains-pr-macro.zone11.xa),
        [ qw(Z11_SPF1_SYNTAX_OK) ],
        undef,
        [],
        []
    ],
    'TOO-COMPLEX' => [
        1,
        q(too-complex.zone11.xa),
        [ qw(Z11_SPF1_SYNTAX_OK) ],
        undef,
        [],
        []
    ],
    'CONTAINS-INCLUDE' => [
        1,
        q(contains-include.zone11.xa),
        [ qw(Z11_SPF1_SYNTAX_OK) ],
        undef,
        [],
        []
    ],
    'CONTAINS-REDIRECT' => [
        1,
        q(contains-redirect.zone11.xa),
        [ qw(Z11_SPF1_SYNTAX_OK) ],
        undef,
        [],
        []
    ],
);

###########

my $datafile = 't/' . basename ($0, '.t') . '.data';

if ( not $ENV{ZONEMASTER_RECORD} ) {
    die q{Stored data file missing} if not -r $datafile;
    Zonemaster::Engine::Nameserver->restore( $datafile );
    Zonemaster::Engine::Profile->effective->set( q{no_network}, 1 );
}

Zonemaster::Engine::Profile->effective->merge( Zonemaster::Engine::Profile->from_json( qq({ "test_cases": [ "$test_case" ] }) ) );

perform_testcase_testing( $test_case, $test_module, \@all_tags, \%subtests, $ENV{ZONEMASTER_SINGLE_SCENARIO}, $ENV{ZONEMASTER_DISABLE_SCENARIO} );

if ( $ENV{ZONEMASTER_RECORD} ) {
    Zonemaster::Engine::Nameserver->save( $datafile );
}

done_testing;