Skip to content

Commit 878e7b5

Browse files
authored
Fix session discard future not being Send (#581)
1 parent 7251955 commit 878e7b5

File tree

1 file changed

+37
-3
lines changed
  • gotham/src/middleware/session

1 file changed

+37
-3
lines changed

gotham/src/middleware/session/mod.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,10 @@ where
284284
{
285285
/// Discards the session, invalidating it for future use and removing the data from the
286286
/// `Backend`.
287-
// TODO: Add test case that covers this.
288287
pub fn discard(
289288
self,
290289
state: &mut State,
291-
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>>>> {
290+
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send>> {
292291
state.put(SessionDropData {
293292
cookie_config: self.cookie_config,
294293
});
@@ -1207,11 +1206,46 @@ mod tests {
12071206

12081207
let state = State::new();
12091208
let m = nm.new_middleware().unwrap();
1210-
let bytes = futures_executor::block_on(m.backend.read_session(&state, identifier))
1209+
let bytes = futures_executor::block_on(m.backend.read_session(&state, identifier.clone()))
12111210
.unwrap()
12121211
.unwrap();
12131212
let updated = bincode::deserialize::<TestSession>(&bytes[..]).unwrap();
12141213

12151214
assert_eq!(updated.val, session.val + 1);
1215+
1216+
let handler = move |mut state: State| {
1217+
async move {
1218+
{
1219+
let session_data = state.take::<SessionData<TestSession>>();
1220+
session_data.discard(&mut state).await.unwrap();
1221+
}
1222+
1223+
Ok((
1224+
state,
1225+
Response::builder()
1226+
.status(StatusCode::NO_CONTENT)
1227+
.body(Body::empty())
1228+
.unwrap(),
1229+
))
1230+
}
1231+
.boxed()
1232+
};
1233+
1234+
let mut state = State::new();
1235+
let mut headers = HeaderMap::new();
1236+
let cookie = Cookie::build("_gotham_session", identifier.value.clone()).finish();
1237+
headers.insert(COOKIE, cookie.to_string().parse().unwrap());
1238+
state.put(headers);
1239+
1240+
let m = nm.new_middleware().unwrap();
1241+
let r = m.call(state, handler);
1242+
if let Err((_, e)) = futures_executor::block_on(r) {
1243+
panic!("error: {:?}", e);
1244+
}
1245+
1246+
let state = State::new();
1247+
let m = nm.new_middleware().unwrap();
1248+
let data = futures_executor::block_on(m.backend.read_session(&state, identifier)).unwrap();
1249+
assert_eq!(data, None);
12161250
}
12171251
}

0 commit comments

Comments
 (0)