File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed
diracx-db/src/diracx/db/sql/pilot_agents Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change 4
4
from os import urandom
5
5
6
6
from sqlalchemy import DateTime , insert , select , update
7
- from sqlalchemy .exc import IntegrityError
7
+ from sqlalchemy .exc import IntegrityError , NoResultFound
8
8
9
9
from diracx .core .exceptions import (
10
10
AuthorizationError ,
@@ -79,7 +79,10 @@ async def verify_pilot_secret(
79
79
) -> None :
80
80
hashed_secret = hash (pilot_secret )
81
81
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
83
86
84
87
pilot_id = pilot ["PilotID" ]
85
88
Original file line number Diff line number Diff line change 2
2
3
3
from fastapi import HTTPException , status
4
4
5
- from diracx .core .exceptions import AuthorizationError
5
+ from diracx .core .exceptions import AuthorizationError , PilotNotFoundError
6
6
from diracx .logic .auth .token import create_token , exchange_token
7
7
8
8
from ..dependencies import (
@@ -36,6 +36,11 @@ async def pilot_login(
36
36
raise HTTPException (
37
37
status_code = status .HTTP_401_UNAUTHORIZED , detail = e .detail
38
38
) 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
39
44
40
45
pilot = await pilot_db .get_pilot_by_reference (pilot_ref = pilot_job_reference )
41
46
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ async def test_create_pilot_and_verify_secret(test_client):
48
48
49
49
assert secret is not None
50
50
51
- request_data = {"pilot_reference " : pilot_reference , "pilot_secret" : secret }
51
+ request_data = {"pilot_job_reference " : pilot_reference , "pilot_secret" : secret }
52
52
53
53
r = test_client .post (
54
54
"/api/auth/pilot-login" ,
@@ -88,7 +88,7 @@ async def test_create_pilot_and_verify_secret(test_client):
88
88
89
89
# ----------------- Wrong password -----------------
90
90
request_data = {
91
- "pilot_reference " : pilot_reference ,
91
+ "pilot_job_reference " : pilot_reference ,
92
92
"pilot_secret" : "My 1ncr3d1bl3 t0k3n" ,
93
93
}
94
94
@@ -102,7 +102,7 @@ async def test_create_pilot_and_verify_secret(test_client):
102
102
assert r .json ()["detail" ] == "bad pilot_id / pilot_secret"
103
103
104
104
# ----------------- Wrong ID -----------------
105
- request_data = {"pilot_id " : 63000 , "pilot_secret" : secret }
105
+ request_data = {"pilot_job_reference " : "It is a reference" , "pilot_secret" : secret }
106
106
107
107
r = test_client .post (
108
108
"/api/auth/pilot-login" ,
You can’t perform that action at this time.
0 commit comments