Skip to content

Commit a5bb28b

Browse files
committed
test(e2e): fix provider profiles, MCP image and mTLS refusal checks
Import the built-in provider profiles the conformance tests use instead of assuming a gateway has them, run the MCP default-version sandbox from the Python image so Podman finds the policy's user, and make the mTLS refusal tests assert a transport error after a CA-only control reaches Health. Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
1 parent 9123110 commit a5bb28b

4 files changed

Lines changed: 84 additions & 49 deletions

File tree

‎tests/suites/conformance/src/policy_validation.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ async fn create_stores_default_mcp_version(cx: &mut Context) -> testkit::Result
7979
testkit::ensure!(endpoint.mcp.is_none(), "the test policy names MCP options");
8080

8181
// The policy is stored at create, so the sandbox needn't become ready.
82-
let sandbox = cx.sandbox("mcp").policy(mcp).create().await?;
82+
// The policy runs the workload as `sandbox`, which the Python image has.
83+
let sandbox = cx
84+
.sandbox("mcp")
85+
.policy(mcp)
86+
.spec(|spec| spec.image = Some(testkit::python_image()))
87+
.create()
88+
.await?;
8389

8490
let stored = sandbox.spec().await?.and_then(|spec| spec.policy);
8591
expect_default_mcp_version("the stored policy", stored.as_ref())?;

‎tests/suites/conformance/src/provider_credentials.rs‎

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ use crate::support::python_sandbox;
2222
const TEST_HOST: &str = "host.openshell.internal";
2323
const TOKEN_ENV: &str = "E2E_PLACEMENT_TOKEN";
2424
const TEST_SECRET: &str = "synthetic-placement-secret";
25+
/// The built-in profiles these tests need. A gateway starts without profiles,
26+
/// so each test imports the one it uses.
27+
const GOOGLE_CLOUD_PROFILE: &str = include_str!("../../../../providers/google-cloud.yaml");
28+
const CLAUDE_CODE_PROFILE: &str = include_str!("../../../../providers/claude-code.yaml");
2529
const PLACEHOLDER_PREFIX: &str = "openshell:resolve:env:";
2630

2731
/// Sends the provider's token from `argv[2]`'s placement to `TEST_HOST` on
@@ -207,32 +211,14 @@ async fn google_metadata_serves_placeholder_token(cx: &mut Context) -> testkit::
207211
const KEY: &str = "GCP_ADC_ACCESS_TOKEN";
208212

209213
let provider = cx.name("gcp");
210-
let cli = cx.cli_handle();
211-
let owned = provider.clone();
212-
cx.on_cleanup(format!("delete provider {provider}"), async move || {
213-
cli.run(["provider", "delete", &owned]).await?.success()?;
214-
Ok(())
215-
});
216-
cx.cli_with_env(
214+
let provider_type = cx.import_profile(GOOGLE_CLOUD_PROFILE).await?;
215+
cx.create_provider_with_config(
216+
&provider,
217+
&provider_type,
217218
&[(KEY, SECRET)],
218-
[
219-
"provider",
220-
"create",
221-
"--name",
222-
&provider,
223-
"--type",
224-
"google-cloud",
225-
"--credential",
226-
KEY,
227-
"--config",
228-
&format!("project_id={PROJECT}"),
229-
"--config",
230-
&format!("service_account_email={EMAIL}"),
231-
],
219+
&[("project_id", PROJECT), ("service_account_email", EMAIL)],
232220
)
233-
.await?
234-
.success()
235-
.context(format!("create provider {provider}"))?;
221+
.await?;
236222

237223
let mut bound = policy::base();
238224
policy::allow(
@@ -327,8 +313,12 @@ async fn create_rejects_unknown_provider(cx: &mut Context) -> testkit::Result {
327313
async fn provider_credentials_are_not_stored_in_sandbox_spec(cx: &mut Context) -> testkit::Result {
328314
const KEY: &str = "ANTHROPIC_API_KEY";
329315
let provider = cx.name("nop");
330-
cx.create_provider(&provider, "claude-code", &[(KEY, "sk-should-not-persist")])
331-
.await?;
316+
cx.install_provider(
317+
&provider,
318+
CLAUDE_CODE_PROFILE,
319+
&[(KEY, "sk-should-not-persist")],
320+
)
321+
.await?;
332322
let sandbox = cx
333323
.sandbox("nop")
334324
.spec(|spec| spec.providers = vec![provider.clone()])

‎tests/suites/features/gateway-mtls/tests/gateway_mtls.rs‎

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,31 @@ async fn foreign_client_certificate_is_rejected(_cx: &mut Context) -> testkit::R
7777
let mut config = ClientConfig::new(gateway.endpoint.clone());
7878
config.ca_cert = Some(read(&dir.join("ca.crt"))?);
7979
config.client_identity = Some(ClientIdentity::new(rogue.cert.pem(), key));
80-
expect_refused(config, "a client certificate from another CA").await
80+
expect_refused(
81+
&gateway,
82+
&dir,
83+
config,
84+
"a client certificate from another CA",
85+
)
86+
.await
8187
}
8288

8389
/// The gateway's port doesn't answer gRPC over plaintext.
8490
#[testkit::test]
8591
async fn plaintext_client_is_rejected(_cx: &mut Context) -> testkit::Result {
86-
let (gateway, _) = mtls_gateway()?;
92+
let (gateway, dir) = mtls_gateway()?;
8793
let endpoint = gateway
8894
.endpoint
8995
.strip_prefix("https://")
9096
.map(|rest| format!("http://{rest}"))
9197
.ok_or_else(|| Error::msg(format!("{} isn't an https endpoint", gateway.endpoint)))?;
92-
expect_refused(ClientConfig::new(endpoint), "a plaintext connection").await
98+
expect_refused(
99+
&gateway,
100+
&dir,
101+
ClientConfig::new(endpoint),
102+
"a plaintext connection",
103+
)
104+
.await
93105
}
94106

95107
/// The gateway under test, which must be an mTLS gateway, and its mTLS
@@ -146,11 +158,20 @@ async fn expect_unauthenticated(client: &OpenShellClient, workspace: &str, how:
146158
}
147159
}
148160

149-
/// Fail unless a client with `config` can't connect, or its Health call
150-
/// fails at the transport.
151-
async fn expect_refused(config: ClientConfig, what: &str) -> Result {
152-
let Ok(client) = OpenShellClient::connect(config).await else {
153-
return Ok(());
161+
/// Fail unless a client with `config` is refused at the transport: it can't
162+
/// connect, or its Health call fails with a transport error rather than a
163+
/// gRPC answer from the gateway. A CA-only client first reaches Health, so a
164+
/// wrong port or a stopped gateway fails the test instead of passing it.
165+
async fn expect_refused(gateway: &Gateway, dir: &Path, config: ClientConfig, what: &str) -> Result {
166+
let mut control = ClientConfig::new(gateway.endpoint.clone());
167+
control.ca_cert = Some(read(&dir.join("ca.crt"))?);
168+
expect_healthy(&connect(control).await?)
169+
.await
170+
.context("the gateway should answer a client that trusts its CA")?;
171+
172+
let client = match OpenShellClient::connect(config).await {
173+
Ok(client) => client,
174+
Err(error) => return expect_transport_error(&error.to_string(), what),
154175
};
155176
match client
156177
.raw_grpc()
@@ -160,23 +181,24 @@ async fn expect_refused(config: ClientConfig, what: &str) -> Result {
160181
Ok(_) => Err(Error::msg(format!(
161182
"the gateway answered Health over {what}"
162183
))),
163-
Err(status)
164-
if matches!(
165-
status.code(),
166-
GrpcCode::Unavailable
167-
| GrpcCode::Unknown
168-
| GrpcCode::Internal
169-
| GrpcCode::Unimplemented
170-
) =>
171-
{
172-
Ok(())
173-
}
174-
Err(status) => {
175-
Err(Error::from(status).context(format!("expected a transport refusal for {what}")))
176-
}
184+
Err(status) => expect_transport_error(&format!("{status:?}"), what),
177185
}
178186
}
179187

188+
/// Fail unless `error` describes a failed transport, not a gRPC status the
189+
/// gateway chose. A refused TLS handshake and a plaintext request to a TLS
190+
/// port both close the connection, so tonic reports them as transport errors.
191+
fn expect_transport_error(error: &str, what: &str) -> Result {
192+
let error_lower = error.to_lowercase();
193+
testkit::ensure!(
194+
["transport error", "connection closed", "tls", "handshake"]
195+
.iter()
196+
.any(|marker| error_lower.contains(marker)),
197+
"expected a transport refusal for {what}; got: {error}"
198+
);
199+
Ok(())
200+
}
201+
180202
fn read(path: &Path) -> Result<Vec<u8>> {
181203
std::fs::read(path).context(format!("read {}", path.display()))
182204
}

‎tests/testkit/testkit/src/provider.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ impl Context {
4141
name: &str,
4242
provider_type: &str,
4343
credentials: &[(&str, &str)],
44+
) -> Result {
45+
self.create_provider_with_config(name, provider_type, credentials, &[])
46+
.await
47+
}
48+
49+
/// [`Context::create_provider`] with `config`, as pairs of key and value
50+
/// for the provider's non-secret configuration.
51+
pub async fn create_provider_with_config(
52+
&self,
53+
name: &str,
54+
provider_type: &str,
55+
credentials: &[(&str, &str)],
56+
config: &[(&str, &str)],
4457
) -> Result {
4558
// Deleting a missing provider succeeds, so register the delete before
4659
// the create.
@@ -56,6 +69,10 @@ impl Context {
5669
for (key, _) in credentials {
5770
args.extend(["--credential", key]);
5871
}
72+
let config: Vec<String> = config.iter().map(|(k, v)| format!("{k}={v}")).collect();
73+
for pair in &config {
74+
args.extend(["--config", pair]);
75+
}
5976
self.cli_with_env(credentials, args)
6077
.await?
6178
.success()

0 commit comments

Comments
 (0)