Skip to content

Commit

Permalink
HPR route service list get (#837)
Browse files Browse the repository at this point in the history
* Remove dbg! in test

* Allow HPR/Oracle/Admin keys to sign for route getters

Allowed to list routes for an OUI.
Allowed to get a specific route with an ID.

This allows HPR to add a mechanism to refresh route details without resetting the stream and needing to parse all the configuration again.
  • Loading branch information
michaeldjeffrey authored Jul 8, 2024
1 parent e55bfaa commit d9f411b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
4 changes: 2 additions & 2 deletions iot_config/src/route_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl iot_config::Route for RouteService {
custom_tracing::record_b58("signer", &request.signer);

let signer = verify_public_key(&request.signer)?;
self.verify_request_signature(&signer, &request, OrgId::Oui(request.oui))
self.verify_request_signature_or_stream(&signer, &request, OrgId::Oui(request.oui))
.await?;

tracing::debug!("list routes");
Expand Down Expand Up @@ -224,7 +224,7 @@ impl iot_config::Route for RouteService {
custom_tracing::record_b58("signer", &request.signer);

let signer = verify_public_key(&request.signer)?;
self.verify_request_signature(&signer, &request, OrgId::RouteId(&request.id))
self.verify_request_signature_or_stream(&signer, &request, OrgId::RouteId(&request.id))
.await?;

tracing::debug!(route_id = request.id, "get route");
Expand Down
51 changes: 45 additions & 6 deletions iot_config/tests/route_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use chrono::Utc;
use futures::{Future, StreamExt, TryFutureExt};
use helium_crypto::{KeyTag, Keypair, PublicKey, Sign};
use helium_proto::services::iot_config::{
self as proto, config_org_client::OrgClient, config_route_client::RouteClient, RouteStreamReqV1,
self as proto, config_org_client::OrgClient, config_route_client::RouteClient, RouteGetReqV1,
RouteListReqV1, RouteStreamReqV1,
};
use iot_config::{
admin::{AuthCache, KeyType},
Expand All @@ -24,6 +25,48 @@ use tonic::{
Streaming,
};

#[sqlx::test]
async fn packet_router_can_access_route_list(pool: Pool<Postgres>) {
let signing_keypair = Arc::new(generate_keypair());
let admin_keypair = generate_keypair();
let client_keypair = generate_keypair();

let socket_addr = get_socket_addr().expect("socket addr");

let auth_cache = create_auth_cache(
admin_keypair.public_key().clone(),
client_keypair.public_key().clone(),
&pool,
)
.await;

let _handle = start_server(socket_addr, signing_keypair, auth_cache, pool.clone()).await;
let mut client = connect_client(socket_addr).await;

let org = create_org(socket_addr, &admin_keypair).await;
let route = create_route(&mut client, &org.org.unwrap(), &admin_keypair).await;

// List Routes for OUI
let mut list_request = RouteListReqV1 {
oui: 1,
timestamp: Utc::now().timestamp() as u64,
signer: client_keypair.public_key().to_vec(),
signature: vec![],
};
list_request.signature = client_keypair.sign(&list_request.encode_to_vec()).unwrap();
assert!(client.list(list_request).await.is_ok());

// Get Route
let mut get_request = RouteGetReqV1 {
id: route.id.clone(),
timestamp: Utc::now().timestamp() as u64,
signer: client_keypair.public_key().to_vec(),
signature: vec![],
};
get_request.signature = client_keypair.sign(&get_request.encode_to_vec()).unwrap();
assert!(client.get(get_request).await.is_ok());
}

#[sqlx::test]
async fn stream_sends_all_data_when_since_is_0(pool: Pool<Postgres>) {
let signing_keypair = Arc::new(generate_keypair());
Expand Down Expand Up @@ -295,7 +338,6 @@ async fn assert_route_received(
expected_id: &str,
) {
let msg = receive(stream.next()).await;
dbg!(&msg);
let Ok(proto::RouteStreamResV1 {
action,
data: Some(proto::route_stream_res_v1::Data::Route(streamed_route)),
Expand Down Expand Up @@ -425,10 +467,7 @@ where
T: std::fmt::Debug,
{
match tokio::time::timeout(std::time::Duration::from_secs(5), future).await {
Ok(Some(t)) => {
dbg!(&t);
t
}
Ok(Some(t)) => t,
_other => panic!("message was not received within 5 seconds"),
}
}
Expand Down

0 comments on commit d9f411b

Please sign in to comment.