stream tests: the key reader's rules pinned in every shape Soul mutated
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
bf3f610b66
commit
aa15dfb36e
2 changed files with 30 additions and 7 deletions
|
|
@ -596,6 +596,10 @@ fn the_connector_key_is_read_trimmed_and_its_absence_leaks_nothing() {
|
|||
let dir = tempfile::tempdir().unwrap();
|
||||
std::fs::write(dir.path().join("connector-key"), "canary-key-7f3a91\n").unwrap();
|
||||
assert_eq!(connector_key(dir.path()).unwrap(), "canary-key-7f3a91");
|
||||
for (written, read) in [("canary-key-7f3a91\r\n", "canary-key-7f3a91"), ("canary-key-7f3a91\n\n\n", "canary-key-7f3a91"), (" \t\ncanary-key-7f3a91 \t\r\n\n", "canary-key-7f3a91"), ("canary-key-7f3a91", "canary-key-7f3a91")] {
|
||||
std::fs::write(dir.path().join("connector-key"), written).unwrap();
|
||||
assert_eq!(connector_key(dir.path()).unwrap(), read, "{written:?}");
|
||||
}
|
||||
let empty = tempfile::tempdir().unwrap();
|
||||
let fault = format!("{:#}", connector_key(empty.path()).unwrap_err());
|
||||
assert!(fault.contains("connector-key") && !fault.contains(empty.path().to_str().unwrap()), "{fault}");
|
||||
|
|
@ -605,6 +609,18 @@ fn the_connector_key_is_read_trimmed_and_its_absence_leaks_nothing() {
|
|||
assert!(!fault.contains("canary"), "no byte of the key reaches an error: {fault}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_open_error_carries_any_part_of_the_key() {
|
||||
let key = "zq7Kx-9wVtm3Pd";
|
||||
// Every way open() can fail with the key in hand: a non-loopback endpoint and a configuration the client refuses.
|
||||
for endpoint in ["10.77.0.1:4103", "127.0.0.1:0", "0.0.0.0:4103"] {
|
||||
let fault = format!("{:#}", KitProjector::open(endpoint.parse().unwrap(), key.into(), INSTANCE, KIT_MODEL, Duration::from_secs(1)).err().unwrap());
|
||||
for window in key.as_bytes().windows(4) {
|
||||
assert!(!fault.contains(std::str::from_utf8(window).unwrap()), "{endpoint}: part of the key reached the error: {fault}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_projection_cut_short_is_a_fault() {
|
||||
for stop in [StopReason::MaxOutputTokens, StopReason::Refusal, StopReason::ToolUse, StopReason::ContextWindow] {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use std::process::{Command, Output};
|
||||
|
||||
const CANARY: &str = "canary-key-7f3a91";
|
||||
const CANARY: &str = "zq7Kx-9wVtm3Pd";
|
||||
|
||||
fn run(credentials: Option<&std::path::Path>, connector: &str) -> Output {
|
||||
let mut command = Command::new(env!("CARGO_BIN_EXE_mind-stream"));
|
||||
|
|
@ -32,13 +32,20 @@ fn a_missing_credentials_directory_names_the_variable_and_a_missing_key_names_th
|
|||
assert!(stderr.contains("connector-key"), "{stderr}");
|
||||
}
|
||||
|
||||
/// Every four-byte run of the key: a partial key is as much a leak as the whole.
|
||||
fn leaks(shown: &str) -> Option<&str> {
|
||||
CANARY.as_bytes().windows(4).map(|window| std::str::from_utf8(window).unwrap()).find(|run| shown.contains(run))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_key_is_never_printed() {
|
||||
fn no_byte_run_of_the_key_is_printed_on_any_startup_path() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
std::fs::write(dir.path().join("connector-key"), format!("{CANARY}\n")).unwrap();
|
||||
// A non-loopback connector ends startup after the key was read and handed over.
|
||||
let output = run(Some(dir.path()), "10.77.0.1:4103");
|
||||
let shown = format!("{}{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr));
|
||||
assert!(shown.contains("not a loopback address"), "the key was read and startup went on to the endpoint check: {shown}");
|
||||
assert!(!shown.contains(CANARY), "{shown}");
|
||||
// A non-loopback connector and a configuration the client refuses both end startup after the key was read and handed over.
|
||||
for (connector, ending) in [("10.77.0.1:4103", "not a loopback address"), ("127.0.0.1:0", "could not be configured")] {
|
||||
let output = run(Some(dir.path()), connector);
|
||||
let shown = format!("{}{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr));
|
||||
assert!(shown.contains(ending), "{connector}: the key was read and startup went on: {shown}");
|
||||
assert_eq!(leaks(&shown), None, "{connector}: {shown}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue