Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
0f3ec94e
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0f3ec94e
编写于
4月 03, 2019
作者:
Y
Yuriy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added mysql protocol test
上级
e91fd22b
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
168 addition
and
10 deletion
+168
-10
dbms/programs/server/MySQLHandler.cpp
dbms/programs/server/MySQLHandler.cpp
+23
-5
dbms/programs/server/MySQLHandler.h
dbms/programs/server/MySQLHandler.h
+0
-3
dbms/src/Core/MySQLProtocol.h
dbms/src/Core/MySQLProtocol.h
+1
-1
dbms/tests/integration/helpers/cluster.py
dbms/tests/integration/helpers/cluster.py
+1
-1
dbms/tests/integration/test_mysql_protocol/__init__.py
dbms/tests/integration/test_mysql_protocol/__init__.py
+0
-0
dbms/tests/integration/test_mysql_protocol/configs/config.xml
.../tests/integration/test_mysql_protocol/configs/config.xml
+20
-0
dbms/tests/integration/test_mysql_protocol/configs/users.xml
dbms/tests/integration/test_mysql_protocol/configs/users.xml
+23
-0
dbms/tests/integration/test_mysql_protocol/test.py
dbms/tests/integration/test_mysql_protocol/test.py
+100
-0
未找到文件。
dbms/programs/server/MySQLHandler.cpp
浏览文件 @
0f3ec94e
...
...
@@ -36,7 +36,7 @@ void MySQLHandler::run()
try
{
Handshake
handshake
(
connection_id
,
VERSION_
FULL
);
Handshake
handshake
(
connection_id
,
VERSION_
STRING
);
packet_sender
.
sendPacket
<
Handshake
>
(
handshake
,
true
);
LOG_TRACE
(
log
,
"Sent handshake"
);
...
...
@@ -82,10 +82,24 @@ void MySQLHandler::run()
packet
.
readPayload
(
std
::
move
(
handshake_response
.
auth_response
));
password
=
packet
.
value
;
}
LOG_TRACE
(
log
,
"password: "
<<
password
);
try
{
connection_context
.
setUser
(
handshake_response
.
username
,
password
,
socket
().
address
(),
""
);
connection_context
.
setCurrentDatabase
(
handshake_response
.
database
);
connection_context
.
setCurrentQueryId
(
""
);
LOG_ERROR
(
log
,
"Authentication for user "
<<
handshake_response
.
username
<<
" succeeded."
);
}
catch
(
const
NetException
&
)
{
throw
;
}
catch
(
const
Exception
&
exc
)
{
LOG_ERROR
(
log
,
"Authentication for user "
<<
handshake_response
.
username
<<
" failed."
);
packet_sender
.
sendPacket
(
ERR_Packet
(
exc
.
code
(),
"00000"
,
exc
.
message
()),
true
);
throw
;
}
OK_Packet
ok_packet
(
0
,
handshake_response
.
capability_flags
,
0
,
0
,
0
,
0
,
""
);
packet_sender
.
sendPacket
(
ok_packet
,
true
);
...
...
@@ -187,6 +201,10 @@ void MySQLHandler::comQuery(String payload)
LOG_TRACE
(
log
,
"Sent columns definitions."
);
if
(
!
(
capabilities
&
Capability
::
CLIENT_DEPRECATE_EOF
))
{
packet_sender
.
sendPacket
(
EOF_Packet
(
0
,
0
));
}
while
(
Block
block
=
res
.
in
->
read
())
{
size_t
rows
=
block
.
rows
();
...
...
dbms/programs/server/MySQLHandler.h
浏览文件 @
0f3ec94e
...
...
@@ -34,9 +34,6 @@ private:
Poco
::
Logger
*
log
;
Context
connection_context
;
std
::
shared_ptr
<
ReadBuffer
>
in
;
std
::
shared_ptr
<
WriteBuffer
>
out
;
MySQLProtocol
::
PacketSender
packet_sender
;
uint32_t
connection_id
=
0
;
...
...
dbms/src/Core/MySQLProtocol.h
浏览文件 @
0f3ec94e
...
...
@@ -365,7 +365,7 @@ public:
{
String
result
;
result
.
append
(
1
,
0xfe
);
result
.
append
(
plugin_name
);
writeNulTerminatedString
(
result
,
plugin_name
);
result
.
append
(
auth_plugin_data
);
return
result
;
}
...
...
dbms/tests/integration/helpers/cluster.py
浏览文件 @
0f3ec94e
...
...
@@ -102,7 +102,7 @@ class ClickHouseCluster:
self
.
with_hdfs
=
False
self
.
with_mongo
=
False
self
.
docker_client
=
None
self
.
docker_client
=
None
# type: docker.DockerClient
self
.
is_up
=
False
...
...
dbms/tests/integration/test_mysql_protocol/__init__.py
0 → 100644
浏览文件 @
0f3ec94e
dbms/tests/integration/test_mysql_protocol/configs/config.xml
0 → 100644
浏览文件 @
0f3ec94e
<?xml version="1.0"?>
<yandex>
<logger>
<level>
trace
</level>
<log>
/var/log/clickhouse-server/clickhouse-server.log
</log>
<errorlog>
/var/log/clickhouse-server/clickhouse-server.err.log
</errorlog>
<size>
1000M
</size>
<count>
10
</count>
</logger>
<tcp_port>
9000
</tcp_port>
<mysql_port>
9001
</mysql_port>
<listen_host>
127.0.0.1
</listen_host>
<max_concurrent_queries>
500
</max_concurrent_queries>
<mark_cache_size>
5368709120
</mark_cache_size>
<path>
./clickhouse/
</path>
<users_config>
users.xml
</users_config>
</yandex>
dbms/tests/integration/test_mysql_protocol/configs/users.xml
0 → 100644
浏览文件 @
0f3ec94e
<?xml version="1.0"?>
<yandex>
<profiles>
<default>
</default>
</profiles>
<users>
<default>
<password>
123
</password>
<networks
incl=
"networks"
replace=
"replace"
>
<ip>
::/0
</ip>
</networks>
<profile>
default
</profile>
<quota>
default
</quota>
</default>
</users>
<quotas>
<default>
</default>
</quotas>
</yandex>
dbms/tests/integration/test_mysql_protocol/test.py
0 → 100644
浏览文件 @
0f3ec94e
# coding: utf-8
import
os
import
pytest
import
pymysql.connections
from
docker.models.containers
import
Container
from
helpers.cluster
import
ClickHouseCluster
SCRIPT_DIR
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
cluster
=
ClickHouseCluster
(
__file__
,
base_configs_dir
=
os
.
path
.
join
(
SCRIPT_DIR
,
'./configs'
))
node
=
cluster
.
add_instance
(
'node'
,
with_mysql
=
True
)
server_port
=
9001
@
pytest
.
fixture
(
scope
=
"module"
)
def
started_cluster
():
cluster
.
start
()
try
:
yield
cluster
finally
:
cluster
.
shutdown
()
@
pytest
.
fixture
(
scope
=
'module'
)
def
mysql_container
(
started_cluster
):
# type: (ClickHouseCluster) -> Container
yield
started_cluster
.
docker_client
.
containers
.
get
(
started_cluster
.
get_instance_docker_id
(
'mysql1'
))
@
pytest
.
fixture
(
scope
=
'module'
)
def
server_address
(
started_cluster
):
yield
started_cluster
.
get_instance_ip
(
'node'
)
def
test_select
(
mysql_container
,
server_address
):
# type: (Container, str) -> None
code
,
(
stdout
,
stderr
)
=
mysql_container
.
exec_run
(
'''
mysql --protocol tcp -h {host} -P {port} default -u default --enable-cleartext-plugin --password=123
-e "select 1 as a;"
-e "select 'тест' as b;"
'''
.
format
(
host
=
server_address
,
port
=
server_port
),
demux
=
True
)
assert
stdout
==
'a
\n
1
\n
b
\n
тест
\n
'
def
test_authentication
(
mysql_container
,
server_address
):
# type: (Container, str) -> None
code
,
(
stdout
,
stderr
)
=
mysql_container
.
exec_run
(
'''
mysql --protocol tcp -h {host} -P {port} default -u default --enable-cleartext-plugin --password=abc -e "select 1 as a;"
'''
.
format
(
host
=
server_address
,
port
=
server_port
),
demux
=
True
)
assert
stderr
==
'mysql: [Warning] Using a password on the command line interface can be insecure.
\n
'
\
'ERROR 193 (00000): Wrong password for user default
\n
'
def
test_change_database
(
mysql_container
,
server_address
):
# type: (Container, str) -> None
code
,
(
stdout
,
stderr
)
=
mysql_container
.
exec_run
(
'''
mysql --protocol tcp -h {host} -P {port} default -u default --enable-cleartext-plugin --password=123
-e "use system;"
-e "select count(*) from (select name from tables limit 1);"
-e "use system2;"
'''
.
format
(
host
=
server_address
,
port
=
server_port
),
demux
=
True
)
assert
stdout
==
'count()
\n
1
\n
'
assert
stderr
==
"mysql: [Warning] Using a password on the command line interface can be insecure.
\n
"
\
"ERROR 81 (00000) at line 1: Database system2 doesn't exist
\n
"
def
test_py_client
(
server_address
):
with
pytest
.
raises
(
pymysql
.
InternalError
)
as
exc_info
:
pymysql
.
connections
.
Connection
(
host
=
server_address
,
user
=
'default'
,
password
=
'abacab'
,
database
=
'default'
,
port
=
server_port
)
assert
exc_info
.
value
.
args
==
(
193
,
'Wrong password for user default'
)
client
=
pymysql
.
connections
.
Connection
(
host
=
server_address
,
user
=
'default'
,
password
=
'123'
,
database
=
'default'
,
port
=
server_port
)
with
pytest
.
raises
(
pymysql
.
InternalError
)
as
exc_info
:
client
.
query
(
'select name from tables'
)
assert
exc_info
.
value
.
args
==
(
60
,
"Table default.tables doesn't exist."
)
cursor
=
client
.
cursor
(
pymysql
.
cursors
.
DictCursor
)
cursor
.
execute
(
"select 1 as a, 'тест' as b"
)
assert
cursor
.
fetchall
()
==
[{
'a'
:
'1'
,
'b'
:
'тест'
}]
client
.
select_db
(
'system'
)
with
pytest
.
raises
(
pymysql
.
InternalError
)
as
exc_info
:
client
.
select_db
(
'system2'
)
assert
exc_info
.
value
.
args
==
(
81
,
"Database system2 doesn't exist"
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录