Merge pull request #3464 from influxdata/dom/empty-org-bucket
fix: reject empty org & bucketpull/24376/head
commit
8e2e9b9082
|
@ -8,6 +8,9 @@ use snafu::{ResultExt, Snafu};
|
||||||
pub enum OrgBucketMappingError {
|
pub enum OrgBucketMappingError {
|
||||||
#[snafu(display("Invalid database name: {}", source))]
|
#[snafu(display("Invalid database name: {}", source))]
|
||||||
InvalidDatabaseName { source: DatabaseNameError },
|
InvalidDatabaseName { source: DatabaseNameError },
|
||||||
|
|
||||||
|
#[snafu(display("missing org/bucket value"))]
|
||||||
|
NotSpecified,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Map an InfluxDB 2.X org & bucket into an IOx DatabaseName.
|
/// Map an InfluxDB 2.X org & bucket into an IOx DatabaseName.
|
||||||
|
@ -24,6 +27,11 @@ pub fn org_and_bucket_to_database<'a, O: AsRef<str>, B: AsRef<str>>(
|
||||||
let org: Cow<'_, str> = utf8_percent_encode(org.as_ref(), NON_ALPHANUMERIC).into();
|
let org: Cow<'_, str> = utf8_percent_encode(org.as_ref(), NON_ALPHANUMERIC).into();
|
||||||
let bucket: Cow<'_, str> = utf8_percent_encode(bucket.as_ref(), NON_ALPHANUMERIC).into();
|
let bucket: Cow<'_, str> = utf8_percent_encode(bucket.as_ref(), NON_ALPHANUMERIC).into();
|
||||||
|
|
||||||
|
// An empty org or bucket is not acceptable.
|
||||||
|
if org.is_empty() || bucket.is_empty() {
|
||||||
|
return Err(OrgBucketMappingError::NotSpecified);
|
||||||
|
}
|
||||||
|
|
||||||
let db_name = format!("{}{}{}", org.as_ref(), SEPARATOR, bucket.as_ref());
|
let db_name = format!("{}{}{}", org.as_ref(), SEPARATOR, bucket.as_ref());
|
||||||
|
|
||||||
DatabaseName::new(db_name).context(InvalidDatabaseNameSnafu)
|
DatabaseName::new(db_name).context(InvalidDatabaseNameSnafu)
|
||||||
|
@ -72,4 +80,11 @@ mod tests {
|
||||||
let got = org_and_bucket_to_database("org!", "bucket").unwrap();
|
let got = org_and_bucket_to_database("org!", "bucket").unwrap();
|
||||||
assert_eq!(got.as_str(), "org%21_bucket");
|
assert_eq!(got.as_str(), "org%21_bucket");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_empty_org_bucket() {
|
||||||
|
let err = org_and_bucket_to_database("", "")
|
||||||
|
.expect_err("should fail with empty org/bucket valuese");
|
||||||
|
assert!(matches!(err, OrgBucketMappingError::NotSpecified));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue