Secure controller to compute communication using HTTP basic authentication

This commit is contained in:
grossmj committed 2021-11-18 18:37:10 +10:30
1 parent 55e50dae4b
commit 38388f7ae5
24 files changed
+483 -416

No files matched your search

+14 -8
View File
@@ -27,27 +27,33 @@ from gns3server.compute.project import Project
pytestmark = pytest.mark.asyncio
async def test_udp_allocation(app: FastAPI, client: AsyncClient, compute_project: Project) -> None:
async def test_udp_allocation(app: FastAPI, compute_client: AsyncClient, compute_project: Project) -> None:
response = await client.post(app.url_path_for("compute:allocate_udp_port", project_id=compute_project.id), json={})
response = await compute_client.post(app.url_path_for("compute:allocate_udp_port", project_id=compute_project.id), json={})
assert response.status_code == status.HTTP_201_CREATED
assert response.json()['udp_port'] is not None
async def test_interfaces(app: FastAPI, client: AsyncClient) -> None:
async def test_interfaces(app: FastAPI, compute_client: AsyncClient) -> None:
response = await client.get(app.url_path_for("compute:network_interfaces"))
response = await compute_client.get(app.url_path_for("compute:network_interfaces"))
assert response.status_code == status.HTTP_200_OK
assert isinstance(response.json(), list)
async def test_version_output(app: FastAPI, client: AsyncClient) -> None:
async def test_version_output(app: FastAPI, compute_client: AsyncClient) -> None:
response = await client.get(app.url_path_for("compute:compute_version"))
response = await compute_client.get(app.url_path_for("compute:compute_version"))
assert response.status_code == status.HTTP_200_OK
assert response.json() == {'local': True, 'version': __version__}
async def test_compute_authentication(app: FastAPI, compute_client: AsyncClient) -> None:
response = await compute_client.get(app.url_path_for("compute:compute_version"), auth=("admin", "invalid_password"))
assert response.status_code == status.HTTP_401_UNAUTHORIZED
# @pytest.mark.asyncio
# async def test_debug_output(compute_api):
#
@@ -55,7 +61,7 @@ async def test_version_output(app: FastAPI, client: AsyncClient) -> None:
# assert response.status_code == 200
async def test_statistics_output(app: FastAPI, client: AsyncClient) -> None:
async def test_statistics_output(app: FastAPI, compute_client: AsyncClient) -> None:
response = await client.get(app.url_path_for("compute:compute_statistics"))
response = await compute_client.get(app.url_path_for("compute:compute_statistics"))
assert response.status_code == status.HTTP_200_OK