Skip to content

Commit

Permalink
[Commtest] add mock olm accounts, configure creating authenticated de…
Browse files Browse the repository at this point in the history
…vice

Summary:
To properly test WebSocket one device is not enough. We should send message from one device and receive it on another.
Adding two more, generated via local `olm`.

Depends on D9311

Test Plan: Run tests and make sure new credentials works.

Reviewers: michal, bartek, varun, jon

Reviewed By: michal, bartek

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D9312
  • Loading branch information
xsanm committed Oct 11, 2023
1 parent f5edade commit a217796
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 15 deletions.
11 changes: 8 additions & 3 deletions services/commtest/src/identity/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ 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,
Expand All @@ -16,7 +19,7 @@ pub struct DeviceInfo {
pub access_token: String,
}

pub async fn create_device() -> DeviceInfo {
pub async fn create_device(keys: Option<&ClientPublicKeys>) -> DeviceInfo {
let password = "pass";
let username: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
Expand All @@ -25,9 +28,11 @@ pub async fn create_device() -> DeviceInfo {
.collect();

// TODO: Generate dynamic valid olm account info
let example_payload = r#"{\"notificationIdentityPublicKeys\":{\"curve25519\":\"DYmV8VdkjwG/VtC8C53morogNJhpTPT/4jzW0/cxzQo\",\"ed25519\":\"D0BV2Y7Qm36VUtjwyQTJJWYAycN7aMSJmhEsRJpW2mk\"},\"primaryIdentityPublicKeys\":{\"curve25519\":\"Y4ZIqzpE1nv83kKGfvFP6rifya0itRg2hifqYtsISnk\",\"ed25519\":\"cSlL+VLLJDgtKSPlIwoCZg0h0EmHlQoJC08uV/O+jvg\"}}"#;
let keys = keys.unwrap_or_else(|| &DEFAULT_CLIENT_KEYS);
let example_payload =
serde_json::to_string(&keys).expect("Failed to serialize example payload");
// The ed25519 value from the olm payload
let device_id = r#"cSlL+VLLJDgtKSPlIwoCZg0h0EmHlQoJC08uV/O+jvg"#;
let device_id = &keys.primary_identity_public_keys.ed25519;

let mut client_registration = Registration::new();
let opaque_registration_request =
Expand Down
1 change: 1 addition & 0 deletions services/commtest/src/identity/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod device;
pub mod olm_account_infos;
48 changes: 48 additions & 0 deletions services/commtest/src/identity/olm_account_infos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct IdentityPublicKeys {
pub ed25519: String,
pub curve25519: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ClientPublicKeys {
pub primary_identity_public_keys: IdentityPublicKeys,
pub notification_identity_public_keys: IdentityPublicKeys,
}

lazy_static! {
pub static ref DEFAULT_CLIENT_KEYS: ClientPublicKeys = ClientPublicKeys {
primary_identity_public_keys: IdentityPublicKeys {
ed25519: "cSlL+VLLJDgtKSPlIwoCZg0h0EmHlQoJC08uV/O+jvg".to_string(),
curve25519: "Y4ZIqzpE1nv83kKGfvFP6rifya0itRg2hifqYtsISnk".to_string(),
},
notification_identity_public_keys: IdentityPublicKeys {
ed25519: "D0BV2Y7Qm36VUtjwyQTJJWYAycN7aMSJmhEsRJpW2mk".to_string(),
curve25519: "DYmV8VdkjwG/VtC8C53morogNJhpTPT/4jzW0/cxzQo".to_string(),
}
};
pub static ref MOCK_CLIENT_KEYS_1: ClientPublicKeys = ClientPublicKeys {
primary_identity_public_keys: IdentityPublicKeys {
ed25519: "lbp5cS9fH5NnWIJbZ57wGBzDBGvmjoq6gMBHsIyXfJ4".to_string(),
curve25519: "x74rEeVzfTcjm+B2yLN/wgfvHEzEtphQ/JeQfIrzPzQ".to_string(),
},
notification_identity_public_keys: IdentityPublicKeys {
ed25519: "+mi3TltiSK2883cm0TK2mkSKPcQb+WVfshltTSVgA2Y".to_string(),
curve25519: "GI8V9FwOYIqxB2TzQN31nXKR8y3/B3k+ZOCgxkTlUlI".to_string(),
},
};
pub static ref MOCK_CLIENT_KEYS_2: ClientPublicKeys = ClientPublicKeys {
primary_identity_public_keys: IdentityPublicKeys {
ed25519: "ZXx1ADCFxFm6P+UmVhX0A1tuqUoBU7lYjig/gMzSEJI".to_string(),
curve25519: "zHfP5eeD3slrgidtNRknHw3NKtJ7hA+vinaT3ACIhRA".to_string(),
},
notification_identity_public_keys: IdentityPublicKeys {
ed25519: "TqzVFQLnJvt9JfMVU54d6InEd/wQV3DCplBuj5axTlU".to_string(),
curve25519: "nRVVaf+Iz2MfEFtQtzrvV/EmTivqKpOeHlCt9OWYUxM".to_string(),
},
};
}
2 changes: 1 addition & 1 deletion services/commtest/tests/grpc_client_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use commtest::identity::device::create_device;
#[tokio::test]
async fn verify_access_token() {
use grpc_clients::identity::unauthenticated::client::verify_user_access_token;
let device_info = create_device().await;
let device_info = create_device(None).await;

let token_valid = verify_user_access_token(
"http://127.0.0.1:50054",
Expand Down
4 changes: 2 additions & 2 deletions services/commtest/tests/identity_access_tokens_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use proto::{UploadOneTimeKeysRequest, VerifyUserAccessTokenRequest};

#[tokio::test]
async fn verify_access_token() {
let device_info = create_device().await;
let device_info = create_device(None).await;

let mut identity_client =
IdentityClientServiceClient::connect("http://127.0.0.1:50054")
Expand All @@ -34,7 +34,7 @@ async fn verify_access_token() {

#[tokio::test]
async fn upload_one_time_keys() {
let device_info = create_device().await;
let device_info = create_device(None).await;

let mut identity_client =
IdentityClientServiceClient::connect("http://127.0.0.1:50054")
Expand Down
2 changes: 1 addition & 1 deletion services/commtest/tests/identity_keyserver_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tonic::{transport::Endpoint, Request};

#[tokio::test]
async fn set_prekey() {
let device_info = create_device().await;
let device_info = create_device(None).await;

let channel = Endpoint::from_static("http://[::1]:50054")
.connect()
Expand Down
2 changes: 1 addition & 1 deletion services/commtest/tests/identity_one_time_key_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use commtest::identity::device::create_device;

#[tokio::test]
async fn verify_access_token() {
let device_info = create_device().await;
let device_info = create_device(None).await;

let mut identity_client =
IdentityClientServiceClient::connect("http://127.0.0.1:50054")
Expand Down
2 changes: 1 addition & 1 deletion services/commtest/tests/identity_prekey_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tonic::{transport::Endpoint, Request};

#[tokio::test]
async fn set_prekey() {
let device_info = create_device().await;
let device_info = create_device(None).await;

let channel = Endpoint::from_static("http://[::1]:50054")
.connect()
Expand Down
8 changes: 4 additions & 4 deletions services/commtest/tests/identity_tunnelbroker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use tunnelbroker_messages::RefreshKeyRequest;
#[tokio::test]
#[should_panic]
async fn test_tunnelbroker_invalid_auth() {
let mut device_info = create_device().await;
let mut device_info = create_device(None).await;
device_info.access_token = "".to_string();
let mut socket = create_socket(&device_info).await;

Expand All @@ -30,7 +30,7 @@ async fn test_tunnelbroker_invalid_auth() {

#[tokio::test]
async fn test_tunnelbroker_valid_auth() {
let device_info = create_device().await;
let device_info = create_device(None).await;
let mut socket = create_socket(&device_info).await;

socket
Expand All @@ -42,7 +42,7 @@ async fn test_tunnelbroker_valid_auth() {

#[tokio::test]
async fn test_refresh_keys_request_upon_depletion() {
let device_info = create_device().await;
let device_info = create_device(None).await;

let mut identity_client =
IdentityClientServiceClient::connect("http://127.0.0.1:50054")
Expand Down Expand Up @@ -95,7 +95,7 @@ async fn test_refresh_keys_request_upon_depletion() {
// from Tunnelbroker to refresh keys
// Create session as a keyserver

let device_info = create_device().await;
let device_info = create_device(None).await;
let mut socket = create_socket(&device_info).await;

// Have keyserver receive any websocket messages
Expand Down
4 changes: 2 additions & 2 deletions services/commtest/tests/tunnelbroker_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tunnelbroker_messages::RefreshKeyRequest;
#[tokio::test]
async fn send_refresh_request() {
// Create session as a keyserver
let device_info = create_device().await;
let device_info = create_device(None).await;
let mut socket = create_socket(&device_info).await;

// Send request for keyserver to refresh keys (identity service)
Expand Down Expand Up @@ -51,7 +51,7 @@ async fn send_refresh_request() {
/// then recalled once a device connects
#[tokio::test]
async fn persist_messages() {
let device_info = create_device().await;
let device_info = create_device(None).await;

// Send request for keyserver to refresh keys (identity service)
let mut tunnelbroker_client =
Expand Down

0 comments on commit a217796

Please sign in to comment.