diff --git a/src/handler.rs b/src/handler.rs index cafb9086..0a1bd9f5 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -247,7 +247,7 @@ impl Reply { #[cfg(test)] pub(crate) fn as_msg(&self) -> &I { match self.0.as_ref().unwrap() { - ReplyResult::Ok(ref resp) => resp, + &ReplyResult::Ok(ref resp) => resp, _ => panic!(), } } @@ -255,7 +255,7 @@ impl Reply { #[cfg(test)] pub(crate) fn as_err(&self) -> Option<&E> { match self.0.as_ref().unwrap() { - ReplyResult::Err(ref err) => Some(err), + &ReplyResult::Err(ref err) => Some(err), _ => None, } } diff --git a/src/middleware/session.rs b/src/middleware/session.rs index 13948ac2..b926842f 100644 --- a/src/middleware/session.rs +++ b/src/middleware/session.rs @@ -37,7 +37,7 @@ //! use actix_web::{server, App, HttpRequest, Result}; //! use actix_web::middleware::session::{RequestSession, SessionStorage, CookieSessionBackend}; //! -//! fn index(mut req: HttpRequest) -> Result<&'static str> { +//! fn index(req: HttpRequest) -> Result<&'static str> { //! // access session data //! if let Some(count) = req.session().get::("counter")? { //! println!("SESSION value: {}", count); @@ -525,3 +525,30 @@ impl SessionBackend for CookieSessionBackend { }) } } + +#[cfg(test)] +mod tests { + use super::*; + use application::App; + use test; + + #[test] + fn cookie_session() { + let mut srv = test::TestServer::with_factory(|| { + App::new() + .middleware(SessionStorage::new( + CookieSessionBackend::signed(&[0; 32]).secure(false), + )) + .resource("/", |r| { + r.f(|req| { + let _ = req.session().set("counter", 100); + "test" + }) + }) + }); + + let request = srv.get().uri(srv.url("/")).finish().unwrap(); + let response = srv.execute(request.send()).unwrap(); + assert!(response.cookie("actix-session").is_some()); + } +}