summaryrefslogtreecommitdiff
path: root/src/test/fixtures/cookie.rs
blob: 0b5ec9b69e90ab67c9a99228d34e899730bed8fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use axum::extract::FromRef;
use uuid::Uuid;

use crate::{
    clock::RequestedAt, login::app::Logins, name::Name, password::Password,
    token::extract::IdentityCookie,
};

pub fn not_logged_in() -> IdentityCookie {
    IdentityCookie::new()
}

pub async fn logged_in<App>(
    app: &App,
    credentials: &(Name, Password),
    now: &RequestedAt,
) -> IdentityCookie
where
    Logins: FromRef<App>,
{
    let (name, password) = credentials;
    let secret = Logins::from_ref(app)
        .with_password(name, password, now)
        .await
        .expect("should succeed given known-valid credentials");

    IdentityCookie::new().set(secret)
}

pub fn fictitious() -> IdentityCookie {
    let token = Uuid::new_v4().to_string();
    IdentityCookie::new().set(token)
}