Commit c5578a43 authored by David Foucher's avatar David Foucher

Fix autorisation with 2 files for same mail adress

parent 83541366
Pipeline #2927 passed with stage
in 1 minute and 55 seconds
......@@ -528,7 +528,6 @@ async def test_authentification(patch_authorisations, client, mock_get):
"file": "/règles nationales/CPF.rules"
}
patch_authorisations([body])
mock_get(status_code=200)
date = datetime.datetime.today().strftime('%y%m%d')
token = hash(f"{body['email']}.{body['password']}.{date}")
resp = await client.post("/authentification", body=body)
......@@ -547,7 +546,6 @@ async def test_authentification_with_no_authorisation(patch_authorisations, clie
}
auth = []
patch_authorisations(auth)
mock_get(status_code=500)
resp = await client.post("/authentification", body=body)
assert resp.status == HTTPStatus.INTERNAL_SERVER_ERROR
......@@ -564,7 +562,25 @@ async def test_authentification_with_2_records(patch_authorisations, client, moc
"file": "/règles nationales/CPF.rules"}]
auth.append(body.copy())
patch_authorisations(auth)
mock_get(status_code=200)
date = datetime.datetime.today().strftime('%y%m%d')
token = hash(f"{body['email']}.{body['password']}.{date}")
resp = await client.post("/authentification", body=body)
assert resp.status == HTTPStatus.OK
assert json.loads(resp.body) == {
"token": token
}
async def test_authentification_with_2_files(patch_authorisations, client, mock_get):
body = {
"email": "test@test.fr",
"password": "test",
"file": "/règles nationales/CPF.rules"
}
auth = body
auth["file"] = "/rémunération/AREF.rulse|/règles nationales/CPF.rules"
patch_authorisations([auth])
date = datetime.datetime.today().strftime('%y%m%d')
token = hash(f"{body['email']}.{body['password']}.{date}")
resp = await client.post("/authentification", body=body)
......@@ -584,7 +600,6 @@ async def test_authentification_with_bad_matching_pattern(patch_authorisations,
auth = body.copy()
auth['file'] = "*"
patch_authorisations([auth])
mock_get(status_code=200)
resp = await client.post("/authentification", body=body)
assert resp.status == HTTPStatus.UNPROCESSABLE_ENTITY
......@@ -599,7 +614,6 @@ async def test_authentification_with_bad_email(patch_authorisations, client, moc
auth = body.copy()
auth['email'] = 'test@test.fr'
patch_authorisations([auth])
mock_get(status_code=401)
resp = await client.post("/authentification", body=body)
assert resp.status == HTTPStatus.UNAUTHORIZED
......@@ -617,7 +631,6 @@ async def test_authentification_with_token(patch_authorisations, client, mock_ge
"token": token
}
patch_authorisations([auth])
mock_get(status_code=200)
resp = await client.post("/authentification", body=body)
assert resp.status == HTTPStatus.OK
......
......@@ -199,7 +199,7 @@ async def authent(request, response):
atoken = hash(f"{aemail}.{apassword}.{date}")
if data.get('email') == aemail and data.get('password') == apassword:
try:
if re.match(afile, data.get('file')):
if any(bool(re.match(afile, f)) for f in data.get('file').split("|")):
authsuccess = True
logger.debug(f"authentification succeed for {data.get('file')} modification")
break
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment