]>
git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests.recursor-dnssec/test_API.py
4 from recursortests
import RecursorTest
6 class APIRecursorTest(RecursorTest
):
11 # we don't need all the auth stuff
15 confdir
= os
.path
.join('configs', cls
._confdir
)
16 cls
.createConfigDir(confdir
)
18 cls
.generateRecursorConfig(confdir
)
19 cls
.startRecursor(confdir
, cls
._recursorPort
)
22 def tearDownClass(cls
):
23 cls
.tearDownRecursor()
25 class APIAllowedRecursorTest(APIRecursorTest
):
29 _wsPassword
= 'secretpassword'
30 _apiKey
= 'secretapikey'
32 _config_template
= """
35 webserver-address=127.0.0.1
37 webserver-allow-from=127.0.0.1
39 """ % (_wsPort
, _wsPassword
, _apiKey
)
42 self
.waitForTCPSocket("127.0.0.1", self
._wsPort
)
43 headers
= {'x-api-key': self
._apiKey
}
44 url
= 'http://127.0.0.1:' + str(self
._wsPort
) + '/api/v1/servers/localhost/statistics'
45 r
= requests
.get(url
, headers
=headers
, timeout
=self
._wsTimeout
)
47 self
.assertEqual(r
.status_code
, 200)
48 self
.assertTrue(r
.json())
50 class APIDeniedRecursorTest(APIRecursorTest
):
54 _wsPassword
= 'secretpassword'
55 _apiKey
= 'secretapikey'
57 _config_template
= """
60 webserver-address=127.0.0.1
62 webserver-allow-from=192.0.2.1
64 """ % (_wsPort
, _wsPassword
, _apiKey
)
67 self
.waitForTCPSocket("127.0.0.1", self
._wsPort
)
68 headers
= {'x-api-key': self
._apiKey
}
69 url
= 'http://127.0.0.1:' + str(self
._wsPort
) + '/api/v1/servers/localhost/statistics'
71 r
= requests
.get(url
, headers
=headers
, timeout
=self
._wsTimeout
)
72 self
.assertTrue(False)
73 except requests
.exceptions
.ConnectionError
as exp
: