Skip to content

Commit 55441af

Browse files
fix: Fixing tests
1 parent 31c6303 commit 55441af

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

diracx-db/src/diracx/db/sql/pilot_agents/db.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from os import urandom
55

66
from sqlalchemy import DateTime, insert, select, update
7-
from sqlalchemy.exc import IntegrityError
7+
from sqlalchemy.exc import IntegrityError, NoResultFound
88

99
from diracx.core.exceptions import (
1010
AuthorizationError,
@@ -79,7 +79,10 @@ async def verify_pilot_secret(
7979
) -> None:
8080
hashed_secret = hash(pilot_secret)
8181

82-
pilot = await self.get_pilot_by_reference(pilot_job_reference)
82+
try:
83+
pilot = await self.get_pilot_by_reference(pilot_job_reference)
84+
except NoResultFound as e:
85+
raise PilotNotFoundError(pilot_ref=pilot_job_reference) from e
8386

8487
pilot_id = pilot["PilotID"]
8588

diracx-routers/src/diracx/routers/auth/pilot.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from fastapi import HTTPException, status
44

5-
from diracx.core.exceptions import AuthorizationError
5+
from diracx.core.exceptions import AuthorizationError, PilotNotFoundError
66
from diracx.logic.auth.token import create_token, exchange_token
77

88
from ..dependencies import (
@@ -36,6 +36,11 @@ async def pilot_login(
3636
raise HTTPException(
3737
status_code=status.HTTP_401_UNAUTHORIZED, detail=e.detail
3838
) from e
39+
except PilotNotFoundError as e:
40+
raise HTTPException(
41+
status_code=status.HTTP_401_UNAUTHORIZED,
42+
detail="bad pilot_id / pilot_secret",
43+
) from e
3944

4045
pilot = await pilot_db.get_pilot_by_reference(pilot_ref=pilot_job_reference)
4146

diracx-routers/tests/auth/test_pilot_auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def test_create_pilot_and_verify_secret(test_client):
4848

4949
assert secret is not None
5050

51-
request_data = {"pilot_reference": pilot_reference, "pilot_secret": secret}
51+
request_data = {"pilot_job_reference": pilot_reference, "pilot_secret": secret}
5252

5353
r = test_client.post(
5454
"/api/auth/pilot-login",
@@ -88,7 +88,7 @@ async def test_create_pilot_and_verify_secret(test_client):
8888

8989
# ----------------- Wrong password -----------------
9090
request_data = {
91-
"pilot_reference": pilot_reference,
91+
"pilot_job_reference": pilot_reference,
9292
"pilot_secret": "My 1ncr3d1bl3 t0k3n",
9393
}
9494

@@ -102,7 +102,7 @@ async def test_create_pilot_and_verify_secret(test_client):
102102
assert r.json()["detail"] == "bad pilot_id / pilot_secret"
103103

104104
# ----------------- Wrong ID -----------------
105-
request_data = {"pilot_id": 63000, "pilot_secret": secret}
105+
request_data = {"pilot_job_reference": "It is a reference", "pilot_secret": secret}
106106

107107
r = test_client.post(
108108
"/api/auth/pilot-login",

0 commit comments

Comments
 (0)