]> git.ipfire.org Git - thirdparty/pdns.git/blame - regression-tests.api/test_RecursorConfig.py
code review from otto, thanks
[thirdparty/pdns.git] / regression-tests.api / test_RecursorConfig.py
CommitLineData
41942bb3 1import json
41942bb3 2import unittest
c1374bdb 3from test_helper import ApiTestCase, is_recursor
41942bb3
CH
4
5
c1374bdb 6@unittest.skipIf(not is_recursor(), "Only applicable to recursors")
35189b7d 7class RecursorAllowFromConfig(ApiTestCase):
41942bb3 8
c1374bdb 9 def test_config_allow_from_get(self):
46d06a12 10 r = self.session.get(self.url("/api/v1/servers/localhost/config/allow-from"))
c1374bdb 11 self.assert_success_json(r)
41942bb3 12
c1374bdb 13 def test_config_allow_from_replace(self):
bd0320fe 14 payload = {'value': ["127.0.0.1"]}
41942bb3 15 r = self.session.put(
46d06a12 16 self.url("/api/v1/servers/localhost/config/allow-from"),
41942bb3
CH
17 data=json.dumps(payload),
18 headers={'content-type': 'application/json'})
c1374bdb 19 self.assert_success_json(r)
41942bb3 20 data = r.json()
f9a7adb0 21 self.assertIn("value", data)
4bfebc93
CH
22 self.assertEqual(len(data["value"]), 1)
23 self.assertEqual("127.0.0.1/32", data["value"][0])
35f26cc5 24
bfa1ae26
OM
25 def test_config_allow_from_replace_empty(self):
26 payload = {'value': []}
27 r = self.session.put(
28 self.url("/api/v1/servers/localhost/config/allow-from"),
29 data=json.dumps(payload),
30 headers={'content-type': 'application/json'})
31 self.assert_success_json(r)
32 data = r.json()
33 self.assertIn("value", data)
34 self.assertEqual(len(data["value"]), 0)
35
c1374bdb 36 def test_config_allow_from_replace_error(self):
35f26cc5
CH
37 """Test the error case, should return 422."""
38 payload = {'value': ["abcdefgh"]}
39 r = self.session.put(
46d06a12 40 self.url("/api/v1/servers/localhost/config/allow-from"),
35f26cc5
CH
41 data=json.dumps(payload),
42 headers={'content-type': 'application/json'})
4bfebc93 43 self.assertEqual(r.status_code, 422)
35f26cc5 44 data = r.json()
faa0f891 45 self.assertIn('Unable to convert', data['error'])
35189b7d
KF
46
47
48@unittest.skipIf(not is_recursor(), "Only applicable to recursors")
49class RecursorAllowNotifyFromConfig(ApiTestCase):
50
51 def test_config_allow_notify_from_get(self):
52 r = self.session.get(self.url("/api/v1/servers/localhost/config/allow-notify-from"))
53 self.assert_success_json(r)
54
55 def test_config_allow_notify_from_replace(self):
56 payload = {'value': ["127.0.0.1"]}
57 r = self.session.put(
58 self.url("/api/v1/servers/localhost/config/allow-notify-from"),
59 data=json.dumps(payload),
60 headers={'content-type': 'application/json'})
61 self.assert_success_json(r)
62 data = r.json()
63 self.assertIn("value", data)
64 self.assertEqual(len(data["value"]), 1)
65 self.assertEqual("127.0.0.1/32", data["value"][0])
66
bfa1ae26
OM
67 def test_config_allow_notify_from_replace_empty(self):
68 payload = {'value': []}
69 r = self.session.put(
70 self.url("/api/v1/servers/localhost/config/allow-notify-from"),
71 data=json.dumps(payload),
72 headers={'content-type': 'application/json'})
73 self.assert_success_json(r)
74 data = r.json()
75 self.assertIn("value", data)
76 self.assertEqual(len(data["value"]), 0)
77
35189b7d
KF
78 def test_config_allow_notify_from_replace_error(self):
79 """Test the error case, should return 422."""
80 payload = {'value': ["abcdefgh"]}
81 r = self.session.put(
82 self.url("/api/v1/servers/localhost/config/allow-notify-from"),
83 data=json.dumps(payload),
84 headers={'content-type': 'application/json'})
85 self.assertEqual(r.status_code, 422)
86 data = r.json()
87 self.assertIn('Unable to convert', data['error'])