Skip to content

Commit 20671a9

Browse files
committed
fixup! Add SynapseReader support for access tokens and refresh tokens
1 parent d0e9ea2 commit 20671a9

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
INSERT INTO access_tokens
2+
(
3+
id,
4+
user_id,
5+
device_id,
6+
token,
7+
refresh_token_id,
8+
used
9+
)
10+
VALUES
11+
(
12+
42,
13+
'@alice:example.com',
14+
'ADEVICE',
15+
'syt_aaaaaaaaaaaaaa_aaaa',
16+
7,
17+
TRUE
18+
),
19+
(
20+
43,
21+
'@alice:example.com',
22+
'ADEVICE',
23+
'syt_AAAAAAAAAAAAAA_AAAA',
24+
8,
25+
FALSE
26+
);
27+
28+
INSERT INTO refresh_tokens
29+
(
30+
id,
31+
user_id,
32+
device_id,
33+
token,
34+
next_token_id,
35+
expiry_ts,
36+
ultimate_session_expiry_ts
37+
)
38+
VALUES
39+
(
40+
7,
41+
'@alice:example.com',
42+
'ADEVICE',
43+
'syr_bbbbbbbbbbbbb_bbbb',
44+
8,
45+
1738096199000,
46+
1778096199000
47+
),
48+
(
49+
8,
50+
'@alice:example.com',
51+
'ADEVICE',
52+
'syr_cccccccccccc_cccc',
53+
NULL,
54+
1748096199000,
55+
1778096199000
56+
);

crates/syn2mas/src/synapse_reader/mod.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,4 +608,33 @@ mod test {
608608
);
609609
assert_debug_snapshot!(refresh_tokens);
610610
}
611+
612+
#[sqlx::test(
613+
migrator = "MIGRATOR",
614+
fixtures("user_alice", "access_token_alice_with_unused_refresh_token")
615+
)]
616+
async fn test_read_access_and_unused_refresh_tokens(pool: PgPool) {
617+
let mut conn = pool.acquire().await.expect("failed to get connection");
618+
let mut reader = SynapseReader::new(&mut conn, false)
619+
.await
620+
.expect("failed to make SynapseReader");
621+
622+
let access_tokens: BTreeSet<SynapseAccessToken> = reader
623+
.read_unrefreshable_access_tokens()
624+
.try_collect()
625+
.await
626+
.expect("failed to read Synapse access tokens");
627+
628+
let refresh_tokens: BTreeSet<SynapseRefreshableTokenPair> = reader
629+
.read_refreshable_token_pairs()
630+
.try_collect()
631+
.await
632+
.expect("failed to read Synapse refresh tokens");
633+
634+
assert!(
635+
access_tokens.is_empty(),
636+
"there are no unrefreshable access tokens"
637+
);
638+
assert_debug_snapshot!(refresh_tokens);
639+
}
611640
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
source: crates/syn2mas/src/synapse_reader/mod.rs
3+
expression: refresh_tokens
4+
---
5+
{
6+
SynapseRefreshableTokenPair {
7+
user_id: FullUserId(
8+
"@alice:example.com",
9+
),
10+
device_id: "ADEVICE",
11+
access_token: "syt_AAAAAAAAAAAAAA_AAAA",
12+
refresh_token: "syr_cccccccccccc_cccc",
13+
valid_until_ms: None,
14+
last_validated: None,
15+
},
16+
SynapseRefreshableTokenPair {
17+
user_id: FullUserId(
18+
"@alice:example.com",
19+
),
20+
device_id: "ADEVICE",
21+
access_token: "syt_aaaaaaaaaaaaaa_aaaa",
22+
refresh_token: "syr_bbbbbbbbbbbbb_bbbb",
23+
valid_until_ms: None,
24+
last_validated: None,
25+
},
26+
}

0 commit comments

Comments
 (0)