use super::common::{chunk, resource_key, sample_manifest, store_id, FakeGeneration, ResourceSpec};
use crate::imp::compiler::{Compiler, CompilerConfig};
use crate::imp::core::{Bytes32, Bytes48, TrustedHostKey};
const DECRYPTION_KEY_SENTINEL: [u8; 32] = [0xDE; 32]; const BLS_SECRET_SENTINEL: [u8; 32] = [0x5E; 32]; const SECRET_SALT_SENTINEL: [u8; 32] = [0x5A; 32];
fn cfg(dir: &std::path::Path) -> CompilerConfig {
CompilerConfig {
output_dir: dir.to_path_buf(),
obfuscate: false,
optimize: false,
template_override: None,
uniform_blob_len: 64 * 1024,
}
}
fn generations() -> Vec<FakeGeneration> {
let a = chunk(b"PUBLIC-CIPHERTEXT-MARKER-AAAA");
let b = chunk(b"PUBLIC-CIPHERTEXT-MARKER-BBBB");
vec![FakeGeneration {
root: Bytes32([0x11; 32]),
generation_id: 1,
resources: vec![ResourceSpec {
resource_key: resource_key("index.html"),
chunks: vec![a, b],
}],
}]
}
fn trusted_pubkey() -> [u8; 48] {
[0x42u8; 48] }
fn store_pubkey() -> Bytes48 {
Bytes48([0xCD; 48]) }
fn contains(haystack: &[u8], needle: &[u8]) -> bool {
if needle.is_empty() || haystack.len() < needle.len() {
return false;
}
haystack.windows(needle.len()).any(|w| w == needle)
}
#[test]
fn test_module_is_secretless() {
let dir = std::env::temp_dir().join(format!("digc-secretless-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let trusted = vec![TrustedHostKey {
public_key: trusted_pubkey(),
label: "dig-host-key-v1".into(),
}];
let outcome = Compiler::compile(
&cfg(&dir),
store_id(),
store_pubkey(),
&generations(),
sample_manifest(),
super::common::no_auth(),
&trusted,
None,
None,
)
.expect("compiles");
let module = std::fs::read(&outcome.result.output_path).expect("read emitted module");
assert!(
!contains(&module, &DECRYPTION_KEY_SENTINEL),
"module leaks a decryption key"
);
assert!(
!contains(&module, &BLS_SECRET_SENTINEL),
"module leaks a BLS signing secret"
);
assert!(
!contains(&module, &SECRET_SALT_SENTINEL),
"module leaks the SecretSalt"
);
assert!(
contains(&module, &store_pubkey().0),
"store public key missing from module — scan would be vacuous"
);
assert!(
contains(&module, &trusted_pubkey()),
"trusted host public key missing from module"
);
assert!(
contains(&module, b"sample-store"),
"public manifest name missing from module"
);
assert!(
contains(&module, b"PUBLIC-CIPHERTEXT-MARKER-AAAA"),
"served ciphertext missing from module"
);
std::fs::remove_dir_all(&dir).ok();
}