Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
Saved passwords: approvals off needs Bitwarden (audit F-10)
Lin (kwant bot)b7c6eefbace6
diff --git a/docs/saved-passwords.md b/docs/saved-passwords.mdindex c552beab..48088585 100644--- a/docs/saved-passwords.md+++ b/docs/saved-passwords.md@@ -7,7 +7,19 @@ Kwnt can fill website logins in a team's, channel's or bot's browser. The passwo| Built-in | encrypted files in `<data>/kwnt-vault/`, with the key next to them | yes || Bitwarden | the person's own Bitwarden (or Vaultwarden) account, folder `kwnt` | after the person unlocks it once |-The built-in store protects against copies of the data folder. It does **not** protect against a bot that runs as the same Linux user with approvals off. That bot can read the key file. Use Bitwarden when bots run with approvals off.+The built-in store protects against copies of the data folder. It does **not** protect against a bot that runs as the same Linux user with approvals off. That bot can read the key file, and the API token next to it, and with them every built-in saved password (audit F-10, 2026-10-20). Kwnt's name filter on those files is not enough: shell wildcards get past it.++## Approvals off needs Bitwarden++Since 2026-10-20, approvals off and passwords in the built-in store are not allowed together. The server enforces this:++- Switching approvals off returns 409 `{error, needs_bitwarden: true, local_count}` while the built-in store holds any password. This covers a space, a bot, and a bot set to `inherit` from a space that is off. It also applies in Bitwarden mode when built-in passwords were never moved: they still open with the built-in key. Move them with `POST /api/passwords/migrate` first.+- While any space or bot has approvals off, saving into the built-in store (`POST …/passwords` or `…/passwords/pending`) returns 409 `{error, needs_bitwarden: true}`. A captured login keeps waiting.+- While any space or bot has approvals off, going back from Bitwarden to the built-in store (`DELETE /api/passwords/bitwarden`) returns 409 `{error, needs_bitwarden: true, local_count}`, unless the built-in store is empty.+- A space that is off counts even if every bot in it overrides to `ask`, because a new bot there would inherit `off`.+- An install that was already in this state keeps its approvals as they are. `GET /api/passwords/store` shows `exposed: true`, and kwnt logs one warning at start (a count, no secrets). Moving the passwords to Bitwarden or turning approvals back on clears it.++With Bitwarden, the API token alone doesn't show a password: that needs the master password. The DevTools gap below still applies in Bitwarden mode.## Bitwarden: what holds and what doesn't@@ -47,10 +59,13 @@ Vault:```json{"store": "local" | "bitwarden", "locked": bool, "local_count": n,+ "approvals_off": bool, "exposed": bool,"bitwarden": {"server_url", "email", "login": "password" | "api_key", "client_id","unlocked", "unlocked_at", "item_count", "last_sync"} | null}```+ `approvals_off`: any space or bot has approvals off. `exposed`: approvals are off and `local_count > 0`.+- `POST /api/passwords/bitwarden/unlock` returns the store status.- Body: `{server_url?, email?, master_password, client_id?, client_secret?, two_factor_provider?, two_factor_token?, new_device_otp?}`.- `server_url` and `email` are needed only the first time. That first unlock also makes Bitwarden the store.@@ -63,11 +78,12 @@ Vault:- 400 for bad input- 502 when Bitwarden is unreachable or refuses- `POST /api/passwords/bitwarden/lock` returns the store status.-- `DELETE /api/passwords/bitwarden {master_password}` goes back to the built-in store. The vault must be unlocked, and the items stay in Bitwarden.+- `DELETE /api/passwords/bitwarden {master_password}` goes back to the built-in store. The vault must be unlocked, and the items stay in Bitwarden. While approvals are off anywhere and the built-in store isn't empty, it returns 409 (see above).- `POST /api/passwords/migrate` returns `{moved, failed}`. It runs once, when the person triggers it. Each built-in password is deleted locally only after Bitwarden has it.## Tests+- `cargo test --test approvals_passwords_test` checks the approvals-off rules above.- `cargo test bitwarden` runs the unit tests and route checks, with known-answer vectors for the key derivation and the cipher format.- The end-to-end tests run against a throwaway Vaultwarden:diff --git a/src/db/approval_modes.rs b/src/db/approval_modes.rsindex a78fd7d6..87718d08 100644--- a/src/db/approval_modes.rs+++ b/src/db/approval_modes.rs@@ -95,6 +95,20 @@ impl Database {Ok(())}+ /// Whether approvals are off for any existing space or bot. A space that is off counts even+ /// when every bot in it overrides to `ask`: a new bot there would inherit `off`.+ pub async fn any_approvals_off(&self) -> Result<bool, DbError> {+ let row: Option<(i64,)> = sqlx::query_as(+ "SELECT 1 FROM approval_modes WHERE mode = 'off' AND (+ (scope = 'space' AND id IN (SELECT id FROM spaces))+ OR (scope = 'kwant' AND id IN (SELECT id FROM kwants))+ ) LIMIT 1",+ )+ .fetch_optional(&self.pool)+ .await?;+ Ok(row.is_some())+ }+/// A bot's approvals in `space`: its override, else the space's.pub async fn kwant_approvals_in(&self, space: &SpaceId, kwant_id: &str) -> Result<ApprovalMode, DbError> {let space_mode = self.space_approvals(space).await?;diff --git a/src/main.rs b/src/main.rsindex 629633d2..0d63ae18 100644--- a/src/main.rs+++ b/src/main.rs@@ -151,6 +151,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {let state = AppState::new(config.clone(), db, tools, broker, router);// Saved passwords left in a bot's folder by older versions move into the vaultkwnt::server::passwords::migrate_all(&state).await;+ kwnt::server::passwords::warn_if_exposed(&state).await;kwnt::server::scheduler::spawn_background(state.clone(), shutdown.clone());kwnt::server::engine_routes::spawn_startup_check(state.clone());let app = create_router(state);diff --git a/src/server/approval_modes.rs b/src/server/approval_modes.rsindex 0732a23e..49a26d62 100644--- a/src/server/approval_modes.rs+++ b/src/server/approval_modes.rs@@ -8,7 +8,7 @@ use super::{AppState,};use crate::db::{- approval_modes::{valid_mode, ApprovalMode, INHERIT},+ approval_modes::{valid_mode, ApprovalMode, INHERIT, OFF},spaces::SpaceId,};use axum::{@@ -87,6 +87,11 @@ pub async fn put_space(if !valid_mode(mode) {return error(StatusCode::BAD_REQUEST, "approvals must be \"ask\" or \"off\"");}+ if mode == OFF {+ if let Some(r) = super::passwords::refuse_approvals_off(&state).await {+ return r;+ }+ }if state.db.set_space_approvals(&space, mode).await.is_err() {return internal();}@@ -132,10 +137,18 @@ pub async fn put_kwant(if !(valid_mode(mode) || mode == INHERIT) {return error(StatusCode::BAD_REQUEST, "approvals must be \"inherit\", \"ask\" or \"off\"");}- match state.db.space_of_kwant(&id).await {- Ok(Some(_)) => {}+ let space = match state.db.space_of_kwant(&id).await {+ Ok(Some(s)) => s,Ok(None) => return error(StatusCode::NOT_FOUND, "no such bot"),Err(_) => return internal(),+ };+ // `inherit` in a space that is off switches the bot off too+ let turns_off = mode == OFF+ || (mode == INHERIT && matches!(state.db.space_approvals(&space).await.as_deref(), Ok(OFF) | Err(_)));+ if turns_off {+ if let Some(r) = super::passwords::refuse_approvals_off(&state).await {+ return r;+ }}if state.db.set_kwant_approvals(&id, mode).await.is_err() {return internal();diff --git a/src/server/passwords.rs b/src/server/passwords.rsindex c5bcabc0..7e0b5150 100644--- a/src/server/passwords.rs+++ b/src/server/passwords.rs@@ -29,6 +29,16 @@//!//! While Bitwarden is locked, the per-owner routes answer 423 `{error, locked: true}` and the//! browser fills nothing.+//!+//! Approvals off and the built-in store don't mix (audit F-10): a bot that can run commands can+//! read kwnt's data folder, and the built-in store's key and the API token sit there, so it could+//! read every built-in saved password. So, while any space or bot has approvals off:+//! - saving a password into the built-in store answers 409 `{error, needs_bitwarden: true}`;+//! - going back from Bitwarden to the built-in store answers 409 `{error, needs_bitwarden: true,+//! local_count}` unless the built-in store is empty.+//!+//! and switching approvals off answers 409 while the built-in store holds any password (see+//! [`refuse_approvals_off`]). An install already in that state is reported as `exposed: true`.use super::AppState;use crate::db::spaces::SpaceId;@@ -196,6 +206,9 @@ pub async fn save(if body.password.is_empty() {return error(StatusCode::BAD_REQUEST, "password is empty");}+ if let Some(r) = refuse_local_save(&state).await {+ return r;+ }let source = body.origin.filter(|o| !o.trim().is_empty()).or(body.domain).unwrap_or_default();let Ok(origin) = normalize_origin(&source) else {return error(StatusCode::BAD_REQUEST, "origin must be an http(s) address like https://example.com");@@ -286,6 +299,10 @@ pub async fn save_pending(State(state): State<AppState>, headers: HeaderMap, Patlet Some(ctrl) = open_controller(&state, &id, &owner).await else {return error(StatusCode::NOT_FOUND, "no password is waiting to be saved");};+ // Refused before it's taken, so it keeps waiting until Bitwarden is set up+ if let Some(r) = refuse_local_save(&state).await {+ return r;+ }let Some(p) = ctrl.take_pending().await else {return error(StatusCode::NOT_FOUND, "no password is waiting to be saved");};@@ -312,19 +329,85 @@ pub async fn discard_pending(State(state): State<AppState>, headers: HeaderMap,/// `{store: "local" | "bitwarden", locked, bitwarden: null | {server_url, email, login:/// "password" | "api_key", client_id, unlocked, unlocked_at, item_count, last_sync},-/// local_count}`. `local_count` is how many passwords the built-in store still holds (what-/// `migrate` would move).+/// local_count, approvals_off, exposed}`. `local_count` is how many passwords the built-in store+/// still holds (what `migrate` would move). `approvals_off`: any space or bot has approvals off.+/// `exposed`: both at once, so a bot could read those passwords; nothing changes it on its own.async fn store_json(state: &AppState) -> Value {let vault = &state.credentials;- let owners = all_owners(state).await;+ let local_count = local_count(state).await;+ let approvals_off = approvals_off_anywhere(state).await;json!({"store": vault.store_name(),"locked": vault.is_locked().await,"bitwarden": vault.bitwarden().status().await,- "local_count": vault.local_count(&owners).await,+ "local_count": local_count,+ "approvals_off": approvals_off,+ "exposed": approvals_off && local_count > 0,})}+/// How many passwords the built-in store holds. In Bitwarden mode these are leftovers that were+/// never moved, still readable with the built-in key.+pub async fn local_count(state: &AppState) -> usize {+ state.credentials.local_count(&all_owners(state).await).await+}++/// Whether any space or bot has approvals off. A failed read counts as off.+pub async fn approvals_off_anywhere(state: &AppState) -> bool {+ state.db.any_approvals_off().await.unwrap_or(true)+}++/// The 409 for switching approvals off while the built-in store holds passwords: a bot with+/// approvals off could read them (audit F-10). Bitwarden mode with nothing left in the built-in+/// store is fine. `None` when approvals may go off.+pub async fn refuse_approvals_off(state: &AppState) -> Option<Response> {+ let n = local_count(state).await;+ if n == 0 {+ return None;+ }+ tracing::info!(local_count = n, "refused to switch approvals off while the built-in store holds passwords");+ Some(+ (+ StatusCode::CONFLICT,+ Json(json!({+ "error": "approvals can't be switched off while passwords are saved on this server: a bot that can run commands could read them. Move them to Bitwarden first.",+ "needs_bitwarden": true,+ "local_count": n,+ })),+ )+ .into_response(),+ )+}++/// The 409 for saving into the built-in store while approvals are off anywhere.+async fn refuse_local_save(state: &AppState) -> Option<Response> {+ if state.credentials.store_name() != "local" || !approvals_off_anywhere(state).await {+ return None;+ }+ Some(+ (+ StatusCode::CONFLICT,+ Json(json!({+ "error": "passwords can't be saved on this server while approvals are off: a bot that can run commands could read them. Use Bitwarden, or turn approvals back on.",+ "needs_bitwarden": true,+ })),+ )+ .into_response(),+ )+}++/// On start: one warning, without secrets, when approvals are off and the built-in store holds+/// passwords. Approvals are left as the person set them.+pub async fn warn_if_exposed(state: &AppState) {+ let n = local_count(state).await;+ if n > 0 && approvals_off_anywhere(state).await {+ tracing::warn!(+ local_count = n,+ "approvals are off while passwords are saved on this server: a bot that can run commands could read them. Move them to Bitwarden or turn approvals back on."+ );+ }+}+#[allow(clippy::result_large_err)]async fn person(state: &AppState, headers: &HeaderMap) -> Result<(), Response> {super::mcp_suggest::refuse_agent_tokens(state, headers, REFUSAL).await@@ -381,6 +464,19 @@ pub async fn forget_bitwarden(State(state): State<AppState>, headers: HeaderMap,if !state.credentials.bitwarden().is_configured() {return Json(store_json(&state).await).into_response();}+ // Back to the built-in store would expose what it still holds to bots with approvals off+ let n = local_count(&state).await;+ if n > 0 && approvals_off_anywhere(&state).await {+ return (+ StatusCode::CONFLICT,+ Json(json!({+ "error": "approvals are off, so this server can't go back to its built-in password store while it still holds passwords. Turn approvals back on first.",+ "needs_bitwarden": true,+ "local_count": n,+ })),+ )+ .into_response();+ }if let Err(r) = check_master_password(&state, &master_password_of(&body)).await {return r;}diff --git a/tests/approvals_passwords_test.rs b/tests/approvals_passwords_test.rsnew file mode 100644index 00000000..56abf9af--- /dev/null+++ b/tests/approvals_passwords_test.rs@@ -0,0 +1,297 @@+//! Approvals off and the built-in password store don't mix (audit 2026-10-20, F-10): a bot with+//! approvals off could read the built-in store's key and the API token from kwnt's data folder,+//! and with them every built-in saved password.+//!+//! - Switching approvals off (space, bot, or a bot set to inherit an off space) answers 409+//! `{error, needs_bitwarden: true, local_count}` while the built-in store holds any password,+//! in Bitwarden mode too (leftovers open with the built-in key).+//! - While approvals are off anywhere, saving into the built-in store answers 409 and going back+//! from Bitwarden to the built-in store answers 409 unless it is empty.+//! - An install already in that state shows `exposed: true` and keeps its approvals.++use axum::{+ body::{to_bytes, Body},+ http::{Request, StatusCode},+ Router,+};+use kwnt::{+ broker::PermissionBroker,+ config::Config,+ db::{+ models::{Kwant, NewTeam},+ spaces::SpaceId,+ Database,+ },+ router::LayaRouter,+ sandbox::{bitwarden::BitwardenConfig, bitwarden::CONFIG_FILE, browser::BrowserController, credentials::VAULT_DIR, PendingCapture},+ server::{create_router, AppState},+ tools::ToolRunner,+};+use serde_json::{json, Value};+use tempfile::{tempdir, TempDir};+use tower::ServiceExt;++struct Env {+ app: Router,+ state: AppState,+ bot: Kwant,+ team: String,+ _tmp: TempDir,+}++/// A fresh server; with `bitwarden`, Bitwarden is set up (and locked, as after a restart).+async fn setup(bitwarden: bool) -> Env {+ let tmp = tempdir().unwrap();+ let data = tmp.path().join("data");+ let db = Database::init(&data).await.unwrap();+ if bitwarden {+ let dir = data.join(VAULT_DIR);+ std::fs::create_dir_all(&dir).unwrap();+ #[cfg(unix)]+ {+ use std::os::unix::fs::PermissionsExt;+ std::fs::set_permissions(&data, std::fs::Permissions::from_mode(0o700)).unwrap();+ std::fs::set_permissions(&dir, std::fs::Permissions::from_mode(0o700)).unwrap();+ }+ let cfg = BitwardenConfig {+ server_url: "https://vault.bitwarden.test".into(),+ email: "[email protected]".into(),+ client_id: None,+ device_id: "d".into(),+ };+ std::fs::write(dir.join(CONFIG_FILE), serde_json::to_vec(&cfg).unwrap()).unwrap();+ }+ let config = Config { data_dir: data.clone(), browser_cdp_url: Some("http://127.0.0.1:9".into()), ..Config::default() };+ let state = AppState::new(+ config.clone(),+ db,+ ToolRunner::new(data.join("workspace")),+ PermissionBroker::new(),+ LayaRouter::new(config.laya_url.clone()),+ );+ assert_eq!(state.credentials.store_name(), if bitwarden { "bitwarden" } else { "local" });+ let bot = state.db.list_kwants(&SpaceId::default_space()).await.unwrap().remove(0);+ let new_team = NewTeam {+ name: "t".into(),+ description: None,+ icon: None,+ lead_kwant_id: bot.id.clone(),+ member_kwants: vec![bot.id.clone()],+ workspace_path: None,+ repo_url: None,+ };+ let team = state.db.create_team(&SpaceId::default_space(), &new_team).await.unwrap().id;+ Env { app: create_router(state.clone()), state, bot, team, _tmp: tmp }+}++impl Env {+ async fn person(&self, method: &str, uri: &str, body: Option<Value>) -> (StatusCode, Value) {+ let req = Request::builder()+ .method(method)+ .uri(uri)+ .header("content-type", "application/json")+ .header("authorization", format!("Bearer {}", self.state.api_token.reveal()));+ let body = body.map(|b| Body::from(b.to_string())).unwrap_or_else(Body::empty);+ let resp = self.app.clone().oneshot(req.body(body).unwrap()).await.unwrap();+ let status = resp.status();+ let bytes = to_bytes(resp.into_body(), usize::MAX).await.unwrap();+ (status, serde_json::from_slice(&bytes).unwrap_or(Value::Null))+ }+ async fn space_approvals(&self, mode: &str) -> (StatusCode, Value) {+ let uri = format!("/api/spaces/{}/approvals", SpaceId::default_space().as_str());+ self.person("PUT", &uri, Some(json!({"approvals": mode}))).await+ }+ async fn bot_approvals(&self, mode: &str) -> (StatusCode, Value) {+ self.person("PUT", &format!("/api/kwants/{}/approvals", self.bot.id), Some(json!({"approvals": mode}))).await+ }+ async fn save(&self, password: &str) -> (StatusCode, Value) {+ let body = json!({"origin": "https://a.test", "username": "u", "password": password});+ self.person("POST", &format!("/api/sandbox/{}/passwords", self.team), Some(body)).await+ }+ /// A password straight into the built-in store, as an older install left it.+ async fn local_password(&self) {+ self.state.credentials.local().save(&self.team, "https://old.test", "u", "DUMMY-LOCAL-PW").await.unwrap();+ }+ async fn store(&self) -> Value {+ self.person("GET", "/api/passwords/store", None).await.1+ }+ async fn effective(&self) -> String {+ self.state.db.kwant_approvals(&self.bot.id).await.unwrap().effective+ }+}++fn assert_needs_bitwarden(s: StatusCode, v: &Value, count: Option<u64>) {+ assert_eq!(s, StatusCode::CONFLICT, "{v}");+ assert_eq!(v["needs_bitwarden"], true, "{v}");+ assert!(v["error"].as_str().is_some_and(|e| !e.is_empty()), "{v}");+ if let Some(n) = count {+ assert_eq!(v["local_count"], n, "{v}");+ }+ assert!(!v.to_string().contains("DUMMY"), "no password in a refusal: {v}");+}++#[tokio::test]+async fn approvals_off_is_refused_while_the_built_in_store_holds_passwords() {+ let e = setup(false).await;+ let (s, v) = e.save("DUMMY-PW-1").await;+ assert_eq!(s, StatusCode::OK, "{v}");++ let (s, v) = e.space_approvals("off").await;+ assert_needs_bitwarden(s, &v, Some(1));+ let (s, v) = e.bot_approvals("off").await;+ assert_needs_bitwarden(s, &v, Some(1));+ assert_eq!(e.effective().await, "ask", "nothing switched off");+ assert_eq!(e.state.db.space_approvals(&SpaceId::default_space()).await.unwrap(), "ask");++ // Approvals on stays allowed+ assert_eq!(e.space_approvals("ask").await.0, StatusCode::OK);+ assert_eq!(e.bot_approvals("ask").await.0, StatusCode::OK);+ assert_eq!(e.bot_approvals("inherit").await.0, StatusCode::OK, "inherit of a space that asks");+}++#[tokio::test]+async fn inheriting_an_off_space_counts_as_switching_off() {+ let e = setup(false).await;+ // The bot asks on its own while the space goes off, with nothing saved yet+ assert_eq!(e.bot_approvals("ask").await.0, StatusCode::OK);+ assert_eq!(e.space_approvals("off").await.0, StatusCode::OK);+ // A password from before (an older install): the bot can't be moved onto the space's off+ e.local_password().await;+ let (s, v) = e.bot_approvals("inherit").await;+ assert_needs_bitwarden(s, &v, Some(1));+ assert_eq!(e.effective().await, "ask");+ assert_eq!(e.bot_approvals("ask").await.0, StatusCode::OK);+}++#[tokio::test]+async fn approvals_off_is_allowed_with_an_empty_built_in_store() {+ let e = setup(false).await;+ let (s, v) = e.space_approvals("off").await;+ assert_eq!(s, StatusCode::OK, "{v}");+ let (s, v) = e.bot_approvals("off").await;+ assert_eq!(s, StatusCode::OK, "{v}");+ assert_eq!(e.effective().await, "off");+ let st = e.store().await;+ assert_eq!(st["approvals_off"], true, "{st}");+ assert_eq!(st["exposed"], false, "{st}");+}++#[tokio::test]+async fn with_approvals_off_nothing_new_is_saved_in_the_built_in_store() {+ for scope in ["space", "bot", "inherit"] {+ let e = setup(false).await;+ match scope {+ "space" => assert_eq!(e.space_approvals("off").await.0, StatusCode::OK),+ "bot" => assert_eq!(e.bot_approvals("off").await.0, StatusCode::OK),+ _ => {+ // A space that is off, its bots overriding to ask: still off for new bots+ assert_eq!(e.space_approvals("off").await.0, StatusCode::OK);+ for k in e.state.db.list_kwants(&SpaceId::default_space()).await.unwrap() {+ e.state.db.set_kwant_approvals(&k.id, "ask").await.unwrap();+ }+ }+ }+ let (s, v) = e.save("DUMMY-PW-OFF").await;+ assert_needs_bitwarden(s, &v, None);+ assert_eq!(e.store().await["local_count"], 0, "{scope}: nothing saved");++ // A password the browser captured keeps waiting+ let ctrl = BrowserController::new(9);+ e.state.browser_controllers.lock().await.insert(e.team.clone(), ctrl.clone());+ ctrl.hold_for_confirmation(PendingCapture {+ origin: "https://login.example.test".into(),+ username: "carol".into(),+ password: "DUMMY-CAPTURED-PW".into(),+ captured_at: "2026-10-20T00:00:00Z".into(),+ })+ .await;+ let (s, v) = e.person("POST", &format!("/api/sandbox/{}/passwords/pending", e.team), None).await;+ assert_needs_bitwarden(s, &v, None);+ let (_, list) = e.person("GET", &format!("/api/sandbox/{}/passwords", e.team), None).await;+ assert_eq!(list["pending"]["username"], "carol", "{scope}: still waiting: {list}");+ assert_eq!(list["passwords"].as_array().map(Vec::len), Some(0));++ // Approvals back on: saving works again+ assert_eq!(e.space_approvals("ask").await.0, StatusCode::OK);+ assert_eq!(e.bot_approvals("ask").await.0, StatusCode::OK);+ let (s, v) = e.save("DUMMY-PW-ON").await;+ assert_eq!(s, StatusCode::OK, "{scope}: {v}");+ }+}++#[tokio::test]+async fn bitwarden_mode_allows_approvals_off_unless_built_in_leftovers_remain() {+ let e = setup(true).await;+ let (s, v) = e.space_approvals("off").await;+ assert_eq!(s, StatusCode::OK, "Bitwarden with an empty built-in store: {v}");+ // Saving goes to Bitwarden, not refused for approvals (locked here: 423)+ let (s, v) = e.save("DUMMY-PW-BW").await;+ assert_eq!(s, StatusCode::LOCKED, "{v}");+ assert_eq!(e.space_approvals("ask").await.0, StatusCode::OK);++ // Passwords never moved out of the built-in store open with its key: refused too+ e.local_password().await;+ let (s, v) = e.space_approvals("off").await;+ assert_needs_bitwarden(s, &v, Some(1));+ let (s, v) = e.bot_approvals("off").await;+ assert_needs_bitwarden(s, &v, Some(1));+}++#[tokio::test]+async fn going_back_to_the_built_in_store_is_refused_while_approvals_are_off() {+ let e = setup(true).await;+ assert_eq!(e.bot_approvals("off").await.0, StatusCode::OK);+ // Leftovers appear in the built-in store (an older install)+ e.local_password().await;+ let st = e.store().await;+ assert_eq!(st["exposed"], true, "{st}");++ let (s, v) = e.person("DELETE", "/api/passwords/bitwarden", Some(json!({"master_password": "DUMMY-MASTER"}))).await;+ assert_needs_bitwarden(s, &v, Some(1));+ assert_eq!(e.state.credentials.store_name(), "bitwarden", "still Bitwarden");++ // With approvals back on, the refusal is gone (the locked vault then asks for an unlock)+ assert_eq!(e.bot_approvals("ask").await.0, StatusCode::OK);+ let (s, v) = e.person("DELETE", "/api/passwords/bitwarden", Some(json!({"master_password": "DUMMY-MASTER"}))).await;+ assert_ne!(s, StatusCode::CONFLICT, "{v}");+}++#[tokio::test]+async fn going_back_with_an_empty_built_in_store_is_not_refused() {+ let e = setup(true).await;+ assert_eq!(e.space_approvals("off").await.0, StatusCode::OK);+ let (s, v) = e.person("DELETE", "/api/passwords/bitwarden", Some(json!({"master_password": "DUMMY-MASTER"}))).await;+ assert_ne!(s, StatusCode::CONFLICT, "nothing to expose: {v}");+}++#[tokio::test]+async fn an_install_already_exposed_is_reported_and_left_as_is() {+ let e = setup(false).await;+ let st = e.store().await;+ assert_eq!((st["approvals_off"].clone(), st["exposed"].clone()), (json!(false), json!(false)), "{st}");++ // Approvals were switched off before this release, then a password was saved+ e.state.db.set_kwant_approvals(&e.bot.id, "off").await.unwrap();+ e.local_password().await;+ let st = e.store().await;+ assert_eq!(st["store"], "local");+ assert_eq!(st["local_count"], 1);+ assert_eq!(st["approvals_off"], true);+ assert_eq!(st["exposed"], true, "{st}");+ assert!(!st.to_string().contains("DUMMY"), "{st}");+ kwnt::server::passwords::warn_if_exposed(&e.state).await;+ assert_eq!(e.effective().await, "off", "approvals are not changed silently");++ // Turning approvals back on clears it+ assert_eq!(e.bot_approvals("ask").await.0, StatusCode::OK);+ assert_eq!(e.store().await["exposed"], false);+}++#[tokio::test]+async fn approvals_off_of_a_deleted_bot_does_not_count() {+ let e = setup(false).await;+ e.state.db.set_kwant_approvals("no-such-bot", "off").await.unwrap();+ assert!(!e.state.db.any_approvals_off().await.unwrap());+ let (s, v) = e.save("DUMMY-PW-2").await;+ assert_eq!(s, StatusCode::OK, "{v}");+}diff --git a/tests/saved_passwords_test.rs b/tests/saved_passwords_test.rsindex 515aca28..cb24d803 100644--- a/tests/saved_passwords_test.rs+++ b/tests/saved_passwords_test.rs@@ -374,7 +374,9 @@ async fn bots_cannot_name_kwnt_secret_files_even_with_approvals_off() {let (s, _) = e.person("PUT", &format!("/api/kwants/{}/approvals", bot.id), Some(json!({"approvals": "off"}))).await;assert_eq!(s, StatusCode::OK);let team = e.team("t", None).await;- e.person("POST", &format!("/api/sandbox/{team}/passwords"), Some(json!({"origin": "https://a.test", "username": "u", "password": "DUMMY-OFF-PW"}))).await;+ // With approvals off nothing new goes into the built-in store (F-10)+ let (s, _) = e.person("POST", &format!("/api/sandbox/{team}/passwords"), Some(json!({"origin": "https://a.test", "username": "u", "password": "DUMMY-OFF-PW"}))).await;+ assert_eq!(s, StatusCode::CONFLICT);let folder = tempdir().unwrap();let turn = e.turn_token(folder.path()).await;