mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-06 07:26:43 -04:00
Fix spacetime login --token falling through to web login (#4579)
## Bug PR #4367 (login/logout UX overhaul) accidentally removed the early `return Ok(())` after saving a token via `spacetime login --token`. This caused the command to fall through into the web login flow (`spacetimedb_login_and_save`), which fails when no browser or server is available. ## Impact All tests that use `spacetime login --token` are broken: - 4 replication tests (`test_enable_disable_replication`, `test_enable_replication_on_suspended_database`, `test_enable_replication_fails_if_not_suspended`, `test_prefer_leader`) - 5 teams tests (`test_permissions_clear_org`, `test_permissions_delete_org`, `test_org_permissions_mut_sql_org_members`, `test_org_permissions_private_tables`, `test_permissions_publish_org_members`) ## Fix One line: restore `return Ok(())` after the `--token` branch. --------- Signed-off-by: Zeke Foppa <196249+bfops@users.noreply.github.com> Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com> Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com> Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
154287c52f
commit
c5fa5d6fe7
@@ -71,6 +71,7 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E
|
||||
Ok(identity) => println!("Logged in with identity {identity}"),
|
||||
Err(_) => println!("Token saved."),
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(server) = server_issued_login {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use spacetimedb_smoketests::{require_local_server, Smoketest};
|
||||
use std::fs;
|
||||
use std::process::Output;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
fn output_stdout(output: &Output) -> String {
|
||||
String::from_utf8_lossy(&output.stdout).to_string()
|
||||
@@ -170,3 +171,62 @@ fn cli_logging_in_twice_works() {
|
||||
second_stdout
|
||||
);
|
||||
}
|
||||
|
||||
fn try_until_timeout<F: FnMut() -> Option<R>, R>(timeout: Duration, mut f: F) -> Option<R> {
|
||||
let start = Instant::now();
|
||||
loop {
|
||||
match f() {
|
||||
Some(result) => return Some(result),
|
||||
None => {
|
||||
if start.elapsed() > timeout {
|
||||
return None;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(200));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Test that `spacetime login --token <token>` exits immediately after saving
|
||||
/// the token, without falling through to the interactive web login flow.
|
||||
///
|
||||
/// Without the fix in PR #4579, the command would fall through to the web
|
||||
/// login flow, which hangs waiting for a browser callback.
|
||||
#[test]
|
||||
fn cli_login_with_token() {
|
||||
use std::io::Read;
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
let test = Smoketest::builder().autopublish(false).build();
|
||||
let cli_path = spacetimedb_guard::ensure_binaries_built();
|
||||
|
||||
let mut child = Command::new(&cli_path)
|
||||
.arg("--config-path")
|
||||
.arg(&test.config_path)
|
||||
.args(["login", "--token", "test-dummy-token", "--no-browser"])
|
||||
.env_remove("BROWSER")
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.expect("Failed to spawn spacetime login");
|
||||
|
||||
// Run with timeout in case something goes wrong and it tries to open the browser for login.
|
||||
let timeout = Duration::from_secs(5);
|
||||
let Some(status) = try_until_timeout(timeout, || child.try_wait().expect("Failed to poll child")) else {
|
||||
child.kill().ok();
|
||||
panic!(
|
||||
"spacetime login --token hung for >{timeout:?} — \
|
||||
likely fell through to web login flow"
|
||||
);
|
||||
};
|
||||
let mut stdout = String::new();
|
||||
child.stdout.take().unwrap().read_to_string(&mut stdout).unwrap();
|
||||
assert!(
|
||||
status.success(),
|
||||
"spacetime login --token failed (exit {status}):\n{stdout}"
|
||||
);
|
||||
assert!(
|
||||
stdout.contains("Token saved."),
|
||||
"Expected 'Token saved.' in output, got: {stdout}"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user