mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-23 01:16:30 +00:00
Fix a Panic in admin commands (#779)
We have a panic when we send SHOW or ;;;;;;;;;;;;;;;;; to admin database. This PR fixes these panics and adds a couple of tests
This commit is contained in:
committed by
GitHub
parent
cbf4d58144
commit
8f9a2b8e6f
14
src/admin.rs
14
src/admin.rs
@@ -55,7 +55,12 @@ where
|
|||||||
|
|
||||||
let query_parts: Vec<&str> = query.trim_end_matches(';').split_whitespace().collect();
|
let query_parts: Vec<&str> = query.trim_end_matches(';').split_whitespace().collect();
|
||||||
|
|
||||||
match query_parts[0].to_ascii_uppercase().as_str() {
|
match query_parts
|
||||||
|
.first()
|
||||||
|
.unwrap_or(&"")
|
||||||
|
.to_ascii_uppercase()
|
||||||
|
.as_str()
|
||||||
|
{
|
||||||
"BAN" => {
|
"BAN" => {
|
||||||
trace!("BAN");
|
trace!("BAN");
|
||||||
ban(stream, query_parts).await
|
ban(stream, query_parts).await
|
||||||
@@ -84,7 +89,12 @@ where
|
|||||||
trace!("SHUTDOWN");
|
trace!("SHUTDOWN");
|
||||||
shutdown(stream).await
|
shutdown(stream).await
|
||||||
}
|
}
|
||||||
"SHOW" => match query_parts[1].to_ascii_uppercase().as_str() {
|
"SHOW" => match query_parts
|
||||||
|
.get(1)
|
||||||
|
.unwrap_or(&"")
|
||||||
|
.to_ascii_uppercase()
|
||||||
|
.as_str()
|
||||||
|
{
|
||||||
"HELP" => {
|
"HELP" => {
|
||||||
trace!("SHOW HELP");
|
trace!("SHOW HELP");
|
||||||
show_help(stream).await
|
show_help(stream).await
|
||||||
|
|||||||
@@ -91,6 +91,27 @@ describe "Admin" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
[
|
||||||
|
"SHOW ME THE MONEY",
|
||||||
|
"SHOW ME THE WAY",
|
||||||
|
"SHOW UP",
|
||||||
|
"SHOWTIME",
|
||||||
|
"HAMMER TIME",
|
||||||
|
"SHOWN TO BE TRUE",
|
||||||
|
"SHOW ",
|
||||||
|
"SHOW ",
|
||||||
|
"SHOW 1",
|
||||||
|
";;;;;"
|
||||||
|
].each do |cmd|
|
||||||
|
describe "Bad command #{cmd}" do
|
||||||
|
it "does not panic and responds with PG::SystemError" do
|
||||||
|
admin_conn = PG::connect(processes.pgcat.admin_connection_string)
|
||||||
|
expect { admin_conn.async_exec(cmd) }.to raise_error(PG::SystemError).with_message(/Unsupported/)
|
||||||
|
admin_conn.close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "PAUSE" do
|
describe "PAUSE" do
|
||||||
it "pauses all pools" do
|
it "pauses all pools" do
|
||||||
admin_conn = PG::connect(processes.pgcat.admin_connection_string)
|
admin_conn = PG::connect(processes.pgcat.admin_connection_string)
|
||||||
|
|||||||
Reference in New Issue
Block a user