diff --git a/src/regps/app/api/exceptions.py b/src/regps/app/api/exceptions.py index 9161695..e6bd977 100644 --- a/src/regps/app/api/exceptions.py +++ b/src/regps/app/api/exceptions.py @@ -14,3 +14,7 @@ def __init__(self, detail: str, status_code: int): class DigestVerificationFailedException(HTTPException): def __init__(self, detail: str, status_code: int): super().__init__(status_code=status_code, detail=detail) + +class PresentRevocationFailedException(HTTPException): + def __init__(self, detail: str, status_code: int): + super().__init__(status_code=status_code, detail=detail) diff --git a/src/regps/app/api/utils/pydantic_models.py b/src/regps/app/api/utils/pydantic_models.py index ccc7844..c4e734d 100644 --- a/src/regps/app/api/utils/pydantic_models.py +++ b/src/regps/app/api/utils/pydantic_models.py @@ -46,11 +46,17 @@ class LoginRequest(BaseModel): said: str = Field(examples=login_examples["request"]["said"]) vlei: str = Field(examples=login_examples["request"]["vlei"]) +class PresentRevocationRequest(BaseModel): + said: str = Field(examples=login_examples["request"]["said"]) + vlei: str = Field(examples=login_examples["request"]["vlei"]) class LoginResponse(BaseModel): aid: str = Field(examples=login_examples["response"]["aid"]) said: str = Field(examples=login_examples["response"]["said"]) +class PresentRevocationResponse(BaseModel): + aid: str = Field(examples=login_examples["response"]["aid"]) + said: str = Field(examples=login_examples["response"]["said"]) class CheckLoginResponse(BaseModel): aid: str = Field(examples=check_login_examples["response"]["aid"]) diff --git a/src/regps/app/fastapi_app.py b/src/regps/app/fastapi_app.py index 5774bfa..d609494 100644 --- a/src/regps/app/fastapi_app.py +++ b/src/regps/app/fastapi_app.py @@ -14,7 +14,7 @@ LoginRequest, LoginResponse, CheckLoginResponse, - UploadResponse, + UploadResponse, PresentRevocationRequest, PresentRevocationResponse, ) from regps.app.api.exceptions import ( VerifierServiceException, @@ -63,6 +63,28 @@ async def login(response: Response, data: LoginRequest): raise HTTPException(status_code=500, detail=str(e)) +@app.post("/present_revocation", response_model=PresentRevocationResponse) +async def present_revocation(response: Response, data: PresentRevocationRequest): + """ + Given an AID and vLEI, returns information about the revocation + """ + try: + logger.info(f"PresentRevocation: sending login cred {str(data)[:50]}...") + resp = api_controller.login(data.said, data.vlei) + return JSONResponse(status_code=202, content=resp) + except VerifierServiceException as e: + logger.error(f"PresentRevocation: Exception: {e}") + response.status_code = e.status_code + return JSONResponse(content=e.detail, status_code=e.status_code) + except HTTPException as e: + logger.error(f"PresentRevocation: Exception: {e}") + response.status_code = e.status_code + return JSONResponse(content=e.detail, status_code=e.status_code) + except Exception as e: + logger.error(f"PresentRevocation: Exception: {e}") + raise HTTPException(status_code=500, detail=str(e)) + + @app.get("/checklogin/{aid}", response_model=CheckLoginResponse) async def check_login_route( response: Response, diff --git a/tests/unit/test_service.py b/tests/unit/test_service.py index e53e16f..82b0e4e 100644 --- a/tests/unit/test_service.py +++ b/tests/unit/test_service.py @@ -54,7 +54,7 @@ def test_ends(): result = client.get(f"/checklogin/{AID}", headers=headers) assert result.status_code == 200 - assert result.text == '{"aid":"EP4kdoVrDh4Mpzh2QbocUYIv4IjLZLDU367UO0b40f6x","said":"EElnd1DKvcDzzh7u7jBjsg2X9WgdQQuhgiu80i2VR-gk","lei":"875500ELOZEL05BVXV37","msg":"AID EP4kdoVrDh4Mpzh2QbocUYIv4IjLZLDU367UO0b40f6x w/ lei 875500ELOZEL05BVXV37 presented valid credential"}' + assert result.text == '{"aid":"EP4kdoVrDh4Mpzh2QbocUYIv4IjLZLDU367UO0b40f6x","said":"EElnd1DKvcDzzh7u7jBjsg2X9WgdQQuhgiu80i2VR-gk","lei":"875500ELOZEL05BVXV37","msg":"AID EP4kdoVrDh4Mpzh2QbocUYIv4IjLZLDU367UO0b40f6x w/ lei 875500ELOZEL05BVXV37 has valid login account"}' result = client.get(f"/upload/{AID}/{DIG}", headers=headers) assert result.status_code == 401 # fail because this signature should not verify