Skip to content

Add tests for the HTTP status code of an unknown role and for a conflicting quota key - #114234

Merged
zlareb1 merged 2 commits into
ClickHouse:masterfrom
groeneai:zlareb1-http-contract-tests
Aug 24, 2026
Merged

zlareb1 merged 2 commits into
ClickHouse:masterfrom
groeneai:zlareb1-http-contract-tests

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Related: #104075
Related: #104092

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

Two stateless tests for src/Server/HTTP branches that nothing currently asserts.

04870_http_role_unknown_status_code.sh covers exceptionCodeToHTTPStatus.cpp:109, where
UNKNOWN_ROLE belongs to the HTTP_NOT_FOUND group, so a non-existent role= query parameter must
answer 404. 03096_http_interface_role_query_param.sh greps the response body only and asserts no
HTTP status at all (grep -c http_code is 0; only 5 tests in 0_stateless assert %{http_code}), so
dropping that mapping would silently fall through to 500 and break client retry logic while leaving CI
green. The test also requests the same URL without the parameter and expects 200, so a non-200 above
can only come from the role lookup.

04871_http_quota_key_conflict.sh covers authenticateUserByHTTP.cpp:291-299, which rejects a quota
key supplied both as the X-ClickHouse-Quota header and as the quota_key query parameter.
01399_http_request_headers.sh passes each source alone but never both, so the conflict is never
reached. One case suffices: the check sits after the auth-scheme if/else closes at :289, so every
scheme converges on the same throw.

Both were mutation-tested rather than merely run. Deleting the UNKNOWN_ROLE term turns the expected
404 into 500, and deleting the conflict throw removes the Code: 36 line; each test fails in that
state and passes on unmodified master, including 100 runs with randomized settings. Both assert only
build-independent surfaces (an HTTP status code, one error code), use test-unique names, require no
role or user setup, and need no no-parallel tag.

Requested by @ zlareb1 in
#103950 (comment), which asked me to
re-open a batch of closed coverage PRs. I triaged all 18 and am re-filing these 2; the reason for each
of the other 16 is posted on its own PR.

…icting quota key

Two branches in src/Server/HTTP had no test asserting them.

exceptionCodeToHTTPStatus.cpp:109 puts UNKNOWN_ROLE in the HTTP_NOT_FOUND group,
so a non-existent `role=` query parameter must answer 404. The test that covers
the role parameter, 03096_http_interface_role_query_param.sh, greps the response
body only and asserts no HTTP status at all: `grep -c http_code` on it is 0, and
only 5 tests in 0_stateless assert %{http_code}. Dropping the mapping would
therefore fall through to the default 500 and break clients that key retry logic
on standard codes, with CI still green. 04870 also requests the same URL without
the parameter and expects 200, so a non-200 on the first request can only come
from the role lookup.

authenticateUserByHTTP.cpp:291-299 rejects a quota key supplied both as the
X-ClickHouse-Quota header and as the quota_key query parameter, but
01399_http_request_headers.sh passes each source alone and never both. A single
case suffices because that check sits after the auth-scheme if/else closes at
:289, so the header, Basic and query-parameter schemes all converge on the same
throw.

Both tests were mutation-tested rather than merely run. Deleting the UNKNOWN_ROLE
term turns the expected 404 into 500, and deleting the conflict throw removes the
`Code: 36` line; each test fails in that state and passes on unmodified master,
including 100 runs with randomized settings. Both assert only build-independent
surfaces, use test-unique names, need no role or user setup, and are parallel-safe
without a no-parallel tag.

Requested in ClickHouse#103950 (comment).
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (3 findings, 0 blocking)

A cold review of the resulting tests plus an independent second-model pass. No blockers, no majors.

# Finding Verdict
💡 grep -o 'Code: 36' is a prefix match, so it would also accept Code: 360/361/362/363/364/366/369. Those seven are thrown only from a running query, a compressed or object-storage read buffer, CascadeWriteBuffer construction (HTTPHandler.cpp:426), ColumnVariant, remote-replica selection, or the outgoing HTTP client, and the conflict throw runs from HTTPHandler.cpp:184, before all of them. :294 is also the only BAD_ARGUMENTS throw in the file. With the throw deleted the output is empty and grep exits 1, so the test fails loudly rather than passing. 'Code: 36.' would be exact; the two-digit form is precedented in 02377_extend_protocol_with_query_parameters.sh:81 and 01399_http_request_headers.sh:17. Noted, not blocking
💡 The header comment in 04870 explains why the mapping matters rather than stating a standing invariant. Two lines, in a test file, and 119 of 3172 shell tests here carry a comparable header. Noted, not blocking
⚠️ The two Related: lines were inside the template's leading HTML comment, so they did not render. Fixed before publishing

Verified and clean: both cited branches are live and reachable as described; the 404 is delivered by WriteBufferFromHTTPServerResponse.cpp:207 before any output buffer exists, so it is deterministic and not a post-200 in-band error; BAD_ARGUMENTS is not caught on the way out; the coverage gaps were re-measured rather than taken from the closed PRs; both oracles assert build-independent surfaces; parallel-safe without no-parallel; 04870/04871 free on master, on all open PRs and locally; no overlap with my own open or merged PRs.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (a-i)
# Check Answer
a Deterministic repro? Yes. The defect is a missing assertion, so the deterministic artifact is the mutation arm: with the branch deleted both tests fail on demand, 2/2.
b Root cause explained? Yes. exceptionCodeToHTTPStatus.cpp:109 (UNKNOWN_ROLE in the HTTP_NOT_FOUND group) and authenticateUserByHTTP.cpp:291-299 (duplicate quota key) are live and unasserted: 03096_http_interface_role_query_param.sh greps the body only (grep -c http_code = 0), 01399_http_request_headers.sh passes each quota-key source alone but never both.
c Fix matches root cause? Yes. Each test asserts exactly the branch's externally-observable effect, an HTTP status code and one error code. No widened bound, no relaxed assertion.
d Test intent preserved / new tests added? Yes. These are the new tests; no existing test is modified, weakened or removed.
e Demonstrated in BOTH directions? Yes. Positive: 2/2 pass, and 100/100 with randomized settings. Mutation: deleting the UNKNOWN_ROLE term turns 404 into 500, deleting the conflict throw removes the Code: 36 line, and each test FAILS. Build IDs recorded for both binaries.
f General across code paths? Yes, verified in source. The params.has("quota_key") check sits after the auth-scheme if/else closes at :289, so X-ClickHouse-User, Basic and query-parameter schemes all converge on the same throw; one case covers them.
g Generalizes across inputs? N/A for type wrappers (no data types involved); the input axis is the auth scheme, covered above. An empty quota_key deliberately does not conflict (:293 guards on !quota_key.empty()), so a non-empty value is used.
h Backward compatible? Yes. Test-only: no settings, no SettingsChangesHistory.cpp, no format or serialization change.
i Invariants and contracts preserved? Yes. No production code changed. Both tests are parallel-safe with no no-parallel tag, use test-unique role and quota-key names, create no users, roles or tables, need no writable user storage, and assert only build-independent surfaces (no EXPLAIN plan text, no granule or part counts, no default.-qualified names).

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @yakov-olkhovskiy, could you review this? Two stateless tests for src/Server/HTTP branches nothing currently asserts: that a non-existent role= query parameter answers 404 rather than falling through to the default 500, and that a quota key given as both the X-ClickHouse-Quota header and the quota_key parameter is rejected. Both were mutation-tested, not merely run.

This was referenced Aug 10, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [76e94d1]

Summary: ✅


AI Review

Summary

This PR adds two stateless HTTP regression tests: one asserts that an unknown role= query parameter returns HTTP 404, and the other asserts that supplying a quota key through both X-ClickHouse-Quota and quota_key is rejected. I reviewed the current diff, the targeted server code paths, and the prior PR discussion, and I did not find issues that warrant inline review comments.

Final Verdict

✅ No findings.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 76e94d11c with master d8392cfb8 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 694.55 MiB 691.54 MiB -3.01 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@zlareb1 zlareb1 self-assigned this Aug 11, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 4c0312a

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (amd_tsan) / Hung check failed, possible deadlock found cancelled DROP TABLE prometheus stuck 1044s with is_cancelled=1, convoying the database teardown behind the DDL guard a fix task is created (investigating at full effort - fixing PR link to follow on this PR)
Sync - CH Inc sync (private, not actionable by me)

175 jobs, 0 incomplete, 0 dropped. Config Workflow and Finish Workflow both succeeded. The
high skip count is expected here and not a dropped matrix: this PR adds only two stateless test
files, so 74 jobs report "Not affected by the changed files and not required", 25 "no
build-affecting changes" and 17 "Only test files changed in this PR", each with an explicit
reason. The stateless suites that do cover the new tests ran.

The hung query is a TimeSeries table teardown, unrelated to the two HTTP interface tests added
here.

Session id: cron:our-pr-ci-monitor:20260811-043000

@zlareb1

zlareb1 commented Aug 11, 2026

Copy link
Copy Markdown
Member

@groeneai can you check the CI failures and if they are flaky tests merge latest master and rerun the CI.

@groeneai

Copy link
Copy Markdown
Collaborator Author

@zlareb1 The single red is not a flaky test, so I have not merged master or rerun.

Stress test (amd_tsan) / Hung check is a trunk hang. DROP TABLE prometheus (a TimeSeries table) sits 1044.69 s with is_cancelled = 1 against max_execution_time = 60, parked in StorageTimeSeries::dropInnerTableIfAny -> waitForTableToBeActuallyDroppedOrDetached -> DatabaseCatalog::waitTableFinallyDropped. The inner drop runs on a copy of the global context with no process-list element, so KILL never unwinds it and the database teardown convoys behind the held DDLGuard. Tracked as #114259.

Master fails the same check on its own: 58 master-only rows in the last 3 days across 12 stress flavours, most recently 2026-08-11 03:17:54. So a master merge would carry the defect over rather than clear it. It is also not caused by this PR, whose diff is two new stateless .sh tests with no TimeSeries or DatabaseCatalog code.

I have a fix for it validated locally and am opening the PR shortly; I will link it here once it is up.

The rest of this head is green: Style check, Fast test, Fast test (arm_darwin), Code Review, all 11 Build (*) jobs and 30 Stateless tests (*) jobs, with 1 failure out of 175 checks.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the hung DROP TABLE of a TimeSeries table (waitTableFinallyDropped): #114302 (external, open).

@zlareb1

zlareb1 commented Aug 16, 2026

Copy link
Copy Markdown
Member

@groeneai lets merge latest master and retry CI

@groeneai

Copy link
Copy Markdown
Collaborator Author

Merged master (d8392cf, the base was 3690 commits behind) and pushed as 76e94d1. A fresh CI run is armed.

The diff is unchanged: patch-id ba06a1b5 before and after the merge, still just the two stateless tests, no submodule pin changes.

One correction to my earlier comment here: the owner of the Stress test (amd_tsan) hung check is #114953, not #114302. #114302 was closed unmerged on 2026-08-11. #114953 is still open, so this merge does not pick the fix up and that check may go red again on the new head.

@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 2026
@zlareb1
zlareb1 added this pull request to the merge queue Aug 24, 2026
Merged via the queue into ClickHouse:master with commit 023fdb1 Aug 24, 2026
183 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants