这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions server/tests-py/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
from http import HTTPStatus
from urllib.parse import urlparse
from ruamel.yaml.comments import CommentedMap as OrderedDict # to avoid '!!omap' in yaml
# from collections import OrderedDict
# import socketserver
import threading
import http.server
import json
import queue
import socket
import subprocess
import time
import uuid
import string
import random
import os
Expand Down Expand Up @@ -292,7 +289,8 @@ def anyq(self, u, q, h):
)
# NOTE: make sure we preserve key ordering so we can test the ordering
# properties in the graphql spec properly
return resp.status_code, resp.json(object_pairs_hook=OrderedDict)
# Returning response headers to get the request id from response
return resp.status_code, resp.json(object_pairs_hook=OrderedDict), resp.headers

def sql(self, q):
conn = self.engine.connect()
Expand Down
2 changes: 1 addition & 1 deletion server/tests-py/test_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def get_parameterized_sql(self, hge_ctx, query, variables):
headers['X-Hasura-Admin-Secret'] = admin_secret

request = { 'query': { 'query': query, 'variables': variables }, 'user': {} }
status_code, response = hge_ctx.anyq('/v1/graphql/explain', request, headers)
status_code, response, _ = hge_ctx.anyq('/v1/graphql/explain', request, headers)
assert status_code == 200, (request, status_code, response)

sql = response['sql']
Expand Down
4 changes: 2 additions & 2 deletions server/tests-py/test_v1_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,13 @@ def test_export_replace(self, hge_ctx):
headers = {}
if hge_ctx.hge_key is not None:
headers['X-Hasura-Admin-Secret'] = hge_ctx.hge_key
export_code, export_resp = hge_ctx.anyq(url, export_query, headers)
export_code, export_resp, _ = hge_ctx.anyq(url, export_query, headers)
assert export_code == 200, export_resp
replace_query = {
'type': 'replace_metadata',
'args': export_resp
}
replace_code, replace_resp = hge_ctx.anyq(url, replace_query, headers)
replace_code, replace_resp, _ = hge_ctx.anyq(url, replace_query, headers)
assert replace_code == 200, replace_resp


Expand Down
34 changes: 20 additions & 14 deletions server/tests-py/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,28 @@ def test_forbidden_when_admin_secret_reqd(hge_ctx, conf):
headers = conf['headers']

# Test without admin secret
code, resp = hge_ctx.anyq(conf['url'], conf['query'], headers)
code, resp, resp_hdrs = hge_ctx.anyq(conf['url'], conf['query'], headers)
#assert code in [401,404], "\n" + yaml.dump({
assert code in status, "\n" + yaml.dump({
"expected": "Should be access denied as admin secret is not provided",
"actual": {
"code": code,
"response": resp
}
},
'request id': resp_hdrs.get('x-request-id')
})

# Test with random admin secret
headers['X-Hasura-Admin-Secret'] = base64.b64encode(os.urandom(30))
code, resp = hge_ctx.anyq(conf['url'], conf['query'], headers)
code, resp, resp_hdrs = hge_ctx.anyq(conf['url'], conf['query'], headers)
#assert code in [401,404], "\n" + yaml.dump({
assert code in status, "\n" + yaml.dump({
"expected": "Should be access denied as an incorrect admin secret is provided",
"actual": {
"code": code,
"response": resp
}
},
'request id': resp_hdrs.get('x-request-id')
})


Expand All @@ -112,14 +114,15 @@ def test_forbidden_webhook(hge_ctx, conf):
status = [401, 404]

h = {'Authorization': 'Bearer ' + base64.b64encode(base64.b64encode(os.urandom(30))).decode('utf-8')}
code, resp = hge_ctx.anyq(conf['url'], conf['query'], h)
code, resp, resp_hdrs = hge_ctx.anyq(conf['url'], conf['query'], h)
#assert code in [401,404], "\n" + yaml.dump({
assert code in status, "\n" + yaml.dump({
"expected": "Should be access denied as it is denied from webhook",
"actual": {
"code": code,
"response": resp
}
},
'request id': resp_hdrs.get('x-request-id')
})


Expand Down Expand Up @@ -232,12 +235,12 @@ def validate_gql_ws_q(hge_ctx, endpoint, query, headers, exp_http_response, retr


def validate_http_anyq(hge_ctx, url, query, headers, exp_code, exp_response):
code, resp = hge_ctx.anyq(url, query, headers)
code, resp, resp_hdrs = hge_ctx.anyq(url, query, headers)
print(headers)
assert code == exp_code, resp
print('http resp: ', resp)
if exp_response:
return assert_graphql_resp_expected(resp, exp_response, query)
return assert_graphql_resp_expected(resp, exp_response, query, resp_hdrs)
else:
return resp, True

Expand All @@ -247,7 +250,7 @@ def validate_http_anyq(hge_ctx, url, query, headers, exp_code, exp_response):
#
# Returns 'resp' and a bool indicating whether the test passed or not (this
# will always be True unless we are `--accepting`)
def assert_graphql_resp_expected(resp_orig, exp_response_orig, query):
def assert_graphql_resp_expected(resp_orig, exp_response_orig, query, resp_hdrs={}):
# Prepare actual and respected responses so comparison takes into
# consideration only the ordering that we care about:
resp = collapse_order_not_selset(resp_orig, query)
Expand All @@ -260,16 +263,19 @@ def assert_graphql_resp_expected(resp_orig, exp_response_orig, query):
yml = yaml.YAML()
# https://yaml.readthedocs.io/en/latest/example.html#output-of-dump-as-a-string :
dump_str = StringIO()
yml.dump({
test_output = {
# Keep strict received order when displaying errors:
'response': resp_orig,
'expected': exp_response_orig,
'diff':
(lambda diff:
'diff':
(lambda diff:
"(results differ only in their order of keys)" if diff == {} else diff)
(stringify_keys(jsondiff.diff(exp_response, resp)))
}, stream=dump_str)
assert matched, dump_str.getvalue()
}
if 'x-request-id' in resp_hdrs:
test_output['request id'] = resp_hdrs['x-request-id']
yml.dump(test_output, stream=dump_str)
assert matched, '\n' + dump_str.getvalue()
return resp, matched # matched always True unless --accept

# This really sucks; newer ruamel made __eq__ ignore ordering:
Expand Down