Skip to content

Commit

Permalink
Split large service tests into smaller ones
Browse files Browse the repository at this point in the history
  • Loading branch information
0rzech committed Aug 26, 2024
1 parent badf0be commit 5bfeaaf
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ mod tests {
}

#[tokio::test]
async fn same_site_test() -> anyhow::Result<()> {
async fn same_site_strict_test() -> anyhow::Result<()> {
let session_store = MemoryStore::default();
let session_layer =
SessionManagerLayer::new(session_store).with_same_site(SameSite::Strict);
Expand All @@ -687,6 +687,11 @@ mod tests {

assert!(cookie_value_matches(&res, |s| s.contains("SameSite=Strict")));

Ok(())
}

#[tokio::test]
async fn same_site_lax_test() -> anyhow::Result<()> {
let session_store = MemoryStore::default();
let session_layer = SessionManagerLayer::new(session_store).with_same_site(SameSite::Lax);
let svc = ServiceBuilder::new()
Expand All @@ -698,6 +703,11 @@ mod tests {

assert!(cookie_value_matches(&res, |s| s.contains("SameSite=Lax")));

Ok(())
}

#[tokio::test]
async fn same_site_none_test() -> anyhow::Result<()> {
let session_store = MemoryStore::default();
let session_layer = SessionManagerLayer::new(session_store).with_same_site(SameSite::None);
let svc = ServiceBuilder::new()
Expand All @@ -713,7 +723,7 @@ mod tests {
}

#[tokio::test]
async fn expiry_test() -> anyhow::Result<()> {
async fn expiry_on_session_end_test() -> anyhow::Result<()> {
let session_store = MemoryStore::default();
let session_layer =
SessionManagerLayer::new(session_store).with_expiry(Expiry::OnSessionEnd);
Expand All @@ -726,6 +736,11 @@ mod tests {

assert!(cookie_value_matches(&res, |s| !s.contains("Max-Age")));

Ok(())
}

#[tokio::test]
async fn expiry_on_inactivity_test() -> anyhow::Result<()> {
let session_store = MemoryStore::default();
let inactivity_duration = time::Duration::hours(2);
let session_layer = SessionManagerLayer::new(session_store)
Expand All @@ -740,6 +755,11 @@ mod tests {
let expected_max_age = inactivity_duration.whole_seconds();
assert!(cookie_has_expected_max_age(&res, expected_max_age));

Ok(())
}

#[tokio::test]
async fn expiry_at_date_time_test() -> anyhow::Result<()> {
let session_store = MemoryStore::default();
let expiry_time = time::OffsetDateTime::now_utc() + time::Duration::weeks(1);
let session_layer =
Expand All @@ -758,9 +778,7 @@ mod tests {
}

#[tokio::test]
async fn always_save_test() -> anyhow::Result<()> {
// on-session-end expiry

async fn expiry_on_session_end_always_save_test() -> anyhow::Result<()> {
let session_store = MemoryStore::default();
let session_layer = SessionManagerLayer::new(session_store.clone())
.with_expiry(Expiry::OnSessionEnd)
Expand All @@ -784,8 +802,11 @@ mod tests {
assert!(sid1 == sid2);
assert!(rec1.expiry_date < rec2.expiry_date);

// on-inactivity expiry
Ok(())
}

#[tokio::test]
async fn expiry_on_inactivity_always_save_test() -> anyhow::Result<()> {
let session_store = MemoryStore::default();
let inactivity_duration = time::Duration::hours(2);
let session_layer = SessionManagerLayer::new(session_store.clone())
Expand All @@ -811,8 +832,11 @@ mod tests {
assert!(sid1 == sid2);
assert!(rec1.expiry_date < rec2.expiry_date);

// at-date-time expiry
Ok(())
}

#[tokio::test]
async fn expiry_at_date_time_always_save_test() -> anyhow::Result<()> {
let session_store = MemoryStore::default();
let expiry_time = time::OffsetDateTime::now_utc() + time::Duration::weeks(1);
let session_layer = SessionManagerLayer::new(session_store.clone())
Expand Down

0 comments on commit 5bfeaaf

Please sign in to comment.