Skip to content

Commit f424325

Browse files
committed
fix: cleanup
1 parent 65103c7 commit f424325

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
clean:
2+
docker compose down --volumes --remove-orphans || true && \
3+
docker image prune -a --force || true
4+
15
format:
26
docker build --target=format -t package:format -f dockerfile . && \
37
docker run --rm \
@@ -18,7 +22,7 @@ lint:
1822
package:lint
1923
docker rmi package:lint || true
2024

21-
test:
25+
test: clean
2226
docker compose run test_runner; \
2327
EXIT_CODE=$$?; \
2428
docker compose down; \

fastapi_clerk_auth/__init__.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,16 @@ async def __call__(self, request: Request) -> Optional[HTTPAuthorizationCredenti
151151
scheme, credentials = get_authorization_scheme_param(authorization)
152152
if not (authorization and scheme and credentials):
153153
if self.auto_error:
154-
raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Not Authenticated")
154+
raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Forbidden")
155155
return None
156156
if scheme.lower() != "bearer":
157157
if self.auto_error:
158-
raise HTTPException(
159-
status_code=HTTP_403_FORBIDDEN,
160-
detail="Invalid Authentication Credentials",
161-
)
158+
raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Forbidden")
162159
return None
163160

164161
decoded_token: dict | None = self._decode_token(token=credentials)
165162
if not decoded_token and self.auto_error:
166-
raise HTTPException(
167-
status_code=HTTP_403_FORBIDDEN,
168-
detail="Invalid Authentication Credentials",
169-
)
163+
raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Forbidden")
170164
response = HTTPAuthorizationCredentials(scheme=scheme, credentials=credentials, decoded=decoded_token)
171165
if self.add_state:
172166
request.state.clerk_auth = response

tests/test_package.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ def test_protected_route_access_granted(jwt_token):
1313
assert response.status_code == 200
1414

1515

16+
def test_protected_route_access_granted_decoded(jwt_token):
17+
response = requests.get("http://mock_api_server:8001/protected", headers={"Authorization": f"Bearer {jwt_token}"})
18+
assert response.status_code == 200
19+
assert "user" in response.json()
20+
assert response.json()["user"]["sub"] == "1234567890"
21+
22+
1623
def test_protected_route_access_denied():
1724
response = requests.get("http://mock_api_server:8001/protected")
1825
assert response.status_code == 403
26+
27+
28+
def test_protected_route_access_denied_bad_token(jwt_token):
29+
response = requests.get("http://mock_api_server:8001/protected", headers={"Authorization": f"Bearer {jwt_token}invalid"})
30+
assert response.status_code == 403

0 commit comments

Comments
 (0)