userver: samples/digest_auth_service/tests/test_proxy.py
Loading...
Searching...
No Matches
samples/digest_auth_service/tests/test_proxy.py
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',
20 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',
39 'wrong-password',
40 challenge,
41 )
42
43 response = await service_client.get(
44 '/v1/hello-proxy',
45 headers={'Proxy-Authorization': auth_header},
46 )
47 assert response.status == 401
48 assert 'Proxy-Authenticate' in response.headers