]> git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests.api/test_Basics.py
Make sure we can install unsigned packages.
[thirdparty/pdns.git] / regression-tests.api / test_Basics.py
1 import requests
2 import socket
3 import time
4 from test_helper import ApiTestCase
5
6
7 class TestBasics(ApiTestCase):
8
9 def test_unauth(self):
10 r = requests.get(self.url("/api/v1/servers/localhost"))
11 self.assertEquals(r.status_code, requests.codes.unauthorized)
12
13 def test_index_html(self):
14 r = requests.get(self.url("/"), auth=('admin', self.server_web_password))
15 self.assertEquals(r.status_code, requests.codes.ok)
16
17 def test_split_request(self):
18 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
19 s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
20 s.connect((self.server_address, self.server_port))
21
22 parts = ("GET / HTTP/1.0\r\n", "Content-Type: text/plain\r\n\r\n")
23
24 print("Sending request")
25 for part in parts:
26 print("Sending %s" % part)
27 s.sendall(part.encode('ascii'))
28 time.sleep(0.5)
29
30 resp = s.recv(4096, socket.MSG_WAITALL)
31 s.close()
32
33 print("response", repr(resp))
34
35 status = resp.splitlines(0)[0]
36 if b'400' in status:
37 raise Exception('Got unwanted response: %s' % status)
38
39 def test_cors(self):
40 r = self.session.options(self.url("/api/v1/servers/localhost"))
41 # look for CORS headers
42
43 self.assertEquals(r.status_code, requests.codes.ok)
44 self.assertEquals(r.headers['access-control-allow-origin'], "*")
45 self.assertEquals(r.headers['access-control-allow-headers'], 'Content-Type, X-API-Key')
46 self.assertEquals(r.headers['access-control-allow-methods'], 'GET, POST, PUT, PATCH, DELETE, OPTIONS')
47
48 print("response", repr(r.headers))