Compare commits
2 changed files with 9 additions and 201 deletions
|
|
@ -4416,10 +4416,7 @@ pub(crate) mod tests {
|
||||||
let err = node
|
let err = node
|
||||||
.start_wallet_child()
|
.start_wallet_child()
|
||||||
.expect_err("a missing binary fails");
|
.expect_err("a missing binary fails");
|
||||||
// The refusal names the configured path: the old `spawn <label>` copy
|
assert!(err.contains("spawn"), "{err}");
|
||||||
// could not say which program was missing.
|
|
||||||
assert!(err.contains("/nonexistent/onionwire-wallet-rpc"), "{err}");
|
|
||||||
assert!(err.contains("not found"), "{err}");
|
|
||||||
let status = node.wallet_child_status();
|
let status = node.wallet_child_status();
|
||||||
assert_eq!(status.state, WalletChildState::Off);
|
assert_eq!(status.state, WalletChildState::Off);
|
||||||
assert!(!status.running);
|
assert!(!status.running);
|
||||||
|
|
|
||||||
|
|
@ -551,15 +551,6 @@ impl WalletChild {
|
||||||
&self,
|
&self,
|
||||||
creds: impl FnOnce() -> Result<(String, Zeroizing<String>)>,
|
creds: impl FnOnce() -> Result<(String, Zeroizing<String>)>,
|
||||||
) -> Result<Option<WalletClient>> {
|
) -> Result<Option<WalletClient>> {
|
||||||
// Pre-flight the wallet RPC binary before anything is spawned: a bin
|
|
||||||
// that cannot be exec'd must not cost a daemon launch (and its
|
|
||||||
// readiness wait) first, and `exec`'s errno alone cannot say *which*
|
|
||||||
// path was missing.
|
|
||||||
// A bare name is the copy next to this binary, when one is there.
|
|
||||||
// An absolute path is the caller's (Android jniLibs, a test fake).
|
|
||||||
let bin = resolve_wallet_rpc_bin(&self.wallet_rpc_bin, bundled_wallet_rpc_dir().as_deref());
|
|
||||||
check_wallet_rpc_bin(&self.wallet_rpc_bin, &bin, bare_bin_resolvable())?;
|
|
||||||
|
|
||||||
// Local chain source: own the daemon first, so the wallet child has
|
// Local chain source: own the daemon first, so the wallet child has
|
||||||
// something to dial. Either a spawned `monerod` or the in-process
|
// something to dial. Either a spawned `monerod` or the in-process
|
||||||
// Cuprate node — both bind `DEFAULT_MONEROD_RPC_PORT` on loopback, so
|
// Cuprate node — both bind `DEFAULT_MONEROD_RPC_PORT` on loopback, so
|
||||||
|
|
@ -619,6 +610,9 @@ impl WalletChild {
|
||||||
let port = Self::pick_port()?;
|
let port = Self::pick_port()?;
|
||||||
let login = format!("{user}:{}", pass.as_str());
|
let login = format!("{user}:{}", pass.as_str());
|
||||||
let daemon = Self::daemon_address(&self.source);
|
let daemon = Self::daemon_address(&self.source);
|
||||||
|
// A bare name is the copy next to this binary, when one is there.
|
||||||
|
// An absolute path is the caller's (Android jniLibs, a test fake).
|
||||||
|
let bin = resolve_wallet_rpc_bin(&self.wallet_rpc_bin, bundled_wallet_rpc_dir().as_deref());
|
||||||
let argv = Self::wallet_rpc_argv(
|
let argv = Self::wallet_rpc_argv(
|
||||||
&bin,
|
&bin,
|
||||||
port,
|
port,
|
||||||
|
|
@ -787,9 +781,7 @@ pub struct ChildConfig {
|
||||||
/// The user's chain-source choice. `None` is receive-only: nothing spawns.
|
/// The user's chain-source choice. `None` is receive-only: nothing spawns.
|
||||||
pub source: ChainSource,
|
pub source: ChainSource,
|
||||||
/// `monero-wallet-rpc`. A bare name is resolved on `PATH`; Android passes an
|
/// `monero-wallet-rpc`. A bare name is resolved on `PATH`; Android passes an
|
||||||
/// absolute path out of the app's native library directory. On a target
|
/// absolute path out of the app's native library directory.
|
||||||
/// with no `PATH` to resolve it (Android), a bare name is refused rather
|
|
||||||
/// than persisted — it could only fail at `exec`.
|
|
||||||
pub wallet_rpc_bin: PathBuf,
|
pub wallet_rpc_bin: PathBuf,
|
||||||
/// `arti`, run as the SOCKS child for a `.onion` daemon only.
|
/// `arti`, run as the SOCKS child for a `.onion` daemon only.
|
||||||
pub arti_bin: PathBuf,
|
pub arti_bin: PathBuf,
|
||||||
|
|
@ -860,14 +852,6 @@ impl ChildConfig {
|
||||||
if self.wallet_rpc_bin.as_os_str().is_empty() {
|
if self.wallet_rpc_bin.as_os_str().is_empty() {
|
||||||
return Err(ChildError("monero-wallet-rpc path required".into()));
|
return Err(ChildError("monero-wallet-rpc path required".into()));
|
||||||
}
|
}
|
||||||
// A bare name is only resolvable through `PATH`. Where this target has
|
|
||||||
// no `PATH` to search (an app sandbox), accepting it here would persist
|
|
||||||
// a setting that can only fail at `exec`, so refuse it with the path in
|
|
||||||
// the message. The resolved-bin existence check is the start path's job
|
|
||||||
// (`check_wallet_rpc_bin`): at save time the file may not be created yet.
|
|
||||||
if !bare_bin_resolvable() && self.wallet_rpc_bin.components().nth(1).is_none() {
|
|
||||||
return Err(bare_bin_refused(&self.wallet_rpc_bin));
|
|
||||||
}
|
|
||||||
if self.arti_bin.as_os_str().is_empty() {
|
if self.arti_bin.as_os_str().is_empty() {
|
||||||
return Err(ChildError("arti path required".into()));
|
return Err(ChildError("arti path required".into()));
|
||||||
}
|
}
|
||||||
|
|
@ -1278,60 +1262,6 @@ fn resolve_wallet_rpc_bin(configured: &Path, beside: Option<&Path>) -> PathBuf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Can a spawned child resolve a bare `argv[0]` through `PATH` on this target?
|
|
||||||
/// An app sandbox (Android) has no `PATH` for a child to search, so a bare name
|
|
||||||
/// there can only fail at `exec`; a desktop can resolve one. Compile-time, so
|
|
||||||
/// the core needs no runtime platform probe.
|
|
||||||
const fn bare_bin_resolvable() -> bool {
|
|
||||||
!cfg!(target_os = "android")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bare_bin_refused(configured: &Path) -> ChildError {
|
|
||||||
ChildError(format!(
|
|
||||||
"monero-wallet-rpc: {} is a bare name and this platform has no PATH to resolve it; \
|
|
||||||
configure an absolute path",
|
|
||||||
configured.display()
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pre-flight the wallet RPC binary *before* `exec`, so the failure names the
|
|
||||||
/// path and the reason instead of a bare `os error 2`.
|
|
||||||
///
|
|
||||||
/// `resolved` is what `spawn` would use; `configured` is what the caller set.
|
|
||||||
/// A bare name is `PATH`'s job where a `PATH` exists — this does not search
|
|
||||||
/// one, and does not fall back anywhere. On a target with no `PATH`
|
|
||||||
/// (`bare_resolvable == false`) a bare name is refused outright.
|
|
||||||
fn check_wallet_rpc_bin(configured: &Path, resolved: &Path, bare_resolvable: bool) -> Result<()> {
|
|
||||||
if resolved.components().nth(1).is_none() {
|
|
||||||
return if bare_resolvable {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(bare_bin_refused(configured))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
let named = if resolved == configured {
|
|
||||||
configured.display().to_string()
|
|
||||||
} else {
|
|
||||||
format!(
|
|
||||||
"{} (configured {})",
|
|
||||||
resolved.display(),
|
|
||||||
configured.display()
|
|
||||||
)
|
|
||||||
};
|
|
||||||
match fs::metadata(resolved) {
|
|
||||||
Ok(meta) if !meta.is_file() => Err(ChildError(format!(
|
|
||||||
"monero-wallet-rpc: {named} is not a file"
|
|
||||||
))),
|
|
||||||
Ok(meta) if meta.permissions().mode() & 0o111 == 0 => Err(ChildError(format!(
|
|
||||||
"monero-wallet-rpc: {named} is not executable"
|
|
||||||
))),
|
|
||||||
Ok(_) => Ok(()),
|
|
||||||
Err(e) => Err(ChildError(format!(
|
|
||||||
"monero-wallet-rpc: {named} not found ({e})"
|
|
||||||
))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn executable_file(path: &Path) -> bool {
|
fn executable_file(path: &Path) -> bool {
|
||||||
std::fs::metadata(path)
|
std::fs::metadata(path)
|
||||||
.is_ok_and(|meta| meta.is_file() && meta.permissions().mode() & 0o111 != 0)
|
.is_ok_and(|meta| meta.is_file() && meta.permissions().mode() & 0o111 != 0)
|
||||||
|
|
@ -1349,12 +1279,10 @@ fn spawn(argv: &[String], what: &str) -> Result<Child> {
|
||||||
let (bin, args) = argv
|
let (bin, args) = argv
|
||||||
.split_first()
|
.split_first()
|
||||||
.ok_or_else(|| ChildError(format!("empty argv for {what}")))?;
|
.ok_or_else(|| ChildError(format!("empty argv for {what}")))?;
|
||||||
Command::new(bin).args(args).spawn().map_err(|e| {
|
Command::new(bin)
|
||||||
// Both halves matter: the label keeps the copy readable, `argv[0]`
|
.args(args)
|
||||||
// says which program actually failed (a bare name vs. an absolute
|
.spawn()
|
||||||
// path — the difference the Android report could not show).
|
.map_err(|e| ChildError(format!("spawn {what}: {e}")))
|
||||||
ChildError(format!("spawn {what} ({bin}): {e}"))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn kill_slot(slot: &Mutex<Option<Child>>, what: &str) -> Result<()> {
|
fn kill_slot(slot: &Mutex<Option<Child>>, what: &str) -> Result<()> {
|
||||||
|
|
@ -2017,123 +1945,6 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The spawn error must name the *program that failed* (`argv[0]`), not
|
|
||||||
/// just the human label: on Android the two differ, and which one it was is
|
|
||||||
/// the whole diagnosis.
|
|
||||||
#[test]
|
|
||||||
fn a_spawn_error_names_argv0_and_the_label() {
|
|
||||||
let dir = tmp_dir("spawn-missing");
|
|
||||||
fs::create_dir_all(&dir).unwrap();
|
|
||||||
let missing = dir.join("libmonerowalletrpc.so");
|
|
||||||
let argv = vec![missing.display().to_string(), "--version".into()];
|
|
||||||
|
|
||||||
let err = spawn(&argv, "monero-wallet-rpc").expect_err("a missing program cannot spawn");
|
|
||||||
let msg = err.to_string();
|
|
||||||
assert!(msg.starts_with("spawn monero-wallet-rpc ("), "{msg}");
|
|
||||||
assert!(msg.contains(&missing.display().to_string()), "{msg}");
|
|
||||||
// The errno is carried through verbatim: no invented cause.
|
|
||||||
assert!(msg.contains("No such file or directory"), "{msg}");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pre-flight: a bin that is not an existing regular executable is refused
|
|
||||||
/// with the configured path in the message, before `exec` gets a say.
|
|
||||||
#[test]
|
|
||||||
fn a_missing_wallet_rpc_bin_is_refused_with_the_configured_path() {
|
|
||||||
let dir = tmp_dir("preflight-missing");
|
|
||||||
fs::create_dir_all(&dir).unwrap();
|
|
||||||
let configured = dir.join("libmonerowalletrpc.so");
|
|
||||||
|
|
||||||
let err = check_wallet_rpc_bin(&configured, &configured, true)
|
|
||||||
.expect_err("a bin that does not exist cannot be spawned");
|
|
||||||
let msg = err.to_string();
|
|
||||||
assert!(msg.contains(&configured.display().to_string()), "{msg}");
|
|
||||||
assert!(msg.contains("not found"), "{msg}");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn a_wallet_rpc_bin_that_is_not_a_file_is_refused() {
|
|
||||||
let dir = tmp_dir("preflight-dir");
|
|
||||||
let configured = dir.join("libmonerowalletrpc.so");
|
|
||||||
fs::create_dir_all(&configured).unwrap();
|
|
||||||
|
|
||||||
let err = check_wallet_rpc_bin(&configured, &configured, true)
|
|
||||||
.expect_err("a directory cannot be executed");
|
|
||||||
let msg = err.to_string();
|
|
||||||
assert!(msg.contains(&configured.display().to_string()), "{msg}");
|
|
||||||
assert!(msg.contains("not a file"), "{msg}");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn a_wallet_rpc_bin_without_any_execute_bit_is_refused() {
|
|
||||||
let dir = tmp_dir("preflight-noexec");
|
|
||||||
fs::create_dir_all(&dir).unwrap();
|
|
||||||
let configured = dir.join("libmonerowalletrpc.so");
|
|
||||||
fs::write(&configured, b"not a program\n").unwrap();
|
|
||||||
let mut perms = fs::metadata(&configured).unwrap().permissions();
|
|
||||||
perms.set_mode(0o644);
|
|
||||||
fs::set_permissions(&configured, perms).unwrap();
|
|
||||||
|
|
||||||
let err = check_wallet_rpc_bin(&configured, &configured, true)
|
|
||||||
.expect_err("a file with no execute bit cannot be spawned");
|
|
||||||
let msg = err.to_string();
|
|
||||||
assert!(msg.contains(&configured.display().to_string()), "{msg}");
|
|
||||||
assert!(msg.contains("not executable"), "{msg}");
|
|
||||||
|
|
||||||
let mut perms = fs::metadata(&configured).unwrap().permissions();
|
|
||||||
perms.set_mode(0o755);
|
|
||||||
fs::set_permissions(&configured, perms).unwrap();
|
|
||||||
assert!(
|
|
||||||
check_wallet_rpc_bin(&configured, &configured, true).is_ok(),
|
|
||||||
"an executable file passes the pre-flight"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A bare name is only resolvable through `PATH`. Where the target has no
|
|
||||||
/// `PATH` to search (an app sandbox), it is refused with the path in the
|
|
||||||
/// message; on a desktop the pre-flight leaves it to `exec`.
|
|
||||||
#[test]
|
|
||||||
fn a_bare_wallet_rpc_bin_is_refused_where_path_cannot_resolve_it() {
|
|
||||||
let bare = Path::new("monero-wallet-rpc");
|
|
||||||
|
|
||||||
let err = check_wallet_rpc_bin(bare, bare, false)
|
|
||||||
.expect_err("a bare name cannot resolve in an app sandbox");
|
|
||||||
let msg = err.to_string();
|
|
||||||
assert!(msg.contains("monero-wallet-rpc"), "{msg}");
|
|
||||||
assert!(msg.contains("bare name"), "{msg}");
|
|
||||||
|
|
||||||
assert!(
|
|
||||||
check_wallet_rpc_bin(bare, bare, true).is_ok(),
|
|
||||||
"a desktop leaves a bare name to PATH"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The start path refuses a missing bin before spawning anything, and says
|
|
||||||
/// which configured path was missing.
|
|
||||||
#[test]
|
|
||||||
fn start_refuses_a_wallet_rpc_bin_that_is_not_there() {
|
|
||||||
let dir = tmp_dir("start-missing-bin");
|
|
||||||
let store = open_store(&dir);
|
|
||||||
let missing = dir.join("wallet").join("libmonerowalletrpc.so");
|
|
||||||
let child = WalletChild::new(
|
|
||||||
ChainSource::Remote {
|
|
||||||
host: "127.0.0.1".into(),
|
|
||||||
port: 18089,
|
|
||||||
},
|
|
||||||
dir.join("wallet"),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
.with_wallet_rpc_bin(missing.clone());
|
|
||||||
|
|
||||||
let err = child
|
|
||||||
.start(&store)
|
|
||||||
.expect_err("a missing wallet rpc bin cannot spawn");
|
|
||||||
let msg = err.to_string();
|
|
||||||
assert!(msg.contains(&missing.display().to_string()), "{msg}");
|
|
||||||
assert!(msg.contains("not found"), "{msg}");
|
|
||||||
assert!(!child.running(), "nothing may be left running: {msg}");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn monerod_argv_binds_loopback_and_uses_the_datadir() {
|
fn monerod_argv_binds_loopback_and_uses_the_datadir() {
|
||||||
let dir = tmp_dir("monerod-argv");
|
let dir = tmp_dir("monerod-argv");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue