Skip to content

Commit 56b5959

Browse files
authored
Revert "Temporarily disable API key verification (#1181)" (#1182)
This reverts commit 46764f0.
1 parent 40da182 commit 56b5959

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed

jbi/router.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ def api_key_auth(
6767

6868
@router.post(
6969
"/bugzilla_webhook",
70-
# TODO:
71-
# dependencies=[Depends(api_key_auth)],
70+
dependencies=[Depends(api_key_auth)],
7271
)
7372
async def bugzilla_webhook(
7473
request: Request,

tests/unit/test_router.py

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base64
12
import json
23
import os
34
from datetime import datetime
@@ -19,34 +20,34 @@ def test_read_root(anon_client):
1920
assert get_settings().jira_base_url in infos["configuration"]["jira_base_url"]
2021

2122

22-
# @pytest.mark.parametrize(
23-
# "endpoint",
24-
# [
25-
# "/whiteboard_tags",
26-
# "/dl_queue/",
27-
# "/jira_projects/",
28-
# "/powered_by_jbi/",
29-
# "/bugzilla_webhooks/",
30-
# ],
31-
# )
32-
# def test_get_protected_endpoints(
33-
# endpoint, webhook_request_factory, mocked_bugzilla, anon_client, test_api_key
34-
# ):
35-
# resp = anon_client.get(endpoint)
36-
# assert resp.status_code == 401
37-
38-
# # Supports authentication via `X-Api-Key` header
39-
# resp = anon_client.get(endpoint, headers={"X-Api-Key": test_api_key})
40-
# assert resp.status_code == 200
41-
42-
# # Supports authentication via Basic Auth header
43-
# username_password = ":" + test_api_key
44-
# credentials_b64 = base64.b64encode(username_password.encode("utf8")).decode("utf8")
45-
# resp = anon_client.get(
46-
# endpoint,
47-
# headers={"Authorization": f"Basic {credentials_b64}"},
48-
# )
49-
# assert resp.status_code == 200
23+
@pytest.mark.parametrize(
24+
"endpoint",
25+
[
26+
"/whiteboard_tags",
27+
"/dl_queue/",
28+
"/jira_projects/",
29+
"/powered_by_jbi/",
30+
"/bugzilla_webhooks/",
31+
],
32+
)
33+
def test_get_protected_endpoints(
34+
endpoint, webhook_request_factory, mocked_bugzilla, anon_client, test_api_key
35+
):
36+
resp = anon_client.get(endpoint)
37+
assert resp.status_code == 401
38+
39+
# Supports authentication via `X-Api-Key` header
40+
resp = anon_client.get(endpoint, headers={"X-Api-Key": test_api_key})
41+
assert resp.status_code == 200
42+
43+
# Supports authentication via Basic Auth header
44+
username_password = ":" + test_api_key
45+
credentials_b64 = base64.b64encode(username_password.encode("utf8")).decode("utf8")
46+
resp = anon_client.get(
47+
endpoint,
48+
headers={"Authorization": f"Basic {credentials_b64}"},
49+
)
50+
assert resp.status_code == 200
5051

5152

5253
def test_whiteboard_tags(authenticated_client):
@@ -260,25 +261,25 @@ def test_webhook_is_500_if_queue_raises_Exception(
260261
assert response.status_code == 500
261262

262263

263-
# def test_webhook_is_401_if_unathenticated(
264-
# webhook_request_factory, mocked_bugzilla, anon_client
265-
# ):
266-
# response = anon_client.post(
267-
# "/bugzilla_webhook",
268-
# data={},
269-
# )
270-
# assert response.status_code == 401
271-
272-
273-
# def test_webhook_is_401_if_wrong_key(
274-
# webhook_request_factory, mocked_bugzilla, anon_client
275-
# ):
276-
# response = anon_client.post(
277-
# "/bugzilla_webhook",
278-
# headers={"X-Api-Key": "not the right key"},
279-
# data={},
280-
# )
281-
# assert response.status_code == 401
264+
def test_webhook_is_401_if_unathenticated(
265+
webhook_request_factory, mocked_bugzilla, anon_client
266+
):
267+
response = anon_client.post(
268+
"/bugzilla_webhook",
269+
data={},
270+
)
271+
assert response.status_code == 401
272+
273+
274+
def test_webhook_is_401_if_wrong_key(
275+
webhook_request_factory, mocked_bugzilla, anon_client
276+
):
277+
response = anon_client.post(
278+
"/bugzilla_webhook",
279+
headers={"X-Api-Key": "not the right key"},
280+
data={},
281+
)
282+
assert response.status_code == 401
282283

283284

284285
def test_webhook_is_422_if_bug_information_missing(

0 commit comments

Comments
 (0)