Skip to content

Commit 198f59c

Browse files
committed
fix: bake blocking scripts into test-manager via include_bytes!
1 parent 07a7aec commit 198f59c

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

nym-vpn-core/crates/test/test-manager/src/tests/config_nym.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ pub const BOOTSTRAP_SCRIPT: &[u8] = include_bytes!(concat!(
1414
"ssh-setup.sh"
1515
));
1616

17+
/// Blocking scripts executed inside the guest VM during circumvention tests. Baked into the
18+
/// binary so the test-manager has no filesystem dependency on the source tree at runtime.
19+
pub const IP_BLOCK_SCRIPT: &[u8] = include_bytes!(concat!(
20+
env!("CARGO_MANIFEST_DIR"),
21+
"/../scripts/blocking/ip_block.sh"
22+
));
23+
pub const SNI_BLOCK_SCRIPT: &[u8] = include_bytes!(concat!(
24+
env!("CARGO_MANIFEST_DIR"),
25+
"/../scripts/blocking/sni_block.sh"
26+
));
27+
pub const DELAYED_IP_BLOCK_SCRIPT: &[u8] = include_bytes!(concat!(
28+
env!("CARGO_MANIFEST_DIR"),
29+
"/../scripts/blocking/delayed_ip_block.sh"
30+
));
31+
1732
/// Constants that are accessible from each test via `TEST_CONFIG`.
1833
/// The constants must be initialized before running any tests using `TEST_CONFIG.init()`.
1934
#[derive(Debug, Clone)]

nym-vpn-core/crates/test/test-manager/src/vm/provision.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use crate::{
66
config::{OsType, Provisioner, VmConfig},
7-
tests::config_nym::BOOTSTRAP_SCRIPT,
7+
tests::config_nym::{
8+
BOOTSTRAP_SCRIPT, DELAYED_IP_BLOCK_SCRIPT, IP_BLOCK_SCRIPT, SNI_BLOCK_SCRIPT,
9+
},
810
};
911
use anyhow::{Context, Result, bail};
1012
use ssh2::{File, Session};
@@ -150,17 +152,19 @@ fn blocking_ssh(
150152
ssh_send_file_with_opts(&session, &source, temp_dir, FileOpts { executable: true })
151153
.with_context(|| format!("Failed to send '{source:?}' to remote"))?;
152154

153-
// Transfer blocking scripts
155+
// Transfer blocking scripts. Their contents are baked into this binary via include_bytes!,
156+
// so we write them to the guest directly rather than reading them off the host filesystem.
154157
if matches!(os_type, OsType::Linux | OsType::Macos) {
155-
let blocking_scripts_dir =
156-
Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/../scripts/blocking"));
157-
let scripts = ["ip_block.sh", "sni_block.sh", "delayed_ip_block.sh"];
158-
159-
for script in &scripts {
160-
let source = blocking_scripts_dir.join(script);
161-
log::debug!("Source: {}", source.display());
162-
ssh_send_file_with_opts(&session, &source, temp_dir, FileOpts { executable: true })
163-
.with_context(|| format!("Failed to send blocking script '{script}' to remote"))?;
158+
let scripts: [(&str, &[u8]); 3] = [
159+
("ip_block.sh", IP_BLOCK_SCRIPT),
160+
("sni_block.sh", SNI_BLOCK_SCRIPT),
161+
("delayed_ip_block.sh", DELAYED_IP_BLOCK_SCRIPT),
162+
];
163+
164+
for (name, content) in &scripts {
165+
let dest = temp_dir.join(name);
166+
ssh_write_with_opts(&session, &dest, *content, FileOpts { executable: true })
167+
.with_context(|| format!("Failed to send blocking script '{name}' to remote"))?;
164168
}
165169
}
166170

0 commit comments

Comments
 (0)