Skip to content

Commit 438c9be

Browse files
committed
use token list endpoint in integration test
1 parent 5bbfa20 commit 438c9be

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

nexus/tests/integration_tests/device_auth.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -650,20 +650,15 @@ async fn test_admin_logout_deletes_tokens(cptestctx: &ControlPlaneTestContext) {
650650
)
651651
.await;
652652

653-
// TODO: we are using the fetch my tokens endpoint, authed as user1, to
654-
// check the tokens, but we will likely have a list tokens for user endpoint
655-
// (accessible to silo admins only) so they can feel good about there being
656-
// no tokens or sessions for a given user
657-
658653
// no tokens for user 1 yet
659-
let tokens = get_tokens_as(testctx, AuthnMode::SiloUser(user1.id)).await;
654+
let tokens = get_user_tokens(testctx, user1.id).await;
660655
assert!(tokens.is_empty());
661656

662657
// create a token for user1
663658
get_device_token(testctx, AuthnMode::SiloUser(user1.id)).await;
664659

665660
// now there is a token for user1
666-
let tokens = get_tokens_as(testctx, AuthnMode::SiloUser(user1.id)).await;
661+
let tokens = get_user_tokens(testctx, user1.id).await;
667662
assert_eq!(tokens.len(), 1);
668663

669664
let logout_url = format!("/v1/users/{}/logout", user1.id);
@@ -679,7 +674,7 @@ async fn test_admin_logout_deletes_tokens(cptestctx: &ControlPlaneTestContext) {
679674
.await
680675
.expect("User has no perms, can't delete another user's tokens");
681676

682-
let tokens = get_tokens_as(testctx, AuthnMode::SiloUser(user1.id)).await;
677+
let tokens = get_user_tokens(testctx, user1.id).await;
683678
assert_eq!(tokens.len(), 1);
684679

685680
// user 1 can hit the logout endpoint for themselves
@@ -693,14 +688,14 @@ async fn test_admin_logout_deletes_tokens(cptestctx: &ControlPlaneTestContext) {
693688
.await
694689
.expect("User 1 should be able to delete their own tokens");
695690

696-
let tokens = get_tokens_as(testctx, AuthnMode::SiloUser(user1.id)).await;
691+
let tokens = get_user_tokens(testctx, user1.id).await;
697692
assert!(tokens.is_empty());
698693

699694
// create another couple of tokens for user1
700695
get_device_token(testctx, AuthnMode::SiloUser(user1.id)).await;
701696
get_device_token(testctx, AuthnMode::SiloUser(user1.id)).await;
702697

703-
let tokens = get_tokens_as(testctx, AuthnMode::SiloUser(user1.id)).await;
698+
let tokens = get_user_tokens(testctx, user1.id).await;
704699
assert_eq!(tokens.len(), 2);
705700

706701
// make user 2 fleet admin to show that fleet admin does not inherit
@@ -724,7 +719,7 @@ async fn test_admin_logout_deletes_tokens(cptestctx: &ControlPlaneTestContext) {
724719
.await
725720
.expect("Fleet admin is not sufficient to delete another user's tokens");
726721

727-
let tokens = get_tokens_as(testctx, AuthnMode::SiloUser(user1.id)).await;
722+
let tokens = get_user_tokens(testctx, user1.id).await;
728723
assert_eq!(tokens.len(), 2);
729724

730725
// make user 2 a silo admin so they can delete user 1's tokens
@@ -748,22 +743,26 @@ async fn test_admin_logout_deletes_tokens(cptestctx: &ControlPlaneTestContext) {
748743
.expect("Silo admin should be able to delete user 1's tokens");
749744

750745
// they're gone!
751-
let tokens = get_tokens_as(testctx, AuthnMode::SiloUser(user1.id)).await;
746+
let tokens = get_user_tokens(testctx, user1.id).await;
752747
assert!(tokens.is_empty());
753748
}
754749

755750
async fn get_tokens_priv(
756751
testctx: &ClientTestContext,
757752
) -> Vec<views::DeviceAccessToken> {
758-
get_tokens_as(testctx, AuthnMode::PrivilegedUser).await
753+
NexusRequest::object_get(testctx, "/v1/me/access-tokens")
754+
.authn_as(AuthnMode::PrivilegedUser)
755+
.execute_and_parse_unwrap::<ResultsPage<views::DeviceAccessToken>>()
756+
.await
757+
.items
759758
}
760759

761-
async fn get_tokens_as(
760+
async fn get_user_tokens(
762761
testctx: &ClientTestContext,
763-
authn_mode: AuthnMode,
762+
user_id: Uuid,
764763
) -> Vec<views::DeviceAccessToken> {
765764
NexusRequest::object_get(testctx, "/v1/me/access-tokens")
766-
.authn_as(authn_mode)
765+
.authn_as(AuthnMode::SiloUser(user_id))
767766
.execute_and_parse_unwrap::<ResultsPage<views::DeviceAccessToken>>()
768767
.await
769768
.items

0 commit comments

Comments
 (0)