Commit d0897c2
Fix the causes of the REST self link console warnings (#1415)
* Only warn about REST self links the API isn't expected to change
ensureSelfLink() compares the requested url against the self link in the
response, but strips embed params from the requested url only. The REST API
echoes the request's embed params into the self link, so every request that
embeds a subresource looked broken and flooded the console:
The response for '.../bundles/<uuid>/bitstreams?page=0&size=5' has the self
link '.../bitstreams?page=0&embed=accessStatus&size=5'. These don't match.
The same warning also fired when the API clamped an oversized page size
(?size=9999 comes back as ?size=1000), which the REST contract mandates:
a size over the configured maximum is reset to the maximum, no error thrown.
Narrow the warning so it only fires on differences the API isn't expected to
introduce: strip embed params from both sides, and accept a page size that
shrank when the response's own page.size confirms the smaller value. A self
link that contradicts the payload it describes is still reported, as are
differing page/sort params, extra params, a size larger than requested, and a
missing self link.
The self-link normalization itself is left untouched. The response is keyed in
the object cache by that href, so which url it is normalized to stays exactly
as it was; only whether we warn changes.
Adds the first spec for this service - ensureSelfLink was untested.
Closes dataquest-dev/dspace-customers#862
* Don't accept an empty page as a clamped page size, and pin the rest
Mutation testing of the new spec turned up one behaviour bug and a set of
assertions that were never actually pinned down.
isReducedPageSize() accepted any smaller page size the response's page block
confirmed, including zero: asking for size=10 and getting a self link claiming
size=0 with "page": {"size": 0} was silently swallowed. A configured maximum is
never zero, so an empty page is not a clamp - require the effective size to be
greater than zero and let that case be reported again.
Also drop a redundant hasValue(payload) - the caller already guarantees it - and
note in the doc comment that running the self link through
getUrlWithoutEmbedParams() drops a fragment and a trailing slash too, so
differences limited to those stop being reported as well.
Tests added for the gaps mutation testing exposed, each verified to fail against
the corresponding mutant:
- the page size rule tested on its own, without embed params also in play
- the exact text of the warning, not just a substring
- sibling _links surviving the self link being normalized
- `size` matched as a whole param, so `pagesize` isn't mistaken for it
- a page block confirming the size only as a string is not confirmation
- an empty page is reported
- a cross-origin self link is passed through untouched
- reordered params are neither reported nor rewritten
* Cover the case where an accepted clamp hides another differing param
When isReducedPageSize() accepts a reduced page size, isUnexpectedSelfLink()
re-compares the remaining parts rather than returning early, so a legitimate
clamp can't mask a genuinely wrong page/sort. Nothing defended that: dropping
the second urlPartsDiffer() call left all 22 tests green while silently
swallowing the defect.
* Don't report a self link that only percent decoded a param value
The remaining self link warning on the home page came from the usage statistics
request: the frontend sends uri=http%3A%2F%2F... and the REST API echoes it back
decoded as uri=http://... Same value, different representation - comparing the
raw strings compares encodings, not values, which is the same kind of false
alarm as the echoed embed params.
Percent decode both sides before comparing. Decoding happens per part, after the
url was split, so a decoded & can't merge two params, and a malformed sequence
falls back to the raw part. A value that differs beyond its encoding still warns.
With this, an item page, the home page and a search page all load with zero self
link warnings against a DSpace 9.1 backend.
Also trims the doc comments on these helpers down to what isn't already obvious
from the code.
* Stop asking the REST API for pages it will never serve
Seven call sites asked for 9999 or 10000 elements to mean "give me everything".
The REST API caps a page at 1000 (Spring Data REST's spring.data.rest.max-page-size,
which DSpace leaves at its default) and silently reduces anything larger, so those
requests never returned more than 1000 anyway - they just claimed something the API
does not honour, and the difference between the requested and the effective size is
what showed up in the self link and produced the console warnings of #862:
GET /core/items/<uuid>/bundles?embed=primaryBitstream&size=9999
self ...?embed=primaryBitstream&size=1000
Introduce MAX_PAGE_SIZE next to FindListOptions and use it instead. Verified against
a DSpace 9.1 backend that this returns the identical page - same totalElements, same
contents - while the self link now matches the request exactly:
?size=9999 -> self ?size=1000 page {size: 1000, totalElements: 1}
?size=1000 -> self ?size=1000 page {size: 1000, totalElements: 1}
This is upstream issue DSpace#2513, whose fix (DSpace#3694) removed 9999 from seven components
but missed BundleDataService.findByItemAndName - still on main, dspace-9_x, dtq-dev
and dtq-dev-9-base. The three clarin-* call sites are ours.
* Stop percent-encoding the usagereports uri param
The frontend sent uri=http%3A%2F%2F... and the REST API echoed it back decoded as
uri=http://..., which made the self link differ from the requested url and produced
the self link warning on the home page.
RequestParam encodes by default; pass encodeValue=false, exactly as
AuthorizationDataService already does for its own uri param (upstream DSpace#3045/DSpace#3046),
and carry the same TODO noting this belongs in the backend.
* Report a reduced page size again, now that nothing asks for an impossible one
Filtering the page size out of the self link comparison treated the symptom: the
frontend went on asking for 9999, the API went on reducing it to 1000, and the code
here just stopped saying so. With every call site now within MAX_PAGE_SIZE, a page
size the API reduced means a caller asked for something it was never going to get -
which is exactly what this warning exists to surface.
Drops isReducedPageSize, getPageSizes and PAGE_SIZE_PARAM, and with them the need to
pass the response payload into isUnexpectedSelfLink at all.
What stays is the part that is a genuine comparison bug rather than a filter: embed
params and percent encoding are two ways of writing the same request, so both sides
are brought to the same form before being compared. A difference in an actual value
is still reported.
Spec goes from 25 cases to 17: the nine that pinned the page size filtering are gone,
replaced by one asserting a reduced page size warns.
* Use MAX_PAGE_SIZE for the license lookups too
Three CLARIN license components already asked for exactly 1000, so they never
triggered the warning - but leaving the bare literal next to a newly introduced
MAX_PAGE_SIZE just invites the question why one place names the limit and the
other repeats it. Same value, no behaviour change; the constant now says where
the number comes from.
* Drop the uri encoding workaround instead of copying its TODO
An earlier commit here made UsageReportDataService skip encoding its uri param,
copying the workaround and the TODO that AuthorizationDataService carries:
// TODO fix encode the uri parameter in the self link in the backend and set
// encodeValue to true afterwards
Measured against a DSpace 9.1 backend, that TODO is based on a misreading - there
is nothing to fix in the backend. It does not decode the self link; it re-encodes
the parameter values minimally, and ':' and '/' are legal in a query component per
RFC 3986, so it has no reason to escape them:
sent probe=a%25b -> self probe=a%25b (not decoded)
sent probe=a%20b -> self probe=a%20b (not decoded)
sent probe=a+b -> self probe=a%20b ('+' is a space in form encoding)
sent uri=http%3A%2F%2Fx -> self uri=http://x
encodeURIComponent on the frontend simply encodes more than it has to. Both urls
are valid and denote the same value.
Since the comparison now decodes both sides, the encoding no longer matters, so
put the param back on the default: encoding is the safer choice for a value that
could contain '&' or '#'. Verified in a browser - the home page still logs no self
link warning with encoding restored.
The same workaround in AuthorizationDataService is left alone: it is upstream code,
it works either way, and it is out of scope here.
* Pass the already split request url into isUnexpectedSelfLink
ensureSelfLink splits the requested url into parts before the comparison, then
isUnexpectedSelfLink split the same string a second time. The branch runs on every
response whose self link differs, which after this change is every embedded list
response, so the duplicate work is not rare.
Takes the parts instead. No behaviour change.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Merge the MAX_PAGE_SIZE import into the existing one
section-license.component.ts already imported FindListOptions from
find-list-options.model, so adding MAX_PAGE_SIZE as a second import of the same
module - under a different specifier - left the file importing one module twice.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6487711 commit d0897c2
13 files changed
Lines changed: 308 additions & 19 deletions
File tree
- src/app
- bitstream-page/clarin-zip-download-page
- clarin-licenses/clarin-all-licenses-page
- core
- browse
- data
- registry
- item-page
- edit-item-page
- item-bitstreams
- item-license-mapper
- simple/field-components/clarin-item-versions-field
- submission/sections/clarin-license-resource
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
62 | | - | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | | - | |
| 73 | + | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
Lines changed: 232 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
Lines changed: 46 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
57 | 96 | | |
58 | 97 | | |
59 | 98 | | |
| |||
156 | 195 | | |
157 | 196 | | |
158 | 197 | | |
| 198 | + | |
159 | 199 | | |
160 | | - | |
161 | | - | |
162 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
163 | 206 | | |
164 | 207 | | |
165 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
4 | 14 | | |
5 | 15 | | |
6 | 16 | | |
| |||
0 commit comments