summaryrefslogtreecommitdiffstats
path: root/src/http
diff options
context:
space:
mode:
Diffstat (limited to 'src/http')
-rw-r--r--src/http/mod.rs14
-rw-r--r--src/http/routes/mod.rs14
2 files changed, 28 insertions, 0 deletions
diff --git a/src/http/mod.rs b/src/http/mod.rs
index a77869e..4291021 100644
--- a/src/http/mod.rs
+++ b/src/http/mod.rs
@@ -33,7 +33,21 @@ impl Req {
pub fn query_get(&self, key: &str) -> Option<String> {
self.query_pairs.iter().find(|(k, _)| k == key).map(|(_, v)| v.clone())
}
+ /// Reading a cookie off a request is internal plumbing; the auth tests need it in order to forge one.
+ ///
+ /// Module-internal in a production build, `pub` only under `test-support`:
+ /// one body behind two visibility declarations, exactly one of which compiles.
+ #[cfg(feature = "test-support")]
pub fn cookie(&self, name: &str) -> Option<String> {
+ Self::cookie_impl(self, name)
+ }
+
+ #[cfg(not(feature = "test-support"))]
+ pub(crate) fn cookie(&self, name: &str) -> Option<String> {
+ Self::cookie_impl(self, name)
+ }
+
+ fn cookie_impl(&self, name: &str) -> Option<String> {
self.cookies.iter().find(|(k, _)| k == name).map(|(_, v)| v.clone())
}
}
diff --git a/src/http/routes/mod.rs b/src/http/routes/mod.rs
index 1ef7fde..0ffecb0 100644
--- a/src/http/routes/mod.rs
+++ b/src/http/routes/mod.rs
@@ -43,7 +43,21 @@ pub(crate) fn logout(req: &Req) -> Res {
res
}
+/// The router dispatches to it. The login tests drive a live listener, so they cannot move into the module.
+///
+/// Module-internal in a production build, `pub` only under `test-support`:
+/// one body behind two visibility declarations, exactly one of which compiles.
+#[cfg(feature = "test-support")]
pub fn login(state: &State, req: &Req) -> Res {
+ login_impl(state, req)
+}
+
+#[cfg(not(feature = "test-support"))]
+pub(crate) fn login(state: &State, req: &Req) -> Res {
+ login_impl(state, req)
+}
+
+fn login_impl(state: &State, req: &Req) -> Res {
let given = req.form_get("password").unwrap_or_default();
let page = Page::new("Sign in", csrf(state, req));
if auth::password_ok(&state.cfg, &given) {