-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpdns_redis_test
More file actions
executable file
·85 lines (74 loc) · 2.18 KB
/
pdns_redis_test
File metadata and controls
executable file
·85 lines (74 loc) · 2.18 KB
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
#!/bin/bash
#
# This is a magic test script. If run using bash, it will run the tests using
# whatever Python interpretors are found in /usr/bin/ and /usr/local/bin/.
#
# Or, you can manually run it like so: python3 pdns_redis_test
#
MAGIC="""\
"
for interp in /usr/bin/python?.? /usr/local/bin/python?.?; do
if [ -e "$interp" ]; then
echo "==== Testing with $interp ===="
$interp $0 || exit 1
fi
done
echo "==== All passed! ===="
exit 0
"""
import pdns_redis
import sys
try:
from cStringIO import StringIO
except:
from io import StringIO
def assertEquals(v1, v2, label=None):
if (v1 == v2):
print('OK: %s' % (label or v1))
else:
print('FAILED: %s != %s' % (v1, v2))
assert(v1 == v2)
pdns_redis.DEBUG = True
pr = pdns_redis.PdnsRedis().ParseArgs(['-R', 'mock:0'])
# The basics...
assertEquals(
pdns_redis.AddOp(pr, 'example.com', 'A', 'self', '5M').Run(),
'Added A record to example.com.')
assertEquals(
pdns_redis.QueryOp(pr, 'example.com').Query(),
[('example.com', 'A', '300', 'self')])
# Test the wildcard mechanism. The QueryOp should return nothing, but
# the FancyQueryOp should resolve the domain using the wildcard.
assertEquals(
pdns_redis.AddOp(pr, '*.example.com', 'A', '1.2.3.4', '5M').Run(),
'Added A record to *.example.com.')
assertEquals(
pdns_redis.QueryOp(pr, 'foo.example.com', 'A').Query(),
[], label="empty QueryOp response")
assertEquals(
pdns_redis.FancyQueryOp(pr, 'foo.example.com', 'A').Query(),
[('foo.example.com', 'A', '300', '1.2.3.4')])
# Test the PDNS chat server
chat_test_input = """\
HELO\t2
BOGON
AXFR\texample.com
Q\tbad-example.com\tIN\tANY\t1234\t9.9.9.9\t1.2.3.4
Q\tfoo.example.com\tIN\tANY\t1234\t9.9.9.9\t1.2.3.4
"""
expected_chat_output = """\
OK\tpdns-redis.py, by Bjarni R. Einarsson
LOG\tPowerDNS sent bad request: ['BOGON']
FAIL
END
END
DATA\tfoo.example.com\tIN\tA\t300\t-1\t1.2.3.4
END
"""
chat_test_output = StringIO()
pdns_redis.PdnsChatter(
StringIO(chat_test_input), chat_test_output, pr,
wildcards=True).Run()
assertEquals(chat_test_output.getvalue(), expected_chat_output,
label="PdnsChatter behaves correctly")
# vim: syntax=python ts=4 expandtab