Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[rust][contacts] derive contact email from server

Neeraj Gupta4ae8712b2879
diff --git a/mobile/packages/rust/rust/src/api/contacts.rs b/mobile/packages/rust/rust/src/api/contacts.rs
index 17dca746d7..96fdb5c80d 100644
--- a/mobile/packages/rust/rust/src/api/contacts.rs
+++ b/mobile/packages/rust/rust/src/api/contacts.rs
@@ -78,7 +78,6 @@ impl From<WrappedRootContactKey> for CoreWrappedRootContactKey {
#[derive(Clone)]
pub struct ContactData {
pub contact_user_id: i64,
- pub email: String,
pub name: String,
pub birth_date: Option<String>,
}
@@ -87,7 +86,6 @@ impl From<ContactData> for CoreContactData {
fn from(value: ContactData) -> Self {
Self {
contact_user_id: value.contact_user_id,
- email: value.email,
name: value.name,
birth_date: value.birth_date,
}
diff --git a/rust/contacts/src/client.rs b/rust/contacts/src/client.rs
index 7fb6263180..a0e85043e6 100644
--- a/rust/contacts/src/client.rs
+++ b/rust/contacts/src/client.rs
@@ -341,7 +341,7 @@ impl ContactsCtx {
Ok(ContactRecord {
id: entity.id,
contact_user_id: entity.contact_user_id,
- email: Some(data.email),
+ email: entity.email,
name: Some(data.name),
birth_date: data.birth_date,
profile_picture_attachment_id: entity.profile_picture_attachment_id,
diff --git a/rust/contacts/src/crypto.rs b/rust/contacts/src/crypto.rs
index b66c2a2a6c..425caac3bf 100644
--- a/rust/contacts/src/crypto.rs
+++ b/rust/contacts/src/crypto.rs
@@ -64,9 +64,6 @@ pub fn validate_contact_data(data: &ContactData) -> Result<()> {
"contact_user_id must be greater than 0".to_string(),
));
}
- if data.email.trim().is_empty() {
- return Err(ContactsError::InvalidInput("email is required".to_string()));
- }
if data.name.trim().is_empty() {
return Err(ContactsError::InvalidInput("name is required".to_string()));
}
diff --git a/rust/contacts/src/models.rs b/rust/contacts/src/models.rs
index d875d6340f..54a7a31b39 100644
--- a/rust/contacts/src/models.rs
+++ b/rust/contacts/src/models.rs
@@ -11,7 +11,6 @@ pub struct WrappedRootContactKey {
#[serde(rename_all = "camelCase")]
pub struct ContactData {
pub contact_user_id: i64,
- pub email: String,
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub birth_date: Option<String>,
diff --git a/rust/contacts/src/transport.rs b/rust/contacts/src/transport.rs
index 8d380caf6c..0961494014 100644
--- a/rust/contacts/src/transport.rs
+++ b/rust/contacts/src/transport.rs
@@ -38,6 +38,7 @@ pub struct ContactEntityResponse {
pub id: String,
#[serde(rename = "contactUserID")]
pub contact_user_id: i64,
+ pub email: Option<String>,
#[serde(rename = "profilePictureAttachmentID")]
pub profile_picture_attachment_id: Option<String>,
pub encrypted_key: Option<String>,
diff --git a/rust/contacts/tests/contacts_mock.rs b/rust/contacts/tests/contacts_mock.rs
index 969bc885b1..4c44b7535c 100644
--- a/rust/contacts/tests/contacts_mock.rs
+++ b/rust/contacts/tests/contacts_mock.rs
@@ -8,7 +8,6 @@ use mockito::{Matcher, Server};
fn sample_contact() -> ContactData {
ContactData {
contact_user_id: 42,
- email: "[email protected]".to_string(),
name: "B Test".to_string(),
birth_date: Some("2001-04-01".to_string()),
}
@@ -34,6 +33,7 @@ fn wrap_root(root_key: &[u8], master_key: &[u8]) -> WrappedRootContactKey {
fn live_entity_json(
id: &str,
data: &ContactData,
+ email: Option<&str>,
root_key: &[u8],
profile_picture_attachment_id: Option<&str>,
) -> serde_json::Value {
@@ -44,6 +44,7 @@ fn live_entity_json(
serde_json::json!({
"id": id,
"contactUserID": data.contact_user_id,
+ "email": email,
"profilePictureAttachmentID": profile_picture_attachment_id,
"encryptedKey": encrypted_key,
"encryptedData": encrypted_data,
@@ -93,6 +94,7 @@ async fn create_contact_uses_cached_root_key_but_confirms_before_write() {
let root_key = keys::generate_key();
let wrapped_root = wrap_root(&root_key, &master_key);
let contact = sample_contact();
+ let resolved_email = "[email protected]";
let root_mock = server
.mock("GET", "/user-entity/key")
@@ -119,7 +121,16 @@ async fn create_contact_uses_cached_root_key_but_confirms_before_write() {
"contactUserID": contact.contact_user_id
})))
.with_status(200)
- .with_body(live_entity_json("ct_contact1", &contact, &root_key, None).to_string())
+ .with_body(
+ live_entity_json(
+ "ct_contact1",
+ &contact,
+ Some(resolved_email),
+ &root_key,
+ None,
+ )
+ .to_string(),
+ )
.expect(1)
.create_async()
.await;
@@ -138,7 +149,7 @@ async fn create_contact_uses_cached_root_key_but_confirms_before_write() {
create_mock.assert_async().await;
assert_eq!(created.id, "ct_contact1");
assert_eq!(created.contact_user_id, contact.contact_user_id);
- assert_eq!(created.email.as_deref(), Some(contact.email.as_str()));
+ assert_eq!(created.email.as_deref(), Some(resolved_email));
}
#[tokio::test]
@@ -149,6 +160,7 @@ async fn set_profile_picture_uses_signed_upload_url_and_commit() {
let wrapped_root = wrap_root(&root_key, &master_key);
let contact = sample_contact();
let picture_bytes = b"profile-picture-bytes".to_vec();
+ let resolved_email = "[email protected]";
let root_mock = server
.mock("GET", "/user-entity/key")
@@ -167,7 +179,13 @@ async fn set_profile_picture_uses_signed_upload_url_and_commit() {
.create_async()
.await;
- let current_entity = live_entity_json("ct_picture1", &contact, &root_key, None);
+ let current_entity = live_entity_json(
+ "ct_picture1",
+ &contact,
+ Some(resolved_email),
+ &root_key,
+ None,
+ );
let get_contact_for_upload = server
.mock("GET", "/contacts/ct_picture1")
@@ -209,7 +227,13 @@ async fn set_profile_picture_uses_signed_upload_url_and_commit() {
.create_async()
.await;
- let attached_entity = live_entity_json("ct_picture1", &contact, &root_key, Some("ua_picture1"));
+ let attached_entity = live_entity_json(
+ "ct_picture1",
+ &contact,
+ Some(resolved_email),
+ &root_key,
+ Some("ua_picture1"),
+ );
let commit_mock = server
.mock("PUT", "/contacts/ct_picture1/profile-picture")
.with_status(200)
@@ -266,7 +290,13 @@ async fn get_profile_picture_uses_signed_download_url() {
.create_async()
.await;
- let attached_entity = live_entity_json("ct_picture1", &contact, &root_key, Some("ua_picture1"));
+ let attached_entity = live_entity_json(
+ "ct_picture1",
+ &contact,
+ &root_key,
+ Some("ua_picture1"),
+ );
let contact_key = contacts_crypto::unwrap_contact_key(
attached_entity["encryptedKey"].as_str().unwrap(),
&root_key,
diff --git a/rust/contacts/tests/live_contacts.rs b/rust/contacts/tests/live_contacts.rs
index 120d0c06b8..c1b5d20525 100644
--- a/rust/contacts/tests/live_contacts.rs
+++ b/rust/contacts/tests/live_contacts.rs
@@ -113,7 +113,6 @@ async fn live_contacts_crud_and_profile_picture_flow() {
let initial_data = ContactData {
contact_user_id: account_b.user_id,
- email: account_b.email.clone(),
name: "B Contact".to_string(),
birth_date: Some("2001-04-01".to_string()),
};
@@ -139,7 +138,6 @@ async fn live_contacts_crud_and_profile_picture_flow() {
&contact.id,
&ContactData {
contact_user_id: account_b.user_id,
- email: account_b.email.clone(),
name: "B Contact Updated".to_string(),
birth_date: Some("2001-04-02".to_string()),
},