Skip to content

Commit eeff121

Browse files
author
constanze
committed
test(pem): make the compiled-out direct-query build actually pass
The kill-switch build compiled but its tests did not run clean — 28 of 38 failed under --define=PX_PEM_DIRECT_QUERY=disabled before this change, so the disabled configuration was evidently never exercised. Two causes: - Only the two CompiledOut_* tests sat behind the #ifdef. Every other test asserts enabled-path behaviour (valid tokens stream rows, tampered tokens are rejected by the verifier) and ran against the linker stubs, which have none of that behaviour. Guard the enabled-path block, and the trailing benchmark placeholder that uses the exec fixture, with #ifndef. - The CompiledOut_* expectations contradicted the stub they test: DirectQueryServer::ExecuteScript returns UNIMPLEMENTED without consulting credentials, and DIRECT_QUERY_SECURITY.md documents exactly that as the user-visible error, but the tests expected UNAUTHENTICATED. Expect UNIMPLEMENTED, and cover the fail-closed AuthenticateRequest stub directly so 'no token can re-enable the feature' keeps its assertion. kWrongSigningKey is only used by the guarded tests, so it needs [[maybe_unused]] to survive -Wunused-const-variable in a disabled build. Verified with --config=x86_64_sysroot: default 37 tests, 34 passed, 3 skipped --//…:direct_query=false 3 tests, 3 passed
1 parent c1ccb4f commit eeff121

1 file changed

Lines changed: 34 additions & 11 deletions

File tree

src/vizier/services/agent/pem/direct_query_server_test.cc

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ namespace vizier {
4949
namespace agent {
5050

5151
constexpr char kTestSigningKey[] = "test-signing-key-do-not-use-in-prod";
52-
constexpr char kWrongSigningKey[] = "a-different-key";
52+
// Only the enabled-path tests mint a wrong-key token; a
53+
// --//src/vizier/services/agent/pem:direct_query=false build compiles those out.
54+
[[maybe_unused]] constexpr char kWrongSigningKey[] = "a-different-key";
5355

5456
// TokenKind drives MakeBearerToken's claim shape. The verifier
5557
// (direct_query_server.cc:verifyHs256Jwt) checks: HS256 alg, signature, iss=PL,
@@ -196,6 +198,13 @@ class DirectQueryServerTest : public ::testing::Test {
196198
std::unique_ptr<::px::api::vizierpb::VizierService::Stub> stub_;
197199
};
198200

201+
// Everything from here to the toggle section exercises the feature body, so it
202+
// is meaningful only when the feature is compiled in. In a
203+
// --//src/vizier/services/agent/pem:direct_query=false build these entry points
204+
// are linker stubs and the assertions below do not apply; the disabled build's
205+
// contract is covered by the CompiledOut_* tests instead.
206+
#ifndef PX_PEM_DIRECT_QUERY_DISABLED
207+
199208
// 3a. No token → UNAUTHENTICATED (passes against the fail-closed stub today).
200209
TEST_F(DirectQueryServerTest, NoToken_Unauthenticated) {
201210
EXPECT_EQ(::grpc::StatusCode::UNAUTHENTICATED, CallExecuteScript("").error_code());
@@ -823,21 +832,33 @@ TEST_F(DirectQueryServerExecTest, FailSoft_BrokerFailureToleratedByDirectQuery)
823832
// PxL contents. The fixture's auth-only nullptr Carnot is sufficient.
824833
// ===========================================================================
825834

835+
#endif // !PX_PEM_DIRECT_QUERY_DISABLED — end of enabled-path tests
836+
826837
#ifdef PX_PEM_DIRECT_QUERY_DISABLED
827838

828-
// When compiled with PX_PEM_DIRECT_QUERY_DISABLED, every call must short-
829-
// circuit to UNAUTHENTICATED (no JWT verification path exists). This
830-
// includes calls with a valid token — the compile-time toggle is harder
831-
// than the runtime toggle: not even a valid bearer unlocks anything.
832-
TEST_F(DirectQueryServerTest, CompiledOut_ValidToken_StillUnauthenticated) {
839+
// When compiled with PX_PEM_DIRECT_QUERY_DISABLED the RPC is a stub: it
840+
// returns UNIMPLEMENTED without consulting credentials at all, which is both
841+
// what direct_query_server.cc's #else branch does and what
842+
// DIRECT_QUERY_SECURITY.md documents as the user-visible error. A valid token
843+
// changes nothing — the compile-time toggle is harder than the runtime one,
844+
// since no bearer can re-enable a feature that is not in the binary.
845+
TEST_F(DirectQueryServerTest, CompiledOut_ValidToken_StillUnimplemented) {
833846
auto tok = MakeBearerToken(kTestSigningKey, TokenKind::kValid);
834-
EXPECT_EQ(::grpc::StatusCode::UNAUTHENTICATED, CallExecuteScript(tok).error_code())
835-
<< "PX_PEM_DIRECT_QUERY_DISABLED build must short-circuit AT auth — no "
836-
"valid token can re-enable the feature post-compile.";
847+
EXPECT_EQ(::grpc::StatusCode::UNIMPLEMENTED, CallExecuteScript(tok).error_code())
848+
<< "PX_PEM_DIRECT_QUERY_DISABLED build must refuse every call — no valid "
849+
"token can re-enable the feature post-compile.";
837850
}
838851

839-
TEST_F(DirectQueryServerTest, CompiledOut_NoToken_Unauthenticated) {
840-
EXPECT_EQ(::grpc::StatusCode::UNAUTHENTICATED, CallExecuteScript("").error_code());
852+
TEST_F(DirectQueryServerTest, CompiledOut_NoToken_Unimplemented) {
853+
EXPECT_EQ(::grpc::StatusCode::UNIMPLEMENTED, CallExecuteScript("").error_code());
854+
}
855+
856+
// The auth entry point still exists as a stub and still fails closed, so a
857+
// caller that reaches it (rather than ExecuteScript) cannot authenticate
858+
// either. Called directly: the stub ignores both arguments.
859+
TEST(DirectQueryServerCompiledOut, AuthenticateRequest_FailsClosed) {
860+
EXPECT_EQ(::grpc::StatusCode::UNAUTHENTICATED,
861+
AuthenticateRequest(nullptr, "any-signing-key").error_code());
841862
}
842863

843864
#else // PX_PEM_DIRECT_QUERY_DISABLED
@@ -871,12 +892,14 @@ TEST_F(DirectQueryServerTest, ToggleContract_DocumentBothLevels) {
871892
// harness, not a gtest). Tracked as a follow-up; this SKIP names it in
872893
// code so the gap is greppable.
873894
// ===========================================================================
895+
#ifndef PX_PEM_DIRECT_QUERY_DISABLED
874896
TEST_F(DirectQueryServerExecTest, Benchmark_PemDirect_Vs_BrokerPath_RedPlaceholder) {
875897
GTEST_SKIP() << "Follow-up: apples-to-apples bench harness vs the broker path. "
876898
"Dominant latency factor is the dedicated second Carnot exec on "
877899
"the PEM (shared-Carnot path would close it). Integration-level "
878900
"workload, not a gtest.";
879901
}
902+
#endif // !PX_PEM_DIRECT_QUERY_DISABLED
880903

881904
} // namespace agent
882905
} // namespace vizier

0 commit comments

Comments
 (0)