Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion crates/openhuman-core/src/config/user_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ pub(crate) fn rebind_after_credential_change(
rebound.from, rebound.to
));
}
crate::cron::seed::prune_retired_jobs(config).map_err(|error| error.to_string())?;
// Housekeeping, as at boot: a TinyFlows that cannot load must not undo a
// sign-in whose credential is already stored.
if let Err(error) = crate::cron::seed::prune_retired_jobs(config) {
log::warn!("[cron] failed to prune retired jobs after a credential change: {error}");
logs.push(format!("retired cron jobs not pruned: {error}"));
}
crate::core::runtime::context::CoreContext::rebind_default_workspace_with_config(
&config.workspace_dir,
Some(&config.config_path),
Expand Down
29 changes: 29 additions & 0 deletions crates/openhuman-core/src/credentials/ops_credential_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,35 @@ async fn set_credential_installs_a_session_without_touching_the_backend() {
);
}

#[tokio::test]
async fn a_tinyflows_that_cannot_load_does_not_undo_a_sign_in() {
let _env_guard = crate::config::TEST_ENV_LOCK.lock().await;
let tmp = TempDir::new().unwrap();
std::fs::create_dir_all(tmp.path().join("workspace")).unwrap();
let _home = EnvVarGuard::set("HOME", tmp.path());
// The per-user config is reloaded on activation; the env reaches it too.
let _tinyflows = EnvVarGuard::set("OPENHUMAN_COMPONENT_TINYFLOWS", "0");
crate::credentials::test_support::seed_plain_profile_configs(tmp.path(), &["user-42"]);
let mut config = test_config(&tmp);
config.components.tinyflows = false;
config.api_url = Some(spawn_auth_me_status(StatusCode::UNAUTHORIZED).await);
let exp = chrono::Utc::now() + chrono::Duration::hours(1);
let token = jwt_with_payload(json!({ "sub": "user-42", "exp": exp.timestamp() }));

let result = store_session(&DispatchCtx::process_default(), &config, &token, None, None)
.await
.expect("sign-in should survive the skipped cron prune");

// A failed rebind rolls the credential back and returns an error; this
// line is logged only after the rebind succeeded.
assert!(result.value.is_authenticated);
let logs = result.logs.join(" ");
assert!(
logs.contains("process globals rebound after credential install"),
"{logs}"
);
}

#[tokio::test]
async fn set_credential_derives_the_user_id_from_the_jwt_subject() {
let _env_guard = crate::config::TEST_ENV_LOCK.lock().await;
Expand Down
Loading