Skip to content

Commit db91b88

Browse files
committed
fix(test): stop asserting a scheduling race in the forged-identity test
daemon_runtime_rejects_forged_identity_extension failed on the macos-15-intel CI leg. The suite is untouched by this branch and no daemon production code changed here; the leg flakes on main too, so this is a pre-existing defect the lane surfaced rather than a regression. The test asserted that transmitting the forged frame SUCCEEDS. It cannot be relied on to. The forged HELLO is 149 bytes against the 137-byte first-frame envelope cap, so the worker rejects it from the header and closes without ever reading the payload -- deliberately, so that no attacker-controlled bytes are read. send_frame writes the header and the payload as two separate writes, so whether the payload write lands before that close is pure scheduling: it wins on an idle host and loses on a loaded 4-vCPU runner. Both outcomes ARE the rejection, so the transmit result is now recorded and not asserted. Anti-vacuousness is preserved rather than dropped: the test now asserts it connected at all, and the drain check waits for the state it asserts (wait_for_clients 0) instead of sampling the count once, so the bound is a liveness backstop and never the verdict. Verified by mutation, not just by passing: with the envelope cap raised to 512 and the exact-length check removed -- a daemon that accepts the forged identity -- the repaired test goes RED on ASSERT(rejected). The mutation was reverted and the suite is 43/43 green. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent b3fb668 commit db91b88

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

‎tests/test_daemon_runtime.c‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,6 +2666,7 @@ TEST(daemon_runtime_rejects_forged_identity_extension) {
26662666
uint64_t forged_client_id = UINT64_MAX - 1;
26672667
uint64_t forged_process_id = UINT64_MAX;
26682668
bool encoded = false;
2669+
bool connected = false;
26692670
bool sent = false;
26702671
bool rejected = false;
26712672
cbm_daemon_frame_t response_frame = {0};
@@ -2679,12 +2680,27 @@ TEST(daemon_runtime_rejects_forged_identity_extension) {
26792680
&forged_process_id, sizeof(forged_process_id));
26802681
raw = cbm_daemon_ipc_connect(fixture.endpoint, RUNTIME_TEST_TIMEOUT_MS);
26812682
}
2683+
connected = raw != NULL;
26822684
if (raw && encoded) {
2685+
/* The forged HELLO is 149 bytes against the 137-byte first-frame
2686+
* envelope cap, so the worker rejects it from the HEADER and closes
2687+
* without ever reading the payload -- deliberately, so that no
2688+
* attacker-controlled bytes are read (cbm_daemon_ipc_receive_frame_bounded).
2689+
* send_frame writes the header and the payload as two separate writes,
2690+
* so whether the payload write lands before that close is pure
2691+
* scheduling: it wins on an idle host and loses on a loaded one. Both
2692+
* outcomes ARE the rejection, so the transmit result is recorded and
2693+
* NOT asserted -- asserting it made the verdict a coin flip. */
26832694
sent = cbm_daemon_ipc_send_frame(raw, CBM_DAEMON_FRAME_REQUEST, CBM_DAEMON_RUNTIME_OP_HELLO,
26842695
forged, (uint32_t)sizeof(forged));
2685-
int received = cbm_daemon_ipc_receive_frame(raw, RUNTIME_TEST_TIMEOUT_MS, &response_frame,
2686-
&response_payload);
2687-
rejected = received != 1 && cbm_daemon_runtime_service_active_clients(fixture.service) == 0;
2696+
int received = sent ? cbm_daemon_ipc_receive_frame(raw, RUNTIME_TEST_TIMEOUT_MS,
2697+
&response_frame, &response_payload)
2698+
: 0;
2699+
/* Wait for the state actually asserted instead of sampling it once: the
2700+
* forged peer is the only client, so the count is monotonic here and the
2701+
* bound is a liveness backstop, never the verdict. */
2702+
rejected = received != 1 && cbm_daemon_runtime_service_wait_for_clients(
2703+
fixture.service, 0, RUNTIME_TEST_TIMEOUT_MS);
26882704
}
26892705
free(response_payload);
26902706
cbm_daemon_ipc_connection_close(raw);
@@ -2715,7 +2731,7 @@ TEST(daemon_runtime_rejects_forged_identity_extension) {
27152731

27162732
ASSERT_TRUE(started);
27172733
ASSERT_TRUE(encoded);
2718-
ASSERT_TRUE(sent);
2734+
ASSERT_TRUE(connected);
27192735
ASSERT_TRUE(rejected);
27202736
ASSERT_TRUE(valid_after_rejection);
27212737
ASSERT_TRUE(exited);

0 commit comments

Comments
 (0)