Пример #1
0
    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()
Пример #2
0
    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()
Пример #3
0
    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"})
Пример #4
0
    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")
Пример #5
0
    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)
Пример #6
0
 def test_invalid_expected_sct(self) -> None:
     with self.assertRaises(www.WWWError):
         www.WWW("https://invalid-expected-sct.badssl.com/") \
            ._send("", "GET")
Пример #7
0
 def test_dh512(self) -> None:
     with self.assertRaises(www.WWWError):
         www.WWW("https://dh512.badssl.com/")._send("", "GET")
Пример #8
0
 def test_rc4_md5(self) -> None:
     with self.assertRaises(www.WWWError):
         www.WWW("https://rc4-md5.badssl.com/")._send("", "GET")
Пример #9
0
 def test_untrusted_root(self) -> None:
     with self.assertRaises(www.WWWError):
         www.WWW("https://untrusted-root.badssl.com/")._send("", "GET")
Пример #10
0
 def test_self_signed(self) -> None:
     with self.assertRaises(www.WWWError):
         www.WWW("https://self-signed.badssl.com/")._send("", "GET")
Пример #11
0
 def test_webpack_dev_server(self) -> None:
     with self.assertRaises(www.WWWError):
         www.WWW("https://webpack-dev-server.badssl.com/")._send("", "GET")
Пример #12
0
 def test_e_dell_root(self) -> None:
     with self.assertRaises(www.WWWError):
         www.WWW("https://edellroot.badssl.com/")._send("", "GET")
Пример #13
0
    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()
Пример #14
0
 def test_sha1_2017(self) -> None:
     with self.assertRaises(www.WWWError):
         www.WWW("https://sha1-2017.badssl.com/")._send("", "GET")
Пример #15
0
 def test_mitm_software(self) -> None:
     with self.assertRaises(www.WWWError):
         www.WWW("https://mitm-software.badssl.com/")._send("", "GET")
Пример #16
0
 def test_subdomain_preloaded_hsts(self) -> None:
     with self.assertRaises(www.WWWError):
         www.WWW("https://subdomain.preloaded-hsts.badssl.com/") \
            ._send("", "GET")
Пример #17
0
 def test_superfish(self) -> None:
     with self.assertRaises(www.WWWError):
         www.WWW("https://superfish.badssl.com/")._send("", "GET")
Пример #18
0
 def test_wrong_host(self) -> None:
     with self.assertRaises(www.WWWError):
         www.WWW("https://wrong.host.badssl.com/")._send("", "GET")
Пример #19
0
 def test_dsd_test_provider(self) -> None:
     with self.assertRaises(www.WWWError):
         www.WWW("https://dsdtestprovider.badssl.com/")._send("", "GET")
Пример #20
0
 def test_preact_cli(self) -> None:
     with self.assertRaises(www.WWWError):
         www.WWW("https://preact-cli.badssl.com/")._send("", "GET")