From 7dd702cdeb9697b4a0dda9871e015a9574d6283d Mon Sep 17 00:00:00 2001 From: Kevin Swiber Date: Sat, 25 Nov 2023 14:33:25 -0800 Subject: [PATCH] Adding tests for operation auth security. --- src/lib.rs | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 1301387..14260f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1707,6 +1707,74 @@ mod tests { } } + #[test] + fn it_uses_the_security_requirement_on_operations() { + let spec: Spec = serde_json::from_str(get_fixture("echo.postman.json").as_ref()).unwrap(); + let oas = Transpiler::transpile(spec); + match oas { + OpenApi::V3_0(oas) => { + let sr1 = oas + .paths + .get("/basic-auth") + .unwrap() + .get + .as_ref() + .unwrap() + .security + .as_ref() + .unwrap(); + assert_eq!( + sr1.get(0) + .unwrap() + .requirement + .as_ref() + .unwrap() + .get("basicAuth"), + Some(&vec![]) + ); + let sr1 = oas + .paths + .get("/digest-auth") + .unwrap() + .get + .as_ref() + .unwrap() + .security + .as_ref() + .unwrap(); + assert_eq!( + sr1.get(0) + .unwrap() + .requirement + .as_ref() + .unwrap() + .get("digestAuth"), + Some(&vec![]) + ); + + let schemes = oas.components.unwrap().security_schemes.unwrap(); + let basic = schemes.get("basicAuth").unwrap(); + if let ObjectOrReference::Object(basic) = basic { + match basic { + openapi3::SecurityScheme::Http { scheme, .. } => { + assert_eq!(scheme, "basic"); + } + _ => panic!("Expected Http Security Scheme"), + } + } + let digest = schemes.get("digestAuth").unwrap(); + if let ObjectOrReference::Object(digest) = digest { + match digest { + openapi3::SecurityScheme::Http { scheme, .. } => { + assert_eq!(scheme, "digest"); + } + _ => panic!("Expected Http Security Scheme"), + } + } + } + } + } + fn get_fixture(filename: &str) -> String { use std::fs;