Skip to content

Commit 7d060f5

Browse files
authored
Properly ignore devices, threepids and access tokens from AS users (#4122)
2 parents cccb39a + 1e99a6b commit 7d060f5

File tree

4 files changed

+104
-77
lines changed

4 files changed

+104
-77
lines changed

crates/syn2mas/src/mas_writer/mod.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use thiserror::Error;
1616
use thiserror_ext::{Construct, ContextInto};
1717
use tokio::sync::mpsc::{self, Receiver, Sender};
1818
use tracing::{Level, error, info, warn};
19-
use uuid::Uuid;
19+
use uuid::{NonNilUuid, Uuid};
2020

2121
use self::{
2222
constraint_pausing::{ConstraintDescription, IndexDescription},
@@ -197,7 +197,7 @@ pub struct MasWriter {
197197
}
198198

199199
pub struct MasNewUser {
200-
pub user_id: Uuid,
200+
pub user_id: NonNilUuid,
201201
pub username: String,
202202
pub created_at: DateTime<Utc>,
203203
pub locked_at: Option<DateTime<Utc>>,
@@ -210,36 +210,36 @@ pub struct MasNewUser {
210210

211211
pub struct MasNewUserPassword {
212212
pub user_password_id: Uuid,
213-
pub user_id: Uuid,
213+
pub user_id: NonNilUuid,
214214
pub hashed_password: String,
215215
pub created_at: DateTime<Utc>,
216216
}
217217

218218
pub struct MasNewEmailThreepid {
219219
pub user_email_id: Uuid,
220-
pub user_id: Uuid,
220+
pub user_id: NonNilUuid,
221221
pub email: String,
222222
pub created_at: DateTime<Utc>,
223223
}
224224

225225
pub struct MasNewUnsupportedThreepid {
226-
pub user_id: Uuid,
226+
pub user_id: NonNilUuid,
227227
pub medium: String,
228228
pub address: String,
229229
pub created_at: DateTime<Utc>,
230230
}
231231

232232
pub struct MasNewUpstreamOauthLink {
233233
pub link_id: Uuid,
234-
pub user_id: Uuid,
234+
pub user_id: NonNilUuid,
235235
pub upstream_provider_id: Uuid,
236236
pub subject: String,
237237
pub created_at: DateTime<Utc>,
238238
}
239239

240240
pub struct MasNewCompatSession {
241241
pub session_id: Uuid,
242-
pub user_id: Uuid,
242+
pub user_id: NonNilUuid,
243243
pub device_id: Option<String>,
244244
pub human_name: Option<String>,
245245
pub created_at: DateTime<Utc>,
@@ -598,7 +598,7 @@ impl MasWriter {
598598
is_guest,
599599
} in users
600600
{
601-
user_ids.push(user_id);
601+
user_ids.push(user_id.get());
602602
usernames.push(username);
603603
created_ats.push(created_at);
604604
locked_ats.push(locked_at);
@@ -662,7 +662,7 @@ impl MasWriter {
662662
} in passwords
663663
{
664664
user_password_ids.push(user_password_id);
665-
user_ids.push(user_id);
665+
user_ids.push(user_id.get());
666666
hashed_passwords.push(hashed_password);
667667
created_ats.push(created_at);
668668
versions.push(MIGRATED_PASSWORD_VERSION.into());
@@ -705,7 +705,7 @@ impl MasWriter {
705705
} in threepids
706706
{
707707
user_email_ids.push(user_email_id);
708-
user_ids.push(user_id);
708+
user_ids.push(user_id.get());
709709
emails.push(email);
710710
created_ats.push(created_at);
711711
}
@@ -748,7 +748,7 @@ impl MasWriter {
748748
created_at,
749749
} in threepids
750750
{
751-
user_ids.push(user_id);
751+
user_ids.push(user_id.get());
752752
mediums.push(medium);
753753
addresses.push(address);
754754
created_ats.push(created_at);
@@ -793,7 +793,7 @@ impl MasWriter {
793793
} in links
794794
{
795795
link_ids.push(link_id);
796-
user_ids.push(user_id);
796+
user_ids.push(user_id.get());
797797
upstream_provider_ids.push(upstream_provider_id);
798798
subjects.push(subject);
799799
created_ats.push(created_at);
@@ -850,7 +850,7 @@ impl MasWriter {
850850
} in sessions
851851
{
852852
session_ids.push(session_id);
853-
user_ids.push(user_id);
853+
user_ids.push(user_id.get());
854854
device_ids.push(device_id);
855855
human_names.push(human_name);
856856
created_ats.push(created_at);
@@ -1091,7 +1091,7 @@ mod test {
10911091
use futures_util::TryStreamExt;
10921092
use serde::Serialize;
10931093
use sqlx::{Column, PgConnection, PgPool, Row};
1094-
use uuid::Uuid;
1094+
use uuid::{NonNilUuid, Uuid};
10951095

10961096
use crate::{
10971097
LockedMasDatabase, MasWriter,
@@ -1213,7 +1213,7 @@ mod test {
12131213

12141214
writer
12151215
.write_users(vec![MasNewUser {
1216-
user_id: Uuid::from_u128(1u128),
1216+
user_id: NonNilUuid::new(Uuid::from_u128(1u128)).unwrap(),
12171217
username: "alice".to_owned(),
12181218
created_at: DateTime::default(),
12191219
locked_at: None,
@@ -1231,7 +1231,7 @@ mod test {
12311231
/// Tests writing a single user, with a password.
12321232
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]
12331233
async fn test_write_user_with_password(pool: PgPool) {
1234-
const USER_ID: Uuid = Uuid::from_u128(1u128);
1234+
const USER_ID: NonNilUuid = NonNilUuid::new(Uuid::from_u128(1u128)).unwrap();
12351235

12361236
let mut writer = make_mas_writer(&pool).await;
12371237

@@ -1268,7 +1268,7 @@ mod test {
12681268

12691269
writer
12701270
.write_users(vec![MasNewUser {
1271-
user_id: Uuid::from_u128(1u128),
1271+
user_id: NonNilUuid::new(Uuid::from_u128(1u128)).unwrap(),
12721272
username: "alice".to_owned(),
12731273
created_at: DateTime::default(),
12741274
locked_at: None,
@@ -1281,7 +1281,7 @@ mod test {
12811281
writer
12821282
.write_email_threepids(vec![MasNewEmailThreepid {
12831283
user_email_id: Uuid::from_u128(2u128),
1284-
user_id: Uuid::from_u128(1u128),
1284+
user_id: NonNilUuid::new(Uuid::from_u128(1u128)).unwrap(),
12851285
email: "[email protected]".to_owned(),
12861286
created_at: DateTime::default(),
12871287
}])
@@ -1301,7 +1301,7 @@ mod test {
13011301

13021302
writer
13031303
.write_users(vec![MasNewUser {
1304-
user_id: Uuid::from_u128(1u128),
1304+
user_id: NonNilUuid::new(Uuid::from_u128(1u128)).unwrap(),
13051305
username: "alice".to_owned(),
13061306
created_at: DateTime::default(),
13071307
locked_at: None,
@@ -1313,7 +1313,7 @@ mod test {
13131313

13141314
writer
13151315
.write_unsupported_threepids(vec![MasNewUnsupportedThreepid {
1316-
user_id: Uuid::from_u128(1u128),
1316+
user_id: NonNilUuid::new(Uuid::from_u128(1u128)).unwrap(),
13171317
medium: "msisdn".to_owned(),
13181318
address: "441189998819991197253".to_owned(),
13191319
created_at: DateTime::default(),
@@ -1335,7 +1335,7 @@ mod test {
13351335

13361336
writer
13371337
.write_users(vec![MasNewUser {
1338-
user_id: Uuid::from_u128(1u128),
1338+
user_id: NonNilUuid::new(Uuid::from_u128(1u128)).unwrap(),
13391339
username: "alice".to_owned(),
13401340
created_at: DateTime::default(),
13411341
locked_at: None,
@@ -1347,7 +1347,7 @@ mod test {
13471347

13481348
writer
13491349
.write_upstream_oauth_links(vec![MasNewUpstreamOauthLink {
1350-
user_id: Uuid::from_u128(1u128),
1350+
user_id: NonNilUuid::new(Uuid::from_u128(1u128)).unwrap(),
13511351
link_id: Uuid::from_u128(3u128),
13521352
upstream_provider_id: Uuid::from_u128(4u128),
13531353
subject: "12345.67890".to_owned(),
@@ -1368,7 +1368,7 @@ mod test {
13681368

13691369
writer
13701370
.write_users(vec![MasNewUser {
1371-
user_id: Uuid::from_u128(1u128),
1371+
user_id: NonNilUuid::new(Uuid::from_u128(1u128)).unwrap(),
13721372
username: "alice".to_owned(),
13731373
created_at: DateTime::default(),
13741374
locked_at: None,
@@ -1380,7 +1380,7 @@ mod test {
13801380

13811381
writer
13821382
.write_compat_sessions(vec![MasNewCompatSession {
1383-
user_id: Uuid::from_u128(1u128),
1383+
user_id: NonNilUuid::new(Uuid::from_u128(1u128)).unwrap(),
13841384
session_id: Uuid::from_u128(5u128),
13851385
created_at: DateTime::default(),
13861386
device_id: Some("ADEVICE".to_owned()),
@@ -1405,7 +1405,7 @@ mod test {
14051405

14061406
writer
14071407
.write_users(vec![MasNewUser {
1408-
user_id: Uuid::from_u128(1u128),
1408+
user_id: NonNilUuid::new(Uuid::from_u128(1u128)).unwrap(),
14091409
username: "alice".to_owned(),
14101410
created_at: DateTime::default(),
14111411
locked_at: None,
@@ -1417,7 +1417,7 @@ mod test {
14171417

14181418
writer
14191419
.write_compat_sessions(vec![MasNewCompatSession {
1420-
user_id: Uuid::from_u128(1u128),
1420+
user_id: NonNilUuid::new(Uuid::from_u128(1u128)).unwrap(),
14211421
session_id: Uuid::from_u128(5u128),
14221422
created_at: DateTime::default(),
14231423
device_id: Some("ADEVICE".to_owned()),
@@ -1454,7 +1454,7 @@ mod test {
14541454

14551455
writer
14561456
.write_users(vec![MasNewUser {
1457-
user_id: Uuid::from_u128(1u128),
1457+
user_id: NonNilUuid::new(Uuid::from_u128(1u128)).unwrap(),
14581458
username: "alice".to_owned(),
14591459
created_at: DateTime::default(),
14601460
locked_at: None,
@@ -1466,7 +1466,7 @@ mod test {
14661466

14671467
writer
14681468
.write_compat_sessions(vec![MasNewCompatSession {
1469-
user_id: Uuid::from_u128(1u128),
1469+
user_id: NonNilUuid::new(Uuid::from_u128(1u128)).unwrap(),
14701470
session_id: Uuid::from_u128(5u128),
14711471
created_at: DateTime::default(),
14721472
device_id: Some("ADEVICE".to_owned()),

0 commit comments

Comments
 (0)