Skip to main content

kellnr_web_ui/
lib.rs

1pub mod crate_access;
2pub mod error;
3pub mod group;
4pub mod oauth2;
5pub mod session;
6pub mod ui;
7pub mod user;
8
9#[cfg(test)]
10mod test_helper {
11    use std::borrow::Cow;
12
13    use cookie::{Cookie, CookieJar};
14
15    pub(crate) const TEST_KEY: &[u8] = &[1; 64];
16
17    // there has to be a better way to set cookies, i really don't like importing cookie crate just to do this
18    pub(crate) fn encode_cookies<
19        const N: usize,
20        K: Into<Cow<'static, str>>,
21        V: Into<Cow<'static, str>>,
22    >(
23        cookies: [(K, V); N],
24    ) -> String {
25        let mut clear = CookieJar::new();
26        let mut jar = clear.private_mut(&TEST_KEY.try_into().unwrap());
27        for (k, v) in cookies {
28            jar.add(Cookie::new(k, v));
29        }
30        clear
31            .iter()
32            .map(|c| c.encoded().to_string())
33            .collect::<Vec<_>>()
34            .join("; ")
35    }
36}