-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
syn2mas: Add tests for reading and writing threepids (#3907)
* Add `MasWriter` test for e-mail and unsupported threepids * Add `SynapseReader` test for e-mail and unsupported threepids
- Loading branch information
1 parent
69bbcfc
commit c016199
Showing
7 changed files
with
186 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -854,7 +854,9 @@ mod test { | |
use uuid::Uuid; | ||
|
||
use crate::{ | ||
mas_writer::{MasNewUser, MasNewUserPassword}, | ||
mas_writer::{ | ||
MasNewEmailThreepid, MasNewUnsupportedThreepid, MasNewUser, MasNewUserPassword, | ||
}, | ||
LockedMasDatabase, MasWriter, | ||
}; | ||
|
||
|
@@ -1018,4 +1020,69 @@ mod test { | |
|
||
assert_db_snapshot!(&mut conn); | ||
} | ||
|
||
/// Tests writing a single user, with an e-mail address associated. | ||
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")] | ||
async fn test_write_user_with_email(pool: PgPool) { | ||
let mut conn = pool.acquire().await.unwrap(); | ||
let mut writer = make_mas_writer(&pool, &mut conn).await; | ||
|
||
writer | ||
.write_users(vec![MasNewUser { | ||
user_id: Uuid::from_u128(1u128), | ||
username: "alice".to_owned(), | ||
created_at: DateTime::default(), | ||
locked_at: None, | ||
can_request_admin: false, | ||
}]) | ||
.await | ||
.expect("failed to write user"); | ||
|
||
writer | ||
.write_email_threepids(vec![MasNewEmailThreepid { | ||
user_email_id: Uuid::from_u128(2u128), | ||
user_id: Uuid::from_u128(1u128), | ||
email: "[email protected]".to_owned(), | ||
created_at: DateTime::default(), | ||
}]) | ||
.await | ||
.expect("failed to write e-mail"); | ||
|
||
writer.finish().await.expect("failed to finish MasWriter"); | ||
|
||
assert_db_snapshot!(&mut conn); | ||
} | ||
|
||
/// Tests writing a single user, with a unsupported third-party ID | ||
/// associated. | ||
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")] | ||
async fn test_write_user_with_unsupported_threepid(pool: PgPool) { | ||
let mut conn = pool.acquire().await.unwrap(); | ||
let mut writer = make_mas_writer(&pool, &mut conn).await; | ||
|
||
writer | ||
.write_users(vec![MasNewUser { | ||
user_id: Uuid::from_u128(1u128), | ||
username: "alice".to_owned(), | ||
created_at: DateTime::default(), | ||
locked_at: None, | ||
can_request_admin: false, | ||
}]) | ||
.await | ||
.expect("failed to write user"); | ||
|
||
writer | ||
.write_unsupported_threepids(vec![MasNewUnsupportedThreepid { | ||
user_id: Uuid::from_u128(1u128), | ||
medium: "msisdn".to_owned(), | ||
address: "441189998819991197253".to_owned(), | ||
created_at: DateTime::default(), | ||
}]) | ||
.await | ||
.expect("failed to write phone number (unsupported threepid)"); | ||
|
||
writer.finish().await.expect("failed to finish MasWriter"); | ||
|
||
assert_db_snapshot!(&mut conn); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...es/syn2mas/src/mas_writer/snapshots/syn2mas__mas_writer__test__write_user_with_email.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
source: crates/syn2mas/src/mas_writer/mod.rs | ||
expression: db_snapshot | ||
--- | ||
user_emails: | ||
- confirmed_at: "1970-01-01 00:00:00+00" | ||
created_at: "1970-01-01 00:00:00+00" | ||
email: alice@example.org | ||
user_email_id: 00000000-0000-0000-0000-000000000002 | ||
user_id: 00000000-0000-0000-0000-000000000001 | ||
users: | ||
- can_request_admin: "false" | ||
created_at: "1970-01-01 00:00:00+00" | ||
locked_at: ~ | ||
primary_user_email_id: ~ | ||
user_id: 00000000-0000-0000-0000-000000000001 | ||
username: alice |
16 changes: 16 additions & 0 deletions
16
...mas_writer/snapshots/syn2mas__mas_writer__test__write_user_with_unsupported_threepid.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
source: crates/syn2mas/src/mas_writer/mod.rs | ||
expression: db_snapshot | ||
--- | ||
user_unsupported_third_party_ids: | ||
- address: "441189998819991197253" | ||
created_at: "1970-01-01 00:00:00+00" | ||
medium: msisdn | ||
user_id: 00000000-0000-0000-0000-000000000001 | ||
users: | ||
- can_request_admin: "false" | ||
created_at: "1970-01-01 00:00:00+00" | ||
locked_at: ~ | ||
primary_user_email_id: ~ | ||
user_id: 00000000-0000-0000-0000-000000000001 | ||
username: alice |
23 changes: 23 additions & 0 deletions
23
crates/syn2mas/src/synapse_reader/fixtures/threepids_alice.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
INSERT INTO user_threepids | ||
( | ||
user_id, | ||
medium, | ||
address, | ||
validated_at, | ||
added_at | ||
) | ||
VALUES | ||
( | ||
'@alice:example.com', | ||
'email', | ||
'[email protected]', | ||
1554228492026, | ||
1554228549014 | ||
), | ||
( | ||
'@alice:example.com', | ||
'msisdn', | ||
'441189998819991197253', | ||
1555228492026, | ||
1555228549014 | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...s/syn2mas/src/synapse_reader/snapshots/syn2mas__synapse_reader__test__read_threepids.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
source: crates/syn2mas/src/synapse_reader/mod.rs | ||
expression: threepids | ||
--- | ||
{ | ||
SynapseThreepid { | ||
user_id: FullUserId( | ||
"@alice:example.com", | ||
), | ||
medium: "email", | ||
address: "[email protected]", | ||
added_at: MillisecondsTimestamp( | ||
2019-04-02T18:09:09.014Z, | ||
), | ||
}, | ||
SynapseThreepid { | ||
user_id: FullUserId( | ||
"@alice:example.com", | ||
), | ||
medium: "msisdn", | ||
address: "441189998819991197253", | ||
added_at: MillisecondsTimestamp( | ||
2019-04-14T07:55:49.014Z, | ||
), | ||
}, | ||
} |
14 changes: 14 additions & 0 deletions
14
crates/syn2mas/test_synapse_migrations/20250128141011_threepids.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- Copyright 2025 New Vector Ltd. | ||
-- | ||
-- SPDX-License-Identifier: AGPL-3.0-only | ||
-- Please see LICENSE in the repository root for full details. | ||
|
||
-- Brings in the `user_threepids` table from Synapse | ||
|
||
CREATE TABLE user_threepids ( | ||
user_id text NOT NULL, | ||
medium text NOT NULL, | ||
address text NOT NULL, | ||
validated_at bigint NOT NULL, | ||
added_at bigint NOT NULL | ||
); |