1616)
1717from diracx .db .exceptions import DBInBadStateError
1818from diracx .db .sql .pilot_agents .db import PilotAgentsDB
19- from diracx .db .sql .utils .functions import hash
19+ from diracx .db .sql .utils .functions import raw_hash
2020from diracx .testing .time import mock_sqlite_time
2121
2222MAIN_VO = "lhcb"
@@ -70,7 +70,7 @@ async def add_secrets_and_time(
7070 stamps = [pilot ["PilotStamp" ] for pilot in add_stamps ]
7171
7272 secrets = [f"AW0nd3rfulS3cr3t_{ str (i )} " for i in range (len (stamps ))]
73- hashed_secrets = [hash (secret ). encode ( ) for secret in secrets ]
73+ hashed_secrets = [raw_hash (secret ) for secret in secrets ]
7474
7575 # Add creds
7676 await pilot_agents_db .insert_unique_secrets_bulk (
@@ -115,7 +115,7 @@ async def add_secrets_and_time(
115115async def verify_pilot_secret (
116116 pilot_stamp : str ,
117117 pilot_db : PilotAgentsDB ,
118- hashed_secret : str ,
118+ hashed_secret : bytes ,
119119 frozen_time : freezegun .FreezeGun ,
120120) -> None :
121121
@@ -125,9 +125,7 @@ async def verify_pilot_secret(
125125 real_secret_uuid = pilot ["PilotSecretUUID" ]
126126
127127 # 2. Get the secret itself
128- given_secrets = await pilot_db .get_secrets_by_hashed_secrets_bulk (
129- [hashed_secret .encode ()]
130- )
128+ given_secrets = await pilot_db .get_secrets_by_hashed_secrets_bulk ([hashed_secret ])
131129 given_secret = given_secrets [0 ]
132130 given_secret_uuid = given_secret [
133131 "SecretUUID"
@@ -217,23 +215,23 @@ async def test_create_pilot_and_verify_secret(
217215 await verify_pilot_secret (
218216 pilot_db = pilot_agents_db ,
219217 pilot_stamp = stamp ,
220- hashed_secret = hash (secret ),
218+ hashed_secret = raw_hash (secret ),
221219 frozen_time = frozen_time ,
222220 )
223221
224222 with pytest .raises (SecretNotFoundError ):
225223 await verify_pilot_secret (
226224 pilot_db = pilot_agents_db ,
227225 pilot_stamp = stamps [0 ],
228- hashed_secret = hash ("I love stawberries :)" ),
226+ hashed_secret = raw_hash ("I love stawberries :)" ),
229227 frozen_time = frozen_time ,
230228 )
231229
232230 with pytest .raises (PilotNotFoundError ):
233231 await verify_pilot_secret (
234232 pilot_db = pilot_agents_db ,
235233 pilot_stamp = "I am a spider" ,
236- hashed_secret = hash (secrets [0 ]),
234+ hashed_secret = raw_hash (secrets [0 ]),
237235 frozen_time = frozen_time ,
238236 )
239237
@@ -258,7 +256,7 @@ async def test_create_pilot_and_verify_secret_with_delay(
258256 await verify_pilot_secret (
259257 pilot_db = pilot_agents_db ,
260258 pilot_stamp = stamps [0 ],
261- hashed_secret = hash (secrets [0 ]),
259+ hashed_secret = raw_hash (secrets [0 ]),
262260 frozen_time = frozen_time ,
263261 )
264262
@@ -281,7 +279,7 @@ async def test_create_pilot_and_verify_secret_too_much_secret_use(
281279 await verify_pilot_secret (
282280 pilot_db = pilot_agents_db ,
283281 pilot_stamp = stamps [0 ],
284- hashed_secret = hash (secrets [0 ]),
282+ hashed_secret = raw_hash (secrets [0 ]),
285283 frozen_time = frozen_time ,
286284 )
287285
@@ -291,7 +289,7 @@ async def test_create_pilot_and_verify_secret_too_much_secret_use(
291289 await verify_pilot_secret (
292290 pilot_db = pilot_agents_db ,
293291 pilot_stamp = stamps [0 ],
294- hashed_secret = hash (secrets [0 ]),
292+ hashed_secret = raw_hash (secrets [0 ]),
295293 frozen_time = frozen_time ,
296294 )
297295
@@ -316,6 +314,6 @@ async def test_create_pilot_and_login_with_bad_secret(
316314 await verify_pilot_secret (
317315 pilot_db = pilot_agents_db ,
318316 pilot_stamp = stamps [0 ],
319- hashed_secret = hash (secret ),
317+ hashed_secret = raw_hash (secret ),
320318 frozen_time = frozen_time ,
321319 )
0 commit comments