forked from hasura/graphql-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_auth_webhook_cookie.py
68 lines (54 loc) · 2.09 KB
/
test_auth_webhook_cookie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import pytest
@pytest.mark.usefixtures('auth_hook', 'per_class_tests_db_state')
@pytest.mark.admin_secret
class TestWebhookHeaderCookie(object):
@classmethod
def dir(cls):
return 'webhook/insecure'
def test_single_set_cookie_header_in_response(self, hge_ctx):
query = """
query allUsers {
author {
id
name
}
}
"""
query_obj = {
"query": query,
"operationName": "allUsers"
}
headers = {}
headers['cookie'] = "Test"
headers['response-set-cookie-1'] = "__Host-id=1; Secure; Path=/; Domain=example.com"
code, resp, respHeaders = hge_ctx.anyq('/v1/graphql', query_obj, headers)
print("Status Code: ", code)
print("Response: ", resp)
print("Headers: ", respHeaders)
assert 'Set-Cookie' in respHeaders
assert respHeaders['Set-Cookie'] == "__Host-id=1; Secure; Path=/; Domain=example.com"
def test_duplicate_set_cookie_header_in_response(self, hge_ctx):
query = """
query allUsers {
author {
id
name
}
}
"""
query_obj = {
"query": query,
"operationName": "allUsers"
}
headers = {}
headers['cookie'] = "Test"
headers['response-set-cookie-1'] = "__Host-id=1; Secure; Path=/; Domain=example1.com"
headers['response-set-cookie-2'] = "__Host-id=2; Secure; Path=/; Domain=example2.com"
code, resp, respHeaders = hge_ctx.anyq('/v1/graphql', query_obj, headers)
print("Status Code: ", code)
print("Response: ", resp)
print("Headers: ", respHeaders)
assert 'Set-Cookie' in respHeaders
# In python, multiple headers with the same key are concatenated with a comma and
# then sent back in the response. Refer to: https://github.com/psf/requests/issues/4520
assert respHeaders['Set-Cookie'] == "__Host-id=2; Secure; Path=/; Domain=example2.com, __Host-id=1; Secure; Path=/; Domain=example1.com"