Skip to content

chore: case-sensitive config string #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions questdb-rs/src/ingress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1592,8 +1592,8 @@ fn configure_tls(
Ok(Some(Arc::new(config)))
}

fn validate_auto_flush_params(params: &HashMap<String, &String>) -> Result<()> {
if let Some(&auto_flush) = params.get("auto_flush") {
fn validate_auto_flush_params(params: &HashMap<String, String>) -> Result<()> {
if let Some(auto_flush) = params.get("auto_flush") {
if auto_flush.as_str() != "off" {
return Err(error::fmt!(
ConfigError,
Expand Down Expand Up @@ -1692,7 +1692,7 @@ impl Protocol {
}

fn from_schema(schema: &str) -> Result<Self> {
match schema.to_lowercase().as_str() {
match schema {
"tcp" => Ok(Protocol::Tcp),
"tcps" => Ok(Protocol::Tcps),
#[cfg(feature = "ilp-over-http")]
Expand Down Expand Up @@ -1804,14 +1804,10 @@ impl SenderBuilder {
let conf = conf.as_ref();
let conf = questdb_confstr::parse_conf_str(conf)
.map_err(|e| error::fmt!(ConfigError, "Config parse error: {}", e))?;
let service = conf.service().to_lowercase();
let params = conf
.params()
.iter()
.map(|(k, v)| (k.to_lowercase(), v))
.collect::<HashMap<_, _>>();
let service = conf.service();
let params = conf.params();

let protocol = Protocol::from_schema(service.as_str())?;
let protocol = Protocol::from_schema(service)?;

let Some(addr) = params.get("addr") else {
return Err(error::fmt!(
Expand All @@ -1825,7 +1821,7 @@ impl SenderBuilder {
};
let mut builder = SenderBuilder::new(protocol, host, port);

validate_auto_flush_params(&params)?;
validate_auto_flush_params(params)?;

for (key, val) in params.iter().map(|(k, v)| (k.as_str(), v.as_str())) {
builder = match key {
Expand Down
19 changes: 19 additions & 0 deletions questdb-rs/src/tests/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,22 @@ fn test_tls_insecure_skip_verify() -> TestResult {
assert_eq!(server.msgs[0].as_str(), exp);
Ok(())
}

#[test]
fn bad_uppercase_protocol() {
let res = Sender::from_conf("TCP::addr=localhost:9009;");
assert!(res.is_err());
let err = res.unwrap_err();
assert!(err.code() == ErrorCode::ConfigError);
assert!(err.msg() == "Unsupported protocol: TCP");
}

#[test]
fn bad_uppercase_addr() {
let res = Sender::from_conf("tcp::ADDR=localhost:9009;");
assert!(res.is_err());
let err = res.unwrap_err();
eprint!("err: {:?}", err);
assert!(err.code() == ErrorCode::ConfigError);
assert!(err.msg() == "Missing \"addr\" parameter in config string");
}