Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ impl Zitadel {
/// - `service_account_file` should be the Zitadel-generated
/// private key file as documented at [zitadel docs](https://zitadel.com/docs/guides/integrate/service-users/private-key-jwt#2-generate-a-private-key-file)
/// - `aud` - Custom `aud` claim to use for auth (`url` is used if unset)
pub async fn new(url: Url, service_account_file: PathBuf, aud: Option<String>) -> Result<Self> {
pub async fn new(
client: ClientWithMiddleware,
url: Url,
service_account_file: PathBuf,
aud: Option<String>,
) -> Result<Self> {
let retry_policy =
ExponentialBackoff::builder().build_with_max_retries(DEFAULT_MAX_RETRIES);
let client_builder =
ClientBuilder::new(reqwest::Client::builder().timeout(DEFAULT_TIMEOUT).build()?)
.with(RetryTransientMiddleware::new_with_policy(retry_policy));
let client_builder = ClientBuilder::from_client(client)
.with(RetryTransientMiddleware::new_with_policy(retry_policy));
#[cfg(feature = "telemetry")]
let client_builder = client_builder.with(OtelMiddleware);
let client = client_builder.build();
Expand Down
87 changes: 25 additions & 62 deletions tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use famedly_zitadel_rust_client::v2::{
use futures::{StreamExt, TryStreamExt, future};
use josekit::{jws::JwsHeader, jwt::JwtPayload};
use rand::distr::{Alphanumeric, SampleString};
use reqwest_middleware::ClientWithMiddleware;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use test_log::{self, test};
use time::{Duration, OffsetDateTime};
use url::Url;
Expand Down Expand Up @@ -183,19 +183,17 @@ macro_rules! assert_list {
};
}

#[tokio::test]
async fn test_e2e_create_token() -> Result<()> {
async fn mk_zitadel_client() -> Result<Zitadel> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;

assert!(Zitadel::new(url, service_account_file.to_path_buf(), None).await.is_ok());
Ok(())
let client = ClientBuilder::new(reqwest::Client::new()).build();
Zitadel::new(client, url, service_account_file.to_path_buf(), None).await
}

async fn mk_zitadel_client() -> Result<Zitadel> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
Zitadel::new(url, service_account_file.to_path_buf(), None).await
#[tokio::test]
async fn test_e2e_create_token() -> Result<()> {
assert!(mk_zitadel_client().await.is_ok());
Ok(())
}

#[test(tokio::test)]
Expand Down Expand Up @@ -472,9 +470,7 @@ async fn test_e2e_role_and_membership_methods() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_create_organization() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let admins = vec![
(AddOrganizationRequestAdmin::new().with_human(AddHumanUserRequest::new(
Expand Down Expand Up @@ -515,9 +511,7 @@ async fn test_e2e_create_organization() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_create_application() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let project =
zitadel.create_project(V1AddProjectRequest::new("TestProject".to_owned()), None).await?;
Expand Down Expand Up @@ -549,9 +543,7 @@ async fn test_e2e_create_application() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_list_applications() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

// TODO: Figure out why the teardown fails to delete this project
let project =
Expand Down Expand Up @@ -585,9 +577,7 @@ async fn test_e2e_list_applications() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_create_action() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let res = zitadel
.create_action(
Expand Down Expand Up @@ -625,9 +615,7 @@ async fn test_e2e_create_action() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_list_actions() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let mut action_names = Vec::new();

Expand Down Expand Up @@ -658,9 +646,7 @@ async fn test_e2e_list_actions() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_update_action() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let res = zitadel
.create_action(
Expand Down Expand Up @@ -707,9 +693,7 @@ async fn test_e2e_update_action() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_delete_action() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let res = zitadel
.create_action(
Expand Down Expand Up @@ -741,9 +725,7 @@ async fn test_e2e_delete_action() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "trace")]
async fn test_e2e_set_trigger_actions() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let res = zitadel
.create_action(
Expand Down Expand Up @@ -778,9 +760,7 @@ async fn test_e2e_set_trigger_actions() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_create_human_user() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let resp = create_user(&zitadel, "John", "Doe").await;

Expand Down Expand Up @@ -844,9 +824,7 @@ async fn test_e2e_create_user_human_and_machine() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_list_human_users() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let mut users = Vec::new();

Expand Down Expand Up @@ -885,9 +863,7 @@ async fn test_e2e_list_human_users() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_list_idp_links() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let idp_links = vec![];

Expand All @@ -913,9 +889,7 @@ async fn test_e2e_list_idp_links() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_change_user() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let last_name = "Doe";
let first_name = "John";
Expand Down Expand Up @@ -956,9 +930,7 @@ async fn test_e2e_change_user() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_activate_deactivate() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let id = create_user(&zitadel, "John", "Doe").await?;

Expand Down Expand Up @@ -992,9 +964,7 @@ async fn test_e2e_activate_deactivate() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_delete_user() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let deleted_user_name = "John";
let user_last_name = "Doe";
Expand Down Expand Up @@ -1038,9 +1008,7 @@ async fn test_e2e_delete_user() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_user_metadata() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let metadata = vec![("key1", "value1"), ("key2", "value2")];

Expand Down Expand Up @@ -1090,9 +1058,7 @@ async fn test_e2e_user_metadata() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_user_metadata_bulk() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;
let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

let metadata = vec![
SetMetadataEntry::new("key1".to_owned(), "value1".to_owned()),
Expand Down Expand Up @@ -1327,10 +1293,7 @@ async fn test_e2e_token_verification_positive() -> Result<()> {
#[test(tokio::test)]
#[test_log(default_log_filter = "debug")]
async fn test_e2e_organization_scoped_operations() -> Result<()> {
let service_account_file = Path::new(USER_SERVICE_PATH);
let url = Url::parse("http://localhost:8080")?;

let zitadel = Zitadel::new(url, service_account_file.to_path_buf(), None).await?;
let zitadel = mk_zitadel_client().await?;

// Create two organizations to test scoping
let org_name = "test-org-scoped";
Expand Down