MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / validate_active_user_or_key

Function validate_active_user_or_key

chirpstack/src/api/auth/validator.rs:3020–3071  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3018
3019 #[tokio::test]
3020 async fn validate_active_user_or_key() {
3021 let _guard = test::prepare().await;
3022
3023 let users = vec![
3024 user::User {
3025 email: "active@user".into(),
3026 is_active: true,
3027 is_admin: false,
3028 ..Default::default()
3029 },
3030 user::User {
3031 email: "inactive@user".into(),
3032 is_active: false,
3033 is_admin: false,
3034 ..Default::default()
3035 },
3036 ];
3037 for u in &users {
3038 user::create(u.clone()).await.unwrap();
3039 }
3040
3041 let api_key = api_key::test::create_api_key(false, true).await;
3042
3043 let tests = vec![
3044 // active user
3045 ValidatorTest {
3046 validators: vec![ValidateActiveUserOrKey::new()],
3047 id: AuthID::User(users[0].id.into()),
3048 ok: true,
3049 },
3050 // inactive user
3051 ValidatorTest {
3052 validators: vec![ValidateActiveUserOrKey::new()],
3053 id: AuthID::User(users[1].id.into()),
3054 ok: false,
3055 },
3056 // api key
3057 ValidatorTest {
3058 validators: vec![ValidateActiveUserOrKey::new()],
3059 id: AuthID::Key(api_key.id.into()),
3060 ok: true,
3061 },
3062 // non-existing key
3063 ValidatorTest {
3064 validators: vec![ValidateActiveUserOrKey::new()],
3065 id: AuthID::Key(Uuid::new_v4()),
3066 ok: false,
3067 },
3068 ];
3069
3070 run_tests(tests).await;
3071 }
3072
3073 #[tokio::test]
3074 async fn validate_tenant() {

Callers

nothing calls this directly

Calls 5

prepareFunction · 0.85
create_api_keyFunction · 0.85
run_testsFunction · 0.85
unwrapMethod · 0.80
createFunction · 0.50

Tested by

no test coverage detected