#!/usr/bin/perl -w -T
use
SATest; sa_t_init(
"rule_names"
);
BEGIN {
eval
{
require
Digest::SHA; Digest::SHA->
import
(
qw(sha1)
); 1 }
or
do
{
require
Digest::SHA1; Digest::SHA1->
import
(
qw(sha1)
) }
}
our
$RUN_THIS_TEST
;
plan
skip_all
=>
"This test requires 'run_rule_name_tests' set to 'y'."
unless
conf_bool(
'run_rule_name_tests'
);
use
vars
qw(%patterns %anti_patterns)
;
my
$sa
= create_saobj({
'dont_copy_prefs'
=> 1});
$sa
->{conf}->{allow_user_rules} = 1;
$sa
->init(0);
my
@tests
;
while
(
my
(
$test
,
$type
) =
each
%{
$sa
->{conf}->{test_types} }) {
push
@tests
,
$test
;
}
my
$mail
=
"$workdir/rule_names.eml"
;
write_mail();
%patterns
= ();
my
$i
= 1;
for
my
$test
(
@tests
) {
next
if
$test
=~ /^UPPERCASE_\d/;
next
if
$test
eq
"UNIQUE_WORDS"
;
next
if
$test
=~ /^T_MC_/;
$anti_patterns
{
"$test,"
} =
"P_"
.
$i
++;
}
{
plan
tests
=>
scalar
(
keys
%anti_patterns
) +
scalar
(
keys
%patterns
);
diag
"Note: rule_name failures may be only cosmetic but must be fixed before release"
;
};
tstprefs ("
required_score -10000.0
body ZZZZZZZZ /./
body zzzzzzzz /./
");
sarun (
"-L < $mail"
, \
&patterns_run_cb
);
ok_all_patterns();
sub
write_mail {
if
(
open
(MAIL,
">$mail"
)) {
print
MAIL
<<'EOF';
Received: from internal.example.com [127.0.0.1] by localhost
for recipient@example.com; Fri, 07 Oct 2002 09:02:00 +0000
Received: from external.example.org [150.51.53.1] by internal.example.com
for recipient@example.com; Fri, 07 Oct 2002 09:01:00 +0000
Message-ID: <clean.1010101@example.com>
Date: Mon, 07 Oct 2002 09:00:00 +0000
From: Sender <sender@example.com>
MIME-Version: 1.0
To: Recipient <recipient@example.com>
Subject: this trivial message should have no hits
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
EOF
@tests
=
sort
@tests
;
print
MAIL
join
(
"\n"
,
@tests
) .
"\n\n"
;
for
(1..10) {
print
MAIL
join
(
"\n"
, sha1_shuffle(
$_
,
@tests
)) .
"\n\n"
;
}
close
(MAIL);
}
else
{
die
"can't open output file: $!"
;
}
}
sub
fy_shuffle {
for
(
my
$i
=
$#_
;
$i
> 0;
$i
--) {
@_
[
$_
,
$i
] =
@_
[
$i
,
$_
]
for
int
rand
(
$i
+1);
}
return
@_
;
}
sub
sha1_shuffle {
my
$i
=
shift
;
return
map
{
$_
->[0] }
sort
{
$a
->[1] cmp
$b
->[1] }
map
{ [
$_
, sha1(
$_
.
$i
)] }
@_
;
}