Skip to content

Commit

Permalink
Remove a test for an unsupported scenario, add another
Browse files Browse the repository at this point in the history
  • Loading branch information
Gallaecio committed Feb 2, 2024
1 parent 7bba730 commit 561e89c
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,23 +1213,6 @@ def test_meta_copy(self):
]
self.assertEqual(logger.warning.call_args_list, expected_calls)

def test_custom_proxy(self):
"""A manually-set Proxy-Authorization header is not overridden even if
the proxy URL set matches the expected one without the API key."""
self.spider.zyte_smartproxy_enabled = True
crawler = self._mock_crawler(self.spider, self.settings)
smartproxy = self.mwcls.from_crawler(crawler)
smartproxy.open_spider(self.spider)
httpproxy = HttpProxyMiddleware.from_crawler(crawler)

headers = {b'Proxy-Authorization': b'foo'}
meta = {'proxy': 'http://proxy.zyte.com:8011'}
request = Request('https://example.com', headers=headers, meta=meta)
self.assertEqual(smartproxy.process_request(request, self.spider), None)
self.assertEqual(httpproxy.process_request(request, self.spider), None)
self.assertEqual(request.meta['proxy'], 'http://proxy.zyte.com:8011')
self.assertEqual(request.headers[b'Proxy-Authorization'], b'foo')

def test_manual_proxy_same(self):
"""Defining the 'proxy' request meta key with the right URL has the
same effect as not defining it."""
Expand Down Expand Up @@ -1291,3 +1274,20 @@ def test_manual_proxy_different(self):
self.assertEqual(httpproxy.process_request(request, self.spider), None)
self.assertEqual(request.meta['proxy'], 'http://proxy.example.com:8011')
self.assertNotIn(b'Proxy-Authorization', request.headers)

def test_manual_proxy_different_auth(self):
"""Setting a custom 'proxy' request meta with a matching proxy URL
but a different key prevents the middleware from making changes."""
self.spider.zyte_smartproxy_enabled = True
crawler = self._mock_crawler(self.spider, self.settings)
smartproxy = self.mwcls.from_crawler(crawler)
smartproxy.open_spider(self.spider)
httpproxy = HttpProxyMiddleware.from_crawler(crawler)
auth_header = basic_auth_header("altkey", "")

meta = {'proxy': 'http://altkey:@proxy.example.com:8011'}
request = Request('https://example.com', meta=meta)
self.assertEqual(smartproxy.process_request(request, self.spider), None)
self.assertEqual(httpproxy.process_request(request, self.spider), None)
self.assertEqual(request.meta['proxy'], 'http://proxy.example.com:8011')
self.assertEqual(request.headers[b'Proxy-Authorization'], auth_header)

0 comments on commit 561e89c

Please sign in to comment.