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