def test_http_error_no_messsage(self, mock: MagicMock) -> None: fp = io.BytesIO(b"abcd") exc = HTTPError("url", 403, "forbidden", {}, fp) mock.return_value = URLOpenMock(b"msg", exc) with self.assertRaises(www.WWWError): www.WWW("https://example.com").get()
def test_http_error_messsage(self, mock: MagicMock) -> None: fp = io.BytesIO(json.dumps({"message": "xyz"}).encode("utf-8")) exc = HTTPError("url", 403, "forbidden", {}, fp) mock.return_value = URLOpenMock(b"msg", exc) with self.assertRaises(www.WWWError): www.WWW("https://example.com").get()
def test_auth_header(self, mock: MagicMock) -> None: mock.return_value = URLOpenMock() www.WWW("https://example.com", token="xyz").delete() args, _kwargs = mock.call_args req = args[0] self.assertEqual(req.headers, {"Authorization": "bearer xyz"})
def test_method(self, mock: MagicMock) -> None: mock.return_value = URLOpenMock() www.WWW("https://example.com").delete() args, _kwargs = mock.call_args req = args[0] self.assertEqual(req.method, "DELETE")
def test_data(self, mock: MagicMock) -> None: mock.return_value = URLOpenMock() www.WWW("https://example.com", token="abc").delete(a="b", x="y") args, _kwargs = mock.call_args req = args[0] headers = { "Authorization": "bearer abc", "Content-type": "application/json", } self.assertEqual(req.headers, headers) data = { "a": "b", "x": "y", } self.assertEqual(json.loads(req.data.decode("utf-8")), data)
def test_invalid_expected_sct(self) -> None: with self.assertRaises(www.WWWError): www.WWW("https://invalid-expected-sct.badssl.com/") \ ._send("", "GET")
def test_dh512(self) -> None: with self.assertRaises(www.WWWError): www.WWW("https://dh512.badssl.com/")._send("", "GET")
def test_rc4_md5(self) -> None: with self.assertRaises(www.WWWError): www.WWW("https://rc4-md5.badssl.com/")._send("", "GET")
def test_untrusted_root(self) -> None: with self.assertRaises(www.WWWError): www.WWW("https://untrusted-root.badssl.com/")._send("", "GET")
def test_self_signed(self) -> None: with self.assertRaises(www.WWWError): www.WWW("https://self-signed.badssl.com/")._send("", "GET")
def test_webpack_dev_server(self) -> None: with self.assertRaises(www.WWWError): www.WWW("https://webpack-dev-server.badssl.com/")._send("", "GET")
def test_e_dell_root(self) -> None: with self.assertRaises(www.WWWError): www.WWW("https://edellroot.badssl.com/")._send("", "GET")
def test_certificate_error(self, mock: MagicMock) -> None: exc = ssl.CertificateError() mock.return_value = URLOpenMock(b"msg", exc) with self.assertRaises(www.WWWError): www.WWW("https://example.com").get()
def test_sha1_2017(self) -> None: with self.assertRaises(www.WWWError): www.WWW("https://sha1-2017.badssl.com/")._send("", "GET")
def test_mitm_software(self) -> None: with self.assertRaises(www.WWWError): www.WWW("https://mitm-software.badssl.com/")._send("", "GET")
def test_subdomain_preloaded_hsts(self) -> None: with self.assertRaises(www.WWWError): www.WWW("https://subdomain.preloaded-hsts.badssl.com/") \ ._send("", "GET")
def test_superfish(self) -> None: with self.assertRaises(www.WWWError): www.WWW("https://superfish.badssl.com/")._send("", "GET")
def test_wrong_host(self) -> None: with self.assertRaises(www.WWWError): www.WWW("https://wrong.host.badssl.com/")._send("", "GET")
def test_dsd_test_provider(self) -> None: with self.assertRaises(www.WWWError): www.WWW("https://dsdtestprovider.badssl.com/")._send("", "GET")
def test_preact_cli(self) -> None: with self.assertRaises(www.WWWError): www.WWW("https://preact-cli.badssl.com/")._send("", "GET")