Skip to content

feat(ov_api): add and delete ownership voucher in onboarding server #299

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

Closed
wants to merge 5 commits into from
Closed
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
79 changes: 79 additions & 0 deletions integration-tests/tests/ov_management.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
mod common;
use anyhow::{bail, Context, Result};
use common::{Binary, TestContext};

#[tokio::test]
async fn test_ov_management() -> Result<()> {
let mut ctx = TestContext::new().context("Error building test context")?;
// start server
let owner_onboarding_server = ctx
.start_test_server(
Binary::OwnerOnboardingServer,
|cfg| {
Ok(cfg.prepare_config_file(None, |cfg| {
cfg.insert("serviceinfo_api_server_port", &8083);
Ok(())
})?)
},
|_| Ok(()),
)
.context("Error creating owner server")?;
ctx.wait_until_servers_ready()
.await
.context("Error waiting for servers to start")?;

//sending request
let client = reqwest::Client::new();

let add_ov = client
.post(format!(
"http://localhost:{}/management/v1/ownership_voucher", //DevSkim: ignore DS137138
owner_onboarding_server.server_port().unwrap()
))
.header("Authorization", "Bearer TestAdminToken")
.header("X-Number-Of-Vouchers", "1")
.header("content-type", "application/x-pem-file")
.body("THIS IS A INVALID BODY")
.send()
.await?;
let mut failed = Vec::new();
if add_ov.status() != 400 {
failed.push(TestCase {
action: "Add OV",
error: format!("expected 400 got {}", add_ov.status()),
})
}

let ov_list: [&str; 1] = ["89cb17fd-95e7-4de8-a36a-686926a7f88f"];
let delete_ov = client
.post(format!(
"http://localhost:{}/management/v1/ownership_voucher/delete",

Check failure

Code scanning / devskim

Insecure URL

Insecure URL
owner_onboarding_server.server_port().unwrap()
))
.json(&ov_list)
.send()
.await?;
if delete_ov.status() != 400 {
failed.push(TestCase {
action: "Delete OV",
error: format!("expected 400 got {}", delete_ov.status()),
})
}

if failed.is_empty() {
Ok(())
} else {
for failed_case in failed {
eprintln!("Failed test: {:?}", failed_case);
}
bail!("Some tests failed");
}
}

#[derive(Debug)]
struct TestCase {
#[allow(dead_code)]
action: &'static str,
#[allow(dead_code)]
error: String,
}
1 change: 1 addition & 0 deletions owner-onboarding-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ serde_bytes = "0.11"
serde_cbor = "0.11"
log = "0.4"
serde_yaml = "0.8"
serde_json = "1.0.79"
time = "0.3"
hex = "0.4"

Expand Down
5 changes: 4 additions & 1 deletion owner-onboarding-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ use fdo_util::servers::{
};

mod handlers;
mod ov_management;
use crate::ov_management::ov_filter;

pub(crate) struct OwnerServiceUD {
// Trusted keys
Expand Down Expand Up @@ -426,7 +428,8 @@ async fn main() -> Result<()> {
.or(handler_to2_prove_device)
.or(handler_to2_device_service_info_ready)
.or(handler_to2_device_service_info)
.or(handler_to2_done),
.or(handler_to2_done)
.or(ov_filter(user_data.clone())),
)
.recover(fdo_http_wrapper::server::handle_rejection)
.with(warp::log("owner-onboarding-service"));
Expand Down
Loading