1import pytest
    2 
    3import auth_utils
    4 
    5 
    6@pytest.mark.pgsql('auth', files=['test_data.sql'])
    7async def test_authenticate_base_proxy(service_client):
    8    response = await service_client.get('/v1/hello-proxy')
    9    assert response.status == 401
   10 
   11    authentication_header = response.headers['Proxy-Authenticate']
   12    auth_directives = auth_utils.parse_directives(authentication_header)
   13 
   14    auth_utils.auth_directives_assert(auth_directives)
   15 
   16    challenge = auth_utils.construct_challenge(auth_directives)
   17    auth_header = auth_utils.construct_header('username', 'pswd', challenge)
   18 
   19    response = await service_client.get(
   20        '/v1/hello-proxy', headers={'Proxy-Authorization': auth_header},
   21    )
   22    assert response.status == 200
   23    assert 'Proxy-Authentication-Info' in response.headers
   24 
   25 
   26@pytest.mark.pgsql('auth', files=['test_data.sql'])
   27async def test_postgres_wrong_data_proxy(service_client):
   28    response = await service_client.get('/v1/hello-proxy')
   29    assert response.status == 401
   30 
   31    authentication_header = response.headers['Proxy-Authenticate']
   32    auth_directives = auth_utils.parse_directives(authentication_header)
   33 
   34    auth_utils.auth_directives_assert(auth_directives)
   35 
   36    challenge = auth_utils.construct_challenge(auth_directives)
   37    auth_header = auth_utils.construct_header(
   38        'username', 'wrong-password', challenge,
   39    )
   40 
   41    response = await service_client.get(
   42        '/v1/hello-proxy', headers={'Proxy-Authorization': auth_header},
   43    )
   44    assert response.status == 401
   45    assert 'Proxy-Authenticate' in response.headers