Assistant: codex Assistant-Model: gpt-6-astra Assistant-Session: 01a13eab-1e6a-7b33-9c37-372e90ada3a2
37 lines
1.8 KiB
Python
37 lines
1.8 KiB
Python
"""Scoped S3 list-only fixtures; no credentials, live cluster or cloud."""
|
|
import importlib.util
|
|
from pathlib import Path
|
|
import pytest
|
|
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
spec=importlib.util.spec_from_file_location('s3_inventory',ROOT/'tools/bootstrap-recovery/inventory-scaleway.py')
|
|
module=importlib.util.module_from_spec(spec);spec.loader.exec_module(module)
|
|
|
|
|
|
class Client:
|
|
def __init__(self,pages):self.pages=iter(pages);self.calls=[]
|
|
def list_objects_v2(self,**kw):self.calls.append(kw);return next(self.pages)
|
|
|
|
|
|
def test_scoped_list_metadata_follows_continuation_without_reading_contents():
|
|
client=Client([{'IsTruncated':True,'NextContinuationToken':'next'},
|
|
{'Contents':[{'Key':'platform-pg/identity/backup.tar.age','Size':256}]}])
|
|
r=module.list_prefix(client,'platform-pg/identity/')
|
|
assert r['files']==[{'key':'platform-pg/identity/backup.tar.age','bytes':256}]
|
|
assert all(x['Bucket']==module.BUCKET and x['Prefix']=='platform-pg/identity/' for x in client.calls)
|
|
assert client.calls[1]['ContinuationToken']=='next'
|
|
|
|
|
|
def test_wal_and_base_presence_is_recorded_without_traversal():
|
|
client=Client([{'CommonPrefixes':[{'Prefix':'platform-pg/base/'},{'Prefix':'platform-pg/wals/'}]}])
|
|
r=module.inventory(client)
|
|
assert len(client.calls)==1 and len(r['platform-pg/']['directories'])==2
|
|
|
|
|
|
@pytest.mark.parametrize('key',['elsewhere/backup.age','platform-pg/../backup.age','platform-pg/private\nmarker.age'])
|
|
def test_foreign_or_unsafe_metadata_refuses(key):
|
|
with pytest.raises(module.Refused):module.list_prefix(Client([{'Contents':[{'Key':key,'Size':1}]}]),module.PREFIX)
|
|
|
|
|
|
def test_missing_pagination_state_refuses_incomplete_inventory():
|
|
with pytest.raises(module.Refused):module.list_prefix(Client([{'IsTruncated':True}]),module.PREFIX)
|