Skip to content

Commit 3ea5a3e

Browse files
committed
feat: Report key creation times
1 parent 2f3e446 commit 3ea5a3e

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/self_reporting.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::config::Config;
1212
use crate::constants::{Chattype, DC_CHAT_ID_TRASH};
1313
use crate::contact::{ContactId, Origin, import_vcard, mark_contact_id_as_verified};
1414
use crate::context::{Context, get_version_str};
15-
use crate::key::load_self_public_key;
15+
use crate::key::load_self_public_keyring;
1616
use crate::log::LogExt;
1717
use crate::message::{Message, Viewtype};
1818
use crate::tools::{create_id, time};
@@ -23,7 +23,7 @@ const SELF_REPORTING_BOT_VCARD: &str = include_str!("../assets/self-reporting-bo
2323
#[derive(Serialize)]
2424
struct Statistics {
2525
core_version: String,
26-
key_created: i64,
26+
key_created: Vec<i64>,
2727
self_reporting_id: String,
2828
is_chatmail: bool,
2929
contact_stats: Vec<ContactStat>,
@@ -166,11 +166,11 @@ async fn get_self_report(context: &Context) -> Result<String> {
166166
.get_config_u64(Config::SelfReportingLastMsgId)
167167
.await?;
168168

169-
let key_created = load_self_public_key(context)
169+
let key_created: Vec<i64> = load_self_public_keyring(context)
170170
.await?
171-
.primary_key
172-
.created_at()
173-
.timestamp();
171+
.iter()
172+
.map(|k| k.created_at().timestamp())
173+
.collect();
174174

175175
let self_reporting_id = match context.get_config(Config::SelfReportingId).await? {
176176
Some(id) => id,

src/self_reporting/self_reporting_tests.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::securejoin::{get_securejoin_qr, join_securejoin, join_securejoin_with
77
use crate::test_utils::{TestContext, TestContextManager, get_chat_msg};
88
use crate::tools::SystemTime;
99
use pretty_assertions::assert_eq;
10+
use serde_json::{Number, Value};
1011

1112
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
1213
async fn test_send_self_report() -> Result<()> {
@@ -268,3 +269,24 @@ async fn test_self_report_is_chatmail() -> Result<()> {
268269

269270
Ok(())
270271
}
272+
273+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
274+
async fn test_self_report_key_creation_timestamp() -> Result<()> {
275+
// Alice uses a pregenerated key. It was created at this timestamp:
276+
const ALICE_KEY_CREATION_TIME: u128 = 1582855645;
277+
278+
let alice = &TestContext::new_alice().await;
279+
alice.set_config_bool(Config::SelfReporting, true).await?;
280+
281+
let r = get_self_report(alice).await?;
282+
let r: serde_json::Value = serde_json::from_str(&r)?;
283+
let key_created = r.get("key_created").unwrap().as_array().unwrap();
284+
assert_eq!(
285+
key_created,
286+
&vec![Value::Number(
287+
Number::from_u128(ALICE_KEY_CREATION_TIME).unwrap()
288+
)]
289+
);
290+
291+
Ok(())
292+
}

0 commit comments

Comments
 (0)