コード例 #1
0
ファイル: test_auth.py プロジェクト: pastor-robert/httpx
async def test_digest_auth_no_specified_qop():
    url = "https://example.org/"
    auth = DigestAuth(username="******", password="******")

    client = Client(dispatch=MockDigestAuthDispatch(qop=None))
    response = await client.get(url, auth=auth)

    assert response.status_code == 200
    auth = response.json()["auth"]
    assert auth.startswith("Digest ")

    response_fields = [
        field.strip() for field in auth[auth.find(" "):].split(",")
    ]
    digest_data = dict(field.split("=") for field in response_fields)

    assert "qop" not in digest_data
    assert "nc" not in digest_data
    assert "cnonce" not in digest_data
    assert digest_data["username"] == '"tomchristie"'
    assert digest_data["realm"] == '"*****@*****.**"'
    assert len(digest_data["nonce"]) == 64 + 2  # extra quotes
    assert digest_data["uri"] == '"/"'
    assert len(digest_data["response"]) == 64 + 2
    assert len(digest_data["opaque"]) == 64 + 2
    assert digest_data["algorithm"] == "SHA-256"
コード例 #2
0
ファイル: test_auth.py プロジェクト: pastor-robert/httpx
async def test_digest_auth(algorithm, expected_hash_length,
                           expected_response_length):
    url = "https://example.org/"
    auth = DigestAuth(username="******", password="******")

    client = Client(dispatch=MockDigestAuthDispatch(algorithm=algorithm))
    response = await client.get(url, auth=auth)

    assert response.status_code == 200
    auth = response.json()["auth"]
    assert auth.startswith("Digest ")

    response_fields = [
        field.strip() for field in auth[auth.find(" "):].split(",")
    ]
    digest_data = dict(field.split("=") for field in response_fields)

    assert digest_data["username"] == '"tomchristie"'
    assert digest_data["realm"] == '"*****@*****.**"'
    assert "nonce" in digest_data
    assert digest_data["uri"] == '"/"'
    assert len(digest_data["response"]
               ) == expected_response_length + 2  # extra quotes
    assert len(digest_data["opaque"]) == expected_hash_length + 2
    assert digest_data["algorithm"] == algorithm
    assert digest_data["qop"] == "auth"
    assert digest_data["nc"] == "00000001"
    assert len(digest_data["cnonce"]) == 16 + 2