Repository navigation
[DT-3848][risk=no] Add the typed search response check (5d/6) - #3352
otchet-broad wants to merge 2 commits into
Conversation
Add TypedSearchResponseCheck, which checks a response body against the contract (page, total, row fields of the projection, no null fields, dataUse as an object, asset key, facets, counts totals), and TypedSearchResponseTest: the body of each 200 fixture, and a self-test of 11 bodies that each break one rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…se-check Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kevinmarete
left a comment
There was a problem hiding this comment.
A few small things in the response check. Also, CI doesn't run tests on stacked PRs (build.yaml and coverage.yaml only trigger on PRs into develop, and maven.yaml builds with -Dmaven.test.skip=true). Could you confirm ./mvnw test -Dtest='TypedSearch*' passes on this branch?
| if (!paths.isEmpty()) { | ||
| errors.add("row fields outside the projection: " + paths); | ||
| } | ||
| if (hasNull(row)) { |
There was a problem hiding this comment.
Contract §7 says a row has no null and no empty text or list in place of a missing value, but hasNull only catches null, so "datasetName": "" and "study": {} pass. Should empty strings, lists and objects be rejected too?
| "{'view':'studies','total':0,'page':{'offset':0,'limit':2},'results':[],'facets':{'dac':[]}}", | ||
| "{'view':'datasets','total':0,'page':{'offset':0,'limit':25},'results':[],'facets':{'dac':[]}}", | ||
| "{'view':'datasets','total':'3','page':{'offset':0,'limit':2},'results':[],'facets':{'dac':[]}}", | ||
| "{'view':'datasets','total':1,'page':{'offset':0,'limit':2},'results':[{},{}],'facets':{'dac':[]}}", |
There was a problem hiding this comment.
This body has no dataUse, so the dataUse rule (line 95 of the check) rejects it whether or not the rows-vs-total rule works. Adding dataUse: {primary: [], secondary: []} to each row would make it test the intended rule. A case with more rows than limit would also help; 2 rows with limit 2 doesn't cover it.
| "{'view':'datasets','total':'3','page':{'offset':0,'limit':2},'results':[],'facets':{'dac':[]}}", | ||
| "{'view':'datasets','total':1,'page':{'offset':0,'limit':2},'results':[{},{}],'facets':{'dac':[]}}", | ||
| "{'view':'datasets','total':1,'page':{'offset':0,'limit':2},'results':[1],'facets':{'dac':[]}}", | ||
| "{'view':'datasets','total':1,'page':{'offset':0,'limit':2},'results':[{'deletable':true}],'facets':{'dac':[]}}", |
There was a problem hiding this comment.
Same here: without dataUse, this body is rejected whether or not the projection rule works.
| continue; | ||
| } | ||
| JsonNode previous = null; | ||
| for (JsonNode bucket : buckets) { |
There was a problem hiding this comment.
Nit: duplicate bucket values (A:1, A:1) are accepted. Should each value appear only once per facet?
| } | ||
| JsonNode dataUse = row.path("dataUse"); | ||
| if (allowed.contains("dataUse") | ||
| && !(dataUse.path("primary").isArray() && dataUse.path("secondary").isArray())) { |
There was a problem hiding this comment.
Nit: {primary: [], secondary: [], extra: 1} passes. Should unknown keys in dataUse be rejected?
rushtong
left a comment
There was a problem hiding this comment.
Reviewed with Claude and Codex.
1. [Medium] Empty text and empty lists pass the row check: src/test/java/org/broadinstitute/consent/http/typedsearch/TypedSearchResponseCheck.java:90 The check rejects only null in a row. Contract section 7 (typed-search-contract.md:290) also forbids empty text or an empty list in place of a missing value. A row with "datasetName": "" or "url": [] passes.
2. [Medium] Two self-test bodies fail for the wrong reason: src/test/java/org/broadinstitute/consent/http/typedsearch/TypedSearchResponseTest.java:55 The bodies on lines 55 and 57 also lack dataUse, so the dataUse rule fires in each case. The test asserts only that an error exists. The row-count rule and the outside-projection rule are thus not tested. Add a valid dataUse to those rows.
Low Findings
- Page and total compared after coercion:
src/test/java/org/broadinstitute/consent/http/typedsearch/TypedSearchResponseCheck.java:64A stringoffsetorlimit, atotalof3.0, and extrapagekeys all pass. - Wrong type of
facetspasses:src/test/java/org/broadinstitute/consent/http/typedsearch/TypedSearchResponseCheck.java:141With no requested facet,"facets": []ornullgives no error. - Weak bucket checks:
src/test/java/org/broadinstitute/consent/http/typedsearch/TypedSearchResponseCheck.java:155Duplicate bucket values pass, and an object as a bucket value passes.
Addresses
https://broadworkbench.atlassian.net/browse/DT-3848 (epic DT-4500)
Security risk: no — test files only; no application code or configuration changes.
Summary
Adds
TypedSearchResponseCheck, which checks a response body against the contract (#3342): the page of the request, a wholetotal, rows within the page and the projection, nonullfield (a field without a value is absent),dataUseas an object in each projection that has it, the asset key form (id:with the record id, orpos:), the facet buckets (requested keys, size, order by count, then by UTF-8 bytes), and the ten totals of the counts view.TypedSearchResponseTestchecks the body of each 200 fixture, and a self-test of 11 bodies that each break one rule.Stacked on 5a (#3350); merge that first. This is slice 5d of 6 for DT-3848.
Have you read CONTRIBUTING.md lately? If not, do that first.
🤖 Generated with Claude Code