Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions crates/alien-deploy-cli/src/commands/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,8 @@ fn restore_credentials_and_service(
}

fn local_machine_connectivity(executable_path: &Path) -> Result<Option<LocalConnectivity>> {
let output = Command::new(executable_path)
let status_executable = installed_status_executable(executable_path);
let output = Command::new(&status_executable)
.args(["status", "--json"])
.output()
.into_alien_error()
Expand All @@ -1226,6 +1227,19 @@ fn local_machine_connectivity(executable_path: &Path) -> Result<Option<LocalConn
Ok(status.control.connectivity)
}

fn installed_status_executable(service_executable: &Path) -> PathBuf {
let horizond = service_executable.with_file_name("horizond");
if service_executable
.file_name()
.is_some_and(|name| name == "machine-entrypoint")
&& horizond.is_file()
{
horizond
} else {
service_executable.to_path_buf()
}
}

async fn download_manifest(url: &str) -> Result<MachineBundleManifest> {
let response = reqwest::get(url)
.await
Expand Down Expand Up @@ -2457,6 +2471,8 @@ mod tests {
use super::*;
use flate2::{write::GzEncoder, Compression};
use std::io::Write;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpListener;

Expand Down Expand Up @@ -2500,8 +2516,6 @@ mod tests {

#[cfg(unix)]
fn status_executable(directory: &Path, connectivity: &str) -> PathBuf {
use std::os::unix::fs::PermissionsExt;

let path = directory.join(format!("status-{connectivity}"));
std::fs::write(
&path,
Expand Down Expand Up @@ -2534,6 +2548,36 @@ mod tests {
);
}

#[test]
#[cfg(unix)]
fn local_status_bypasses_legacy_machine_entrypoint_wrapper() {
let directory = tempfile::tempdir().expect("status directory");
let entrypoint = directory.path().join("machine-entrypoint");
let wrapper_was_run = directory.path().join("wrapper-was-run");
std::fs::write(
&entrypoint,
format!("#!/bin/sh\ntouch '{}'\nexit 1\n", wrapper_was_run.display()),
)
.expect("write legacy wrapper");
std::fs::set_permissions(&entrypoint, std::fs::Permissions::from_mode(0o755))
.expect("make legacy wrapper executable");

let horizond = directory.path().join("horizond");
std::fs::write(
&horizond,
"#!/bin/sh\nprintf '%s\\n' '{\"control\":{\"connectivity\":\"authenticationFailed\"}}'\n",
)
.expect("write horizond status executable");
std::fs::set_permissions(&horizond, std::fs::Permissions::from_mode(0o755))
.expect("make horizond status executable");

assert_eq!(
local_machine_connectivity(&entrypoint).expect("authentication status"),
Some(LocalConnectivity::AuthenticationFailed)
);
assert!(!wrapper_was_run.exists());
}

#[tokio::test]
async fn refreshed_credentials_wait_for_a_nonempty_machine_token() {
let directory = tempfile::tempdir().expect("token directory");
Expand Down
Loading