Skip to content

Commit

Permalink
factors: Fix some outbound http tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lann Martin <[email protected]>
  • Loading branch information
lann committed Aug 21, 2024
1 parent e9da68a commit 07a238a
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 126 deletions.
15 changes: 15 additions & 0 deletions crates/factor-outbound-http/src/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ impl<'a> WasiHttpView for WasiHttpImplInner<'a> {
mut request: Request<wasmtime_wasi_http::body::HyperOutgoingBody>,
mut config: wasmtime_wasi_http::types::OutgoingRequestConfig,
) -> wasmtime_wasi_http::HttpResult<wasmtime_wasi_http::types::HostFutureIncomingResponse> {
// wasmtime-wasi-http fills in scheme and authority for relative URLs
// (e.g. https://:443/<path>), which makes them hard to reason about.
// Undo that here.
let uri = request.uri_mut();
if uri
.authority()
.is_some_and(|authority| authority.host().is_empty())
{
let mut builder = http::uri::Builder::new();
if let Some(paq) = uri.path_and_query() {
builder = builder.path_and_query(paq.clone());
}
*uri = builder.build().unwrap();
}

if let Some(interceptor) = &self.state.request_interceptor {
match interceptor.intercept(&mut request, &mut config) {
InterceptOutcome::Continue => (),
Expand Down
94 changes: 1 addition & 93 deletions examples/spin-timer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ mod integration_tests {
let spin = env.runtime_mut();
assert_spin_request(
spin,
Request::new(Method::Get, "/test/hello"),
Request::new(Method::Get, "/hello"),
Response::new_with_body(200, "I'm a teapot"),
)?;
assert_spin_request(
spin,
Request::new(Method::Get, "/test/hello/wildcards/should/be/handled"),
Request::new(Method::Get, "/hello/wildcards/should/be/handled"),
Response::new_with_body(200, "I'm a teapot"),
)?;
assert_spin_request(
Expand All @@ -87,7 +87,7 @@ mod integration_tests {
)?;
assert_spin_request(
spin,
Request::new(Method::Get, "/test/hello/test-placement"),
Request::new(Method::Get, "/hello/test-placement"),
Response::new_with_body(200, "text for test"),
)
},
Expand Down Expand Up @@ -183,7 +183,7 @@ mod integration_tests {
let spin = env.runtime_mut();
assert_spin_request(
spin,
Request::new(Method::Get, "/test/hello"),
Request::new(Method::Get, "/hello"),
Response::new_with_body(200, "Hello, Fermyon!\n"),
)?;

Expand Down Expand Up @@ -368,13 +368,13 @@ Caused by:
let spin = env.runtime_mut();
assert_spin_request(
spin,
Request::new(Method::Get, "/test/outbound-allowed"),
Request::new(Method::Get, "/outbound-allowed"),
Response::new_with_body(200, "Hello, Fermyon!\n"),
)?;

assert_spin_request(
spin,
Request::new(Method::Get, "/test/outbound-not-allowed"),
Request::new(Method::Get, "/outbound-not-allowed"),
Response::new_with_body(
500,
"Error::UnexpectedError(\"ErrorCode::HttpRequestDenied\")",
Expand Down Expand Up @@ -421,14 +421,14 @@ Caused by:
Response::new_with_body(expected_status, expected_body),
)
};
ensure_success("/test/hello", 200, "I'm a teapot")?;
ensure_success("/hello", 200, "I'm a teapot")?;
ensure_success(
"/test/hello/wildcards/should/be/handled",
"/hello/wildcards/should/be/handled",
200,
"I'm a teapot",
)?;
ensure_success("/thisshouldfail", 404, "")?;
ensure_success("/test/hello/test-placement", 200, "text for test")?;
ensure_success("/hello/test-placement", 200, "text for test")?;
Ok(())
},
)?;
Expand Down Expand Up @@ -1255,14 +1255,14 @@ route = "/..."
let spin = env.runtime_mut();
assert_spin_request(
spin,
Request::full(Method::Get, "/base/echo", &[], Some("Echo...")),
Request::full(Method::Get, "/echo", &[], Some("Echo...")),
Response::new_with_body(200, "Echo..."),
)?;
assert_spin_request(
spin,
Request::full(
Method::Get,
"/base/assert-headers?k=v",
"/assert-headers?k=v",
&[("X-Custom-Foo", "bar")],
Some(r#"{"x-custom-foo": "bar"}"#),
),
Expand All @@ -1288,24 +1288,24 @@ route = "/..."
let spin = env.runtime_mut();
assert_spin_request(
spin,
Request::full(Method::Get, "/base/echo", &[], Some("Echo...")),
Request::full(Method::Get, "/echo", &[], Some("Echo...")),
Response::new_with_body(200, "Echo..."),
)?;
assert_spin_request(
spin,
Request::full(
Method::Get,
"/base/assert-args?x=y",
"/assert-args?x=y",
&[],
Some(r#"["/base/assert-args", "x=y"]"#),
Some(r#"["/assert-args", "x=y"]"#),
),
Response::new(200),
)?;
assert_spin_request(
spin,
Request::full(
Method::Get,
"/base/assert-env",
"/assert-env",
&[("X-Custom-Foo", "bar")],
Some(r#"{"HTTP_X_CUSTOM_FOO": "bar"}"#),
),
Expand Down Expand Up @@ -1464,7 +1464,7 @@ route = "/..."
spin,
Request::full(
Method::Get,
"/test/outbound-allowed/hello",
"/outbound-allowed/hello",
&[("Host", "google.com")],
Some(""),
),
Expand Down
2 changes: 1 addition & 1 deletion tests/runtime-tests/tests/llm/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ spin_manifest_version = "1"
authors = ["Ryan Levick <[email protected]>"]
description = ""
name = "ai"
trigger = { type = "http", base = "/" }
trigger = { type = "http" }
version = "0.1.0"

[[component]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ async fn handle_middle_impl(req: Request) -> Result<impl IntoResponse, String> {
.header("spin-path-info")
.and_then(|v| v.as_str());
let inbound_rel_path = ensure_some!(inbound_rel_path);
let inbound_base = req
.header("spin-base-path")
.and_then(|v| v.as_str());
ensure_eq!("/", ensure_some!(inbound_base));

let out_req = spin_sdk::http::Request::builder()
.uri("https://back.spin.internal/hello/from/middle")
Expand Down
2 changes: 1 addition & 1 deletion tests/test-components/components/outbound-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async fn send_outbound(_req: Request) -> Result<impl IntoResponse> {
let mut res: http::Response<String> = spin_sdk::http::send(
http::Request::builder()
.method("GET")
.uri("/test/hello")
.uri("/hello")
.body(())?,
)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion tests/testcases/http-smoke-test/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ spin_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A simple application that returns hello and goodbye."
name = "head-rust-sdk-http"
trigger = { type = "http", base = "/test" }
trigger = { type = "http" }
version = "1.0.0"

[variables]
Expand Down
2 changes: 1 addition & 1 deletion tests/testcases/key-value/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ spin_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A simple application that exercises key/value storage."
name = "key-value"
trigger = { type = "http", base = "/test" }
trigger = { type = "http" }
version = "1.0.0"

[[component]]
Expand Down
2 changes: 1 addition & 1 deletion tests/testcases/otel-smoke-test/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ spin_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A simple application that returns hello and goodbye."
name = "head-rust-sdk-http"
trigger = { type = "http", base = "/test" }
trigger = { type = "http" }
version = "1.0.0"

[[component]]
Expand Down
2 changes: 1 addition & 1 deletion tests/testcases/outbound-http-to-same-app/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ spin_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "An application that demonstates a component making an outbound http request to another component in the same application."
name = "local-outbound-http"
trigger = { type = "http", base = "/test" }
trigger = { type = "http" }
version = "1.0.0"

[[component]]
Expand Down
2 changes: 1 addition & 1 deletion tests/testcases/simple-test/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ spin_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A simple application that returns hello and goodbye."
name = "spin-hello-world"
trigger = { type = "http", base = "/test" }
trigger = { type = "http" }
version = "1.0.0"

[variables]
Expand Down
3 changes: 0 additions & 3 deletions tests/testcases/spin-inbound-http/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ description = "Test using the spin inbound-http interface."
name = "spin-inbound-http"
version = "1.0.0"

[application.trigger.http]
base = "/base"

[[trigger.http]]
route = "/..."
[trigger.http.component]
Expand Down
Loading

0 comments on commit 07a238a

Please sign in to comment.