mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
Add test for HTTP GET provides readonly access.
This commit is contained in:
parent
36773b661c
commit
5def95f05b
@ -10,6 +10,7 @@ import socket
|
||||
import subprocess
|
||||
import time
|
||||
import urllib
|
||||
import httplib
|
||||
import xml.dom.minidom
|
||||
import logging
|
||||
import docker
|
||||
@ -652,7 +653,7 @@ class ClickHouseInstance:
|
||||
return self.client.query_and_get_answer_with_error(sql, stdin, timeout, settings, user, password)
|
||||
|
||||
# Connects to the instance via HTTP interface, sends a query and returns the answer
|
||||
def http_query(self, sql, data=None, params=None, user=None, password=None):
|
||||
def http_query(self, sql, data=None, params=None, user=None, password=None, expect_fail_and_get_error=False):
|
||||
if params is None:
|
||||
params = {}
|
||||
else:
|
||||
@ -668,7 +669,23 @@ class ClickHouseInstance:
|
||||
|
||||
url = "http://" + auth + self.ip_address + ":8123/?" + urllib.urlencode(params)
|
||||
|
||||
return urllib.urlopen(url, data).read()
|
||||
open_result = urllib.urlopen(url, data)
|
||||
|
||||
def http_code_and_message():
|
||||
return str(open_result.getcode()) + " " + httplib.responses[open_result.getcode()] + ": " + open_result.read()
|
||||
|
||||
if expect_fail_and_get_error:
|
||||
if open_result.getcode() == 200:
|
||||
raise Exception("ClickHouse HTTP server is expected to fail, but succeeded: " + open_result.read())
|
||||
return http_code_and_message()
|
||||
else:
|
||||
if open_result.getcode() != 200:
|
||||
raise Exception("ClickHouse HTTP server returned " + http_code_and_message())
|
||||
return open_result.read()
|
||||
|
||||
# Connects to the instance via HTTP interface, sends a query, expects an error and return the error message
|
||||
def http_query_and_get_error(self, sql, data=None, params=None, user=None, password=None):
|
||||
return self.http_query(sql=sql, data=data, params=params, user=user, password=password, expect_fail_and_get_error=True)
|
||||
|
||||
def kill_clickhouse(self, stop_start_wait_sec=5):
|
||||
pid = self.get_process_pid("clickhouse")
|
||||
|
20
dbms/tests/integration/test_http_and_readonly/test.py
Normal file
20
dbms/tests/integration/test_http_and_readonly/test.py
Normal file
@ -0,0 +1,20 @@
|
||||
import pytest
|
||||
from helpers.cluster import ClickHouseCluster
|
||||
|
||||
cluster = ClickHouseCluster(__file__)
|
||||
instance = cluster.add_instance('instance')
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def setup_nodes():
|
||||
try:
|
||||
cluster.start()
|
||||
yield cluster
|
||||
|
||||
finally:
|
||||
cluster.shutdown()
|
||||
|
||||
|
||||
def test_http_get_is_readonly():
|
||||
assert "Cannot execute query in readonly mode" in instance.http_query_and_get_error("CREATE TABLE xxx (a Date) ENGINE = MergeTree(a, a, 256)")
|
||||
assert "Cannot modify 'readonly' setting in readonly mode" in instance.http_query_and_get_error("CREATE TABLE xxx (a Date) ENGINE = MergeTree(a, a, 256)", params={"readonly": 0})
|
Loading…
Reference in New Issue
Block a user