Created
November 30, 2023 17:02
-
-
Save vdhanan/07cd60c9474f76d63fa10ef9d909b8ef to your computer and use it in GitHub Desktop.
test plan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/native/native_rust_library/src/lib.rs b/native/native_rust_library/src/lib.rs | |
index 5c927853b..f19940b34 100644 | |
--- a/native/native_rust_library/src/lib.rs | |
+++ b/native/native_rust_library/src/lib.rs | |
@@ -14,8 +14,10 @@ use lazy_static::lazy_static; | |
use serde::Serialize; | |
use std::sync::Arc; | |
use tokio::runtime::{Builder, Runtime}; | |
-use tonic::Status; | |
-use tracing::instrument; | |
+use tonic::metadata::MetadataValue; | |
+use tonic::{Request, Status}; | |
+use tracing::{info, instrument, Level}; | |
+use tracing_subscriber::EnvFilter; | |
mod argon2_tools; | |
@@ -34,14 +36,25 @@ pub const DEVICE_TYPE: DeviceType = DeviceType::Ios; | |
pub const DEVICE_TYPE: DeviceType = DeviceType::Android; | |
lazy_static! { | |
- pub static ref RUNTIME: Arc<Runtime> = Arc::new( | |
- Builder::new_multi_thread() | |
- .worker_threads(1) | |
- .max_blocking_threads(1) | |
- .enable_all() | |
- .build() | |
- .unwrap() | |
- ); | |
+ pub static ref RUNTIME: Arc<Runtime> = { | |
+ let filter = EnvFilter::builder() | |
+ .with_default_directive(Level::INFO.into()) | |
+ .with_env_var(EnvFilter::DEFAULT_ENV) | |
+ .from_env_lossy(); | |
+ | |
+ let subscriber = tracing_subscriber::fmt().with_env_filter(filter).finish(); | |
+ tracing::subscriber::set_global_default(subscriber) | |
+ .expect("Unable to configure tracing"); | |
+ | |
+ Arc::new( | |
+ Builder::new_multi_thread() | |
+ .worker_threads(1) | |
+ .max_blocking_threads(1) | |
+ .enable_all() | |
+ .build() | |
+ .unwrap(), | |
+ ) | |
+ }; | |
} | |
#[cxx::bridge] | |
@@ -185,18 +198,35 @@ fn generate_nonce(promise_id: u32) { | |
} | |
async fn fetch_nonce() -> Result<String, Error> { | |
+ use tokio::time::{sleep, Duration}; | |
let mut identity_client = get_unauthenticated_client( | |
- "http://127.0.0.1:50054", | |
+ "https://identity.staging.commtechnologies.org:50054", | |
CODE_VERSION, | |
DEVICE_TYPE.as_str_name().to_lowercase(), | |
) | |
.await?; | |
- let nonce = identity_client | |
- .generate_nonce(Empty {}) | |
- .await? | |
- .into_inner() | |
- .nonce; | |
- Ok(nonce) | |
+ let response = identity_client.generate_nonce(Empty {}).await?; | |
+ // Capture the cookie from the first response | |
+ let cookie = if let Some(cookie_meta) = response.metadata().get("set-cookie") | |
+ { | |
+ MetadataValue::try_from(cookie_meta.to_str().unwrap()).unwrap() | |
+ } else { | |
+ MetadataValue::from_static("") // Handle the case where there is no cookie | |
+ }; | |
+ info!("cookie: {:?}", cookie); | |
+ | |
+ let i = 0; | |
+ while i < 20 { | |
+ sleep(Duration::from_millis(1000)).await; | |
+ let mut request = Request::new(Empty {}); | |
+ request.metadata_mut().insert("cookie", cookie.clone()); | |
+ identity_client | |
+ .generate_nonce(request) | |
+ .await? | |
+ .into_inner() | |
+ .nonce; | |
+ } | |
+ Ok(response.into_inner().nonce) | |
} | |
fn version_supported(promise_id: u32) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment