Test when we have auth info in url, i.e. socks5://user:pass@host:port and no username/password as params
(self)
| 442 | assert response.headers["Server"] == "SocksTestServer" |
| 443 | |
| 444 | def test_socks_with_auth_in_url(self) -> None: |
| 445 | """ |
| 446 | Test when we have auth info in url, i.e. |
| 447 | socks5://user:pass@host:port and no username/password as params |
| 448 | """ |
| 449 | |
| 450 | def request_handler(listener: socket.socket) -> None: |
| 451 | sock = listener.accept()[0] |
| 452 | |
| 453 | handler = handle_socks5_negotiation( |
| 454 | sock, negotiate=True, username=b"user", password=b"pass" |
| 455 | ) |
| 456 | addr, port = next(handler) |
| 457 | |
| 458 | assert addr == "16.17.18.19" |
| 459 | assert port == 80 |
| 460 | with pytest.raises(StopIteration): |
| 461 | handler.send(True) |
| 462 | |
| 463 | while True: |
| 464 | buf = sock.recv(65535) |
| 465 | if buf.endswith(b"\r\n\r\n"): |
| 466 | break |
| 467 | |
| 468 | sock.sendall( |
| 469 | b"HTTP/1.1 200 OK\r\n" |
| 470 | b"Server: SocksTestServer\r\n" |
| 471 | b"Content-Length: 0\r\n" |
| 472 | b"\r\n" |
| 473 | ) |
| 474 | sock.close() |
| 475 | |
| 476 | self._start_server(request_handler) |
| 477 | proxy_url = f"socks5://user:pass@{self.host}:{self.port}" |
| 478 | with socks.SOCKSProxyManager(proxy_url) as pm: |
| 479 | response = pm.request("GET", "http://16.17.18.19") |
| 480 | |
| 481 | assert response.status == 200 |
| 482 | assert response.data == b"" |
| 483 | assert response.headers["Server"] == "SocksTestServer" |
| 484 | |
| 485 | def test_socks_with_invalid_password(self, monkeypatch: pytest.MonkeyPatch) -> None: |
| 486 | _set_up_fake_getaddrinfo(monkeypatch) |
nothing calls this directly
no test coverage detected