Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mderynck committed Jul 17, 2024
1 parent c41d10f commit 674d6ae
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions engine/apps/auth_token/tests/test_plugin_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from apps.auth_token.auth import PluginAuthentication


INSTANCE_CONTEXT = '{"stack_id": 42, "org_id": 24, "grafana_token": "abc"}'

@pytest.mark.django_db
def test_plugin_authentication_self_hosted_success(make_organization, make_user, make_token_for_organization):
organization = make_organization(stack_id=42, org_id=24)
Expand All @@ -16,7 +18,7 @@ def test_plugin_authentication_self_hosted_success(make_organization, make_user,

headers = {
"HTTP_AUTHORIZATION": token_string,
"HTTP_X-Instance-Context": '{"stack_id": 42, "org_id": 24}',
"HTTP_X-Instance-Context": INSTANCE_CONTEXT,
"HTTP_X-Grafana-Context": '{"UserId": 12}',
}
request = APIRequestFactory().get("/", **headers)
Expand All @@ -34,7 +36,7 @@ def test_plugin_authentication_gcom_success(make_organization, make_user, make_t

headers = {
"HTTP_AUTHORIZATION": "gcom:123",
"HTTP_X-Instance-Context": '{"stack_id": 42, "org_id": 24}',
"HTTP_X-Instance-Context": INSTANCE_CONTEXT,
"HTTP_X-Grafana-Context": '{"UserId": 12}',
}
request = APIRequestFactory().get("/", **headers)
Expand All @@ -52,7 +54,7 @@ def test_plugin_authentication_fail_grafana_context(
organization = make_organization(stack_id=42, org_id=24)
token, token_string = make_token_for_organization(organization)

headers = {"HTTP_AUTHORIZATION": token_string, "HTTP_X-Instance-Context": '{"stack_id": 42, "org_id": 24}'}
headers = {"HTTP_AUTHORIZATION": token_string, "HTTP_X-Instance-Context": INSTANCE_CONTEXT}
if grafana_context is not None:
headers["HTTP_X-Grafana-Context"] = grafana_context

Expand All @@ -63,7 +65,7 @@ def test_plugin_authentication_fail_grafana_context(

@pytest.mark.django_db
@pytest.mark.parametrize("authorization", [None, "", "123", "gcom:123"])
@pytest.mark.parametrize("instance_context", [None, "", "non-json", '"string"', "{}", '{"stack_id": 1, "org_id": 1}'])
@pytest.mark.parametrize("instance_context", [None, "", "non-json", '"string"', "{}", '{"stack_id": 1, "org_id": 1, "grafana_token": "abc"}'])
def test_plugin_authentication_fail(authorization, instance_context):
headers = {}

Expand Down Expand Up @@ -102,7 +104,7 @@ def test_plugin_authentication_gcom_setup_new_user(make_organization):

headers = {
"HTTP_AUTHORIZATION": "gcom:123",
"HTTP_X-Instance-Context": '{"stack_id": 42, "org_id": 24}',
"HTTP_X-Instance-Context": INSTANCE_CONTEXT,
"HTTP_X-Grafana-Context": '{"UserId": 12}',
"HTTP_X-Oncall-User-Context": json.dumps(user_data),
}
Expand Down Expand Up @@ -136,7 +138,7 @@ def test_plugin_authentication_self_hosted_setup_new_user(make_organization, mak

headers = {
"HTTP_AUTHORIZATION": token_string,
"HTTP_X-Instance-Context": '{"stack_id": 42, "org_id": 24}',
"HTTP_X-Instance-Context": INSTANCE_CONTEXT,
"HTTP_X-Grafana-Context": '{"UserId": 12}',
"HTTP_X-Oncall-User-Context": json.dumps(user_data),
}
Expand Down

0 comments on commit 674d6ae

Please sign in to comment.