Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SM-1153] Provide QA test crate #679

Closed
Closed
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
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions crates/test-sync/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "test-sync"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
homepage.workspace = true
repository.workspace = true
license-file.workspace = true
keywords.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bitwarden = { workspace = true, features = ["secrets"] }
tokio = { version = "1.36.0", features = ["rt-multi-thread", "macros"] }
uuid = { version = "^1.7.0", features = ["serde"] }
color-eyre = "0.6"
chrono = { version = "0.4.35", features = [
"clock",
"std",
], default-features = false }
96 changes: 96 additions & 0 deletions crates/test-sync/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
use bitwarden::{
auth::login::AccessTokenLoginRequest, client::client_settings::ClientSettings,
secrets_manager::secrets::SecretsSyncRequest, Client,
};
use chrono::{DateTime, FixedOffset, Utc};
use color_eyre::eyre::Result;
use uuid::Uuid;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
let identity_url = "http://localhost:33656".to_string();
let api_url = " http://localhost:4000".to_string();
let access_token = "access_token_goes_here".to_string();
let organization_id: Uuid = "organization_id_goes_here"
.parse()
.expect("Failed to parse organization ID");

let settings: ClientSettings = ClientSettings {
identity_url,
api_url,
..Default::default()
};

let mut client = bitwarden::Client::new(Some(settings));

let asdf = client
.auth()
.login_access_token(&AccessTokenLoginRequest {
access_token,
state_file: None,
})
.await?;
println!("{:?}", asdf);

call_with_specific_date(&mut client, organization_id).await?;
call_with_current_date(&mut client, organization_id).await?;
call_with_no_date(&mut client, organization_id).await?;

Ok(())
}

async fn call_with_specific_date(client: &mut Client, organization_id: Uuid) -> Result<()> {
let last_sync_date =
DateTime::<FixedOffset>::parse_from_rfc3339("2024-03-25T19:48:06.813330+00:00")
.unwrap()
.with_timezone(&Utc);

call_sync(
client,
&SecretsSyncRequest {
organization_id: organization_id,

Check failure

Code scanning / clippy

redundant field names in struct initialization Error test

redundant field names in struct initialization
last_synced_date: Some(last_sync_date),
},
)
.await?;

Ok(())
}

async fn call_with_current_date(client: &mut Client, organization_id: Uuid) -> Result<()> {
call_sync(
client,
&SecretsSyncRequest {
organization_id: organization_id,

Check failure

Code scanning / clippy

redundant field names in struct initialization Error test

redundant field names in struct initialization
last_synced_date: Some(Utc::now()),
},
)
.await?;

Ok(())
}

async fn call_with_no_date(client: &mut Client, organization_id: Uuid) -> Result<()> {
call_sync(
client,
&SecretsSyncRequest {
organization_id: organization_id,

Check failure

Code scanning / clippy

redundant field names in struct initialization Error test

redundant field names in struct initialization
last_synced_date: None,
},
)
.await?;

Ok(())
}

async fn call_sync(client: &mut Client, request: &SecretsSyncRequest) -> Result<()> {
let sync_response = client.secrets().sync(request).await?;

if sync_response.has_changes {
println!("{:?}", sync_response);
} else {
println!("{:?}", sync_response.has_changes);
}

Ok(())
}
Loading