(
self, start_connection: Any, ClientRequestMock: Any
)
| 595 | spec_set=True, |
| 596 | ) |
| 597 | def test_https_connect_certificate_error( |
| 598 | self, start_connection: Any, ClientRequestMock: Any |
| 599 | ) -> None: |
| 600 | proxy_req = ClientRequest( |
| 601 | "GET", URL("http://proxy.example.com"), loop=self.loop |
| 602 | ) |
| 603 | ClientRequestMock.return_value = proxy_req |
| 604 | |
| 605 | proxy_resp = ClientResponse( |
| 606 | "get", |
| 607 | URL("http://proxy.example.com"), |
| 608 | request_info=mock.Mock(), |
| 609 | writer=None, |
| 610 | continue100=None, |
| 611 | timer=TimerNoop(), |
| 612 | traces=[], |
| 613 | loop=self.loop, |
| 614 | stream_writer=mock.create_autospec( |
| 615 | AbstractStreamWriter, spec_set=True, instance=True |
| 616 | ), |
| 617 | session=mock.Mock(), |
| 618 | ) |
| 619 | proxy_req.send = mock.AsyncMock(return_value=proxy_resp) |
| 620 | proxy_resp.start = mock.AsyncMock(return_value=mock.Mock(status=200)) |
| 621 | |
| 622 | async def make_conn(): |
| 623 | return aiohttp.TCPConnector() |
| 624 | |
| 625 | connector = self.loop.run_until_complete(make_conn()) |
| 626 | connector._resolve_host = mock.AsyncMock( |
| 627 | return_value=[ |
| 628 | { |
| 629 | "hostname": "hostname", |
| 630 | "host": "127.0.0.1", |
| 631 | "port": 80, |
| 632 | "family": socket.AF_INET, |
| 633 | "proto": 0, |
| 634 | "flags": 0, |
| 635 | } |
| 636 | ] |
| 637 | ) |
| 638 | |
| 639 | # Called on connection to http://proxy.example.com |
| 640 | self.loop.create_connection = mock.AsyncMock( |
| 641 | return_value=(mock.Mock(), mock.Mock()) |
| 642 | ) |
| 643 | # Called on connection to https://www.python.org |
| 644 | self.loop.start_tls = mock.AsyncMock(side_effect=ssl.CertificateError) |
| 645 | |
| 646 | req = ClientRequest( |
| 647 | "GET", |
| 648 | URL("https://www.python.org"), |
| 649 | proxy=URL("http://proxy.example.com"), |
| 650 | loop=self.loop, |
| 651 | ) |
| 652 | with self.assertRaises(aiohttp.ClientConnectorCertificateError): |
| 653 | self.loop.run_until_complete( |
| 654 | connector._create_connection(req, None, aiohttp.ClientTimeout()) |
nothing calls this directly
no test coverage detected