@@ -1113,9 +1113,21 @@ mod tests {
1113
1113
1114
1114
#[ sqlx:: test( migrator = "mas_storage_pg::MIGRATOR" ) ]
1115
1115
async fn test_link_existing_account ( pool : PgPool ) {
1116
- let existing_username = "john" ;
1117
- let existing_email =
"[email protected] " ;
1118
- let oidc_email =
"[email protected] " ;
1116
+ #[ allow( clippy:: disallowed_methods) ]
1117
+ let timestamp = chrono:: Utc :: now ( ) . timestamp_millis ( ) ;
1118
+
1119
+ //suffix timestamp to generate unique test data
1120
+ let existing_username = format ! ( "{}{}" , "john" , timestamp) ;
1121
+ let existing_email = format ! ( "{}@{}" , existing_username, "example.com" ) ;
1122
+
1123
+ //existing username matches oidc username
1124
+ let oidc_username = existing_username. clone ( ) ;
1125
+
1126
+ //oidc email is different from existing email
1127
+ let oidc_email: String = format ! ( "{}{}@{}" , "any_email" , timestamp, "example.com" ) ;
1128
+
1129
+ //generate unique subject
1130
+ let subject = format ! ( "{}+{}" , "subject" , timestamp) ;
1119
1131
1120
1132
setup ( ) ;
1121
1133
let state = TestState :: from_pool ( pool) . await . unwrap ( ) ;
@@ -1135,8 +1147,8 @@ mod tests {
1135
1147
} ;
1136
1148
1137
1149
let id_token = serde_json:: json!( {
1138
- "preferred_username" : existing_username . to_owned ( ) ,
1139
- "email" : oidc_email. to_owned ( ) ,
1150
+ "preferred_username" : oidc_username ,
1151
+ "email" : oidc_email,
1140
1152
"email_verified" : true ,
1141
1153
} ) ;
1142
1154
@@ -1209,7 +1221,7 @@ mod tests {
1209
1221
& mut rng,
1210
1222
& state. clock ,
1211
1223
& provider,
1212
- " subject" . to_owned ( ) ,
1224
+ subject. clone ( ) ,
1213
1225
None ,
1214
1226
)
1215
1227
. await
@@ -1231,13 +1243,13 @@ mod tests {
1231
1243
//create a user with an email
1232
1244
let user = repo
1233
1245
. user ( )
1234
- . add ( & mut rng, & state. clock , existing_username. to_owned ( ) )
1246
+ . add ( & mut rng, & state. clock , existing_username. clone ( ) )
1235
1247
. await
1236
1248
. unwrap ( ) ;
1237
1249
1238
1250
let _user_email = repo
1239
1251
. user_email ( )
1240
- . add ( & mut rng, & state. clock , & user, existing_email. to_owned ( ) )
1252
+ . add ( & mut rng, & state. clock , & user, existing_email. clone ( ) )
1241
1253
. await ;
1242
1254
1243
1255
repo. save ( ) . await . unwrap ( ) ;
@@ -1280,12 +1292,12 @@ mod tests {
1280
1292
cookies. save_cookies ( & response) ;
1281
1293
response. assert_status ( StatusCode :: SEE_OTHER ) ;
1282
1294
1283
- // Check that the existing user has a link
1295
+ // Check that the existing user has the oidc link
1284
1296
let mut repo = state. repository ( ) . await . unwrap ( ) ;
1285
1297
1286
1298
let link = repo
1287
1299
. upstream_oauth_link ( )
1288
- . find_by_subject ( & provider, " subject" )
1300
+ . find_by_subject ( & provider, & subject)
1289
1301
. await
1290
1302
. unwrap ( )
1291
1303
. expect ( "link exists" ) ;
@@ -1298,7 +1310,7 @@ mod tests {
1298
1310
. await
1299
1311
. unwrap ( ) ;
1300
1312
1301
- //check that the existing email has been updated
1313
+ //check that the existing user email is updated by oidc email
1302
1314
assert_eq ! ( page. edges. len( ) , 1 ) ;
1303
1315
let email = page. edges . first ( ) . expect ( "email exists" ) ;
1304
1316
0 commit comments