async def test_github_io_false_positive(): respx.get("https://victim.com/").mock(return_value=httpx.Response( 200, text="There isn't a GitHub Pages site here")) respx.head("https://github.com/falsepositive").mock( return_value=httpx.Response(200, text="I'm registered")) takeover = TakeoverChecker() assert not await takeover.check("victim.com", "falsepositive.github.io")
async def test_github_io_true_positive(): respx.get("https://victim.com/").mock(return_value=httpx.Response( 200, text="There isn't a GitHub Pages site here")) respx.head("https://github.com/truepositive").mock( return_value=httpx.Response(404, text="No such user")) takeover = TakeoverChecker() assert await takeover.check("victim.com", "truepositive.github.io")
async def test_http_methods(client): async with respx.mock: url = "https://foo.bar/" m = respx.get(url, status_code=404) respx.post(url, status_code=201) respx.put(url, status_code=202) respx.patch(url, status_code=500) respx.delete(url, status_code=204) respx.head(url, status_code=405) respx.options(url, status_code=501) response = httpx.get(url) assert response.status_code == 404 response = await client.get(url) assert response.status_code == 404 response = httpx.post(url) assert response.status_code == 201 response = await client.post(url) assert response.status_code == 201 response = httpx.put(url) assert response.status_code == 202 response = await client.put(url) assert response.status_code == 202 response = httpx.patch(url) assert response.status_code == 500 response = await client.patch(url) assert response.status_code == 500 response = httpx.delete(url) assert response.status_code == 204 response = await client.delete(url) assert response.status_code == 204 response = httpx.head(url) assert response.status_code == 405 response = await client.head(url) assert response.status_code == 405 response = httpx.options(url) assert response.status_code == 501 response = await client.options(url) assert response.status_code == 501 assert m.called is True assert respx.stats.call_count == 7 * 2