From f46acec96f595b6b42dc4c004e4a262674176cbc Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Fri, 29 Jul 2022 10:35:15 +0100 Subject: [PATCH] Ensure error is returned when NS/DB header are not present --- src/err/mod.rs | 6 ++++++ src/net/export.rs | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/err/mod.rs b/src/err/mod.rs index 18045988..755acad6 100644 --- a/src/err/mod.rs +++ b/src/err/mod.rs @@ -14,6 +14,12 @@ pub enum Error { #[error("The request body contains invalid data")] Request, + #[error("There was no NS header present in the request")] + NoNsHeader, + + #[error("There was no DB header present in the request")] + NoDbHeader, + #[error("There was a problem with authentication")] InvalidAuth, diff --git a/src/net/export.rs b/src/net/export.rs index cf0ee26b..ae13b00f 100644 --- a/src/net/export.rs +++ b/src/net/export.rs @@ -21,9 +21,15 @@ async fn handler(session: Session) -> Result // Get the datastore reference let db = DB.get().unwrap(); // Extract the NS header value - let nsv = session.ns.clone().unwrap(); + let nsv = match session.ns { + Some(ns) => ns, + None => return Err(warp::reject::custom(Error::NoNsHeader)), + }; // Extract the DB header value - let dbv = session.db.clone().unwrap(); + let dbv = match session.db { + Some(db) => db, + None => return Err(warp::reject::custom(Error::NoDbHeader)), + }; // Create a chunked response let (mut chn, bdy) = Body::channel(); // Create a new bounded channel