|
| 1 | +mod utils; |
| 2 | + |
| 3 | +#[cfg(test)] |
| 4 | +mod e2e_cli_host { |
| 5 | + |
| 6 | + use crate::utils::*; |
| 7 | + |
| 8 | + use rexpect::spawn; |
| 9 | + |
| 10 | + const TEST_TIMEOUT: u64 = 10000; |
| 11 | + |
| 12 | + /** |
| 13 | + * Lets us change the target directory for the plugins and repl logic. |
| 14 | + * |
| 15 | + * See the justfile for examples where we switch to testing both plugins from the filesystem and from the HTTP server. |
| 16 | + */ |
| 17 | + fn build_command(plugin_files: &[&str], repl_logic_file: &str) -> String { |
| 18 | + let prefix = |
| 19 | + std::env::var("WASM_TARGET_DIR").unwrap_or("target/wasm32-wasip1/debug".to_string()); |
| 20 | + let mut command = String::from("target/debug/pluginlab"); |
| 21 | + command.push_str(format!(" --repl-logic {}/{}", prefix, repl_logic_file).as_str()); |
| 22 | + plugin_files.iter().for_each(|file| { |
| 23 | + command.push_str(format!(" --plugins {}", file).as_str()); |
| 24 | + }); |
| 25 | + println!("Running command: {}", command); |
| 26 | + command |
| 27 | + } |
| 28 | + |
| 29 | + #[test] |
| 30 | + fn test_without_permission_allow_network() { |
| 31 | + let project_root = find_project_root(); |
| 32 | + println!("Setting current directory to: {:?}", project_root); |
| 33 | + std::env::set_current_dir(&project_root).unwrap(); |
| 34 | + let mut session = spawn( |
| 35 | + &build_command( |
| 36 | + &["target/wasm32-wasip1/debug/plugin_weather.wasm"], |
| 37 | + "repl_logic_guest.wasm", |
| 38 | + ), |
| 39 | + Some(TEST_TIMEOUT), |
| 40 | + ) |
| 41 | + .expect("Can't launch pluginlab with plugin greet"); |
| 42 | + |
| 43 | + session |
| 44 | + .exp_string("[Host] Starting REPL host...") |
| 45 | + .expect("Didn't see startup message"); |
| 46 | + session |
| 47 | + .exp_string("[Host] Loading plugin:") |
| 48 | + .expect("Didn't see plugin loading message"); |
| 49 | + session |
| 50 | + .exp_string("repl(0)>") |
| 51 | + .expect("Didn't see REPL prompt"); |
| 52 | + session |
| 53 | + .send_line("weather Paris") |
| 54 | + .expect("Failed to send command"); |
| 55 | + session |
| 56 | + .exp_string("Error fetching weather: PermissionDenied: network access to wttr.in is not allowed") |
| 57 | + .expect("Didn't get expected error output"); |
| 58 | + } |
| 59 | + |
| 60 | + #[test] |
| 61 | + fn test_without_permission_allow_read() { |
| 62 | + let project_root = find_project_root(); |
| 63 | + println!("Setting current directory to: {:?}", project_root); |
| 64 | + std::env::set_current_dir(&project_root).unwrap(); |
| 65 | + let mut session = spawn( |
| 66 | + &format!( |
| 67 | + "{} --dir tmp/filesystem", |
| 68 | + &build_command( |
| 69 | + &["target/wasm32-wasip1/debug/plugin_ls.wasm"], |
| 70 | + "repl_logic_guest.wasm" |
| 71 | + ) |
| 72 | + ), |
| 73 | + Some(TEST_TIMEOUT), |
| 74 | + ) |
| 75 | + .expect("Can't launch pluginlab with plugin greet"); |
| 76 | + |
| 77 | + session |
| 78 | + .exp_string("[Host] Starting REPL host...") |
| 79 | + .expect("Didn't see startup message"); |
| 80 | + session |
| 81 | + .exp_string("[Host] Loading plugin:") |
| 82 | + .expect("Didn't see plugin loading message"); |
| 83 | + session |
| 84 | + .exp_string("repl(0)>") |
| 85 | + .expect("Didn't see REPL prompt"); |
| 86 | + session.send_line("ls").expect("Failed to send command"); |
| 87 | + session |
| 88 | + .exp_string("ls: : Operation not permitted") |
| 89 | + .expect("Didn't get expected error output"); |
| 90 | + } |
| 91 | +} |
0 commit comments