summaryrefslogtreecommitdiff
path: root/src/test/verify/identity.rs
blob: 8e2d36eb3a22e62c0604b66921e14ba4b27e1673 (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 crate::{
    app::App,
    login::Login,
    name::Name,
    test::{fixtures, verify},
    token::{app::ValidateError, extract::IdentityCookie},
};

pub async fn valid_for_name(app: &App, identity: &IdentityCookie, name: &Name) {
    let secret = identity
        .secret()
        .expect("identity cookie must be set to be valid");
    verify::token::valid_for_name(app, &secret, name).await;
}

pub async fn valid_for_login(app: &App, identity: &IdentityCookie, login: &Login) {
    let secret = identity
        .secret()
        .expect("identity cookie must be set to be valid");
    verify::token::valid_for_login(app, &secret, login).await;
}

pub async fn invalid(app: &App, identity: &IdentityCookie) {
    let secret = identity
        .secret()
        .expect("identity cookie must be set to be invalid");
    let validate_err = app
        .tokens()
        .validate(&secret, &fixtures::now())
        .await
        .expect_err("identity cookie secret must be invalid");
    assert!(matches!(validate_err, ValidateError::InvalidToken));
}