backend: check the image rules without a bucket, and accept a scoped key
A least-privilege key — PutObject / GetObject and no ListBucket — gets a 403
from HeadBucket, and reading that as "the bucket is missing" turned a working
key into a 503. The bucket may well be there and simply not be the key's
business, so a refusal to look at it is no longer a failure; the PUT that
follows is the honest test.
`scripts/check_storage.py` covers what a smoke test cannot, because these are
the rules whose failure is silent: the format read from the magic bytes rather
than the client's word, the key pattern the read route serves and nothing
outside it, a caption that cannot break out of the Markdown it is written into,
what is actually asked of MinIO on a write, and the refusals — unconfigured
storage, a key we never wrote, an object that is gone. boto3's client is a stub,
so it needs no credentials, no bucket and no network.
`frontend/scripts/check-image.mjs` is the third layer: bytes can be stored and
returned perfectly while the `<img>` draws nothing. It builds its own PNG
fixture, drives the page and measures what the browser did — the picture
decoded, the figure is centred on the column, `{width=50%}` is half the column,
the 图注 prints under the picture, an image inside a sentence stays inline, and
「插入图片」 ends with the picture in the paper. Run with `pnpm check:image`; it
needs Playwright, which stays out of the app's dependencies.
This commit is contained in:
@@ -219,7 +219,16 @@ class ImageStore:
|
||||
return
|
||||
except ClientError as error:
|
||||
code = error.response.get("Error", {}).get("Code", "")
|
||||
if code not in {"404", "NoSuchBucket", "NotFound"}:
|
||||
if code in {"404", "NoSuchBucket", "NotFound"}:
|
||||
pass # not there — fall through and make it
|
||||
elif code in {"403", "AccessDenied"}:
|
||||
# Being refused a look at the bucket is not the same as the
|
||||
# bucket being absent. A key scoped to objects alone (PutObject /
|
||||
# GetObject, no ListBucket) gets exactly this answer, and the
|
||||
# upload that follows is the honest test of whether it works —
|
||||
# so return rather than turning a working key into a 503.
|
||||
return
|
||||
else:
|
||||
raise self._unavailable(error) from error
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user