Files
core/test/rust/build/api/tls.rs
T
2026-11-27 06:03:56 +00:00

80 lines
2.8 KiB
Rust

use super::*;
use dever_runtime::{
http::{self, Http2Limits, Limits, PoolLimits, Request},
task, tls,
};
#[test]
fn generated_api_uses_configured_rustls_and_both_http_protocols() {
let root = project(
"api-tls",
"ready() (out:Bool) {out=true}",
"public get ready = app.ready",
);
for name in ["server.pem", "server-key.pem"] {
fs::copy(
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../test/fixtures/tls")
.join(name),
root.join("config").join(name),
)
.unwrap();
}
let (project, program) = analyze(&root);
let artifact = build::build(&project, &program, "main", Profile::Dev, None).unwrap();
for h2 in [false, true] {
let (path, port, mut config) = config(&root);
config["http"]["tls"] =
serde_json::json!({"certificate":"server.pem","key":"server-key.pem"});
config["http"]["limits"] = serde_json::json!({"header_bytes":16384,"body_bytes":4096,"timeout_ms":3000,"connections":8,"http2":if h2{serde_json::json!({"streams":8,"stream_window_bytes":65535,"connection_window_bytes":65535})}else{serde_json::Value::Null}});
fs::write(&path, config.to_string()).unwrap();
let server = Server::start(&artifact.binary, &path, port);
task::run(true, 16, async |scope| {
let tls = tls::client(include_bytes!("../../../fixtures/tls/root.pem")).unwrap();
let limits = Limits {
header_bytes: 16384,
body_bytes: 4096,
timeout_ms: 3000,
connections: 8,
http2: h2.then_some(Http2Limits {
streams: 8,
stream_window_bytes: 65535,
connection_window_bytes: 65535,
}),
};
let client = http::client(
&format!("https://localhost:{port}"),
&tls,
&limits,
&PoolLimits {
idle_ms: 1000,
chunk_bytes: 1024,
read_ms: 3000,
},
scope,
)
.await
.unwrap();
let response = client
.request(Request {
method: "GET".into(),
target: "/demo/service/front/main/ready".into(),
headers: vec![],
body: Default::default(),
})
.await
.unwrap();
assert_eq!(response.status, 200);
assert_eq!(
serde_json::from_slice::<serde_json::Value>(&response.body).unwrap()["data"],
true
);
drop(client);
Ok::<_, String>(())
})
.unwrap()
.unwrap();
server.stop();
}
}