Skip to content

Commit 07a238a

Browse files
committed
factors: Fix some outbound http tests
Signed-off-by: Lann Martin <[email protected]>
1 parent e9da68a commit 07a238a

File tree

13 files changed

+39
-126
lines changed

13 files changed

+39
-126
lines changed

crates/factor-outbound-http/src/wasi.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ impl<'a> WasiHttpView for WasiHttpImplInner<'a> {
8686
mut request: Request<wasmtime_wasi_http::body::HyperOutgoingBody>,
8787
mut config: wasmtime_wasi_http::types::OutgoingRequestConfig,
8888
) -> wasmtime_wasi_http::HttpResult<wasmtime_wasi_http::types::HostFutureIncomingResponse> {
89+
// wasmtime-wasi-http fills in scheme and authority for relative URLs
90+
// (e.g. https://:443/<path>), which makes them hard to reason about.
91+
// Undo that here.
92+
let uri = request.uri_mut();
93+
if uri
94+
.authority()
95+
.is_some_and(|authority| authority.host().is_empty())
96+
{
97+
let mut builder = http::uri::Builder::new();
98+
if let Some(paq) = uri.path_and_query() {
99+
builder = builder.path_and_query(paq.clone());
100+
}
101+
*uri = builder.build().unwrap();
102+
}
103+
89104
if let Some(interceptor) = &self.state.request_interceptor {
90105
match interceptor.intercept(&mut request, &mut config) {
91106
InterceptOutcome::Continue => (),

examples/spin-timer/Cargo.lock

Lines changed: 1 addition & 93 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ mod integration_tests {
7272
let spin = env.runtime_mut();
7373
assert_spin_request(
7474
spin,
75-
Request::new(Method::Get, "/test/hello"),
75+
Request::new(Method::Get, "/hello"),
7676
Response::new_with_body(200, "I'm a teapot"),
7777
)?;
7878
assert_spin_request(
7979
spin,
80-
Request::new(Method::Get, "/test/hello/wildcards/should/be/handled"),
80+
Request::new(Method::Get, "/hello/wildcards/should/be/handled"),
8181
Response::new_with_body(200, "I'm a teapot"),
8282
)?;
8383
assert_spin_request(
@@ -87,7 +87,7 @@ mod integration_tests {
8787
)?;
8888
assert_spin_request(
8989
spin,
90-
Request::new(Method::Get, "/test/hello/test-placement"),
90+
Request::new(Method::Get, "/hello/test-placement"),
9191
Response::new_with_body(200, "text for test"),
9292
)
9393
},
@@ -183,7 +183,7 @@ mod integration_tests {
183183
let spin = env.runtime_mut();
184184
assert_spin_request(
185185
spin,
186-
Request::new(Method::Get, "/test/hello"),
186+
Request::new(Method::Get, "/hello"),
187187
Response::new_with_body(200, "Hello, Fermyon!\n"),
188188
)?;
189189

@@ -368,13 +368,13 @@ Caused by:
368368
let spin = env.runtime_mut();
369369
assert_spin_request(
370370
spin,
371-
Request::new(Method::Get, "/test/outbound-allowed"),
371+
Request::new(Method::Get, "/outbound-allowed"),
372372
Response::new_with_body(200, "Hello, Fermyon!\n"),
373373
)?;
374374

375375
assert_spin_request(
376376
spin,
377-
Request::new(Method::Get, "/test/outbound-not-allowed"),
377+
Request::new(Method::Get, "/outbound-not-allowed"),
378378
Response::new_with_body(
379379
500,
380380
"Error::UnexpectedError(\"ErrorCode::HttpRequestDenied\")",
@@ -421,14 +421,14 @@ Caused by:
421421
Response::new_with_body(expected_status, expected_body),
422422
)
423423
};
424-
ensure_success("/test/hello", 200, "I'm a teapot")?;
424+
ensure_success("/hello", 200, "I'm a teapot")?;
425425
ensure_success(
426-
"/test/hello/wildcards/should/be/handled",
426+
"/hello/wildcards/should/be/handled",
427427
200,
428428
"I'm a teapot",
429429
)?;
430430
ensure_success("/thisshouldfail", 404, "")?;
431-
ensure_success("/test/hello/test-placement", 200, "text for test")?;
431+
ensure_success("/hello/test-placement", 200, "text for test")?;
432432
Ok(())
433433
},
434434
)?;
@@ -1255,14 +1255,14 @@ route = "/..."
12551255
let spin = env.runtime_mut();
12561256
assert_spin_request(
12571257
spin,
1258-
Request::full(Method::Get, "/base/echo", &[], Some("Echo...")),
1258+
Request::full(Method::Get, "/echo", &[], Some("Echo...")),
12591259
Response::new_with_body(200, "Echo..."),
12601260
)?;
12611261
assert_spin_request(
12621262
spin,
12631263
Request::full(
12641264
Method::Get,
1265-
"/base/assert-headers?k=v",
1265+
"/assert-headers?k=v",
12661266
&[("X-Custom-Foo", "bar")],
12671267
Some(r#"{"x-custom-foo": "bar"}"#),
12681268
),
@@ -1288,24 +1288,24 @@ route = "/..."
12881288
let spin = env.runtime_mut();
12891289
assert_spin_request(
12901290
spin,
1291-
Request::full(Method::Get, "/base/echo", &[], Some("Echo...")),
1291+
Request::full(Method::Get, "/echo", &[], Some("Echo...")),
12921292
Response::new_with_body(200, "Echo..."),
12931293
)?;
12941294
assert_spin_request(
12951295
spin,
12961296
Request::full(
12971297
Method::Get,
1298-
"/base/assert-args?x=y",
1298+
"/assert-args?x=y",
12991299
&[],
1300-
Some(r#"["/base/assert-args", "x=y"]"#),
1300+
Some(r#"["/assert-args", "x=y"]"#),
13011301
),
13021302
Response::new(200),
13031303
)?;
13041304
assert_spin_request(
13051305
spin,
13061306
Request::full(
13071307
Method::Get,
1308-
"/base/assert-env",
1308+
"/assert-env",
13091309
&[("X-Custom-Foo", "bar")],
13101310
Some(r#"{"HTTP_X_CUSTOM_FOO": "bar"}"#),
13111311
),
@@ -1464,7 +1464,7 @@ route = "/..."
14641464
spin,
14651465
Request::full(
14661466
Method::Get,
1467-
"/test/outbound-allowed/hello",
1467+
"/outbound-allowed/hello",
14681468
&[("Host", "google.com")],
14691469
Some(""),
14701470
),

tests/runtime-tests/tests/llm/spin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ spin_manifest_version = "1"
22
authors = ["Ryan Levick <[email protected]>"]
33
description = ""
44
name = "ai"
5-
trigger = { type = "http", base = "/" }
5+
trigger = { type = "http" }
66
version = "0.1.0"
77

88
[[component]]

tests/test-components/components/internal-http-middle/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ async fn handle_middle_impl(req: Request) -> Result<impl IntoResponse, String> {
1616
.header("spin-path-info")
1717
.and_then(|v| v.as_str());
1818
let inbound_rel_path = ensure_some!(inbound_rel_path);
19-
let inbound_base = req
20-
.header("spin-base-path")
21-
.and_then(|v| v.as_str());
22-
ensure_eq!("/", ensure_some!(inbound_base));
2319

2420
let out_req = spin_sdk::http::Request::builder()
2521
.uri("https://back.spin.internal/hello/from/middle")

tests/test-components/components/outbound-http/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async fn send_outbound(_req: Request) -> Result<impl IntoResponse> {
1010
let mut res: http::Response<String> = spin_sdk::http::send(
1111
http::Request::builder()
1212
.method("GET")
13-
.uri("/test/hello")
13+
.uri("/hello")
1414
.body(())?,
1515
)
1616
.await?;

tests/testcases/http-smoke-test/spin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ spin_version = "1"
22
authors = ["Fermyon Engineering <[email protected]>"]
33
description = "A simple application that returns hello and goodbye."
44
name = "head-rust-sdk-http"
5-
trigger = { type = "http", base = "/test" }
5+
trigger = { type = "http" }
66
version = "1.0.0"
77

88
[variables]

tests/testcases/key-value/spin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ spin_version = "1"
22
authors = ["Fermyon Engineering <[email protected]>"]
33
description = "A simple application that exercises key/value storage."
44
name = "key-value"
5-
trigger = { type = "http", base = "/test" }
5+
trigger = { type = "http" }
66
version = "1.0.0"
77

88
[[component]]

tests/testcases/otel-smoke-test/spin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ spin_version = "1"
22
authors = ["Fermyon Engineering <[email protected]>"]
33
description = "A simple application that returns hello and goodbye."
44
name = "head-rust-sdk-http"
5-
trigger = { type = "http", base = "/test" }
5+
trigger = { type = "http" }
66
version = "1.0.0"
77

88
[[component]]

tests/testcases/outbound-http-to-same-app/spin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ spin_version = "1"
22
authors = ["Fermyon Engineering <[email protected]>"]
33
description = "An application that demonstates a component making an outbound http request to another component in the same application."
44
name = "local-outbound-http"
5-
trigger = { type = "http", base = "/test" }
5+
trigger = { type = "http" }
66
version = "1.0.0"
77

88
[[component]]

0 commit comments

Comments
 (0)