1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

Fix the session list paginated query

It was broken, and not covered by tests. Both are fixed now.
This commit is contained in:
Quentin Gliech
2023-03-15 15:06:52 +01:00
parent a58fe9774f
commit f2d5f26e86
2 changed files with 24 additions and 3 deletions

View File

@ -232,11 +232,13 @@ impl<'c> BrowserSessionRepository for PgBrowserSessionRepository<'c> {
r#" r#"
SELECT DISTINCT ON (s.user_session_id) SELECT DISTINCT ON (s.user_session_id)
s.user_session_id, s.user_session_id,
s.created_at AS "user_session_created_at",
s.finished_at AS "user_session_finished_at",
u.user_id, u.user_id,
u.username, u.username AS "user_username",
s.created_at, u.primary_user_email_id AS "user_primary_user_email_id",
a.user_session_authentication_id AS "last_authentication_id", a.user_session_authentication_id AS "last_authentication_id",
a.created_at AS "last_authd_at", a.created_at AS "last_authd_at"
FROM user_sessions s FROM user_sessions s
INNER JOIN users u INNER JOIN users u
USING (user_id) USING (user_id)

View File

@ -372,6 +372,16 @@ async fn test_user_session(pool: PgPool) {
assert_eq!(repo.browser_session().count_active(&user).await.unwrap(), 1); assert_eq!(repo.browser_session().count_active(&user).await.unwrap(), 1);
// The session should be in the list of active sessions
let session_list = repo
.browser_session()
.list_active_paginated(&user, Pagination::first(10))
.await
.unwrap();
assert!(!session_list.has_next_page);
assert_eq!(session_list.edges.len(), 1);
assert_eq!(session_list.edges[0], session);
let session_lookup = repo let session_lookup = repo
.browser_session() .browser_session()
.lookup(session.id) .lookup(session.id)
@ -392,6 +402,15 @@ async fn test_user_session(pool: PgPool) {
// The active session counter is back to 0 // The active session counter is back to 0
assert_eq!(repo.browser_session().count_active(&user).await.unwrap(), 0); assert_eq!(repo.browser_session().count_active(&user).await.unwrap(), 0);
// The session should not be in the list of active sessions anymore
let session_list = repo
.browser_session()
.list_active_paginated(&user, Pagination::first(10))
.await
.unwrap();
assert!(!session_list.has_next_page);
assert!(session_list.edges.is_empty());
// Reload the session // Reload the session
let session_lookup = repo let session_lookup = repo
.browser_session() .browser_session()