#![cfg(unix)]
use rexpect::session::PtySession;
const TIMEOUT_MS: u64 = 10_000;
fn spawn(args: &str) -> PtySession {
let bin = env!("CARGO_BIN_EXE_tvc");
let cmd = format!("{bin} {args}");
rexpect::spawn(&cmd, Some(TIMEOUT_MS))
.unwrap_or_else(|e| panic!("spawn failed: {e}\n cmd: {cmd}"))
}
#[test]
fn approve_walks_all_sections_with_yeses() {
let mut session = spawn(
"deploy approve \
--manifest fixtures/manifest.json \
--operator-seed fixtures/seed.hex \
--skip-post",
);
session.exp_string("MANIFEST APPROVAL").unwrap();
session.exp_string("NAMESPACE").unwrap();
session.exp_string("turnkey-prod").unwrap();
session.exp_string("Approve namespace?").unwrap();
session.send_line("y").unwrap();
session.exp_string("ENCLAVE (AWS Nitro)").unwrap();
session
.exp_string("Approve enclave configuration?")
.unwrap();
session.send_line("y").unwrap();
session.exp_string("PIVOT BINARY").unwrap();
session.exp_string("Approve pivot binary?").unwrap();
session.send_line("y").unwrap();
session.exp_string("MANIFEST SET").unwrap();
session.exp_string("operator-alice").unwrap();
session.exp_string("Approve manifest set?").unwrap();
session.send_line("y").unwrap();
session.exp_string("SHARE SET").unwrap();
session.exp_string("Approve share set?").unwrap();
session.send_line("y").unwrap();
session.exp_string("ALL SECTIONS APPROVED").unwrap();
session.exp_string("\"signature\"").unwrap();
session.exp_eof().unwrap();
}
#[test]
fn approve_bails_when_user_rejects_pivot() {
let mut session = spawn(
"deploy approve \
--manifest fixtures/manifest.json \
--operator-seed fixtures/seed.hex \
--skip-post",
);
session.exp_string("Approve namespace?").unwrap();
session.send_line("y").unwrap();
session
.exp_string("Approve enclave configuration?")
.unwrap();
session.send_line("y").unwrap();
session.exp_string("Approve pivot binary?").unwrap();
session.send_line("n").unwrap();
session
.exp_string("operation cancelled by user: approval")
.unwrap();
session.exp_eof().unwrap();
}
#[test]
fn login_with_empty_org_id_bails() {
let temp = tempfile::TempDir::new().unwrap();
let bin = env!("CARGO_BIN_EXE_tvc");
let cmd = format!("{bin} login");
let mut session = rexpect::session::spawn_command(
{
let mut c = std::process::Command::new(bin);
c.arg("login").env("HOME", temp.path());
c
},
Some(TIMEOUT_MS),
)
.unwrap_or_else(|e| panic!("spawn failed: {e}\n cmd: {cmd}"));
session.exp_string("Organization ID").unwrap();
session.send_line("").unwrap();
session.exp_string("Organization ID is required").unwrap();
session.exp_eof().unwrap();
}