-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_acl.py
48 lines (39 loc) · 1.47 KB
/
test_acl.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
""" Tests for the acl dataset
"""
from tempfile import NamedTemporaryFile
import unittest
from rbldnsd import ZoneFile, Rbldnsd, QueryRefused
__all__ = [
'TestAclDataset',
]
def daemon(acl, addr='localhost'):
""" Create an Rbldnsd instance with given ACL
"""
acl_zone = NamedTemporaryFile()
acl_zone.writelines("%s\n" % line for line in acl)
acl_zone.flush()
dnsd = Rbldnsd(daemon_addr=addr)
dnsd.add_dataset('acl', acl_zone)
dnsd.add_dataset('generic', ZoneFile(['test TXT "Success"']))
return dnsd
class TestAclDataset(unittest.TestCase):
def test_refuse_ipv4(self):
with daemon(acl=["127.0.0.1 :refuse"],
addr='127.0.0.1') as dnsd:
self.assertRaises(QueryRefused, dnsd.query, 'test.example.com')
def test_pass_ipv4(self):
with daemon(acl=[ "0.0.0.0/0 :refuse",
"127.0.0.1 :pass" ],
addr='127.0.0.1') as dnsd:
self.assertEqual(dnsd.query('test.example.com'), 'Success')
def test_refuse_ipv6(self):
with daemon(acl=["::1 :refuse"],
addr='::1') as dnsd:
self.assertRaises(QueryRefused, dnsd.query, 'test.example.com')
def test_pass_ipv6(self):
with daemon(acl=[ "0/0 :refuse",
"0::1 :pass" ],
addr='::1') as dnsd:
self.assertEqual(dnsd.query('test.example.com'), 'Success')
if __name__ == '__main__':
unittest.main()