userver: samples/postgres_auth/tests/test_postgres.py
Loading...
Searching...
No Matches
samples/postgres_auth/tests/test_postgres.py
1# /// [Functional test]
2import pytest
3
4
5@pytest.mark.pgsql('auth', files=['test_data.sql'])
6async def test_postgres(service_client):
7 response = await service_client.get('/v1/hello')
8 assert response.status == 401
9 assert response.text == "Empty 'Authorization' header"
10
11 response = await service_client.get(
12 '/v1/hello', headers={'Authorization': 'Bearer THE_USER_TOKEN'},
13 )
14 assert response.status == 200
15 assert 'text/plain' in response.headers['Content-Type']
16 assert response.text == 'Hello world, Dear User!\n'
17 # /// [Functional test]
18
19 response = await service_client.get(
20 '/v1/hello', headers={'Authorization': 'wrong format'},
21 )
22 assert response.status == 401
23 assert b'Bearer some-token' in response.content
24
25 response = await service_client.get(
26 '/v1/hello', headers={'Authorization': 'wrong'},
27 )
28 assert response.status == 401
29 assert b'Bearer some-token' in response.content
30
31 response = await service_client.get(
32 '/v1/hello', headers={'Authorization': 'Bearer wrong-token'},
33 )
34 assert response.status == 403
35
36 response = await service_client.get(
37 '/v1/hello', headers={'Authorization': 'Bearer '},
38 )
39 assert response.status == 403
40
41 response = await service_client.get(
42 '/v1/hello', headers={'Authorization': 'Bearer wrong-scopes-token'},
43 )
44 assert response.status == 403