Cookie jars per folder; pacman repository on Gitea; install guide per platform

- A folder can share its parent's cookie jar, keep its own, or use no
  cookies; sub folders follow. The Cookies tab shows the jar a request
  used. Jars are stored per collection and folder.
- The release workflow builds knock-bin from the deb and uploads it to
  the Gitea pacman repository (needs the GITEA_PACKAGES_TOKEN secret)
- knock-bin installs the desktop entry as knock-app.desktop
- README: install for Arch (signed pacman repo), Ubuntu/Debian,
  Fedora/openSUSE, AppImage, macOS (quarantine) and Windows (SmartScreen)
- release.sh works when the version is already set
This commit is contained in:
2026-11-27 22:12:08 +01:00
parent 59a8000cc0
commit 4b1590e750
13 changed files with 197 additions and 25 deletions
+12
View File
@@ -135,6 +135,18 @@ impl Engine {
}
}
/// Ids of loaded jars that belong to a collection (its own and its folders').
pub fn jar_ids(&self, collection: &str) -> Vec<String> {
let prefix = format!("{collection}/");
self.jars
.lock()
.unwrap()
.keys()
.filter(|k| *k == collection || k.starts_with(&prefix))
.cloned()
.collect()
}
pub fn save_jar(&self, collection: &str) -> String {
let jar = self.jar(collection);
let store = jar.lock().unwrap();
+13
View File
@@ -158,10 +158,23 @@ pub struct FolderMeta {
pub headers: Vec<KeyValue>,
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub vars: IndexMap<String, String>,
/// Cookie jar for this folder and everything below it. Unset shares the
/// jar of the parent (in the end the collection's).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cookies: Option<CookieJarMode>,
#[serde(flatten)]
pub extra: Extra,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum CookieJarMode {
/// A jar of its own, separate from the collection's.
Own,
/// No cookies are stored or sent.
Off,
}
// ---------------------------------------------------------------- request
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
+34
View File
@@ -36,6 +36,9 @@ pub struct RequestContext {
pub collection_settings: CollectionSettings,
pub collection_id: String,
pub env: Option<String>,
/// Cookie jar for this request, from the collection setting and the
/// closest folder that sets one; None means no cookies.
pub jar: Option<String>,
}
pub struct ContextInput<'a> {
@@ -83,6 +86,7 @@ impl RequestContext {
}
let auth = effective_auth(c, input.request_id, &input.request.auth, &ancestors);
let jar = cookie_jar(&c.manifest.id, c.manifest.settings.cookies, &ancestors);
let mut inherited_headers = c.manifest.headers.clone();
for (_, meta) in &ancestors {
inherited_headers.extend(meta.headers.iter().cloned());
@@ -95,6 +99,7 @@ impl RequestContext {
collection_settings: c.manifest.settings.clone(),
collection_id: c.manifest.id.clone(),
env: input.env.map(str::to_string),
jar,
})
}
@@ -119,10 +124,28 @@ impl RequestContext {
collection_settings: CollectionSettings::default(),
collection_id: String::new(),
env: None,
jar: None,
}
}
}
/// The jar id a request uses: the collection id, or `<collection>/<folder>`
/// for a folder with a jar of its own.
pub fn cookie_jar(collection_id: &str, collection_cookies: bool, ancestors: &[(String, FolderMeta)]) -> Option<String> {
if collection_id.is_empty() {
return None;
}
let mut jar = collection_cookies.then(|| collection_id.to_string());
for (id, meta) in ancestors {
match meta.cookies {
Some(CookieJarMode::Own) => jar = Some(format!("{collection_id}/{id}")),
Some(CookieJarMode::Off) => jar = None,
None => {}
}
}
jar
}
pub fn effective_auth(
c: &Collection,
request_id: &str,
@@ -540,6 +563,17 @@ mod tests {
assert_eq!(path_param_names("http://h:8080/u/:id/:other?x=:no"), vec!["id", "other"]);
}
#[test]
fn cookie_jar_follows_the_closest_folder() {
let f = |id: &str, mode: Option<CookieJarMode>| (id.to_string(), FolderMeta { cookies: mode, ..Default::default() });
assert_eq!(cookie_jar("c", true, &[]), Some("c".into()));
assert_eq!(cookie_jar("c", false, &[]), None);
assert_eq!(cookie_jar("c", true, &[f("oidc", Some(CookieJarMode::Off))]), None);
assert_eq!(cookie_jar("c", true, &[f("web", Some(CookieJarMode::Own)), f("web/admin", None)]), Some("c/web".into()));
assert_eq!(cookie_jar("c", false, &[f("web", Some(CookieJarMode::Own))]), Some("c/web".into()));
assert_eq!(cookie_jar("c", true, &[f("web", Some(CookieJarMode::Own)), f("web/x", Some(CookieJarMode::Off))]), None);
}
#[test]
fn jsonc() {
let s = "{\n // c\n \"a\": \"http://x\", /* b */\n \"b\": [1,2,],\n}";
+4 -2
View File
@@ -27,6 +27,8 @@ pub struct RunOutput {
pub missing: Vec<String>,
/// The request was sent a second time after refreshing an expired token.
pub retried: bool,
/// Cookie jar the request used, if any.
pub jar: Option<String>,
}
impl RunOutput {
@@ -111,6 +113,7 @@ pub async fn execute(
error: None,
missing: Vec::new(),
retried: false,
jar: if req.settings.cookies { ctx.jar.clone() } else { None },
};
let base = match prepare(req, ctx) {
Ok(p) => p,
@@ -133,8 +136,7 @@ pub async fn execute(
return out;
}
let transport = transport_for(ctx, &p.url);
let jar = (ctx.collection_settings.cookies && !ctx.collection_id.is_empty())
.then_some(ctx.collection_id.as_str());
let jar = ctx.jar.as_deref();
match engine.send(&p, &transport, jar).await {
Ok(resp) if is_digest && resp.status == 401 => {
let challenge = resp