@@ -1013,7 +1013,7 @@ mod tests {
1013
1013
use mas_data_model:: {
1014
1014
UpstreamOAuthAuthorizationSession , UpstreamOAuthLink , UpstreamOAuthProviderClaimsImports ,
1015
1015
UpstreamOAuthProviderImportPreference , UpstreamOAuthProviderLocalpartPreference ,
1016
- UpstreamOAuthProviderTokenAuthMethod , User ,
1016
+ UpstreamOAuthProviderTokenAuthMethod ,
1017
1017
} ;
1018
1018
use mas_iana:: jose:: JsonWebSignatureAlg ;
1019
1019
use mas_jose:: jwt:: { JsonWebSignatureHeader , Jwt } ;
@@ -1219,21 +1219,8 @@ mod tests {
1219
1219
1220
1220
#[ sqlx:: test( migrator = "mas_storage_pg::MIGRATOR" ) ]
1221
1221
async fn test_link_existing_account ( pool : PgPool ) {
1222
- #[ allow( clippy:: disallowed_methods) ]
1223
- let timestamp = chrono:: Utc :: now ( ) . timestamp_millis ( ) ;
1224
-
1225
- //suffix timestamp to generate unique test data
1226
- let existing_username = format ! ( "{}{}" , "john" , timestamp) ;
1227
- let existing_email = format ! ( "{}@{}" , existing_username, "example.com" ) ;
1228
-
1229
- //existing username matches oidc username
1230
- let oidc_username = existing_username. clone ( ) ;
1231
-
1232
- //oidc email is different from existing email
1233
- let oidc_email: String = format ! ( "{}{}@{}" , "any_email" , timestamp, "example.com" ) ;
1234
-
1235
- //generate unique subject
1236
- let subject = format ! ( "{}+{}" , "subject" , timestamp) ;
1222
+ let existing_username = "john" ;
1223
+ let subject = "subject" ;
1237
1224
1238
1225
setup ( ) ;
1239
1226
let state = TestState :: from_pool ( pool) . await . unwrap ( ) ;
@@ -1253,9 +1240,10 @@ mod tests {
1253
1240
..UpstreamOAuthProviderClaimsImports :: default ( )
1254
1241
} ;
1255
1242
1243
+ //`preferred_username` matches an existing user's username
1256
1244
let id_token_claims = serde_json:: json!( {
1257
- "preferred_username" : oidc_username ,
1258
- "email" : oidc_email ,
1245
+ "preferred_username" : existing_username ,
1246
+ "email" : "any@example.com" ,
1259
1247
"email_verified" : true ,
1260
1248
} ) ;
1261
1249
@@ -1304,7 +1292,7 @@ mod tests {
1304
1292
& state. clock ,
1305
1293
& mut repo,
1306
1294
& provider,
1307
- & subject,
1295
+ subject,
1308
1296
& id_token. into_string ( ) ,
1309
1297
id_token_claims,
1310
1298
)
@@ -1319,15 +1307,11 @@ mod tests {
1319
1307
let cookie_jar = upstream_sessions. save ( cookie_jar, & state. clock ) ;
1320
1308
cookies. import ( cookie_jar) ;
1321
1309
1322
- let user = create_user (
1323
- & mut rng,
1324
- & state. clock ,
1325
- & mut repo,
1326
- existing_username. clone ( ) ,
1327
- existing_email. clone ( ) ,
1328
- )
1329
- . await
1330
- . unwrap ( ) ;
1310
+ let user = repo
1311
+ . user ( )
1312
+ . add ( & mut rng, & state. clock , existing_username. to_owned ( ) )
1313
+ . await
1314
+ . unwrap ( ) ;
1331
1315
1332
1316
repo. save ( ) . await . unwrap ( ) ;
1333
1317
@@ -1364,7 +1348,7 @@ mod tests {
1364
1348
1365
1349
let link = repo
1366
1350
. upstream_oauth_link ( )
1367
- . find_by_subject ( & provider, & subject)
1351
+ . find_by_subject ( & provider, subject)
1368
1352
. await
1369
1353
. unwrap ( )
1370
1354
. expect ( "link exists" ) ;
@@ -1374,20 +1358,7 @@ mod tests {
1374
1358
1375
1359
#[ sqlx:: test( migrator = "mas_storage_pg::MIGRATOR" ) ]
1376
1360
async fn test_link_existing_account_when_not_allowed_by_default ( pool : PgPool ) {
1377
- #[ allow( clippy:: disallowed_methods) ]
1378
- let timestamp = chrono:: Utc :: now ( ) . timestamp_millis ( ) ;
1379
-
1380
- //suffix timestamp to generate unique test data
1381
- let existing_username = format ! ( "{}{}" , "john" , timestamp) ;
1382
- let existing_email = format ! ( "{}@{}" , existing_username, "example.com" ) ;
1383
-
1384
- //existing username matches oidc username
1385
- let oidc_username = existing_username. clone ( ) ;
1386
-
1387
- //oidc email is different from existing email
1388
- let oidc_email: String = format ! ( "{}{}@{}" , "any_email" , timestamp, "example.com" ) ;
1389
-
1390
- let subject = format ! ( "{}+{}" , "subject" , timestamp) ;
1361
+ let existing_username = "john" ;
1391
1362
1392
1363
setup ( ) ;
1393
1364
let state = TestState :: from_pool ( pool) . await . unwrap ( ) ;
@@ -1407,9 +1378,10 @@ mod tests {
1407
1378
..UpstreamOAuthProviderClaimsImports :: default ( )
1408
1379
} ;
1409
1380
1381
+ // `preferred_username` matches an existing user's username
1410
1382
let id_token_claims = serde_json:: json!( {
1411
- "preferred_username" : oidc_username ,
1412
- "email" : oidc_email ,
1383
+ "preferred_username" : existing_username ,
1384
+ "email" : "any@example.com" ,
1413
1385
"email_verified" : true ,
1414
1386
} ) ;
1415
1387
@@ -1457,22 +1429,18 @@ mod tests {
1457
1429
& state. clock ,
1458
1430
& mut repo,
1459
1431
& provider,
1460
- & subject,
1432
+ " subject" ,
1461
1433
& id_token. into_string ( ) ,
1462
1434
id_token_claims,
1463
1435
)
1464
1436
. await
1465
1437
. unwrap ( ) ;
1466
1438
1467
- let _user = create_user (
1468
- & mut rng,
1469
- & state. clock ,
1470
- & mut repo,
1471
- existing_username. clone ( ) ,
1472
- existing_email. clone ( ) ,
1473
- )
1474
- . await
1475
- . unwrap ( ) ;
1439
+ // Provision an user
1440
+ repo. user ( )
1441
+ . add ( & mut rng, & state. clock , existing_username. to_owned ( ) )
1442
+ . await
1443
+ . unwrap ( ) ;
1476
1444
1477
1445
repo. save ( ) . await . unwrap ( ) ;
1478
1446
@@ -1513,21 +1481,6 @@ mod tests {
1513
1481
Jwt :: sign_with_rng ( rng, header, payload, & signer)
1514
1482
}
1515
1483
1516
- async fn create_user (
1517
- rng : & mut ChaChaRng ,
1518
- clock : & impl mas_storage:: Clock ,
1519
- repo : & mut Box < dyn Repository < RepositoryError > + Send + Sync + ' static > ,
1520
- username : String ,
1521
- email : String ,
1522
- ) -> Result < User , anyhow:: Error > {
1523
- //create a user with an email
1524
- let user = repo. user ( ) . add ( rng, clock, username) . await . unwrap ( ) ;
1525
-
1526
- let _user_email = repo. user_email ( ) . add ( rng, clock, & user, email) . await ;
1527
-
1528
- Ok ( user)
1529
- }
1530
-
1531
1484
async fn add_linked_upstream_session (
1532
1485
rng : & mut ChaChaRng ,
1533
1486
clock : & impl mas_storage:: Clock ,
0 commit comments