Skip to content

Commit

Permalink
Added /present_revocation endpoint (#50)
Browse files Browse the repository at this point in the history
* Added /present_revocation endpoint

* Fix messages in tests
  • Loading branch information
aydarng authored Nov 13, 2024
1 parent 557becb commit b4c7d3f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/regps/app/api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 6 additions & 0 deletions src/regps/app/api/utils/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
24 changes: 23 additions & 1 deletion src/regps/app/fastapi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
LoginRequest,
LoginResponse,
CheckLoginResponse,
UploadResponse,
UploadResponse, PresentRevocationRequest, PresentRevocationResponse,
)
from regps.app.api.exceptions import (
VerifierServiceException,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b4c7d3f

Please sign in to comment.