Skip to content

Commit

Permalink
feat: Add preferred username to user metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
tlater-famedly committed Jul 24, 2024
1 parent 6d0674f commit 8fae6fb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/zitadel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,26 @@ impl Zitadel {
}

for user in users {
let user_id = user.ldap_id.clone();
let sync_status: Result<()> = {
let new_user_id = self
.client
.create_human_user(&self.config.famedly.organization_id, user.clone().into())
.await?;

self.client
.set_user_metadata(
Some(&self.config.famedly.organization_id),
new_user_id,
"preferred_username".to_owned(),
&user.preferred_username,
)
.await?;

Ok(())
};

if let Err(error) = self
.client
.create_human_user(&self.config.famedly.organization_id, user.into())
.await
{
tracing::error!("Failed to sync user `{}`: {}", user_id, error);
if let Err(error) = sync_status {
tracing::error!("Failed to sync user `{}`: {}", user.ldap_id, error);
};
}

Expand Down
26 changes: 26 additions & 0 deletions tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@ async fn test_e2e_simple_sync() {
.expect("could not query Zitadel users");

assert!(user.is_some());

if let Some(user) = user {
assert_eq!(user.user_name, "[email protected]");

if let Some(Type::Human(user)) = user.r#type {
let profile = user.profile.expect("user lacks a profile");
let phone = user.phone.expect("user lacks a phone number)");
let email = user.email.expect("user lacks an email address");

assert_eq!(profile.first_name, "Bob");
assert_eq!(profile.last_name, "Tables");
assert_eq!(profile.display_name, "Tables, Bob");
assert_eq!(phone.phone, "+12015550123");
assert!(phone.is_phone_verified);
assert_eq!(email.email, "[email protected]");
assert!(email.is_email_verified);
} else {
panic!("user lacks details");
}

let preferred_username = zitadel
.get_user_metadata(None, &user.id, "preferred_username")
.await
.expect("could not get user metadata");
assert_eq!(preferred_username, Some("Bobby".to_owned()));
};
}

#[test(tokio::test)]
Expand Down

0 comments on commit 8fae6fb

Please sign in to comment.