summaryrefslogtreecommitdiff
path: root/src/test/verify/identity.rs
blob: 226ee7473a8fa6ca7e79599f64c7213e83577699 (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,
    name::Name,
    test::{fixtures, verify},
    token::{app::ValidateError, extract::IdentityCookie},
    user::User,
};

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_user(app: &App, identity: &IdentityCookie, user: &User) {
    let secret = identity
        .secret()
        .expect("identity cookie must be set to be valid");
    verify::token::valid_for_user(app, &secret, user).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));
}