diff --git a/crates/taurus-core/src/runtime/functions/http.rs b/crates/taurus-core/src/runtime/functions/http.rs index 39afa52..5f1f176 100644 --- a/crates/taurus-core/src/runtime/functions/http.rs +++ b/crates/taurus-core/src/runtime/functions/http.rs @@ -71,13 +71,20 @@ impl HttpAuthType { fn from_value(input: &Value) -> Result { match input.kind.as_ref() { Some(Kind::NullValue(_)) | None => Ok(HttpAuthType::None), - Some(Kind::StringValue(value)) => match value.as_str() { - "Bearer" => Ok(HttpAuthType::Bearer), - "Basic" => Ok(HttpAuthType::Basic), - "X-API-Key" => Ok(HttpAuthType::XApiKey), - "undefined" | "" => Ok(HttpAuthType::None), - custom => Ok(HttpAuthType::Custom(custom.to_string())), - }, + Some(Kind::StringValue(value)) => { + if value.eq_ignore_ascii_case("bearer") { + Ok(HttpAuthType::Bearer) + } else if value.eq_ignore_ascii_case("basic") { + Ok(HttpAuthType::Basic) + } else if value.eq_ignore_ascii_case("x-api-key") { + Ok(HttpAuthType::XApiKey) + } else { + match value.as_str() { + "undefined" | "" => Ok(HttpAuthType::None), + custom => Ok(HttpAuthType::Custom(custom.to_string())), + } + } + } _ => Err("Auth Type must be a string or undefined".to_string()), } } @@ -93,15 +100,21 @@ impl HttpAuthPlace { fn from_value(input: &Value) -> Result, String> { match input.kind.as_ref() { Some(Kind::NullValue(_)) | None => Ok(None), - Some(Kind::StringValue(value)) => match value.as_str() { - "Header" => Ok(Some(HttpAuthPlace::Header)), - "Url" => Ok(Some(HttpAuthPlace::Url)), - "undefined" | "" => Ok(None), - other => Err(format!( - "Auth Placement must be 'Header', 'Url', or undefined, got '{}'", - other - )), - }, + Some(Kind::StringValue(value)) => { + if value.eq_ignore_ascii_case("header") { + Ok(Some(HttpAuthPlace::Header)) + } else if value.eq_ignore_ascii_case("url") { + Ok(Some(HttpAuthPlace::Url)) + } else { + match value.as_str() { + "undefined" | "" => Ok(None), + other => Err(format!( + "Auth Placement must be 'Header', 'Url', or undefined, got '{}'", + other + )), + } + } + } _ => Err("Auth Placement must be a string or undefined".to_string()), } } @@ -335,9 +348,7 @@ fn apply_auth( HttpAuthType::Custom(scheme) => { let value = auth_string_value(auth_value, "Custom auth value")?; match place { - HttpAuthPlace::Header => { - insert_header(headers, "authorization", format!("{} {}", scheme, value)) - } + HttpAuthPlace::Header => insert_header(headers, "authorization", value), HttpAuthPlace::Url => append_query_param(url, scheme, &value), } Ok(()) @@ -677,6 +688,34 @@ mod tests { assert_eq!(url, "https://example.test/resource?X-API-Key=a%20b"); } + #[test] + fn auth_type_parses_builtin_values_case_insensitively() { + assert_eq!( + HttpAuthType::from_value(&string_value("bearer")), + Ok(HttpAuthType::Bearer) + ); + assert_eq!( + HttpAuthType::from_value(&string_value("basic")), + Ok(HttpAuthType::Basic) + ); + assert_eq!( + HttpAuthType::from_value(&string_value("x-api-key")), + Ok(HttpAuthType::XApiKey) + ); + } + + #[test] + fn auth_place_parses_values_case_insensitively() { + assert_eq!( + HttpAuthPlace::from_value(&string_value("header")), + Ok(Some(HttpAuthPlace::Header)) + ); + assert_eq!( + HttpAuthPlace::from_value(&string_value("url")), + Ok(Some(HttpAuthPlace::Url)) + ); + } + #[test] fn encode_headers_rejects_null_values() { let headers = Struct {