Skip to content

Commit 29dd0df

Browse files
committed
test: test basic auth
1 parent 898d4a5 commit 29dd0df

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

frost_server/docker-compose.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ services:
1212
- persistence_db_username=sensorthings
1313
- persistence_db_password=ChangeMe
1414
- persistence_autoUpdateDatabase=true
15+
- auth_provider=de.fraunhofer.iosb.ilt.frostserver.auth.basic.BasicAuthProvider
16+
- auth_db_driver=org.postgresql.Driver
17+
- auth_db_url=jdbc:postgresql://database:5432/sensorthings
18+
- auth_db_username=sensorthings
19+
- auth_db_password=ChangeMe
20+
- auth_autoUpdateDatabase=true
1521
ports:
1622
- 8080:8080
1723
- 1883:1883

tests/conftest.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66

77
from frost_sta_client.service.sensorthingsservice import SensorThingsService
8+
from frost_sta_client.service.auth_handler import AuthHandler
89

910
@pytest.fixture(scope='session')
1011
def frost_server():
@@ -15,7 +16,7 @@ def frost_server():
1516
# Start FROST-Server using Podman
1617
subprocess.run(['podman', 'compose', '-f', 'frost_server/docker-compose.yaml', 'up', '-d'])
1718
# Wait for server to start
18-
url = 'http://localhost:8080/FROST-Server/v1.1'
19+
url = 'http://localhost:8080/FROST-Server'
1920
for _ in range(30):
2021
try:
2122
response = requests.get(url)
@@ -25,10 +26,22 @@ def frost_server():
2526
time.sleep(1)
2627
else:
2728
raise RuntimeError('FROST-Server failed to start')
29+
vrl = 'http://localhost:8080/FROST-Server/v1.1'
30+
auth_handler = AuthHandler(
31+
username="read",
32+
password="read"
33+
)
34+
response = requests.get(vrl, auth=auth_handler.add_auth_header())
35+
if response.status_code == 401:
36+
raise RuntimeError('Failed to authorize at FROST-Server')
2837
yield
2938
subprocess.run(['podman', 'compose', '-f', 'frost_server/docker-compose.yaml', 'down'])
3039

3140
@pytest.fixture
3241
def sensorthings_service(frost_server):
3342
url = 'http://localhost:8080/FROST-Server/v1.1'
34-
return SensorThingsService(url)
43+
auth_handler = AuthHandler(
44+
username="admin",
45+
password="admin"
46+
)
47+
return SensorThingsService(url, auth_handler=auth_handler)

0 commit comments

Comments
 (0)