From d68988b2d4aded0c7c8698aa493ea59ae36ed491 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Fri, 24 Jun 2022 08:22:17 -0400 Subject: [PATCH] Set default session cookie name. --- src/main.rs | 8 ++++---- tests/features/session.feature | 2 +- tests/step_defs/test_session.py | 10 ++++++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index b59ea4a..b3eaf6e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,10 +20,10 @@ async fn main() -> tide::Result<()> { async fn app_setup() -> tide::Server<()> { let mut app = tide::new(); app.at("/").get(home); - app.with(SessionMiddleware::new( - MemoryStore::new(), - b"361f953f-56ba-45e6-86ab-9efbf61b745d", - )); + app.with( + SessionMiddleware::new(MemoryStore::new(), b"361f953f-56ba-45e6-86ab-9efbf61b745d") + .with_cookie_name("morethantext.sid"), + ); return app; } diff --git a/tests/features/session.feature b/tests/features/session.feature index cb51f09..8fed299 100644 --- a/tests/features/session.feature +++ b/tests/features/session.feature @@ -5,4 +5,4 @@ Feature: Session Scenario: Session ID is set Given a running server When the home page is accessed - Then there is a session id + Then there is a default session id diff --git a/tests/step_defs/test_session.py b/tests/step_defs/test_session.py index a53caf8..f6d07b2 100644 --- a/tests/step_defs/test_session.py +++ b/tests/step_defs/test_session.py @@ -19,7 +19,13 @@ def access_home_page(server, page): page.request_url(url) -@then("there is a session id") +@then("there is a default session id") def confirm_session(page): """Confirm session id exists.""" - assert len(page.get_cookies()), "No cookies received." + cookies = page.get_cookies() + name = "morethantext.sid" + cookie = None + for holder in cookies: + if holder.name == name: + cookie = holder + assert cookie, f"Did not find cookie {name}, but retrieved {cookies}"