mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-14 17:02:56 +00:00
add regression test
This commit is contained in:
@@ -3899,6 +3899,41 @@ class NeonProxy(PgProtocol):
|
||||
assert response.status_code == expected_code, f"response: {response.json()}"
|
||||
return response.json()
|
||||
|
||||
def http_multiquery(self, *queries, **kwargs):
|
||||
# TODO maybe use default values if not provided
|
||||
user = quote(kwargs["user"])
|
||||
password = quote(kwargs["password"])
|
||||
expected_code = kwargs.get("expected_code")
|
||||
timeout = kwargs.get("timeout")
|
||||
|
||||
json_queries = []
|
||||
for query in queries:
|
||||
if type(query) is str:
|
||||
json_queries.append({"query": query})
|
||||
else:
|
||||
[query, params] = query
|
||||
json_queries.append({"query": query, "params": params})
|
||||
|
||||
queries = [j["query"] for j in json_queries];
|
||||
log.info(f"Executing http queries: {queries}")
|
||||
|
||||
connstr = f"postgresql://{user}:{password}@{self.domain}:{self.proxy_port}/postgres"
|
||||
response = requests.post(
|
||||
f"https://{self.domain}:{self.external_http_port}/sql",
|
||||
data=json.dumps({"queries":json_queries}),
|
||||
headers={
|
||||
"Content-Type": "application/sql",
|
||||
"Neon-Connection-String": connstr,
|
||||
"Neon-Pool-Opt-In": "true",
|
||||
},
|
||||
verify=str(self.test_output_dir / "proxy.crt"),
|
||||
timeout=timeout,
|
||||
)
|
||||
|
||||
if expected_code is not None:
|
||||
assert response.status_code == expected_code, f"response: {response.json()}"
|
||||
return response.json()
|
||||
|
||||
async def http2_query(self, query, args, **kwargs):
|
||||
# TODO maybe use default values if not provided
|
||||
user = kwargs["user"]
|
||||
|
||||
@@ -513,6 +513,35 @@ def test_sql_over_http_pool(static_proxy: NeonProxy):
|
||||
assert "password authentication failed for user" in res["message"]
|
||||
|
||||
|
||||
def test_sql_over_http_pool_settings(static_proxy: NeonProxy):
|
||||
static_proxy.safe_psql("create user http_auth with password 'http' superuser")
|
||||
|
||||
def multiquery(*queries) -> Any:
|
||||
results = static_proxy.http_multiquery(
|
||||
*queries,
|
||||
user="http_auth",
|
||||
password="http",
|
||||
expected_code=200,
|
||||
)
|
||||
|
||||
return [result["rows"] for result in results["results"]]
|
||||
|
||||
[[intervalstyle]] = static_proxy.safe_psql("SHOW IntervalStyle")
|
||||
assert intervalstyle == "postgres", "'postgres' is the default IntervalStyle in postgres"
|
||||
|
||||
result = multiquery("select '0 seconds'::interval as interval")
|
||||
assert result[0][0]["interval"] == "00:00:00", "interval is expected in postgres format"
|
||||
|
||||
result = multiquery(
|
||||
"SET IntervalStyle = 'iso_8601'",
|
||||
"select '0 seconds'::interval as interval",
|
||||
)
|
||||
assert result[1][0]["interval"] == "PT0S", "interval is expected in ISO-8601 format"
|
||||
|
||||
result = multiquery("select '0 seconds'::interval as interval")
|
||||
assert result[0][0]["interval"] == "00:00:00", "interval is expected in postgres format"
|
||||
|
||||
|
||||
def test_sql_over_http_urlencoding(static_proxy: NeonProxy):
|
||||
static_proxy.safe_psql("create user \"http+auth$$\" with password '%+$^&*@!' superuser")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user