PSA/ee/runner/tests/secret_material_tests.rs
Hermes 284313f908
Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

74 lines
2.3 KiB
Rust

use alga_ext_runner::models::SecretEnvelope;
use alga_ext_runner::secrets::resolve_secret_material;
use base64::engine::general_purpose::STANDARD as BASE64_STANDARD;
use base64::Engine as _;
use serde_json::{Map, Value};
fn make_envelope(values: &[(&str, &str)], version: Option<&str>) -> SecretEnvelope {
let json_map: Map<String, Value> = values
.iter()
.map(|(k, v)| ((*k).to_string(), Value::String((*v).to_string())))
.collect();
let ciphertext = Value::Object(json_map);
let ciphertext_b64 = BASE64_STANDARD.encode(ciphertext.to_string());
SecretEnvelope {
ciphertext_b64,
version: version.map(|v| v.to_string()),
algorithm: None,
expires_at: None,
key_path: None,
mount: None,
}
}
#[tokio::test]
async fn resolve_secret_material_returns_plaintext_map() -> anyhow::Result<()> {
let envelope = make_envelope(
&[("ALGA_API_KEY", "sk_test_123"), ("SERVICE_TOKEN", "abc123")],
Some("v1"),
);
let material =
resolve_secret_material("tenant-a", "ext-alpha", Some("install-1"), &envelope).await?;
assert_eq!(
material.values.get("ALGA_API_KEY"),
Some(&"sk_test_123".to_string())
);
assert_eq!(
material.values.get("SERVICE_TOKEN"),
Some(&"abc123".to_string())
);
assert_eq!(material.version.as_deref(), Some("v1"));
Ok(())
}
#[tokio::test]
async fn resolve_secret_material_updates_when_ciphertext_changes() -> anyhow::Result<()> {
let envelope_v1 = make_envelope(&[("ALGA_API_KEY", "sk_old")], Some("v1"));
let first =
resolve_secret_material("tenant-a", "ext-beta", Some("install-99"), &envelope_v1).await?;
assert_eq!(
first.values.get("ALGA_API_KEY"),
Some(&"sk_old".to_string())
);
let envelope_v2 = make_envelope(
&[("ALGA_API_KEY", "sk_new"), ("ANALYTICS_TOKEN", "tok_8")],
Some("v2"),
);
let second =
resolve_secret_material("tenant-a", "ext-beta", Some("install-99"), &envelope_v2).await?;
assert_eq!(
second.values.get("ALGA_API_KEY"),
Some(&"sk_new".to_string())
);
assert_eq!(
second.values.get("ANALYTICS_TOKEN"),
Some(&"tok_8".to_string())
);
assert_eq!(second.version.as_deref(), Some("v2"));
Ok(())
}