diff --git a/services/commtest/Cargo.lock b/services/commtest/Cargo.lock --- a/services/commtest/Cargo.lock +++ b/services/commtest/Cargo.lock @@ -513,12 +513,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[package]] -name = "base64" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" - [[package]] name = "base64" version = "0.21.3" @@ -672,20 +666,16 @@ name = "commtest" version = "0.1.0" dependencies = [ - "anyhow", "async-stream", - "base64 0.20.0", "bytesize", "comm-opaque2", "comm-services-lib", "derive_more", - "futures", "futures-util", "grpc_clients", "hex", "lazy_static", "num_cpus", - "openssl", "prost", "rand", "reqwest", @@ -971,12 +961,6 @@ "percent-encoding", ] -[[package]] -name = "futures" -version = "0.1.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" - [[package]] name = "futures-channel" version = "0.3.28" diff --git a/services/commtest/Cargo.toml b/services/commtest/Cargo.toml --- a/services/commtest/Cargo.toml +++ b/services/commtest/Cargo.toml @@ -10,10 +10,6 @@ tonic = "0.8" tokio = { version = "1.24", features = ["macros", "rt-multi-thread"] } prost = "0.11" -anyhow = "1.0" -base64 = "0.20" -openssl = "0.10" -futures = "0.1" async-stream = "0.3.2" derive_more = "0.99.16" bytesize = "1.1.0" @@ -34,4 +30,3 @@ [build-dependencies] tonic-build = "0.8" -derive_more = "0.99.16" diff --git a/services/commtest/build.rs b/services/commtest/build.rs --- a/services/commtest/build.rs +++ b/services/commtest/build.rs @@ -8,8 +8,9 @@ for path in proto_files { let filename: String = path?.file_name().to_string_lossy().to_string(); - // Avoid passing non protobuf files to tonic - if !filename.ends_with(".proto") { + // Avoid passing non protobuf files to tonic. Also avoid passing identity + // protobuf files since they are already compiled in shared/grpc_clients. + if !filename.ends_with(".proto") || filename.starts_with("identity") { continue; } diff --git a/services/commtest/src/identity/device.rs b/services/commtest/src/identity/device.rs --- a/services/commtest/src/identity/device.rs +++ b/services/commtest/src/identity/device.rs @@ -1,17 +1,19 @@ use comm_opaque2::client::Registration; +use grpc_clients::identity::get_unauthenticated_client; use rand::{distributions::Alphanumeric, Rng}; -mod proto { - tonic::include_proto!("identity.client"); -} + use crate::identity::olm_account_infos::{ ClientPublicKeys, DEFAULT_CLIENT_KEYS, }; -use proto as client; -use proto::{ - identity_client_service_client::IdentityClientServiceClient, DeviceKeyUpload, - IdentityKeyInfo, PreKey, RegistrationFinishRequest, RegistrationStartRequest, + +use grpc_clients::identity::protos::client::{ + DeviceKeyUpload, DeviceType, IdentityKeyInfo, PreKey, + RegistrationFinishRequest, RegistrationStartRequest, }; +pub const PLACEHOLDER_CODE_VERSION: u64 = 0; +pub const DEVICE_TYPE: &str = "service"; + pub struct DeviceInfo { pub username: String, pub user_id: String, @@ -56,15 +58,18 @@ }), one_time_content_prekeys: Vec::new(), one_time_notif_prekeys: Vec::new(), - device_type: client::DeviceType::Keyserver.into(), + device_type: DeviceType::Keyserver.into(), }), }; // TODO: allow endpoint to be configured - let mut identity_client = - IdentityClientServiceClient::connect("http://127.0.0.1:50054") - .await - .expect("Couldn't connect to identitiy service"); + let mut identity_client = get_unauthenticated_client( + "http://127.0.0.1:50054", + PLACEHOLDER_CODE_VERSION, + DEVICE_TYPE.to_string(), + ) + .await + .expect("Couldn't connect to identity service"); let registration_start_response = identity_client .register_password_user_start(registration_start_request) diff --git a/services/commtest/tests/identity_access_tokens_tests.rs b/services/commtest/tests/identity_access_tokens_tests.rs --- a/services/commtest/tests/identity_access_tokens_tests.rs +++ b/services/commtest/tests/identity_access_tokens_tests.rs @@ -1,22 +1,22 @@ -mod proto { - tonic::include_proto!("identity.client"); -} -use proto as client; -mod auth_proto { - tonic::include_proto!("identity.authenticated"); -} -use commtest::identity::device::create_device; -use proto::identity_client_service_client::IdentityClientServiceClient; -use proto::{UploadOneTimeKeysRequest, VerifyUserAccessTokenRequest}; +use commtest::identity::device::{ + create_device, DEVICE_TYPE, PLACEHOLDER_CODE_VERSION, +}; +use grpc_clients::identity::{ + get_unauthenticated_client, + protos::client::{UploadOneTimeKeysRequest, VerifyUserAccessTokenRequest}, +}; #[tokio::test] async fn verify_access_token() { let device_info = create_device(None).await; - let mut identity_client = - IdentityClientServiceClient::connect("http://127.0.0.1:50054") - .await - .expect("Couldn't connect to identitiy service"); + let mut identity_client = get_unauthenticated_client( + "http://127.0.0.1:50054", + PLACEHOLDER_CODE_VERSION, + DEVICE_TYPE.to_string(), + ) + .await + .expect("Couldn't connect to identity service"); let verify_request = VerifyUserAccessTokenRequest { user_id: device_info.user_id, @@ -36,10 +36,13 @@ async fn upload_one_time_keys() { let device_info = create_device(None).await; - let mut identity_client = - IdentityClientServiceClient::connect("http://127.0.0.1:50054") - .await - .expect("Couldn't connect to identitiy service"); + let mut identity_client = get_unauthenticated_client( + "http://127.0.0.1:50054", + PLACEHOLDER_CODE_VERSION, + DEVICE_TYPE.to_string(), + ) + .await + .expect("Couldn't connect to identity service"); let upload_request = UploadOneTimeKeysRequest { user_id: device_info.user_id, diff --git a/services/commtest/tests/identity_keyserver_tests.rs b/services/commtest/tests/identity_keyserver_tests.rs --- a/services/commtest/tests/identity_keyserver_tests.rs +++ b/services/commtest/tests/identity_keyserver_tests.rs @@ -1,47 +1,43 @@ -mod proto { - tonic::include_proto!("identity.client"); -} -use proto as client; -mod auth_proto { - tonic::include_proto!("identity.authenticated"); -} -use auth_proto::identity_client_service_client::IdentityClientServiceClient as AuthClient; -use auth_proto::OutboundKeysForUserRequest; -use client::UploadOneTimeKeysRequest; -use commtest::identity::device::create_device; -use tonic::{transport::Endpoint, Request}; +use commtest::identity::device::{ + create_device, DEVICE_TYPE, PLACEHOLDER_CODE_VERSION, +}; +use grpc_clients::identity::{ + get_auth_client, get_unauthenticated_client, + protos::{ + authenticated::OutboundKeysForUserRequest, client::UploadOneTimeKeysRequest, + }, +}; #[tokio::test] async fn set_prekey() { let device_info = create_device(None).await; - let channel = Endpoint::from_static("http://[::1]:50054") - .connect() - .await - .unwrap(); - - let mut client = - AuthClient::with_interceptor(channel, |mut request: Request<()>| { - let metadata = request.metadata_mut(); - metadata.insert("user_id", device_info.user_id.parse().unwrap()); - metadata.insert("device_id", device_info.device_id.parse().unwrap()); - metadata - .insert("access_token", device_info.access_token.parse().unwrap()); - Ok(request) - }); + let mut client = get_auth_client( + "http://[::1]:50054", + device_info.user_id.clone(), + device_info.device_id.clone(), + device_info.access_token.clone(), + PLACEHOLDER_CODE_VERSION, + DEVICE_TYPE.to_string(), + ) + .await + .expect("Couldn't connect to identity service"); let upload_request = UploadOneTimeKeysRequest { - user_id: device_info.user_id.to_string(), - device_id: device_info.device_id.to_string(), - access_token: device_info.access_token.to_string(), + user_id: device_info.user_id.clone(), + device_id: device_info.device_id, + access_token: device_info.access_token, content_one_time_pre_keys: vec!["content1".to_string()], notif_one_time_pre_keys: vec!["notif1".to_string()], }; - let mut unauthenticated_client = - proto::identity_client_service_client::IdentityClientServiceClient::connect("http://127.0.0.1:50054") - .await - .expect("Couldn't connect to identitiy service"); + let mut unauthenticated_client = get_unauthenticated_client( + "http://127.0.0.1:50054", + PLACEHOLDER_CODE_VERSION, + DEVICE_TYPE.to_string(), + ) + .await + .expect("Couldn't connect to identity service"); unauthenticated_client .upload_one_time_keys(upload_request) diff --git a/services/commtest/tests/identity_one_time_key_tests.rs b/services/commtest/tests/identity_one_time_key_tests.rs --- a/services/commtest/tests/identity_one_time_key_tests.rs +++ b/services/commtest/tests/identity_one_time_key_tests.rs @@ -1,21 +1,21 @@ -mod client { - tonic::include_proto!("identity.client"); -} -mod auth_proto { - tonic::include_proto!("identity.authenticated"); -} -use client::identity_client_service_client::IdentityClientServiceClient; -use client::UploadOneTimeKeysRequest; -use commtest::identity::device::create_device; +use commtest::identity::device::{ + create_device, DEVICE_TYPE, PLACEHOLDER_CODE_VERSION, +}; +use grpc_clients::identity::{ + get_unauthenticated_client, protos::client::UploadOneTimeKeysRequest, +}; #[tokio::test] async fn verify_access_token() { let device_info = create_device(None).await; - let mut identity_client = - IdentityClientServiceClient::connect("http://127.0.0.1:50054") - .await - .expect("Couldn't connect to identity service"); + let mut identity_client = get_unauthenticated_client( + "http://127.0.0.1:50054", + PLACEHOLDER_CODE_VERSION, + DEVICE_TYPE.to_string(), + ) + .await + .expect("Couldn't connect to identity service"); let upload_request = UploadOneTimeKeysRequest { user_id: device_info.user_id, diff --git a/services/commtest/tests/identity_prekey_tests.rs b/services/commtest/tests/identity_prekey_tests.rs --- a/services/commtest/tests/identity_prekey_tests.rs +++ b/services/commtest/tests/identity_prekey_tests.rs @@ -1,34 +1,25 @@ -mod proto { - tonic::include_proto!("identity.client"); -} -use proto as client; -mod auth_proto { - tonic::include_proto!("identity.authenticated"); -} -use auth_proto::identity_client_service_client::IdentityClientServiceClient as AuthClient; -use auth_proto::RefreshUserPreKeysRequest; -use client::PreKey; -use commtest::identity::device::create_device; -use tonic::{transport::Endpoint, Request}; +use commtest::identity::device::{ + create_device, DEVICE_TYPE, PLACEHOLDER_CODE_VERSION, +}; +use grpc_clients::identity::{ + get_auth_client, + protos::{authenticated::RefreshUserPreKeysRequest, client::PreKey}, +}; #[tokio::test] async fn set_prekey() { let device_info = create_device(None).await; - let channel = Endpoint::from_static("http://[::1]:50054") - .connect() - .await - .unwrap(); - - let mut client = - AuthClient::with_interceptor(channel, |mut request: Request<()>| { - let metadata = request.metadata_mut(); - metadata.append("user_id", device_info.user_id.parse().unwrap()); - metadata.append("device_id", device_info.device_id.parse().unwrap()); - metadata - .append("access_token", device_info.access_token.parse().unwrap()); - Ok(request) - }); + let mut client = get_auth_client( + "http://[::1]:50054", + device_info.user_id, + device_info.device_id, + device_info.access_token, + PLACEHOLDER_CODE_VERSION, + DEVICE_TYPE.to_string(), + ) + .await + .expect("Couldn't connect to identity service"); let upload_request = RefreshUserPreKeysRequest { new_content_pre_keys: Some(PreKey { diff --git a/services/commtest/tests/identity_tunnelbroker_tests.rs b/services/commtest/tests/identity_tunnelbroker_tests.rs --- a/services/commtest/tests/identity_tunnelbroker_tests.rs +++ b/services/commtest/tests/identity_tunnelbroker_tests.rs @@ -1,17 +1,11 @@ -mod client { - tonic::include_proto!("identity.client"); -} -mod auth_proto { - tonic::include_proto!("identity.authenticated"); -} -use auth_proto::identity_client_service_client::IdentityClientServiceClient as AuthClient; -use client::identity_client_service_client::IdentityClientServiceClient; -use client::UploadOneTimeKeysRequest; -use commtest::identity::device::create_device; +use commtest::identity::device::{ + create_device, DEVICE_TYPE, PLACEHOLDER_CODE_VERSION, +}; use commtest::tunnelbroker::socket::create_socket; use futures_util::StreamExt; -use tonic::transport::Endpoint; -use tonic::Request; +use grpc_clients::identity::protos::authenticated::OutboundKeysForUserRequest; +use grpc_clients::identity::protos::client::UploadOneTimeKeysRequest; +use grpc_clients::identity::{get_auth_client, get_unauthenticated_client}; use tunnelbroker_messages::RefreshKeyRequest; #[tokio::test] @@ -44,10 +38,13 @@ async fn test_refresh_keys_request_upon_depletion() { let device_info = create_device(None).await; - let mut identity_client = - IdentityClientServiceClient::connect("http://127.0.0.1:50054") - .await - .expect("Couldn't connect to identitiy service"); + let mut identity_client = get_unauthenticated_client( + "http://127.0.0.1:50054", + PLACEHOLDER_CODE_VERSION, + DEVICE_TYPE.to_string(), + ) + .await + .expect("Couldn't connect to identity service"); let upload_request = UploadOneTimeKeysRequest { user_id: device_info.user_id.clone(), @@ -63,22 +60,18 @@ .unwrap(); // Request outbound keys, which should trigger identity service to ask for more keys - let channel = Endpoint::from_static("http://[::1]:50054") - .connect() - .await - .unwrap(); - - let mut client = - AuthClient::with_interceptor(channel, |mut inter_request: Request<()>| { - let metadata = inter_request.metadata_mut(); - metadata.insert("user_id", device_info.user_id.parse().unwrap()); - metadata.insert("device_id", device_info.device_id.parse().unwrap()); - metadata - .insert("access_token", device_info.access_token.parse().unwrap()); - Ok(inter_request) - }); - - let keyserver_request = auth_proto::OutboundKeysForUserRequest { + let mut client = get_auth_client( + "http://[::1]:50054", + device_info.user_id.clone(), + device_info.device_id, + device_info.access_token, + PLACEHOLDER_CODE_VERSION, + DEVICE_TYPE.to_string(), + ) + .await + .expect("Couldn't connect to identity service"); + + let keyserver_request = OutboundKeysForUserRequest { user_id: device_info.user_id.clone(), };