diff --git a/test-fixtures/Cargo.lock b/test-fixtures/Cargo.lock index 0d03918a..1fd82704 100644 --- a/test-fixtures/Cargo.lock +++ b/test-fixtures/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "anyhow" @@ -109,28 +109,49 @@ dependencies = [ "syn 2.0.90", ] +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "elsa" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d98e71ae4df57d214182a2e5cb90230c0192c6ddfcaa05c36453d46a54713e10" dependencies = [ + "indexmap", "stable_deref_trait", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "fastly" -version = "0.10.5" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291f8c77eadfb49f5c258263c4d020143ac00d8b6170cd0c3e8c2e7f15ef2b61" +checksum = "4ddcf5f0d4fedd66a2636a9d04469a8aa62557f82e12d04115a67cbb82b670c0" dependencies = [ "anyhow", "bytes", + "downcast-rs", "elsa", "fastly-macros", "fastly-shared", "fastly-sys", "http", + "itertools", "lazy_static", "mime", "serde", @@ -145,9 +166,9 @@ dependencies = [ [[package]] name = "fastly-macros" -version = "0.10.5" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "318a46d3977f84c106a295b232f73c6553b6c61cfcfd34aa487038e495486285" +checksum = "5e3d69c42f2006e5e774babaecc829a63f4bfd8f845a80bd1553473bfe789b39" dependencies = [ "proc-macro2", "quote", @@ -156,9 +177,9 @@ dependencies = [ [[package]] name = "fastly-shared" -version = "0.10.5" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3d3fae2a497c92302b8f86365c26027345800ead360c758ed6dc25f743fbde" +checksum = "dd73cda7d97b4abe3c3bee2bd78941157413037792c8a685cbcaacfa636380dc" dependencies = [ "bitflags", "http", @@ -166,9 +187,9 @@ dependencies = [ [[package]] name = "fastly-sys" -version = "0.10.5" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a916457afd05221a21c766a4d5f8a32189bc337da45fff5f2ec073170b4985" +checksum = "b8ee1f2773576f963b1841c825b569f1cb2a59a4dbff8348e1b72f22e6e01da3" dependencies = [ "bitflags", "fastly-shared", @@ -199,6 +220,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" + [[package]] name = "hex-literal" version = "0.4.1" @@ -355,6 +382,25 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "indexmap" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.14" diff --git a/test-fixtures/Cargo.toml b/test-fixtures/Cargo.toml index e9701691..ec7a8049 100644 --- a/test-fixtures/Cargo.toml +++ b/test-fixtures/Cargo.toml @@ -7,17 +7,12 @@ edition = "2021" license = "Apache-2.0 WITH LLVM-exception" publish = false -[features] -# Temporary feature used until the fastly SDK is updated -# to a version which contains the fastly_acl hostcalls. -acl_hostcalls = [] - [dependencies] anyhow = "1.0.86" base64 = "0.21.2" -fastly = "0.10.4" -fastly-shared = "0.10.4" -fastly-sys = "0.10.4" +fastly = "0.11.1" +fastly-shared = "0.11.1" +fastly-sys = "0.11.1" hex-literal = "0.4.1" bytes = "1.0.0" http = "1.1.0" diff --git a/test-fixtures/src/bin/acl.rs b/test-fixtures/src/bin/acl.rs index a21b74ef..691f468c 100644 --- a/test-fixtures/src/bin/acl.rs +++ b/test-fixtures/src/bin/acl.rs @@ -1,62 +1,56 @@ //! A guest program to test that acls works properly. +use fastly::acl::Acl; use fastly::Error; +use std::net::{Ipv4Addr, Ipv6Addr}; fn main() -> Result<(), Error> { - // Temporary until fastly SDK is released which - // includes the fastly::acl module. - #[cfg(feature = "acl_hostcalls")] - { - use fastly::acl::Acl; - use std::net::{Ipv4Addr, Ipv6Addr}; - - match Acl::open("DOES-NOT-EXIST") { - Err(fastly::acl::OpenError::AclNotFound) => { /* OK */ } - Err(other) => panic!("expected error opening non-existant acl, got: {:?}", other), - _ => panic!("expected error opening non-existant acl, got Ok"), - } + match Acl::open("DOES-NOT-EXIST") { + Err(fastly::acl::OpenError::AclNotFound) => { /* OK */ } + Err(other) => panic!("expected error opening non-existant acl, got: {:?}", other), + _ => panic!("expected error opening non-existant acl, got Ok"), + } - let acl1 = Acl::open("my-acl-1")?; + let acl1 = Acl::open("my-acl-1")?; - match acl1.try_lookup(Ipv4Addr::new(192, 168, 1, 1).into())? { - Some(lookup_match) => { - assert_eq!(lookup_match.prefix(), "192.168.0.0/16"); - assert!(lookup_match.is_block()); - } - None => panic!("expected match"), - }; - match acl1.try_lookup(Ipv4Addr::new(23, 23, 23, 23).into())? { - Some(lookup_match) => { - assert_eq!(lookup_match.prefix(), "23.23.23.23/32"); - assert!(lookup_match.is_allow()); - } - None => panic!("expected match"), - }; - if let Some(lookup_match) = acl1.try_lookup(Ipv4Addr::new(100, 100, 100, 100).into())? { - panic!("expected no match, got: {:?}", lookup_match); + match acl1.try_lookup(Ipv4Addr::new(192, 168, 1, 1).into())? { + Some(lookup_match) => { + assert_eq!(lookup_match.prefix(), "192.168.0.0/16"); + assert!(lookup_match.is_block()); + } + None => panic!("expected match"), + }; + match acl1.try_lookup(Ipv4Addr::new(23, 23, 23, 23).into())? { + Some(lookup_match) => { + assert_eq!(lookup_match.prefix(), "23.23.23.23/32"); + assert!(lookup_match.is_allow()); } + None => panic!("expected match"), + }; + if let Some(lookup_match) = acl1.try_lookup(Ipv4Addr::new(100, 100, 100, 100).into())? { + panic!("expected no match, got: {:?}", lookup_match); + } - let acl2 = Acl::open("my-acl-2")?; + let acl2 = Acl::open("my-acl-2")?; - match acl2.try_lookup(Ipv6Addr::new(0x2000, 0, 0, 0, 0, 1, 2, 3).into())? { - Some(lookup_match) => { - assert_eq!(lookup_match.prefix(), "2000::/24"); - assert!(lookup_match.is_block()); - } - None => panic!("expected match"), - }; - match acl2.try_lookup(Ipv6Addr::new(0xFACE, 0, 2, 3, 4, 5, 6, 7).into())? { - Some(lookup_match) => { - assert_eq!(lookup_match.prefix(), "face::/16"); - assert!(lookup_match.is_allow()); - } - None => panic!("expected match"), - }; - if let Some(lookup_match) = - acl2.try_lookup(Ipv6Addr::new(0xFADE, 1, 2, 3, 4, 5, 6, 7).into())? - { - panic!("expected no match, got: {:?}", lookup_match); - }; - } + match acl2.try_lookup(Ipv6Addr::new(0x2000, 0, 0, 0, 0, 1, 2, 3).into())? { + Some(lookup_match) => { + assert_eq!(lookup_match.prefix(), "2000::/24"); + assert!(lookup_match.is_block()); + } + None => panic!("expected match"), + }; + match acl2.try_lookup(Ipv6Addr::new(0xFACE, 0, 2, 3, 4, 5, 6, 7).into())? { + Some(lookup_match) => { + assert_eq!(lookup_match.prefix(), "face::/16"); + assert!(lookup_match.is_allow()); + } + None => panic!("expected match"), + }; + if let Some(lookup_match) = + acl2.try_lookup(Ipv6Addr::new(0xFADE, 1, 2, 3, 4, 5, 6, 7).into())? + { + panic!("expected no match, got: {:?}", lookup_match); + }; Ok(()) } diff --git a/test-fixtures/src/bin/inspect.rs b/test-fixtures/src/bin/inspect.rs index 6b2fef16..fe2226ac 100644 --- a/test-fixtures/src/bin/inspect.rs +++ b/test-fixtures/src/bin/inspect.rs @@ -1,10 +1,10 @@ -use fastly::experimental::{inspect, InspectConfig, InspectError, InspectVerdict}; -use fastly::handle::{BodyHandle, RequestHandle}; -use fastly::http::{HeaderName, HeaderValue, Method, StatusCode}; +use fastly::handle::BodyHandle; +use fastly::http::StatusCode; +use fastly::security::{inspect, InspectConfig}; use fastly::{Error, Request, Response}; #[fastly::main] -fn main(mut req: Request) -> Result { +fn main(req: Request) -> Result { let (req, body) = req.into_handles(); let body = body.unwrap_or_else(BodyHandle::new); @@ -16,21 +16,19 @@ fn main(mut req: Request) -> Result { Ok(x) => { let body = format!( "inspect result: waf_response={}, tags={:?}, decision_ms={}ms, verdict={:?}", - x.waf_response(), + x.status(), x.tags(), x.decision_ms().as_millis(), x.verdict() ); - Response::from_status(StatusCode::OK) - .with_body_text_plain(&body) + Response::from_status(StatusCode::OK).with_body_text_plain(&body) } Err(e) => { let body = format!("Error: {e:?}"); - Response::from_status(StatusCode::BAD_REQUEST) - .with_body_text_plain(&body) - }, + Response::from_status(StatusCode::BAD_REQUEST).with_body_text_plain(&body) + } }; Ok(resp) diff --git a/test-fixtures/src/bin/kv_store.rs b/test-fixtures/src/bin/kv_store.rs index eccd5933..6d344720 100644 --- a/test-fixtures/src/bin/kv_store.rs +++ b/test-fixtures/src/bin/kv_store.rs @@ -1,30 +1,43 @@ //! A guest program to test that KV store works properly. -use fastly::kv_store::{KVStore, KVStoreError::KVStoreNotFound}; +use fastly::kv_store::{ + KVStore, + KVStoreError::{ItemNotFound, StoreNotFound}, +}; fn main() { // Check we can't get a store that does not exist match KVStore::open("non_existant") { - Err(KVStoreNotFound(_)) => {} + Err(StoreNotFound(_)) => {} _ => panic!(), } let store_one = KVStore::open("store_one").unwrap().unwrap(); // Test that we can get data using the `data` config key assert_eq!( - store_one.lookup_str("first").unwrap().unwrap(), + store_one.lookup("first").unwrap().take_body().into_string(), "This is some data" ); // Test that we can get data from a file using the `path` config key assert_eq!( - store_one.lookup_str("second").unwrap().unwrap(), + store_one + .lookup("second") + .unwrap() + .take_body() + .into_string(), "More data" ); - let mut empty_store = KVStore::open("empty_store").unwrap().unwrap(); + let empty_store = KVStore::open("empty_store").unwrap().unwrap(); // Check that the value "bar" is not in the store - assert_eq!(empty_store.lookup_str("bar"), Ok(None)); + match empty_store.lookup("bar") { + Err(ItemNotFound) => {} + _ => panic!(), + } empty_store.insert("bar", "foo").unwrap(); // Check that the value "bar" is now in the store - assert_eq!(empty_store.lookup_str("bar").unwrap().unwrap(), "foo"); + assert_eq!( + empty_store.lookup("bar").unwrap().take_body().into_string(), + "foo" + ); }