Skip to content

Commit

Permalink
[fix] Quickwit panics while attempting to parse index_uri (#3692)
Browse files Browse the repository at this point in the history
This PR also normalize the protocol.
For instance postgres:// becomes postgresql after dserialization + serialization.
  • Loading branch information
AyWa authored Jul 28, 2023
1 parent 90c59a2 commit 794eb47
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 11 additions & 4 deletions quickwit/quickwit-common/src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ impl Uri {
bail!("Failed to parse empty URI.");
}
let (protocol, mut path) = match uri_str.split_once(PROTOCOL_SEPARATOR) {
None => (Protocol::File.as_str(), uri_str.to_string()),
Some((protocol, path)) => (protocol, path.to_string()),
None => (Protocol::File, uri_str.to_string()),
Some((protocol, path)) => (Protocol::from_str(protocol)?, path.to_string()),
};
if protocol == Protocol::File.as_str() {
if protocol == Protocol::File {
if path.starts_with('~') {
// We only accept `~` (alias to the home directory) and `~/path/to/something`.
// If there is something following the `~` that is not `/`, we bail.
Expand Down Expand Up @@ -306,7 +306,7 @@ impl Uri {
}
Ok(Self {
uri: format!("{protocol}{PROTOCOL_SEPARATOR}{path}"),
protocol_idx: protocol.len(),
protocol_idx: protocol.as_str().len(),
})
}
}
Expand Down Expand Up @@ -486,6 +486,13 @@ mod tests {
Uri::from_str("azure://account/container/homer/docs/../dognuts").unwrap(),
"azure://account/container/homer/docs/../dognuts"
);

assert_eq!(
Uri::from_str("http://localhost:9000/quickwit")
.unwrap_err()
.to_string(),
"Unknown URI protocol `http`."
);
}

#[test]
Expand Down
10 changes: 5 additions & 5 deletions quickwit/quickwit-config/src/node_config/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ mod tests {
assert_eq!(config.data_dir_path, Path::new("/opt/quickwit/data"));
assert_eq!(
config.metastore_uri,
"postgres://username:password@host:port/db"
"postgresql://username:password@host:port/db"
);
assert_eq!(config.default_index_root_uri, "s3://quickwit-indexes");

Expand Down Expand Up @@ -618,7 +618,7 @@ mod tests {
env_vars.insert("QW_DATA_DIR".to_string(), "test-data-dir".to_string());
env_vars.insert(
"QW_METASTORE_URI".to_string(),
"postgres://test-user:test-password@test-host:4321/test-db".to_string(),
"postgresql://test-user:test-password@test-host:4321/test-db".to_string(),
);
env_vars.insert(
"QW_DEFAULT_INDEX_ROOT_URI".to_string(),
Expand Down Expand Up @@ -672,7 +672,7 @@ mod tests {
);
assert_eq!(
config.metastore_uri,
"postgres://test-user:test-password@test-host:4321/test-db"
"postgresql://test-user:test-password@test-host:4321/test-db"
);
assert_eq!(config.default_index_root_uri, "s3://quickwit-indexes/prod");
}
Expand All @@ -695,7 +695,7 @@ mod tests {
assert_eq!(config.node_id, "node-1");
assert_eq!(
config.metastore_uri,
"postgres://username:password@host:port/db"
"postgresql://username:password@host:port/db"
);
}

Expand All @@ -715,7 +715,7 @@ mod tests {
.unwrap();
assert_eq!(
config.metastore_uri,
"postgres://username:password@host:port/db"
"postgresql://username:password@host:port/db"
);
assert_eq!(config.indexer_config, IndexerConfig::default());
assert_eq!(config.searcher_config, SearcherConfig::default());
Expand Down

0 comments on commit 794eb47

Please sign in to comment.