Skip to content

Commit 0fd8e0e

Browse files
committed
fix(config): distinguish client_id UUID errors from dataset_id errors
Invalid client_id UUIDs were incorrectly mapped to InvalidDatasetId, producing the misleading message "Dataset id is not a valid UUID". Now extracts the field name from the config error string and routes client_id failures to InvalidParameter instead.
1 parent 43dfd70 commit 0fd8e0e

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

packages/cipherstash-proxy/src/config/tandem.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,16 @@ impl TandemConfig {
198198
// - missing parameters are returned by at least two different errors, depending the source of the error
199199
// Easier to inspect the error message.
200200
match err.to_string() {
201-
s if s.contains("UUID parsing failed") => ConfigError::InvalidDatasetId,
201+
s if s.contains("UUID parsing failed") => {
202+
if s.contains("client_id") && !s.contains("keyset") {
203+
ConfigError::InvalidParameter {
204+
name: "client_id".to_string(),
205+
value: "invalid UUID".to_string(),
206+
}
207+
} else {
208+
ConfigError::InvalidDatasetId
209+
}
210+
}
202211
s if s.contains("missing field") => {
203212
let (field, key) = extract_missing_field_and_key(&s);
204213
match (field, key) {
@@ -510,6 +519,22 @@ mod tests {
510519
});
511520
}
512521

522+
#[test]
523+
fn invalid_client_id_uuid() {
524+
with_no_cs_vars(|| {
525+
let result =
526+
TandemConfig::build_path("tests/config/cipherstash-proxy-bad-client-id.toml");
527+
assert!(result.is_err());
528+
let err = result.unwrap_err();
529+
// Should produce InvalidParameter for client_id, not InvalidDatasetId
530+
assert!(
531+
err.to_string().contains("Invalid client_id"),
532+
"Expected 'Invalid client_id' but got: {}",
533+
err
534+
);
535+
});
536+
}
537+
513538
#[test]
514539
fn prometheus_config() {
515540
with_no_cs_vars(|| {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[tls]
2+
certificate_path = "tests/tls/server.cert"
3+
private_key_path = "tests/tls/server.key"
4+
5+
[database]
6+
name = "cipherstash"
7+
host = "localhost"
8+
port = 5532
9+
username = "cipherstash"
10+
password = "password"
11+
12+
[auth]
13+
workspace_crn = "crn:ap-southeast-2.aws:E4UMRN47WJNSMAKR"
14+
client_access_key = "client_access_key"
15+
16+
[encrypt]
17+
default_keyset_id = "484cd205-99e8-41ca-acfe-55a7e25a8ec2"
18+
client_id = "not-a-uuid"
19+
client_key = "a4627031a16b7065726d75746174696f6e900e05030d0608090007020c04010b0a0f6770325f66726f6da16b7065726d75746174696f6e900608000a0204030f01070d090e0b0c056570325f746fa16b7065726d75746174696f6e90000908060701030a05040e020d0b0c0f627033a16b7065726d75746174696f6e982107181d130d05181f08040a181c1002181e010311181818200b0f0e0915181b0c16171819060012181a14"

0 commit comments

Comments
 (0)