Skip to content

Commit e2b0077

Browse files
committed
add allow_existing_users by default
allow_existing_users true by default fix test by make data unique remove useless code
1 parent ce73d21 commit e2b0077

File tree

2 files changed

+24
-11
lines changed
  • crates
    • handlers/src/upstream_oauth2
    • syn2mas/src/synapse_reader/config

2 files changed

+24
-11
lines changed

crates/handlers/src/upstream_oauth2/link.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,9 +1113,21 @@ mod tests {
11131113

11141114
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]
11151115
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);
11191131

11201132
setup();
11211133
let state = TestState::from_pool(pool).await.unwrap();
@@ -1135,8 +1147,8 @@ mod tests {
11351147
};
11361148

11371149
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,
11401152
"email_verified": true,
11411153
});
11421154

@@ -1209,7 +1221,7 @@ mod tests {
12091221
&mut rng,
12101222
&state.clock,
12111223
&provider,
1212-
"subject".to_owned(),
1224+
subject.clone(),
12131225
None,
12141226
)
12151227
.await
@@ -1231,13 +1243,13 @@ mod tests {
12311243
//create a user with an email
12321244
let user = repo
12331245
.user()
1234-
.add(&mut rng, &state.clock, existing_username.to_owned())
1246+
.add(&mut rng, &state.clock, existing_username.clone())
12351247
.await
12361248
.unwrap();
12371249

12381250
let _user_email = repo
12391251
.user_email()
1240-
.add(&mut rng, &state.clock, &user, existing_email.to_owned())
1252+
.add(&mut rng, &state.clock, &user, existing_email.clone())
12411253
.await;
12421254

12431255
repo.save().await.unwrap();
@@ -1280,12 +1292,12 @@ mod tests {
12801292
cookies.save_cookies(&response);
12811293
response.assert_status(StatusCode::SEE_OTHER);
12821294

1283-
// Check that the existing user has a link
1295+
// Check that the existing user has the oidc link
12841296
let mut repo = state.repository().await.unwrap();
12851297

12861298
let link = repo
12871299
.upstream_oauth_link()
1288-
.find_by_subject(&provider, "subject")
1300+
.find_by_subject(&provider, &subject)
12891301
.await
12901302
.unwrap()
12911303
.expect("link exists");
@@ -1298,7 +1310,7 @@ mod tests {
12981310
.await
12991311
.unwrap();
13001312

1301-
//check that the existing email has been updated
1313+
//check that the existing user email is updated by oidc email
13021314
assert_eq!(page.edges.len(), 1);
13031315
let email = page.edges.first().expect("email exists");
13041316

crates/syn2mas/src/synapse_reader/config/oidc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ impl OidcProvider {
342342
response_mode,
343343
claims_imports,
344344
additional_authorization_parameters,
345+
allow_existing_users: true,
345346
})
346347
}
347348
}

0 commit comments

Comments
 (0)