Skip to content

Commit 360f2ce

Browse files
committed
tests(compute-static): remove integration test using hacky Python script
tests(compute-static): add specific test for http method filter function ci(compute-static): install cargo-nextest and viceroy via taiki-e/install-action chore(compute-static): revert toolchain back to stable since fastly compute now works again on Rust 1.91.1
1 parent 3b16d8b commit 360f2ce

File tree

6 files changed

+24
-61
lines changed

6 files changed

+24
-61
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ jobs:
1414
- name: Install Rust stable
1515
run: rustup update stable && rustup default stable && rustup component add clippy rustfmt
1616

17+
- name: Install tools for compute-static tests
18+
uses: taiki-e/install-action@493d7f216ecab2af0602481ce809ab2c72836fa1 # v2.62.62
19+
with:
20+
tool: cargo-nextest,viceroy
21+
1722
- name: Run rustfmt
1823
run: cargo fmt --all -- --check
1924

@@ -25,10 +30,7 @@ jobs:
2530

2631
- name: Run compute-static tests
2732
working-directory: terragrunt/modules/crates-io/compute-static
28-
run: |
29-
curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
30-
cargo install --locked viceroy --version 0.15.0
31-
./scripts/run_tests.sh
33+
run: cargo nextest run
3234

3335
terraform:
3436
name: Terraform configuration

terragrunt/modules/crates-io/compute-static/README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,10 @@ Then, install [Viceroy](https://github.com/fastly/Viceroy) to run the edge funct
3434
cargo install --locked viceroy
3535
```
3636

37-
Due to the fact Viceroy does not allow easily mocking HTTP requests being sent (
38-
see [issue](https://github.com/fastly/Viceroy/issues/442)), some tests use a small Python HTTP
39-
server to work.
40-
For this reason, a wrapper bash script is provided that runs `cargo nextest run` with the test server active in
41-
background. You can therefore run the tests with:
42-
:
37+
Finally, run the tests:
4338

4439
```shell
45-
./run_tests.sh
40+
cargo nextest run
4641
```
4742

4843
## Deployment
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.90"
2+
channel = "stable"
33
targets = ["wasm32-wasip1"]

terragrunt/modules/crates-io/compute-static/scripts/run_tests.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

terragrunt/modules/crates-io/compute-static/scripts/test_http_server.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

terragrunt/modules/crates-io/compute-static/src/main.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,6 @@ fn http_version_to_string(version: Version) -> Option<String> {
245245
#[cfg(test)]
246246
mod tests {
247247
use super::*;
248-
use fastly::experimental::BackendExt;
249-
use fastly::Backend;
250248

251249
fn new_test_config() -> Config {
252250
Config {
@@ -324,21 +322,21 @@ mod tests {
324322
);
325323
}
326324

327-
/// Ensures that the request is forwarded to the primary host for normal queries.
328-
/// Assumes the tests are being executed with the test HTTP Python server active in background (see README.md).
325+
/// Ensures that only GET and HEAD requests are allowed, and that other methods return .
329326
#[test]
330-
fn test_handle_request() {
331-
let config = new_test_config();
332-
Backend::builder(&config.primary_host, &config.primary_host)
333-
.finish()
334-
.unwrap();
335-
let client_req = Request::get(
336-
"https://static.crates.io/crates/libgit2-sys/libgit2-sys-0.12.25+1.3.0.crate",
337-
);
338-
let mut res = handle_request(&config, client_req).unwrap();
339-
assert_eq!(res.get_status(), StatusCode::OK);
340-
// Assuming the function sent a request to the primary host, verify whether the body is the one set in the test server
341-
let body = res.take_body_str();
342-
assert_eq!(body, "test_data");
327+
fn test_limit_http_methods() {
328+
let whitelist = [Method::GET, Method::HEAD];
329+
let blacklist = [Method::POST, Method::PATCH, Method::PUT, Method::DELETE];
330+
for method in whitelist {
331+
let client_req = Request::new(method, "http://example.com");
332+
assert!(limit_http_methods(&client_req).is_none());
333+
}
334+
for method in blacklist {
335+
let client_req = Request::new(method, "http://example.com");
336+
let res = limit_http_methods(&client_req);
337+
assert!(res.is_some());
338+
// Ensure parity between CloudFront and Fastly
339+
assert_eq!(res.unwrap().get_status(), StatusCode::UNAUTHORIZED);
340+
}
343341
}
344342
}

0 commit comments

Comments
 (0)