-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_pgl4rbl.py
executable file
·74 lines (61 loc) · 2.32 KB
/
test_pgl4rbl.py
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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 Develer S.r.L
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
import StringIO
import sys
import pytest
import pgl4rbl
#
# Ugly hack to "configure" pgl4rbl
#
execfile("pgl4rbl.conf")
setattr(pgl4rbl, "CHECK_BAD_HELO", CHECK_BAD_HELO)
setattr(pgl4rbl, "MAX_GREYLIST_TIME", MAX_GREYLIST_TIME)
setattr(pgl4rbl, "MIN_GREYLIST_TIME", MIN_GREYLIST_TIME)
setattr(pgl4rbl, "RBLS", RBLS)
setattr(pgl4rbl, "GREYLIST_WHITELIST", GREYLIST_WHITELIST)
#
# Tests
#
EXPECT_OK = "action=ok You are cleared to land\n\n"
EXPECT_FAIL = "action=defer Are you a spammer? If not, just retry!\n\n"
@pytest.mark.parametrize("triplet", [
( "89.97.188.34", "trinity.develer.com", EXPECT_OK),
( "8.8.8.8", "dns1.google.com", EXPECT_OK),
( "8.8.8.8", "google", EXPECT_FAIL),
( "89.97.188.34", "[ciao]", EXPECT_FAIL),
( "89.97.188.34", "[255.256.1024.12]", EXPECT_FAIL),
])
def test_helo(capsys, monkeypatch, tmpdir, triplet):
# Prepare
setattr(pgl4rbl, "GREYLIST_DB", str(tmpdir))
client_address, helo_name, expected = triplet
mock_data = "client_address=%s\nhelo_name=%s" % (client_address, helo_name)
monkeypatch.setattr('sys.stdin', StringIO.StringIO(mock_data))
# Test
pgl4rbl.process_one()
# Assert
assert capsys.readouterr()[0] == expected