summaryrefslogtreecommitdiff
path: root/src/test/fixtures/identity.rs
blob: 69b5f4ca62b219daef43c94605ea118e0779f0c9 (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
use uuid::Uuid;

use crate::{
    app::App,
    clock::RequestedAt,
    login::extract::{IdentitySecret, IdentityToken},
    password::Password,
};

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

pub async fn logged_in(app: &App, login: &(String, Password), now: &RequestedAt) -> IdentityToken {
    let (name, password) = login;
    let token = app
        .logins()
        .login(name, password, now)
        .await
        .expect("should succeed given known-valid credentials");

    IdentityToken::new().set(token)
}

pub fn secret(identity: &IdentityToken) -> IdentitySecret {
    identity.secret().expect("identity contained a secret")
}

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