]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - regression-tests.api/test_Basics.py
dnsdist: Refactoring to merge the UDP and TCP paths
[thirdparty/pdns.git] / regression-tests.api / test_Basics.py
index dd3de3ef7c2eefb158ba1f43b76ad5d4aa8237d3..eca56505de2955124cd218f42d5a026178342022 100644 (file)
@@ -1,18 +1,16 @@
-import unittest
 import requests
 import socket
-import pprint
 import time
 from test_helper import ApiTestCase
 
 
 class TestBasics(ApiTestCase):
 
-    def test_Unauth(self):
-        r = requests.get(self.url("/servers/localhost"))
+    def test_unauth(self):
+        r = requests.get(self.url("/api/v1/servers/localhost"))
         self.assertEquals(r.status_code, requests.codes.unauthorized)
 
-    def test_SplitRequest(self):
+    def test_split_request(self):
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
         s.connect((self.server_address, self.server_port))
@@ -22,15 +20,25 @@ class TestBasics(ApiTestCase):
         print("Sending request")
         for part in parts:
             print("Sending %s" % part)
-            s.sendall(part)
+            s.sendall(part.encode('ascii'))
             time.sleep(0.5)
 
         resp = s.recv(4096, socket.MSG_WAITALL)
         s.close()
 
-        print "response", repr(resp)
+        print("response", repr(resp))
 
         status = resp.splitlines(0)[0]
-        if '400' in status:
+        if b'400' in status:
             raise Exception('Got unwanted response: %s' % status)
-            print 'Got', status
+
+    def test_cors(self):
+        r = self.session.options(self.url("/api/v1/servers/localhost"))
+        # look for CORS headers
+
+        self.assertEquals(r.status_code, requests.codes.ok)
+        self.assertEquals(r.headers['access-control-allow-origin'], "*")
+        self.assertEquals(r.headers['access-control-allow-headers'], 'Content-Type, X-API-Key')
+        self.assertEquals(r.headers['access-control-allow-methods'], 'GET, POST, PUT, PATCH, DELETE, OPTIONS')
+
+        print("response", repr(r.headers))