]>
git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests.api/test_RecursorConfig.py
3 from test_helper
import ApiTestCase
, is_recursor
6 @unittest.skipIf(not is_recursor(), "Only applicable to recursors")
7 class RecursorAllowFromConfig(ApiTestCase
):
9 def test_config_allow_from_get(self
):
10 r
= self
.session
.get(self
.url("/api/v1/servers/localhost/config/allow-from"))
11 self
.assert_success_json(r
)
13 def test_config_allow_from_replace(self
):
14 payload
= {'value': ["127.0.0.1"]}
16 self
.url("/api/v1/servers/localhost/config/allow-from"),
17 data
=json
.dumps(payload
),
18 headers
={'content-type': 'application/json'})
19 self
.assert_success_json(r
)
21 self
.assertIn("value", data
)
22 self
.assertEqual(len(data
["value"]), 1)
23 self
.assertEqual("127.0.0.1/32", data
["value"][0])
25 def test_config_allow_from_replace_empty(self
):
26 payload
= {'value': []}
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
)
33 self
.assertIn("value", data
)
34 self
.assertEqual(len(data
["value"]), 0)
36 def test_config_allow_from_replace_error(self
):
37 """Test the error case, should return 422."""
38 payload
= {'value': ["abcdefgh"]}
40 self
.url("/api/v1/servers/localhost/config/allow-from"),
41 data
=json
.dumps(payload
),
42 headers
={'content-type': 'application/json'})
43 self
.assertEqual(r
.status_code
, 422)
45 self
.assertIn('Unable to convert', data
['error'])
48 @unittest.skipIf(not is_recursor(), "Only applicable to recursors")
49 class RecursorAllowNotifyFromConfig(ApiTestCase
):
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
)
55 def test_config_allow_notify_from_replace(self
):
56 payload
= {'value': ["127.0.0.1"]}
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
)
63 self
.assertIn("value", data
)
64 self
.assertEqual(len(data
["value"]), 1)
65 self
.assertEqual("127.0.0.1/32", data
["value"][0])
67 def test_config_allow_notify_from_replace_empty(self
):
68 payload
= {'value': []}
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
)
75 self
.assertIn("value", data
)
76 self
.assertEqual(len(data
["value"]), 0)
78 def test_config_allow_notify_from_replace_error(self
):
79 """Test the error case, should return 422."""
80 payload
= {'value': ["abcdefgh"]}
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)
87 self
.assertIn('Unable to convert', data
['error'])