]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add tests for invalid HTTP methods
authorPaul Cuzner <pcuzner@redhat.com>
Mon, 30 Nov 2020 21:04:55 +0000 (10:04 +1300)
committerPaul Cuzner <pcuzner@redhat.com>
Mon, 30 Nov 2020 21:04:55 +0000 (10:04 +1300)
Add tests to confirm that the request handler does not
respond to methods other than GET

Signed-off-by: Paul Cuzner <pcuzner@redhat.com>
src/cephadm/tests/test_cephadm.py

index 0a8829779f82c59c5017516c8bd0b4aa48800b5b..367a2089a7db5c225c7aa6b9b39360ea52ba1f90 100644 (file)
@@ -582,3 +582,53 @@ iMN28C2bKGao5UHvdER1rGy7
         assert exporter.cephadm_cache.host['scrape_errors']
         assert exporter.cephadm_cache.host['scrape_errors'] == ['ValueError exception: wah']
         assert exporter.cephadm_cache.errors == ['host thread stopped']
+
+    # Test the requesthandler does the right thing with invalid methods...
+    # ie. return a "501" - Not Implemented / Unsupported Method
+    def test_invalid_method_HEAD(self):
+        hdrs={"Authorization":f"Bearer {TestCephadmExporter.token}"}
+        req=Request("http://localhost:9443/v1/metadata/health",headers=hdrs, method="HEAD")
+        with pytest.raises(HTTPError, match=r"HTTP Error 501: .*") as e:
+            urlopen(req)
+
+    def test_invalid_method_DELETE(self):
+        hdrs={"Authorization":f"Bearer {TestCephadmExporter.token}"}
+        req=Request("http://localhost:9443/v1/metadata/health",headers=hdrs, method="DELETE")
+        with pytest.raises(HTTPError, match=r"HTTP Error 501: .*") as e:
+            urlopen(req)
+
+    def test_invalid_method_POST(self):
+        hdrs={"Authorization":f"Bearer {TestCephadmExporter.token}"}
+        req=Request("http://localhost:9443/v1/metadata/health",headers=hdrs, method="POST")
+        with pytest.raises(HTTPError, match=r"HTTP Error 501: .*") as e:
+            urlopen(req)
+
+    def test_invalid_method_PUT(self):
+        hdrs={"Authorization":f"Bearer {TestCephadmExporter.token}"}
+        req=Request("http://localhost:9443/v1/metadata/health",headers=hdrs, method="PUT")
+        with pytest.raises(HTTPError, match=r"HTTP Error 501: .*") as e:
+            urlopen(req)
+
+    def test_invalid_method_CONNECT(self):
+        hdrs={"Authorization":f"Bearer {TestCephadmExporter.token}"}
+        req=Request("http://localhost:9443/v1/metadata/health",headers=hdrs, method="CONNECT")
+        with pytest.raises(HTTPError, match=r"HTTP Error 501: .*") as e:
+            urlopen(req)
+
+    def test_invalid_method_TRACE(self):
+        hdrs={"Authorization":f"Bearer {TestCephadmExporter.token}"}
+        req=Request("http://localhost:9443/v1/metadata/health",headers=hdrs, method="TRACE")
+        with pytest.raises(HTTPError, match=r"HTTP Error 501: .*") as e:
+            urlopen(req)
+
+    def test_invalid_method_OPTIONS(self):
+        hdrs={"Authorization":f"Bearer {TestCephadmExporter.token}"}
+        req=Request("http://localhost:9443/v1/metadata/health",headers=hdrs, method="OPTIONS")
+        with pytest.raises(HTTPError, match=r"HTTP Error 501: .*") as e:
+            urlopen(req)
+
+    def test_invalid_method_PATCH(self):
+        hdrs={"Authorization":f"Bearer {TestCephadmExporter.token}"}
+        req=Request("http://localhost:9443/v1/metadata/health",headers=hdrs, method="PATCH")
+        with pytest.raises(HTTPError, match=r"HTTP Error 501: .*") as e:
+            urlopen(req)