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

(-)t/root_spamd_tell_x.t (+58 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use lib '.'; use lib 't';
4
use SATest; sa_t_init("root_spamd_tell_x");
5
use Test;
6
7
use constant TEST_ENABLED => conf_bool('run_root_tests');
8
use constant IS_ROOT => eval { ($> == 0); };
9
use constant RUN_TEST => (TEST_ENABLED && IS_ROOT);
10
11
BEGIN { plan tests => (RUN_TESTS ? 6 : 0) };
12
exit unless RUN_TESTS;
13
14
# ---------------------------------------------------------------------------
15
16
%patterns = (
17
q{ Message successfully } => 'learned',
18
);
19
20
# run spamc as unpriv uid
21
$spamc = "sudo -u nobody $spamc";
22
23
# remove these first
24
unlink('log/user_state/bayes_seen');
25
unlink('log/user_state/bayes_toks');
26
27
# ensure it is writable by all
28
use File::Path; mkpath("log/user_state"); chmod 01777, "log/user_state";
29
30
ok(start_spamd("-L --allow-tell --create-prefs -x"));
31
32
ok(spamcrun("-lx -L ham < data/spam/001", \&patterns_run_cb));
33
ok_all_patterns();
34
35
ok(stop_spamd());
36
37
# ensure these are not owned by root
38
ok check_owner('log/user_state/bayes_seen');
39
ok check_owner('log/user_state/bayes_toks');
40
41
sub check_owner {
42
  my $f = shift;
43
  my @stat = stat $f;
44
45
  print "stat($f) = ".join(', ', @stat)."\n";
46
47
  if (!defined $stat[1]) {
48
    warn "no stat for $f";
49
    return 0;
50
  }
51
  elsif ($stat[4] == 0) {
52
    warn "stat for $f: owner is root";
53
    return 0;
54
  }
55
  else {
56
    return 1;
57
  }
58
}
0
  + *
59
  + *
(-)t/root_spamd_tell_paranoid.t (+58 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use lib '.'; use lib 't';
4
use SATest; sa_t_init("root_spamd_tell_paranoid");
5
use Test;
6
7
use constant TEST_ENABLED => conf_bool('run_root_tests');
8
use constant IS_ROOT => eval { ($> == 0); };
9
use constant RUN_TEST => (TEST_ENABLED && IS_ROOT);
10
11
BEGIN { plan tests => (RUN_TESTS ? 6 : 0) };
12
exit unless RUN_TESTS;
13
14
# ---------------------------------------------------------------------------
15
16
%patterns = (
17
q{ Message successfully } => 'learned',
18
);
19
20
# run spamc as unpriv uid
21
$spamc = "sudo -u nobody $spamc";
22
23
# remove these first
24
unlink('log/user_state/bayes_seen');
25
unlink('log/user_state/bayes_toks');
26
27
# ensure it is writable by all
28
use File::Path; mkpath("log/user_state"); chmod 01777, "log/user_state";
29
30
ok(start_spamd("-L --allow-tell --paranoid"));
31
32
ok(spamcrun("-lx -L ham < data/spam/001", \&patterns_run_cb));
33
ok_all_patterns();
34
35
ok(stop_spamd());
36
37
# ensure these are not owned by root
38
ok check_owner('log/user_state/bayes_seen');
39
ok check_owner('log/user_state/bayes_toks');
40
41
sub check_owner {
42
  my $f = shift;
43
  my @stat = stat $f;
44
45
  print "stat($f) = ".join(', ', @stat)."\n";
46
47
  if (!defined $stat[1]) {
48
    warn "no stat for $f";
49
    return 0;
50
  }
51
  elsif ($stat[4] == 0) {
52
    warn "stat for $f: owner is root";
53
    return 0;
54
  }
55
  else {
56
    return 1;
57
  }
58
}
0
  + *
59
  + *
(-)t/root_spamd_x.t (+46 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use lib '.'; use lib 't';
4
use SATest; sa_t_init("root_spamd_x");
5
use Test;
6
7
use constant TEST_ENABLED => conf_bool('run_root_tests');
8
use constant IS_ROOT => eval { ($> == 0); };
9
use constant RUN_TEST => (TEST_ENABLED && IS_ROOT);
10
11
BEGIN { plan tests => (RUN_TESTS ? 14 : 0) };
12
exit unless RUN_TESTS;
13
14
# ---------------------------------------------------------------------------
15
16
%patterns = (
17
18
q{ Return-Path: sb55sb55@yahoo.com}, 'firstline',
19
q{ Subject: There yours for FREE!}, 'subj',
20
q{ X-Spam-Status: Yes, score=}, 'status',
21
q{ X-Spam-Flag: YES}, 'flag',
22
q{ X-Spam-Level: **********}, 'stars',
23
q{ TEST_ENDSNUMS}, 'endsinnums',
24
q{ TEST_NOREALNAME}, 'noreal',
25
q{ This must be the very last line}, 'lastline',
26
27
);
28
29
# run spamc as unpriv uid
30
$spamc = "sudo -u nobody $spamc";
31
32
ok(start_spamd("-L --create-prefs -x"));
33
34
ok(spamcrun("< data/spam/001", \&patterns_run_cb));
35
ok_all_patterns();
36
37
%patterns = (
38
q{ X-Spam-Status: Yes, score=}, 'status',
39
q{ X-Spam-Flag: YES}, 'flag',
40
             );
41
42
43
ok (spamcrun("< data/spam/018", \&patterns_run_cb));
44
ok_all_patterns();
45
46
ok(stop_spamd());
0
  + *
47
  + *
(-)t/root_spamd_tell_x_paranoid.t (+58 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use lib '.'; use lib 't';
4
use SATest; sa_t_init("root_spamd_tell_x_paranoid");
5
use Test;
6
7
use constant TEST_ENABLED => conf_bool('run_root_tests');
8
use constant IS_ROOT => eval { ($> == 0); };
9
use constant RUN_TEST => (TEST_ENABLED && IS_ROOT);
10
11
BEGIN { plan tests => (RUN_TESTS ? 6 : 0) };
12
exit unless RUN_TESTS;
13
14
# ---------------------------------------------------------------------------
15
16
%patterns = (
17
q{ Message successfully } => 'learned',
18
);
19
20
# run spamc as unpriv uid
21
$spamc = "sudo -u nobody $spamc";
22
23
# remove these first
24
unlink('log/user_state/bayes_seen');
25
unlink('log/user_state/bayes_toks');
26
27
# ensure it is writable by all
28
use File::Path; mkpath("log/user_state"); chmod 01777, "log/user_state";
29
30
ok(start_spamd("-L --allow-tell --create-prefs -x --paranoid"));
31
32
ok(spamcrun("-lx -L ham < data/spam/001", \&patterns_run_cb));
33
ok_all_patterns();
34
35
ok(stop_spamd());
36
37
# ensure these are not owned by root
38
ok check_owner('log/user_state/bayes_seen');
39
ok check_owner('log/user_state/bayes_toks');
40
41
sub check_owner {
42
  my $f = shift;
43
  my @stat = stat $f;
44
45
  print "stat($f) = ".join(', ', @stat)."\n";
46
47
  if (!defined $stat[1]) {
48
    warn "no stat for $f";
49
    return 0;
50
  }
51
  elsif ($stat[4] == 0) {
52
    warn "stat for $f: owner is root";
53
    return 0;
54
  }
55
  else {
56
    return 1;
57
  }
58
}
0
  + *
59
  + *
(-)t/config.dist (+6 lines)
Lines 57-59 Link Here
57
# depending on changes in the third-party modules we import.
57
# depending on changes in the third-party modules we import.
58
run_saw_ampersand_test=n
58
run_saw_ampersand_test=n
59
59
60
# ---------------------------------------------------------------------------
61
62
# The "root_*.t" tests require root privileges, and may create files in
63
# the filesystem as part of the test.  Disabled by default.
64
run_root_tests=n
65
(-)t/root_spamd_tell.t (+58 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use lib '.'; use lib 't';
4
use SATest; sa_t_init("root_spamd_tell");
5
use Test;
6
7
use constant TEST_ENABLED => conf_bool('run_root_tests');
8
use constant IS_ROOT => eval { ($> == 0); };
9
use constant RUN_TEST => (TEST_ENABLED && IS_ROOT);
10
11
BEGIN { plan tests => (RUN_TESTS ? 6 : 0) };
12
exit unless RUN_TESTS;
13
14
# ---------------------------------------------------------------------------
15
16
%patterns = (
17
q{ Message successfully } => 'learned',
18
);
19
20
# run spamc as unpriv uid
21
$spamc = "sudo -u nobody $spamc";
22
23
# remove these first
24
unlink('log/user_state/bayes_seen');
25
unlink('log/user_state/bayes_toks');
26
27
# ensure it is writable by all
28
use File::Path; mkpath("log/user_state"); chmod 01777, "log/user_state";
29
30
ok(start_spamd("-L --allow-tell"));
31
32
ok(spamcrun("-lx -L ham < data/spam/001", \&patterns_run_cb));
33
ok_all_patterns();
34
35
ok(stop_spamd());
36
37
# ensure these are not owned by root
38
ok check_owner('log/user_state/bayes_seen');
39
ok check_owner('log/user_state/bayes_toks');
40
41
sub check_owner {
42
  my $f = shift;
43
  my @stat = stat $f;
44
45
  print "stat($f) = ".join(', ', @stat)."\n";
46
47
  if (!defined $stat[1]) {
48
    warn "no stat for $f";
49
    return 0;
50
  }
51
  elsif ($stat[4] == 0) {
52
    warn "stat for $f: owner is root";
53
    return 0;
54
  }
55
  else {
56
    return 1;
57
  }
58
}
0
  + *
59
  + *
(-)t/root_spamd_x_paranoid.t (+46 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use lib '.'; use lib 't';
4
use SATest; sa_t_init("root_spamd_x_paranoid");
5
use Test;
6
7
use constant TEST_ENABLED => conf_bool('run_root_tests');
8
use constant IS_ROOT => eval { ($> == 0); };
9
use constant RUN_TEST => (TEST_ENABLED && IS_ROOT);
10
11
BEGIN { plan tests => (RUN_TESTS ? 14 : 0) };
12
exit unless RUN_TESTS;
13
14
# ---------------------------------------------------------------------------
15
16
%patterns = (
17
18
q{ Return-Path: sb55sb55@yahoo.com}, 'firstline',
19
q{ Subject: There yours for FREE!}, 'subj',
20
q{ X-Spam-Status: Yes, score=}, 'status',
21
q{ X-Spam-Flag: YES}, 'flag',
22
q{ X-Spam-Level: **********}, 'stars',
23
q{ TEST_ENDSNUMS}, 'endsinnums',
24
q{ TEST_NOREALNAME}, 'noreal',
25
q{ This must be the very last line}, 'lastline',
26
27
);
28
29
# run spamc as unpriv uid
30
$spamc = "sudo -u nobody $spamc";
31
32
ok(start_spamd("-L --create-prefs -x --paranoid"));
33
34
ok(spamcrun("< data/spam/001", \&patterns_run_cb));
35
ok_all_patterns();
36
37
%patterns = (
38
q{ X-Spam-Status: Yes, score=}, 'status',
39
q{ X-Spam-Flag: YES}, 'flag',
40
             );
41
42
43
ok (spamcrun("< data/spam/018", \&patterns_run_cb));
44
ok_all_patterns();
45
46
ok(stop_spamd());
0
  + *
47
  + *
(-)t/root_spamd.t (+48 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# run with:   sudo prove -v t/root_spamd*
4
5
use lib '.'; use lib 't';
6
use SATest; sa_t_init("root_spamd");
7
use Test;
8
9
use constant TEST_ENABLED => conf_bool('run_root_tests');
10
use constant IS_ROOT => eval { ($> == 0); };
11
use constant RUN_TEST => (TEST_ENABLED && IS_ROOT);
12
13
BEGIN { plan tests => (RUN_TESTS ? 14 : 0) };
14
exit unless RUN_TESTS;
15
16
# ---------------------------------------------------------------------------
17
18
%patterns = (
19
20
q{ Return-Path: sb55sb55@yahoo.com}, 'firstline',
21
q{ Subject: There yours for FREE!}, 'subj',
22
q{ X-Spam-Status: Yes, score=}, 'status',
23
q{ X-Spam-Flag: YES}, 'flag',
24
q{ X-Spam-Level: **********}, 'stars',
25
q{ TEST_ENDSNUMS}, 'endsinnums',
26
q{ TEST_NOREALNAME}, 'noreal',
27
q{ This must be the very last line}, 'lastline',
28
29
);
30
31
# run spamc as unpriv uid
32
$spamc = "sudo -u nobody $spamc";
33
34
ok(start_spamd("-L"));
35
36
ok(spamcrun("< data/spam/001", \&patterns_run_cb));
37
ok_all_patterns();
38
39
%patterns = (
40
q{ X-Spam-Status: Yes, score=}, 'status',
41
q{ X-Spam-Flag: YES}, 'flag',
42
             );
43
44
45
ok (spamcrun("< data/spam/018", \&patterns_run_cb));
46
ok_all_patterns();
47
48
ok(stop_spamd());
0
  + *
49
  + *

Return to bug 5480