Skip to content

Commit f9ce1a1

Browse files
committed
fix rust style
1 parent 4e62fb4 commit f9ce1a1

File tree

1 file changed

+27
-44
lines changed
  • crates/handlers/src/upstream_oauth2

1 file changed

+27
-44
lines changed

crates/handlers/src/upstream_oauth2/link.rs

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -509,13 +509,11 @@ pub(crate) async fn get(
509509
})
510510
.await?;
511511

512-
if provider.allow_existing_users && maybe_existing_user.is_some(){
512+
if provider.allow_existing_users && maybe_existing_user.is_some() {
513513
// use existing user if allowed
514-
ctx
515-
.with_existing_user(maybe_existing_user.unwrap())
514+
ctx.with_existing_user(maybe_existing_user.unwrap())
516515
.with_localpart(localpart, true)
517-
}
518-
else if res.valid() {
516+
} else if res.valid() {
519517
// The username passes the policy check, add it to the context
520518
ctx.with_localpart(
521519
localpart,
@@ -845,23 +843,22 @@ pub(crate) async fn post(
845843
)
846844
.into_response());
847845
}
848-
846+
849847
let mut existing_user: Option<mas_data_model::User> = None;
850848

851849
//search and use existing users if allowed
852850
if provider.allow_existing_users {
853851
existing_user = repo.user().find_by_username(&username).await?;
854852
}
855853

856-
857-
let user = if existing_user.is_some(){
854+
let user = if existing_user.is_some() {
858855
existing_user.unwrap()
859856
} else {
860857
REGISTRATION_COUNTER.add(1, &[KeyValue::new(PROVIDER, provider.id.to_string())]);
861-
858+
862859
// Now we can create the user
863860
let user = repo.user().add(&mut rng, &clock, username).await?;
864-
861+
865862
if let Some(terms_url) = &site_config.tos_uri {
866863
repo.user_terms()
867864
.accept_terms(&mut rng, &clock, &user, terms_url.clone())
@@ -870,14 +867,14 @@ pub(crate) async fn post(
870867

871868
// And schedule the job to provision it
872869
let mut job = ProvisionUserJob::new(&user);
873-
870+
874871
// If we have a display name, set it during provisioning
875872
if let Some(name) = display_name {
876873
job = job.set_display_name(name);
877874
}
878-
875+
879876
repo.queue_job().schedule_job(&mut rng, &clock, job).await?;
880-
877+
881878
user
882879
};
883880

@@ -1124,17 +1121,17 @@ mod tests {
11241121
async fn test_link_existing_account(pool: PgPool) {
11251122
#[allow(clippy::disallowed_methods)]
11261123
let timestamp = chrono::Utc::now().timestamp_millis();
1127-
1124+
11281125
//suffix timestamp to generate unique test data
1129-
let existing_username = format!("{}{}", "john",timestamp);
1130-
let existing_email = format!("{}@{}", existing_username, "example.com");
1131-
1126+
let existing_username = format!("{}{}", "john", timestamp);
1127+
let existing_email = format!("{}@{}", existing_username, "example.com");
1128+
11321129
//existing username matches oidc username
1133-
let oidc_username = existing_username.clone();
1130+
let oidc_username = existing_username.clone();
11341131

11351132
//oidc email is different from existing email
1136-
let oidc_email: String = format!("{}{}@{}", "any_email", timestamp,"example.com");
1137-
1133+
let oidc_email: String = format!("{}{}@{}", "any_email", timestamp, "example.com");
1134+
11381135
//generate unique subject
11391136
let subject = format!("{}+{}", "subject", timestamp);
11401137

@@ -1227,13 +1224,7 @@ mod tests {
12271224

12281225
let link = repo
12291226
.upstream_oauth_link()
1230-
.add(
1231-
&mut rng,
1232-
&state.clock,
1233-
&provider,
1234-
subject.clone(),
1235-
None,
1236-
)
1227+
.add(&mut rng, &state.clock, &provider, subject.clone(), None)
12371228
.await
12381229
.unwrap();
12391230

@@ -1331,17 +1322,17 @@ mod tests {
13311322
async fn test_link_existing_account_when_not_allowed(pool: PgPool) {
13321323
#[allow(clippy::disallowed_methods)]
13331324
let timestamp = chrono::Utc::now().timestamp_millis();
1334-
1325+
13351326
//suffix timestamp to generate unique test data
1336-
let existing_username = format!("{}{}", "john",timestamp);
1337-
let existing_email = format!("{}@{}", existing_username, "example.com");
1338-
1327+
let existing_username = format!("{}{}", "john", timestamp);
1328+
let existing_email = format!("{}@{}", existing_username, "example.com");
1329+
13391330
//existing username matches oidc username
1340-
let oidc_username = existing_username.clone();
1331+
let oidc_username = existing_username.clone();
13411332

13421333
//oidc email is different from existing email
1343-
let oidc_email: String = format!("{}{}@{}", "any_email", timestamp,"example.com");
1344-
1334+
let oidc_email: String = format!("{}{}@{}", "any_email", timestamp, "example.com");
1335+
13451336
let subject = format!("{}+{}", "subject", timestamp);
13461337

13471338
setup();
@@ -1433,13 +1424,7 @@ mod tests {
14331424

14341425
let link = repo
14351426
.upstream_oauth_link()
1436-
.add(
1437-
&mut rng,
1438-
&state.clock,
1439-
&provider,
1440-
subject.clone(),
1441-
None,
1442-
)
1427+
.add(&mut rng, &state.clock, &provider, subject.clone(), None)
14431428
.await
14441429
.unwrap();
14451430

@@ -1485,8 +1470,6 @@ mod tests {
14851470
response.assert_status(StatusCode::OK);
14861471
response.assert_header_value(CONTENT_TYPE, "text/html; charset=utf-8");
14871472

1488-
assert!(response
1489-
.body().contains("Unexpected error"));
1490-
1473+
assert!(response.body().contains("Unexpected error"));
14911474
}
14921475
}

0 commit comments

Comments
 (0)