Skip to content

Commit c53fd05

Browse files
fix(testkit): reject explicit credential bindings in profiles
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent c13ef9a commit c53fd05

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

‎tests/testkit/testkit/src/profile.rs‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
//! cx.import_profile(&profile.to_yaml()?).await?;
2424
//! ```
2525
//!
26-
//! Profile endpoints are policy endpoints, so [`policy::Endpoint`] configures
27-
//! them. Setters are named after the YAML fields they set.
26+
//! [`policy::Endpoint`] configures profile endpoints. Setters are named after
27+
//! the YAML fields they set, but explicit credential bindings belong in
28+
//! sandbox policy, not reusable profiles.
2829
//!
2930
//! [`policy::Endpoint`]: crate::policy::Endpoint
3031
@@ -127,7 +128,17 @@ impl Profile {
127128
}
128129

129130
/// The profile as YAML, as `profile export` writes it.
131+
/// Returns an error if an endpoint specifies `credential_binding`.
130132
pub fn to_yaml(&self) -> Result<String> {
133+
for endpoint in &self.profile.endpoints {
134+
if endpoint.credential_binding.is_some() {
135+
return Err(Error::msg(format!(
136+
"provider profile {} endpoint {}:{} cannot set credential_binding; \
137+
set it in sandbox policy to bind a concrete provider",
138+
self.profile.id, endpoint.host, endpoint.port
139+
)));
140+
}
141+
}
131142
profile_to_yaml(&ProviderTypeProfile::from_proto(&self.profile))
132143
.map_err(Error::from_display)
133144
.context(format!("render provider profile {}", self.profile.id))
@@ -248,6 +259,20 @@ binaries: [/usr/bin/curl, /usr/bin/python*]
248259
assert_eq!(parsed(&yaml), expected, "rendered:\n{yaml}");
249260
}
250261

262+
#[test]
263+
fn rejects_explicit_credential_binding() {
264+
let error = Profile::new("example")
265+
.endpoint("api.example.test", 443, |ep| {
266+
ep.credential_binding("provider");
267+
})
268+
.to_yaml()
269+
.expect_err("a profile must not silently drop an explicit binding")
270+
.to_string();
271+
assert!(error.contains("api.example.test:443"), "{error}");
272+
assert!(error.contains("credential_binding"), "{error}");
273+
assert!(error.contains("sandbox policy"), "{error}");
274+
}
275+
251276
/// A profile with only an id has the display name and category the
252277
/// gateway requires.
253278
#[test]

0 commit comments

Comments
 (0)