mirror of
https://github.com/telemt/telemt.git
synced 2026-10-11 03:45:58 +03:00
WEB Bridge Sideband
This commit is contained in:
@@ -18,6 +18,30 @@ fn render_page(bootstrap: &str, candidate_count: usize) -> BridgePage {
|
||||
15,
|
||||
120,
|
||||
0,
|
||||
false,
|
||||
&SecureRandom::new(),
|
||||
)
|
||||
}
|
||||
|
||||
fn render_diagnostic_page(bootstrap: &str) -> BridgePage {
|
||||
render(
|
||||
"proxy.example.com",
|
||||
bootstrap,
|
||||
2 * 1024 * 1024,
|
||||
32 * 1024 * 1024,
|
||||
16 * 1024,
|
||||
1024,
|
||||
true,
|
||||
4,
|
||||
[3, 5, 8, 12],
|
||||
25,
|
||||
10,
|
||||
90,
|
||||
15,
|
||||
15,
|
||||
120,
|
||||
0,
|
||||
true,
|
||||
&SecureRandom::new(),
|
||||
)
|
||||
}
|
||||
@@ -77,6 +101,7 @@ fn rendered_page_embeds_the_configured_bridge_timing_policy() {
|
||||
11,
|
||||
119,
|
||||
4,
|
||||
false,
|
||||
&SecureRandom::new(),
|
||||
);
|
||||
|
||||
@@ -128,6 +153,7 @@ fn disabled_negotiation_does_not_arm_a_carrier_deadline() {
|
||||
15,
|
||||
120,
|
||||
0,
|
||||
false,
|
||||
&SecureRandom::new(),
|
||||
);
|
||||
assert!(page.body.contains(
|
||||
@@ -190,3 +216,87 @@ fn rendered_page_preserves_exact_v1_status_control_envelope() {
|
||||
);
|
||||
assert!(!page.body.contains("port.postMessage({t:'status',state,"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bridge_diagnostic_sideband_is_absent_by_default() {
|
||||
let page = render_page("IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII", 4);
|
||||
|
||||
assert!(page.body.contains("<body>\n<script nonce=\""));
|
||||
assert!(page.body.contains(
|
||||
"carrierCapabilities='https,https-lanes,websocket,websocket-lanes';\nconst responseBody="
|
||||
));
|
||||
assert!(!page.body.contains("/api/v1/diagnostic"));
|
||||
assert!(!page.body.contains("TelemtBridgeDiagnostics"));
|
||||
for event in [
|
||||
"runtime_started",
|
||||
"status_posted",
|
||||
"hello_received",
|
||||
"boundary_timeout",
|
||||
"hello_timeout",
|
||||
"client_close_before_hello",
|
||||
"document_unloaded_before_hello",
|
||||
"runtime_error_before_hello",
|
||||
] {
|
||||
assert!(!page.body.contains(event));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enabled_bridge_diagnostics_use_the_https_sideband_only() {
|
||||
let page = render_diagnostic_page("JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ");
|
||||
|
||||
assert!(!page.body.contains("__"));
|
||||
assert!(page.body.contains("fetch(relayOrigin+'/api/v1/diagnostic'"));
|
||||
assert!(page.body.contains("JSON.stringify({v:1,event})"));
|
||||
assert!(page.body.contains("'Content-Type':'application/json'"));
|
||||
assert!(page.body.contains("keepalive:true"));
|
||||
for event in [
|
||||
"runtime_started",
|
||||
"status_posted",
|
||||
"hello_received",
|
||||
"boundary_timeout",
|
||||
"hello_timeout",
|
||||
"client_close_before_hello",
|
||||
"document_unloaded_before_hello",
|
||||
"runtime_error_before_hello",
|
||||
] {
|
||||
assert!(page.body.contains(event));
|
||||
}
|
||||
assert_eq!(page.body.matches("/api/v1/diagnostic").count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bridge_diagnostic_hooks_preserve_native_and_recovery_contracts() {
|
||||
let page = render_diagnostic_page("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK");
|
||||
let status_report = page.body.find("clientDiagnostics.statusPosted()").unwrap();
|
||||
let native_status = page
|
||||
.body
|
||||
.find("port.postMessage({t:'status',state})")
|
||||
.unwrap();
|
||||
let hello_report = page.body.find("clientDiagnostics.helloReceived()").unwrap();
|
||||
let create_started = page.body.find("createStarted=true;if(helloTimer)").unwrap();
|
||||
let boundary_initialized = page.body.find("initialized=true;port=nextPort;").unwrap();
|
||||
let boundary_activated = page
|
||||
.body
|
||||
.find("clientDiagnostics.boundaryActivated()")
|
||||
.unwrap();
|
||||
let port_handler = page.body.find("port.onmessage=message=>").unwrap();
|
||||
let bootstrap_replaced = page.body.find("bootstrap=policy.bootstrap;").unwrap();
|
||||
let diagnostic_rebound = page
|
||||
.body
|
||||
.find("clientDiagnostics.setBootstrap(bootstrap)")
|
||||
.unwrap();
|
||||
let limits_replaced = page
|
||||
.body
|
||||
.find("batchLimit=policy.limits.carrier_batch_bytes")
|
||||
.unwrap();
|
||||
|
||||
assert!(native_status < status_report);
|
||||
assert!(hello_report < create_started);
|
||||
assert!(boundary_initialized < boundary_activated);
|
||||
assert!(boundary_activated < port_handler);
|
||||
assert!(bootstrap_replaced < diagnostic_rebound);
|
||||
assert!(diagnostic_rebound < limits_replaced);
|
||||
assert!(page.body.contains("clientDiagnostics.helloTimeout()"));
|
||||
assert!(!page.body.contains("port.postMessage({t:'status',state,"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user