Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ service.
clients there from the variables. A missing variable fails the test; it
never skips it.
- **Documentation.** Document the variables in the fixture's module docs, so
anyone can run the suite against their own deployment by setting them.
anyone can run the suite against their own deployment by setting them, and
add a row for each to the
[environment contract table](tests/support/README.md#environment-contract).

The Keycloak fixture is `tests/support/keycloak`. Run the suite that uses it
with:
Expand Down Expand Up @@ -639,11 +641,27 @@ nix run .#openshell-test-runner -- run \

#### Gateway overrides in an environment

An environment overrides gateway settings by writing the tables to change to
`/etc/openshell-test/gateway-overrides.toml` in a playbook that runs before the
installer. The file holds whole tables, such as `[openshell.gateway]` or
`[openshell.drivers.podman]`, and is not a complete configuration. Each
installer applies it to the gateway's own file:
An environment overrides gateway settings with the `gateway_overrides` role,
which takes a name and the tables to change, such as `[openshell.gateway]` or
`[openshell.drivers.podman]`:

```yaml
- name: Push configuration to supervisors
ansible.builtin.include_role:
name: gateway_overrides
vars:
gateway_overrides_name: config-push
gateway_overrides_content: |
[openshell.gateway]
config_delivery_mode = "push"
```

The role writes each name as its own marked block in
`/etc/openshell-test/gateway-overrides.toml`, so writers keep each other's
settings, and `gateway_overrides_state: absent` removes a name's block.
Two blocks must not declare the same table. Don't write the file
directly. The file is not a complete configuration. Each installer applies it
to the gateway's own file:

- `binaries` applies it to the `/etc/openshell/gateway.toml` it generates.
- `deb` and `rpm` apply it to the service user's
Expand Down
20 changes: 20 additions & 0 deletions tests/suites/conformance/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

152 changes: 66 additions & 86 deletions tests/suites/conformance/src/credential_gating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use sandbox_clients_support::{self as clients, http, scripts};
use serde_json::json;
use testkit::policy::{self, Access, Endpoint as _};
use testkit::sdk::raw::proto;
use testkit::{Context, Error, GrpcCode, PYTHON_BINARIES, Result, ResultExt as _, Sandbox};
use testkit::{
Context, Credential, Error, GrpcCode, PYTHON_BINARIES, Profile, Result, ResultExt as _, Sandbox,
};

const BASH: &str = "/usr/bin/bash";

Expand Down Expand Up @@ -194,15 +196,12 @@ async fn policy_binding_updates_provider_environment_live(cx: &mut Context) -> t
#[testkit::test]
async fn profile_rest_endpoint_rewrites_header_and_body(cx: &mut Context) -> testkit::Result {
let server = HttpRecorder::start("ok").await?;
let sandbox = profile_endpoint_sandbox(
cx,
"rwrt",
&format!(
"{{host: {TEST_HOST}, port: {}, path: /probe, protocol: rest, access: full, \
enforcement: enforce, request_body_credential_rewrite: true}}",
server.port
),
)
let sandbox = profile_endpoint_sandbox(cx, "rwrt", server.port, |ep| {
ep.rest(Access::Full)
.path("/probe")
.enforce()
.request_body_credential_rewrite(true);
})
.await?;
let token = provider_token(&sandbox).await?;
let body = json!({ "credential": token }).to_string();
Expand Down Expand Up @@ -245,15 +244,10 @@ async fn profile_rest_endpoint_rewrites_header_and_body(cx: &mut Context) -> tes
#[testkit::test]
async fn profile_websocket_endpoint_rewrites_text_frames(cx: &mut Context) -> testkit::Result {
let server = WebSocketRecorder::start().await?;
let sandbox = profile_endpoint_sandbox(
cx,
"wstxt",
&format!(
"{{host: {TEST_HOST}, port: {}, path: /ws, protocol: websocket, \
enforcement: enforce, access: read-write, websocket_credential_rewrite: true}}",
server.port
),
)
let sandbox = profile_endpoint_sandbox(cx, "wstxt", server.port, |ep| {
ep.websocket(Access::ReadWrite).path("/ws").enforce();
ep.websocket_credential_rewrite = true;
})
.await?;
sandbox
.run_python(
Expand Down Expand Up @@ -380,31 +374,30 @@ async fn send_binary_frame(
/// `endpoints`, its profile declares the REST and WebSocket ports as its
/// endpoints; without, a policy must bind the provider explicitly.
async fn install_gating_provider(cx: &Context, endpoints: Option<(u16, u16)>) -> Result<String> {
let endpoints = endpoints.map_or_else(Vec::new, |(rest, websocket)| {
vec![
format!("{{host: {TEST_HOST}, port: {rest}, protocol: rest, access: full}}"),
format!(
"{{host: {TEST_HOST}, port: {websocket}, protocol: websocket, access: read-write}}"
),
]
});
install_provider_with_endpoints(cx, &endpoints).await
let mut profile = gating_profile(&cx.name("cg"));
if let Some((rest, websocket)) = endpoints {
profile = profile
.endpoint(TEST_HOST, rest, |ep| {
ep.rest(Access::Full);
})
.endpoint(TEST_HOST, websocket, |ep| {
ep.websocket(Access::ReadWrite);
});
}
install_gating_profile(cx, &profile).await
}

/// A long-running sandbox with a provider from
/// [`install_provider_with_endpoints`] whose profile declares `endpoint`, a
/// YAML flow mapping, and a policy that allows the same endpoint.
async fn profile_endpoint_sandbox(cx: &Context, suffix: &str, endpoint: &str) -> Result<Sandbox> {
let provider = install_provider_with_endpoints(cx, &[endpoint.to_string()]).await?;
let policy = policy::base_with(&format!(
"network_policies:
credential_gating:
name: credential_gating
endpoints: [{endpoint}]
binaries: {binaries}
",
binaries = policy::binaries_yaml(PYTHON_BINARIES),
))?;
/// A long-running sandbox with the same endpoint in its provider profile and policy.
async fn profile_endpoint_sandbox(
cx: &Context,
suffix: &str,
port: u16,
configure: impl Fn(&mut proto::NetworkEndpoint),
) -> Result<Sandbox> {
let profile = gating_profile(&cx.name("cg")).endpoint(TEST_HOST, port, &configure);
let provider = install_gating_profile(cx, &profile).await?;
let mut policy = policy::base();
configure(allow_host(&mut policy, "credential_gating", port));
create_sandbox(cx, suffix, policy, &[&provider]).await
}

Expand All @@ -419,55 +412,42 @@ async fn install_bound_provider(
port: u16,
) -> Result<String> {
let name = cx.name(suffix);
let profile = format!(
"id: {name}
display_name: E2E static endpoint binding
category: other
credentials:
- name: bound_token
env_vars: [{env_var}]
required: true
auth_style: bearer
header_name: authorization
endpoints:
- {{host: {TEST_HOST}, port: {port}, path: /allowed/**, protocol: rest, access: full, enforcement: enforce}}
binaries: [{BASH}]
"
);
let profile = Profile::new(&name)
.display_name("E2E static endpoint binding")
.credential(bearer_credential("bound_token", env_var))
.endpoint(TEST_HOST, port, |ep| {
ep.rest(Access::Full).path("/allowed/**").enforce();
})
.binaries([BASH])
.to_yaml()?;
cx.install_provider(&name, &profile, &[(env_var, secret)])
.await?;
Ok(name)
}

/// Install a run-unique provider holding `TEST_SECRET` in `TOKEN_ENV`, whose
/// profile declares `endpoints`, each a YAML flow mapping.
async fn install_provider_with_endpoints(cx: &Context, endpoints: &[String]) -> Result<String> {
let name = cx.name("cg");
let endpoints = if endpoints.is_empty() {
String::new()
} else {
format!("endpoints: [{}]\n", endpoints.join(", "))
};
let binaries: String = PYTHON_BINARIES
.iter()
.map(|path| format!(" - path: {path}\n"))
.collect();
let profile = format!(
"id: {name}
display_name: E2E Credential Gating
category: other
credentials:
- name: token
env_vars: [{TOKEN_ENV}]
required: true
auth_style: bearer
header_name: authorization
{endpoints}binaries:
{binaries}"
);
cx.install_provider(&name, &profile, &[(TOKEN_ENV, TEST_SECRET)])
.await?;
Ok(name)
fn bearer_credential(name: &str, env_var: &str) -> Credential {
Credential::new(name)
.env_var(env_var)
.required()
.auth_style("bearer")
.header_name("authorization")
}

fn gating_profile(name: &str) -> Profile {
Profile::new(name)
.display_name("E2E Credential Gating")
.credential(bearer_credential("token", TOKEN_ENV))
.binaries(PYTHON_BINARIES.iter().copied())
}

async fn install_gating_profile(cx: &Context, profile: &Profile) -> Result<String> {
cx.install_provider(
profile.id(),
&profile.to_yaml()?,
&[(TOKEN_ENV, TEST_SECRET)],
)
.await?;
Ok(profile.id().to_string())
}

fn sandbox_with(
Expand Down
16 changes: 16 additions & 0 deletions tests/suites/continuity/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/suites/drivers/podman/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion tests/suites/features/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading