mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
6e8da71ece
(Work here originally done by awjchen, rebased and fixed up for merge by jberryman) This is part of a merge train towards GHC 9.2 compatibility. The main issue is the use of the new abstract `KeyMap` in 2.0. See: https://hackage.haskell.org/package/aeson-2.0.3.0/changelog Alex's original work is here: #4305 BEHAVIOR CHANGE NOTE: This change causes a different arbitrary ordering of serialized Json, for example during metadata export. CLI users care about this in particular, and so we need to call it out as a _behavior change_ as we did in v2.5.0. The good news though is that after this change ordering should be more stable (alphabetical key order). See: https://hasurahq.slack.com/archives/C01M20G1YRW/p1654012632634389 PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4611 Co-authored-by: awjchen <13142944+awjchen@users.noreply.github.com> GitOrigin-RevId: 700265162c782739b2bb88300ee3cda3819b2e87
62 lines
2.5 KiB
Python
62 lines
2.5 KiB
Python
import ruamel.yaml as yaml
|
|
import re
|
|
import json
|
|
|
|
class TestConfigAPI():
|
|
def test_config_api_user_role_error(self, hge_ctx):
|
|
admin_secret = hge_ctx.hge_key
|
|
auth_hook = hge_ctx.hge_webhook
|
|
jwt_conf = hge_ctx.hge_jwt_conf
|
|
if jwt_conf is not None:
|
|
jwt_conf_dict = json.loads(hge_ctx.hge_jwt_conf)
|
|
|
|
headers = { 'x-hasura-role': 'user' }
|
|
if admin_secret is not None:
|
|
headers['x-hasura-admin-secret'] = admin_secret
|
|
|
|
resp = hge_ctx.http.get(hge_ctx.hge_url + '/v1alpha1/config', headers=headers)
|
|
|
|
assert resp.status_code == 400, resp
|
|
|
|
def test_config_api(self, hge_ctx):
|
|
admin_secret = hge_ctx.hge_key
|
|
auth_hook = hge_ctx.hge_webhook
|
|
jwt_conf = hge_ctx.hge_jwt_conf
|
|
if jwt_conf is not None:
|
|
jwt_conf_dict = json.loads(hge_ctx.hge_jwt_conf)
|
|
|
|
headers = { 'x-hasura-role': 'admin' }
|
|
if admin_secret is not None:
|
|
headers['x-hasura-admin-secret'] = admin_secret
|
|
|
|
resp = hge_ctx.http.get(hge_ctx.hge_url + '/v1alpha1/config', headers=headers)
|
|
|
|
assert resp.status_code == 200, resp
|
|
|
|
body = resp.json()
|
|
assert body['is_admin_secret_set'] == (admin_secret is not None)
|
|
assert body['is_auth_hook_set'] == (auth_hook is not None)
|
|
assert body['is_jwt_set'] == (jwt_conf is not None)
|
|
|
|
if jwt_conf is not None:
|
|
claims_format = "json"
|
|
if 'claims_namespace_path' in jwt_conf_dict:
|
|
assert body['jwt']['claims_namespace_path'] == jwt_conf_dict['claims_namespace_path']
|
|
assert body['jwt']['claims_format'] == claims_format
|
|
else:
|
|
claims_namespace = "https://hasura.io/jwt/claims"
|
|
if 'claims_namespace' in jwt_conf_dict:
|
|
claims_namespace = jwt_conf_dict['claims_namespace']
|
|
if 'claims_format' in jwt_conf_dict:
|
|
claims_format = jwt_conf_dict['claims_format']
|
|
assert body['jwt']['claims_namespace'] == claims_namespace
|
|
assert body['jwt']['claims_format'] == claims_format
|
|
else:
|
|
assert body['jwt'] == []
|
|
|
|
# test if the request fails without auth headers if admin secret is set
|
|
if admin_secret is not None:
|
|
resp = hge_ctx.http.get(hge_ctx.hge_url + '/v1alpha1/config')
|
|
body = resp.json()
|
|
assert ((resp.status_code == 401) or (resp.status_code == 400))
|