From 4939f76d606849cc1f9824d1e388c213cf4ccdaf Mon Sep 17 00:00:00 2001 From: Macpie Date: Thu, 6 Jun 2024 13:06:14 -0700 Subject: [PATCH] Make CoverageObjectReqV1 valid --- .../post_migration/mobile_config-pubkeys.sql | 14 ++++++++++ test_mobile/README.md | 4 ++- test_mobile/tests/common/hotspot.rs | 24 ++++++++++-------- test_mobile/tests/common/mod.rs | 20 +++++++++++++-- test_mobile/tests/integration_test.rs | 8 ++++-- test_mobile/tests/pc_keypair.bin | Bin 0 -> 65 bytes 6 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 test_mobile/tests/pc_keypair.bin diff --git a/docker/mobile/postgres_seeder/post_migration/mobile_config-pubkeys.sql b/docker/mobile/postgres_seeder/post_migration/mobile_config-pubkeys.sql index 4949d45ef..88d2ac497 100644 --- a/docker/mobile/postgres_seeder/post_migration/mobile_config-pubkeys.sql +++ b/docker/mobile/postgres_seeder/post_migration/mobile_config-pubkeys.sql @@ -37,5 +37,19 @@ VALUES 'verifier' ) ON CONFLICT (pubkey, key_role) DO UPDATE +SET + updated_at = CURRENT_TIMESTAMP; + +INSERT INTO + registered_keys (pubkey, key_role, created_at, updated_at, name) +VALUES + ( + '13te9quF3s24VNrQmBRHnoNSwWPg48Jh2hfJdqFQoiFYiDcDAsp', + 'pcs', + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP, + 'Authorized Coverage Object Key' + ) ON CONFLICT (pubkey, key_role) DO +UPDATE SET updated_at = CURRENT_TIMESTAMP; \ No newline at end of file diff --git a/test_mobile/README.md b/test_mobile/README.md index 9d2939f47..749a8b3f7 100644 --- a/test_mobile/README.md +++ b/test_mobile/README.md @@ -21,4 +21,6 @@ **NOTE:** The test will `docker compose up` on start and `docker compose stop` at the end. It is up to **you** to `docker compose down` if you want to clean up. [^files]: Maps of hexes used -![Hexes](docs/hexes.jpg "Hexes") \ No newline at end of file +![Hexes](docs/hexes.jpg "Hexes") + +key pair for coverage object `13te9quF3s24VNrQmBRHnoNSwWPg48Jh2hfJdqFQoiFYiDcDAsp` \ No newline at end of file diff --git a/test_mobile/tests/common/hotspot.rs b/test_mobile/tests/common/hotspot.rs index dad841e9f..33574cbc5 100644 --- a/test_mobile/tests/common/hotspot.rs +++ b/test_mobile/tests/common/hotspot.rs @@ -2,20 +2,19 @@ use anyhow::Result; use backon::{ExponentialBuilder, Retryable}; use chrono::Utc; use h3o::CellIndex; -use helium_crypto::{KeyTag, Keypair, PublicKeyBinary, Sign}; +use helium_crypto::{Keypair, PublicKeyBinary, Sign}; use helium_proto::services::poc_mobile::{ coverage_object_req_v1::KeyType, Client as PocMobileClient, CoverageObjectReqV1, RadioHexSignalLevel, SpeedtestReqV1, WifiHeartbeatReqV1, }; use prost::Message; -use rand::rngs::OsRng; use sqlx::postgres::PgPoolOptions; -use std::str::FromStr; +use std::{str::FromStr, sync::Arc}; use tonic::{metadata::MetadataValue, transport::Channel, Request}; use tracing::instrument; use uuid::Uuid; -use crate::common::{hours_ago, now, TimestampToDateTime}; +use crate::common::{generate_keypair, hours_ago, now, TimestampToDateTime}; #[derive(Debug)] pub struct Hotspot { @@ -36,8 +35,8 @@ impl Hotspot { .await .expect("client connect"); - let keypair = Keypair::generate(KeyTag::default(), &mut OsRng); - let wallet = Keypair::generate(KeyTag::default(), &mut OsRng); + let keypair = generate_keypair(); + let wallet = generate_keypair(); let b58 = keypair.public_key().to_string(); tracing::info!(hotspot = b58, "hotspot connected to ingester"); @@ -98,12 +97,16 @@ impl Hotspot { } #[instrument(skip(self), fields(hotspot = %self.b58))] - pub async fn submit_coverage_object(&mut self, uuid: Uuid) -> Result<()> { + pub async fn submit_coverage_object( + &mut self, + uuid: Uuid, + pcs_keypair: Arc, + ) -> Result<()> { let coverage_claim_time = now() - hours_ago(24); let pub_key = self.keypair.public_key().to_vec(); let mut coverage_object_req = CoverageObjectReqV1 { - pub_key: pub_key.clone(), + pub_key: pcs_keypair.public_key().to_vec(), uuid: uuid.as_bytes().to_vec(), coverage_claim_time, coverage: vec![RadioHexSignalLevel { @@ -117,8 +120,7 @@ impl Hotspot { key_type: Some(KeyType::HotspotKey(pub_key)), }; - coverage_object_req.signature = self - .keypair + coverage_object_req.signature = pcs_keypair .sign(&coverage_object_req.encode_to_vec()) .expect("sign"); @@ -266,5 +268,7 @@ async fn populate_mobile_metadata( .execute(&pool) .await?; + pool.close().await; + Ok(()) } diff --git a/test_mobile/tests/common/mod.rs b/test_mobile/tests/common/mod.rs index 33090ff04..38b53cc6f 100644 --- a/test_mobile/tests/common/mod.rs +++ b/test_mobile/tests/common/mod.rs @@ -1,6 +1,12 @@ -use std::time::{SystemTime, UNIX_EPOCH}; - +use anyhow::Result; use chrono::{DateTime, NaiveDateTime, TimeZone, Utc}; +use helium_crypto::{KeyTag, Keypair}; +use rand::rngs::OsRng; +use std::{ + sync::Arc, + time::{SystemTime, UNIX_EPOCH}, +}; +use tracing::instrument; pub mod docker; pub mod hotspot; @@ -28,3 +34,13 @@ pub fn now() -> u64 { pub fn hours_ago(hours: i64) -> u64 { chrono::Duration::hours(hours).num_milliseconds() as u64 } + +pub fn generate_keypair() -> Keypair { + Keypair::generate(KeyTag::default(), &mut OsRng) +} + +pub async fn load_pcs_keypair() -> Result> { + let data = std::fs::read("tests/pc_keypair.bin").map_err(helium_crypto::Error::from)?; + let pcs_keypair = Arc::new(helium_crypto::Keypair::try_from(&data[..])?); + Ok(pcs_keypair) +} diff --git a/test_mobile/tests/integration_test.rs b/test_mobile/tests/integration_test.rs index 2b25e1f98..4039ec724 100644 --- a/test_mobile/tests/integration_test.rs +++ b/test_mobile/tests/integration_test.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use common::{docker::Docker, hotspot::Hotspot, hours_ago}; +use common::{docker::Docker, hotspot::Hotspot, hours_ago, load_pcs_keypair}; use test_mobile::cli::assignment::CENTER_CELL; use uuid::Uuid; @@ -24,12 +24,16 @@ async fn main() -> Result<()> { } } + let pcs_keypair = load_pcs_keypair().await?; + let api_token = "api-token".to_string(); let mut hotspot1 = Hotspot::new(api_token, CENTER_CELL).await?; let co_uuid = Uuid::new_v4(); - hotspot1.submit_coverage_object(co_uuid).await?; + hotspot1 + .submit_coverage_object(co_uuid, pcs_keypair.clone()) + .await?; hotspot1 .submit_speedtest(500_000_000, 500_000_000, 25) diff --git a/test_mobile/tests/pc_keypair.bin b/test_mobile/tests/pc_keypair.bin new file mode 100644 index 0000000000000000000000000000000000000000..29d23f31913c9247242418d67222f7a0a2e8ec2c GIT binary patch literal 65 zcmV-H0KWeLGGNV|TWCQC94b_ZiPVmvS$YG{U6|TG_y9~J?V-K>e5L()l_g3j=GSv# XC?0*0JniVrFXI4Ld~YC4u*?is$=4n} literal 0 HcmV?d00001