-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds support for two new hostcalls: - fastly_acl::open - fastly_acl::lookup
- Loading branch information
1 parent
274230f
commit eeac2f4
Showing
26 changed files
with
1,019 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
use crate::{common::Test, common::TestResult, viceroy_test}; | ||
use hyper::{body::to_bytes, StatusCode}; | ||
use viceroy_lib::config::FastlyConfig; | ||
use viceroy_lib::error::{AclConfigError, FastlyConfigError}; | ||
|
||
viceroy_test!(acl_works, |is_component| { | ||
const FASTLY_TOML: &str = r#" | ||
name = "acl" | ||
description = "acl test" | ||
authors = ["Test User <[email protected]>"] | ||
language = "rust" | ||
[local_server] | ||
acls.my-acl-1 = "../test-fixtures/data/my-acl-1.json" | ||
acls.my-acl-2 = {file = "../test-fixtures/data/my-acl-2.json"} | ||
"#; | ||
|
||
let resp = Test::using_fixture("acl.wasm") | ||
.adapt_component(is_component) | ||
.using_fastly_toml(FASTLY_TOML)? | ||
.log_stderr() | ||
.log_stdout() | ||
.against_empty() | ||
.await?; | ||
|
||
assert_eq!(resp.status(), StatusCode::OK); | ||
assert!(to_bytes(resp.into_body()) | ||
.await | ||
.expect("can read body") | ||
.to_vec() | ||
.is_empty()); | ||
|
||
Ok(()) | ||
}); | ||
|
||
fn bad_config_test(local_server_fragment: &str) -> Result<FastlyConfig, FastlyConfigError> { | ||
let toml = format!( | ||
r#" | ||
name = "acl" | ||
description = "acl test" | ||
authors = ["Test User <[email protected]>"] | ||
language = "rust" | ||
[local_server] | ||
{} | ||
"#, | ||
local_server_fragment | ||
); | ||
|
||
toml.parse::<FastlyConfig>() | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn bad_config_invalid_path() -> TestResult { | ||
const TOML_FRAGMENT: &str = "acls.bad = 1"; | ||
match bad_config_test(TOML_FRAGMENT) { | ||
Err(FastlyConfigError::InvalidAclDefinition { | ||
err: AclConfigError::InvalidType, | ||
.. | ||
}) => (), | ||
Err(_) => panic!( | ||
"expected a FastlyConfigError::InvalidAclDefinition with AclConfigError::InvalidType" | ||
), | ||
_ => panic!("Expected an error"), | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn bad_config_missing_key() -> TestResult { | ||
const TOML_FRAGMENT: &str = "acls.bad = { \"other\" = true }"; | ||
match bad_config_test(TOML_FRAGMENT) { | ||
Err(FastlyConfigError::InvalidAclDefinition { | ||
err: AclConfigError::MissingFile, | ||
.. | ||
}) => (), | ||
Err(_) => panic!( | ||
"expected a FastlyConfigError::InvalidAclDefinition with AclConfigError::MissingFile" | ||
), | ||
_ => panic!("Expected an error"), | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn bad_config_missing_file() -> TestResult { | ||
const TOML_FRAGMENT: &str = "acls.bad = \"/does/not/exist\""; | ||
match bad_config_test(TOML_FRAGMENT) { | ||
Err(FastlyConfigError::InvalidAclDefinition { | ||
err: AclConfigError::IoError(_), | ||
.. | ||
}) => (), | ||
Err(_) => panic!( | ||
"expected a FastlyConfigError::InvalidAclDefinition with AclConfigError::IoError" | ||
), | ||
_ => panic!("Expected an error"), | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn bad_config_invalid_json() -> TestResult { | ||
const TOML_FRAGMENT: &str = "acls.bad = \"../Cargo.toml\""; | ||
match bad_config_test(TOML_FRAGMENT) { | ||
Err(FastlyConfigError::InvalidAclDefinition { | ||
err: AclConfigError::JsonError(_), | ||
.. | ||
}) => (), | ||
Err(_) => panic!( | ||
"expected a FastlyConfigError::InvalidAclDefinition with AclConfigError::JsonError" | ||
), | ||
_ => panic!("Expected an error"), | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod acl; | ||
mod args; | ||
mod async_io; | ||
mod body; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.