async def test_bad_domain(mock_server): client = aio_cooker_client.CookerClient( cooker_domain_name="this-should-not-resolve.example.org", client_id="a_valid_client", client_secret="a_valid_secret", cache_ttl=10, ) with pytest.raises(aio_cooker_client.CookerConnectionError): _ = await client.get_credential()
async def test_server_404(mock_server): client = aio_cooker_client.CookerClient( credential_endpoint_override=f"http://localhost:8080/this-should-not-exist", token_endpoint_override=f"http://localhost:8080/oauth2/token", client_id="a_valid_client", client_secret="a_valid_secret", cache_ttl=10, ) with pytest.raises(aio_cooker_client.CookerResponseError): _ = await client.get_credential()
async def test_wrong_credentials(mock_server): client = aio_cooker_client.CookerClient( credential_endpoint_override=f"http://localhost:8080/v1/credential", token_endpoint_override=f"http://localhost:8080/oauth2/token", client_id="not_a_valid_id", client_secret="not_a_valid_secret", cache_ttl=10, ) with pytest.raises(aio_cooker_client.CookerTokenError): _ = await client.get_credential()
async def test_timeout(mock_server): client = aio_cooker_client.CookerClient( credential_endpoint_override=f"http://localhost:8080/timeout", token_endpoint_override=f"http://localhost:8080/oauth2/token", client_id="a_valid_client", client_secret="a_valid_secret", cache_ttl=10, client_timeout=1, ) with pytest.raises(aio_cooker_client.CookerConnectionError): _ = await client.get_credential()
async def test_get_credential(mock_server): client = aio_cooker_client.CookerClient( credential_endpoint_override=f"http://localhost:8080/v1/credentials", token_endpoint_override=f"http://localhost:8080/oauth2/token", client_id="a_valid_client", client_secret="a_valid_secret", cache_ttl=10, ) cred = await client.get_credential() assert cred.policy == "a_policy" assert cred.signature == "a_policy_signature" assert cred.key_pair_id == "a_key_pair_id"