v0.2.6-pre.003-fix.002

This commit is contained in:
2026-08-20 21:33:46 +02:00
parent 0e72914237
commit 3fa4ab251a
13 changed files with 652 additions and 81 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-config-lib/tests/ownership.rs
// version: 4
// version: 5
//! Workspace ownership audits for KSP application configuration boundaries.
@@ -81,6 +81,10 @@ fn collect_environment_names(source: &str, names: &mut std::collections::BTreeSe
index += 1;
continue;
};
if !environment_name_start_boundary(bytes, index) {
index += 1;
continue;
}
let mut end = index + prefix_length;
while end < bytes.len() {
let byte = bytes[end];
@@ -94,6 +98,7 @@ fn collect_environment_names(source: &str, names: &mut std::collections::BTreeSe
if let std::result::Result::Ok(candidate) = candidate
&& candidate.len() > prefix_length
&& !candidate.ends_with('_')
&& environment_name_end_boundary(bytes, end)
&& !is_environment_namespace_label(candidate)
{
names.insert(candidate.to_owned());
@@ -106,6 +111,22 @@ fn is_environment_namespace_label(candidate: &str) -> bool {
return matches!(candidate, "KSP_PUBLIC" | "KSP_SECRET" | "KSPB_PUBLIC" | "KSPB_SECRET");
}
fn environment_name_end_boundary(bytes: &[u8], end: usize) -> bool {
if end >= bytes.len() {
return true;
}
let next = bytes[end];
return !next.is_ascii_alphanumeric() && next != b'_';
}
fn environment_name_start_boundary(bytes: &[u8], index: usize) -> bool {
if index == 0 {
return true;
}
let previous = bytes[index - 1];
return !previous.is_ascii_alphanumeric() && previous != b'_';
}
fn dotenv_example_assignments(source: &str) -> std::collections::BTreeMap<String, usize> {
let mut assignments = std::collections::BTreeMap::<String, usize>::new();
for (line_index, line) in source.lines().enumerate() {
@@ -267,6 +288,8 @@ fn environment_name_scanner_ignores_namespace_labels_but_keeps_concrete_names()
const KSP_SECRET_API_KEY: &str = "KSP_SECRET_API_KEY";
const KSPB_PUBLIC_ENDPOINT: &str = "KSPB_PUBLIC_ENDPOINT";
const KSPB_SECRET_TOKEN: &str = "KSPB_SECRET_TOKEN";
const FILE_ID_COMPOSITE_KSP_APP_WALLET_DESK: &str = "cfg.composite.ksp-app-wallet-desk";
const KSP_PUBLIC_RPC_URL_SUFFIXED: &str = "not-an-env";
"#;
let mut names = std::collections::BTreeSet::<String>::new();
collect_environment_names(source, &mut names);
@@ -278,6 +301,8 @@ fn environment_name_scanner_ignores_namespace_labels_but_keeps_concrete_names()
assert!(names.contains("KSP_SECRET_API_KEY"));
assert!(names.contains("KSPB_PUBLIC_ENDPOINT"));
assert!(names.contains("KSPB_SECRET_TOKEN"));
assert!(!names.contains("KSP_APP_WALLET_DESK"));
assert!(!names.contains("KSP_PUBLIC_RPC_URL_SUFFIXED"));
}
#[test]