Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPR route service list get #837

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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