Per collection/folder auth

This commit is contained in:
Torbjörn Molin committed 2026-10-19 12:38:38 +02:00
1 parent d5e7b484fc
commit 47ee07d9ff
16 files changed
+1569 -58

No files matched your search

+68
View File
@@ -170,3 +170,71 @@ fn opens_a_collection_and_shows_its_requests() {
});
assert_eq!(client.seen.lock().unwrap()[0].url, "http://dev/users");
}
#[test]
fn folder_auth_and_consolidate_dialogs() {
let rt = tokio::runtime::Runtime::new().unwrap();
let dir = tempfile::tempdir().unwrap();
std::fs::create_dir(dir.path().join("api")).unwrap();
std::fs::write(
dir.path().join("api/users.http"),
"### List users\nGET http://x/users\nAuthorization: Bearer {{token}}\n\n### Me\nGET http://x/me\n",
)
.unwrap();
let client = Arc::new(FakeClient::default());
let mut h = harness(&rt, client.clone());
let root = std::fs::canonicalize(dir.path()).unwrap();
h.state_mut().dispatch(Action::OpenCollection(root.clone()));
step_until(&mut h, "the collection", |h| !h.state().state.collections.is_empty());
h.state_mut().dispatch(Action::ConsolidateAuth {
dir: root.clone(),
target: None,
});
h.step();
h.step();
assert!(h.query_by_label("Consolidate auth").is_some());
h.get_by_label("Apply").click();
step_until(&mut h, "the folder settings file", |_| {
root.join(".reqlite/folder.json").is_file()
});
step_until(&mut h, "the rewritten file", |_| {
std::fs::read_to_string(root.join("api/users.http")).is_ok_and(|t| !t.contains("Authorization"))
});
// The request without a header got `# @no-auth`, so it sends nothing.
h.state_mut().dispatch(Action::OpenRequest {
file: root.join("api/users.http"),
index: 1,
});
h.step();
let tab = h.state().state.active.unwrap();
h.state_mut()
.dispatch(Action::SetRequestTab(tab, reqlite_app::state::RequestTab::Auth));
h.step();
assert!(h.query_by_label_contains("@no-auth").is_some());
h.state_mut()
.dispatch(Action::SetRequestTab(tab, reqlite_app::state::RequestTab::Params));
h.state_mut().dispatch(Action::EditFolderAuth(root.join("api")));
h.step();
h.step();
assert!(h.query_by_label("Folder auth").is_some());
h.get_by_label("Bearer token").click();
h.step();
// The URL bar has a Save button too, so save through the dialog's state.
let Some(reqlite_app::state::Dialog::FolderAuth(ed)) = h.state().state.dialog.clone() else {
panic!("no folder auth dialog")
};
assert_eq!(
ed.auth,
reqlite_core::folder::FolderAuth::Header("Bearer {{token}}".into())
);
h.state_mut().dispatch(Action::SetFolderAuth {
dir: ed.dir,
auth: ed.auth,
});
step_until(&mut h, "the api folder settings", |_| {
root.join("api/.reqlite/folder.json").is_file()
});
}