10
10
from requests import Response
11
11
12
12
HEADER_SESSION = "X-DATABEND-SESSION"
13
+ HEADER_CAPS = "X-DATABEND-CLIENT-CAPS"
13
14
# Define the URLs and credentials
14
15
query_url = "http://localhost:8000/v1/query"
15
16
login_url = "http://localhost:8000/v1/session/login"
@@ -22,10 +23,9 @@ def wrapper(self, *args, **kwargs):
22
23
print (f"---- { func .__name__ } { args [:1 ]} " )
23
24
resp : Response = func (self , * args , ** kwargs )
24
25
self .session_header = resp .headers .get (HEADER_SESSION )
26
+ json_str = base64 .urlsafe_b64decode (self .session_header )
25
27
last = self .session_header_json
26
- self .session_header_json = json .loads (
27
- base64 .urlsafe_b64decode (self .session_header )
28
- )
28
+ self .session_header_json = json .loads (json_str )
29
29
if last :
30
30
if last ["id" ] != self .session_header_json ["id" ]:
31
31
print (
@@ -72,7 +72,7 @@ def login(self):
72
72
auth = auth ,
73
73
headers = {
74
74
"Content-Type" : "application/json" ,
75
- "X-DATABEND-CLIENT-CAPS" : "session_header" ,
75
+ HEADER_CAPS : "session_header" ,
76
76
},
77
77
json = payload ,
78
78
)
@@ -83,7 +83,10 @@ def do_logout(self, _case_id):
83
83
response = self .client .post (
84
84
logout_url ,
85
85
auth = auth ,
86
- headers = {HEADER_SESSION : self .session_header },
86
+ headers = {
87
+ HEADER_CAPS : "session_header" ,
88
+ HEADER_SESSION : self .session_header
89
+ },
87
90
)
88
91
return response
89
92
@@ -95,6 +98,7 @@ def do_query(self, query, url=query_url):
95
98
auth = auth ,
96
99
headers = {
97
100
"Content-Type" : "application/json" ,
101
+ HEADER_CAPS : "session_header" ,
98
102
HEADER_SESSION : self .session_header ,
99
103
},
100
104
json = query_payload ,
@@ -109,7 +113,7 @@ def set_fake_last_refresh_time(self):
109
113
).decode ("ascii" )
110
114
111
115
112
- def main ():
116
+ def test_session ():
113
117
client = Client ()
114
118
client .login ()
115
119
@@ -134,6 +138,32 @@ def main():
134
138
pprint (query_resp .get ("session" ).get ("need_keep_alive" ))
135
139
136
140
141
+ # without X-DATABEND-CLIENT-CAPS:
142
+ # 1. query still works
143
+ # 2. X-DATABEND-SESSION is ignored
144
+ def test_no_session ():
145
+ client = requests .session ()
146
+ payload = {"sql" : "select * from numbers(100)" , "pagination" : {"max_rows_per_page" : 2 }}
147
+ resp = client .post (
148
+ query_url ,
149
+ auth = auth ,
150
+ headers = {"Content-Type" : "application/json" , HEADER_SESSION : "xxx" },
151
+ json = payload ,
152
+ )
153
+ resp = resp .json ()
154
+ next_uri = resp .get ("next_uri" )
155
+ resp = client .get (
156
+ f"http://localhost:8000/{ next_uri } " ,
157
+ auth = auth ,
158
+ )
159
+ resp = resp .json ()
160
+ assert len (resp ["data" ]) == 2 , resp
161
+
162
+ def main ():
163
+ test_no_session ()
164
+ test_session ()
165
+
166
+
137
167
if __name__ == "__main__" :
138
168
import logging
139
169
0 commit comments