Repository navigation
Expand file tree
/
Copy pathtest_s3files.py
More file actions
690 lines (583 loc) · 24.9 KB
/
Copy pathtest_s3files.py
File metadata and controls
690 lines (583 loc) · 24.9 KB
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
"""S3 Files (s3files-2025-05-05) tests.
Driven via raw HTTP since botocore doesn't ship `s3files` in the version
pinned for the rest of the suite. The wire format here is exactly what
the AWS CLI / SDKs send: REST/JSON with camelCase fields and the routes
documented at docs.aws.amazon.com/AmazonS3/.../API_Operations_Amazon_S3_Files.html.
"""
import json
import os
import urllib.error
import urllib.parse
import urllib.request
import uuid
ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
BUCKET_ARN = "arn:aws:s3:::test-bucket"
ROLE_ARN = "arn:aws:iam::000000000000:role/s3files-role"
def _auth(account="000000000000", region="us-east-1"):
return (
f"AWS4-HMAC-SHA256 "
f"Credential={account}/20260504/{region}/s3files/aws4_request, "
f"SignedHeaders=host, Signature=00"
)
def _req(method, path, body=None, query=None, account=None, region="us-east-1"):
url = ENDPOINT + path
if query:
url += "?" + urllib.parse.urlencode(query, doseq=True)
data = None
headers = {"Authorization": _auth(account or "000000000000", region)}
if body is not None:
data = json.dumps(body).encode()
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
# 30s instead of 10s: under CI xdist contention the first request into the
# s3files handler can trigger lazy imports of large service modules whose
# import-time work exceeds 10s on the shared 2-core Linux runner (same
# failure class documented in tests/test_rds_data.py). The handler itself
# is sub-ms once loaded, so 30s leaves a wide margin without slowing real
# failures meaningfully.
try:
resp = urllib.request.urlopen(req, timeout=30)
raw = resp.read()
return resp.status, json.loads(raw) if raw else {}
except urllib.error.HTTPError as e:
raw = e.read()
try:
return e.code, json.loads(raw)
except Exception:
return e.code, {"raw": raw.decode("latin-1", "replace")}
def _uid():
return uuid.uuid4().hex[:6]
def _resource_tags_path(resource_id):
return "/resource-tags/" + urllib.parse.quote(resource_id, safe="")
# ---------------------------------------------------------------------------
# File systems
# ---------------------------------------------------------------------------
def test_create_file_system_uses_put_and_camel_case():
status, body = _req("PUT", "/file-systems", {
"bucket": BUCKET_ARN,
"roleArn": ROLE_ARN,
"tags": [{"key": "Name", "value": f"fs-{_uid()}"}],
})
assert status == 201, body
assert body["fileSystemId"].startswith("fs-")
assert body["fileSystemArn"].startswith("arn:aws:s3files:")
assert body["bucket"] == BUCKET_ARN
assert body["roleArn"] == ROLE_ARN
assert body["status"] == "available"
assert isinstance(body["creationTime"], int)
assert body["ownerId"] == "000000000000"
fs_id = body["fileSystemId"]
_req("DELETE", f"/file-systems/{fs_id}")
def test_file_systems_are_region_scoped():
_, east_fs = _req(
"PUT",
"/file-systems",
{"bucket": BUCKET_ARN, "roleArn": ROLE_ARN},
region="us-east-1",
)
_, west_fs = _req(
"PUT",
"/file-systems",
{"bucket": BUCKET_ARN, "roleArn": ROLE_ARN},
region="us-west-2",
)
try:
_, east_list = _req("GET", "/file-systems", region="us-east-1")
_, west_list = _req("GET", "/file-systems", region="us-west-2")
east_ids = {fs["fileSystemId"] for fs in east_list["fileSystems"]}
west_ids = {fs["fileSystemId"] for fs in west_list["fileSystems"]}
assert east_fs["fileSystemId"] in east_ids
assert east_fs["fileSystemId"] not in west_ids
assert west_fs["fileSystemId"] in west_ids
assert west_fs["fileSystemId"] not in east_ids
assert ":us-east-1:" in east_fs["fileSystemArn"]
assert ":us-west-2:" in west_fs["fileSystemArn"]
finally:
_req(
"DELETE",
f"/file-systems/{east_fs['fileSystemId']}",
region="us-east-1",
)
_req(
"DELETE",
f"/file-systems/{west_fs['fileSystemId']}",
region="us-west-2",
)
def test_legacy_child_state_restores_beside_parent_resource():
from ministack.core.responses import (
AccountScopedDict,
get_account_id,
get_region,
set_request_account_id,
set_request_region,
)
from ministack.services import s3files as service
original_account = get_account_id()
original_region = get_region()
account_id = "111111111111"
boot_region = "us-east-1"
resource_region = "us-west-2"
fs_id = "fs-11111111111111111"
mt_id = "fsmt-11111111111111111"
ap_id = "fsap-11111111111111111"
file_systems = AccountScopedDict()
mount_targets = AccountScopedDict()
access_points = AccountScopedDict()
set_request_account_id(account_id)
set_request_region(boot_region)
file_systems[fs_id] = {
"fileSystemId": fs_id,
"fileSystemArn": (
f"arn:aws:s3files:{resource_region}:{account_id}:file-system/{fs_id}"
),
}
mount_targets[mt_id] = {"mountTargetId": mt_id, "fileSystemId": fs_id}
access_points[ap_id] = {
"accessPointId": ap_id,
"fileSystemId": fs_id,
"accessPointArn": (
f"arn:aws:s3files:{resource_region}:{account_id}:"
f"file-system/{fs_id}/access-point/{ap_id}"
),
}
payload = {
"file_systems": file_systems,
"mount_targets": mount_targets,
"access_points": access_points,
}
for state_key, resource_id, value in (
("policies", fs_id, "legacy-policy"),
("sync_configs", fs_id, {"latestVersionNumber": 1}),
("tags", ap_id, [{"key": "legacy", "value": "true"}]),
):
store = AccountScopedDict()
store[resource_id] = value
payload[state_key] = store
service.reset()
try:
service.load_persisted_state(payload)
assert service._file_systems.get_scoped(
account_id, resource_region, fs_id
)["fileSystemId"] == fs_id
assert service._mount_targets.get_scoped(
account_id, resource_region, mt_id
)["fileSystemId"] == fs_id
assert service._access_points.get_scoped(
account_id, resource_region, ap_id
)["fileSystemId"] == fs_id
assert service._policies.get_scoped(
account_id, resource_region, fs_id
) == "legacy-policy"
assert service._sync_configs.get_scoped(
account_id, resource_region, fs_id
) == {"latestVersionNumber": 1}
assert service._tags.get_scoped(account_id, resource_region, ap_id) == [
{"key": "legacy", "value": "true"}
]
finally:
service.reset()
set_request_account_id(original_account)
set_request_region(original_region)
def test_legacy_orphaned_mount_target_restores_to_availability_zone_region():
from ministack.core.responses import (
AccountScopedDict,
get_account_id,
get_region,
set_request_account_id,
set_request_region,
)
from ministack.services import s3files as service
original_account = get_account_id()
original_region = get_region()
account_id = "111111111111"
boot_region = "us-east-1"
resource_region = "us-west-2"
mt_id = "fsmt-11111111111111111"
mount_targets = AccountScopedDict()
set_request_account_id(account_id)
set_request_region(boot_region)
mount_targets[mt_id] = {
"mountTargetId": mt_id,
"fileSystemId": "fs-11111111111111111",
"availabilityZoneId": f"{resource_region}-az1",
}
service.reset()
try:
service.load_persisted_state({"mount_targets": mount_targets})
assert service._mount_targets.get_scoped(
account_id, resource_region, mt_id
)["mountTargetId"] == mt_id
assert (
service._mount_targets.get_scoped(account_id, boot_region, mt_id) is None
)
finally:
service.reset()
set_request_account_id(original_account)
set_request_region(original_region)
def test_reset_clears_s3files_state_across_regions():
from ministack.core.responses import get_region, set_request_region
from ministack.services import s3files as service
original_region = get_region()
stores = (
service._file_systems,
service._mount_targets,
service._access_points,
service._policies,
service._sync_configs,
service._tags,
)
service.reset()
try:
for region in ("us-east-1", "us-west-2"):
set_request_region(region)
for store in stores:
store[f"resource-{region}"] = {"region": region}
service.reset()
assert all(not store.has_any() for store in stores)
finally:
service.reset()
set_request_region(original_region)
def test_create_file_system_post_is_not_supported():
status, body = _req("POST", "/file-systems", {
"bucket": BUCKET_ARN,
"roleArn": ROLE_ARN,
})
assert status == 400
assert body.get("__type") == "ValidationException"
def test_create_file_system_missing_required_fields():
status, body = _req("PUT", "/file-systems", {})
assert status == 400
assert body.get("__type") == "ValidationException"
def test_get_and_list_file_systems_camel_case():
s, body = _req("PUT", "/file-systems", {"bucket": BUCKET_ARN, "roleArn": ROLE_ARN})
fs_id = body["fileSystemId"]
try:
s, got = _req("GET", f"/file-systems/{fs_id}")
assert s == 200
assert got["fileSystemId"] == fs_id
assert got["bucket"] == BUCKET_ARN
s, listed = _req("GET", "/file-systems")
assert s == 200
assert any(fs["fileSystemId"] == fs_id for fs in listed["fileSystems"])
s, filtered = _req("GET", "/file-systems", query={"bucket": BUCKET_ARN})
assert s == 200
assert all(fs["bucket"] == BUCKET_ARN for fs in filtered["fileSystems"])
finally:
_req("DELETE", f"/file-systems/{fs_id}")
def test_get_file_system_not_found():
s, body = _req("GET", "/file-systems/fs-deadbeefdeadbeefdead")
assert s == 404
assert body.get("__type") == "ResourceNotFoundException"
def test_delete_file_system_returns_204():
s, body = _req("PUT", "/file-systems", {"bucket": BUCKET_ARN, "roleArn": ROLE_ARN})
fs_id = body["fileSystemId"]
s, _ = _req("DELETE", f"/file-systems/{fs_id}")
assert s == 204
# ---------------------------------------------------------------------------
# Mount targets
# ---------------------------------------------------------------------------
def test_mount_target_lifecycle():
s, fs = _req("PUT", "/file-systems", {"bucket": BUCKET_ARN, "roleArn": ROLE_ARN})
fs_id = fs["fileSystemId"]
try:
s, mt = _req("PUT", "/mount-targets", {
"fileSystemId": fs_id,
"subnetId": "subnet-12345678",
"securityGroups": ["sg-12345678"],
})
assert s == 200
assert mt["mountTargetId"].startswith("fsmt-")
assert mt["fileSystemId"] == fs_id
assert mt["securityGroups"] == ["sg-12345678"]
mt_id = mt["mountTargetId"]
s, got = _req("GET", f"/mount-targets/{mt_id}")
assert s == 200 and got["mountTargetId"] == mt_id
s, listed = _req("GET", "/mount-targets", query={"fileSystemId": fs_id})
assert s == 200
assert any(m["mountTargetId"] == mt_id for m in listed["mountTargets"])
s, updated = _req("PUT", f"/mount-targets/{mt_id}", {
"securityGroups": ["sg-aaaaaaaa", "sg-bbbbbbbb"],
})
assert s == 200
assert updated["securityGroups"] == ["sg-aaaaaaaa", "sg-bbbbbbbb"]
s, _ = _req("DELETE", f"/mount-targets/{mt_id}")
assert s == 204
finally:
_req("DELETE", f"/file-systems/{fs_id}")
def test_create_mount_target_requires_filesystem():
s, body = _req("PUT", "/mount-targets", {"subnetId": "subnet-12345678"})
assert s == 400
assert body.get("__type") == "ValidationException"
def test_update_mount_target_requires_security_groups():
s, fs = _req("PUT", "/file-systems", {"bucket": BUCKET_ARN, "roleArn": ROLE_ARN})
fs_id = fs["fileSystemId"]
try:
s, mt = _req("PUT", "/mount-targets", {
"fileSystemId": fs_id,
"subnetId": "subnet-12345678",
})
s, body = _req("PUT", f"/mount-targets/{mt['mountTargetId']}", {})
assert s == 400
assert body.get("__type") == "ValidationException"
finally:
_req("DELETE", f"/file-systems/{fs_id}")
# ---------------------------------------------------------------------------
# Access points
# ---------------------------------------------------------------------------
def test_access_point_lifecycle():
s, fs = _req("PUT", "/file-systems", {"bucket": BUCKET_ARN, "roleArn": ROLE_ARN})
fs_id = fs["fileSystemId"]
try:
s, ap = _req("PUT", "/access-points", {
"fileSystemId": fs_id,
"posixUser": {"uid": 1000, "gid": 1000},
"rootDirectory": {"path": "/data"},
"tags": [{"key": "Name", "value": "ap-test"}],
})
assert s == 200
assert ap["accessPointId"].startswith("fsap-")
assert ap["fileSystemId"] == fs_id
assert ap["accessPointArn"].startswith("arn:aws:s3files:")
assert "/access-point/" in ap["accessPointArn"]
assert ap["name"] == "ap-test"
s, listed = _req("GET", "/access-points", query={"fileSystemId": fs_id})
assert s == 200
assert any(a["accessPointId"] == ap["accessPointId"] for a in listed["accessPoints"])
s, _ = _req("DELETE", f"/access-points/{ap['accessPointId']}")
assert s == 204
finally:
_req("DELETE", f"/file-systems/{fs_id}")
def test_list_access_points_requires_filesystem_id():
s, body = _req("GET", "/access-points")
assert s == 400
assert body.get("__type") == "ValidationException"
# ---------------------------------------------------------------------------
# File-system policy
# ---------------------------------------------------------------------------
def test_file_system_policy_lifecycle():
s, fs = _req("PUT", "/file-systems", {"bucket": BUCKET_ARN, "roleArn": ROLE_ARN})
fs_id = fs["fileSystemId"]
try:
policy_doc = json.dumps({"Version": "2012-10-17", "Statement": []})
s, _ = _req("PUT", f"/file-systems/{fs_id}/policy", {"policy": policy_doc})
assert s == 200
s, got = _req("GET", f"/file-systems/{fs_id}/policy")
assert s == 200
assert got["fileSystemId"] == fs_id
assert got["policy"] == policy_doc
s, _ = _req("DELETE", f"/file-systems/{fs_id}/policy")
assert s == 204
s, body = _req("GET", f"/file-systems/{fs_id}/policy")
assert s == 404
finally:
_req("DELETE", f"/file-systems/{fs_id}")
# ---------------------------------------------------------------------------
# Synchronization configuration
# ---------------------------------------------------------------------------
def test_synchronization_configuration_lifecycle_and_optimistic_locking():
s, fs = _req("PUT", "/file-systems", {"bucket": BUCKET_ARN, "roleArn": ROLE_ARN})
fs_id = fs["fileSystemId"]
try:
s, _ = _req("PUT", f"/file-systems/{fs_id}/synchronization-configuration", {
"expirationDataRules": [{"daysAfterLastAccess": 7}],
"importDataRules": [{"prefix": "", "trigger": "NEW_OBJECTS"}],
})
assert s == 200
s, got = _req("GET", f"/file-systems/{fs_id}/synchronization-configuration")
assert s == 200
assert got["latestVersionNumber"] == 1
assert got["expirationDataRules"][0]["daysAfterLastAccess"] == 7
# stale version → 409
s, body = _req("PUT", f"/file-systems/{fs_id}/synchronization-configuration", {
"expirationDataRules": [{"daysAfterLastAccess": 14}],
"importDataRules": [{"prefix": "", "trigger": "NEW_OBJECTS"}],
"latestVersionNumber": 99,
})
assert s == 409
assert body.get("__type") == "ConflictException"
# correct version → 200, bump
s, _ = _req("PUT", f"/file-systems/{fs_id}/synchronization-configuration", {
"expirationDataRules": [{"daysAfterLastAccess": 14}],
"importDataRules": [{"prefix": "", "trigger": "NEW_OBJECTS"}],
"latestVersionNumber": 1,
})
assert s == 200
s, got = _req("GET", f"/file-systems/{fs_id}/synchronization-configuration")
assert got["latestVersionNumber"] == 2
finally:
_req("DELETE", f"/file-systems/{fs_id}")
# ---------------------------------------------------------------------------
# Tagging
# ---------------------------------------------------------------------------
def test_resource_tags_lifecycle_uses_resource_tags_path():
s, fs = _req("PUT", "/file-systems", {"bucket": BUCKET_ARN, "roleArn": ROLE_ARN})
fs_id = fs["fileSystemId"]
try:
s, _ = _req("POST", f"/resource-tags/{fs_id}", {
"tags": [{"key": "Env", "value": "test"}, {"key": "Owner", "value": "ministack"}],
})
assert s == 200
s, listed = _req("GET", f"/resource-tags/{fs_id}")
assert s == 200
tags = {t["key"]: t["value"] for t in listed["tags"]}
assert tags == {"Env": "test", "Owner": "ministack"}
s, _ = _req("DELETE", f"/resource-tags/{fs_id}", query={"tagKeys": ["Env"]})
assert s == 200
s, listed = _req("GET", f"/resource-tags/{fs_id}")
assert {t["key"] for t in listed["tags"]} == {"Owner"}
finally:
_req("DELETE", f"/file-systems/{fs_id}")
def test_tag_unknown_resource_returns_404():
s, body = _req("POST", "/resource-tags/fs-deadbeefdeadbeefdead", {
"tags": [{"key": "k", "value": "v"}],
})
assert s == 404
assert body.get("__type") == "ResourceNotFoundException"
def test_resource_tags_accept_file_system_and_access_point_arns():
s, fs = _req("PUT", "/file-systems", {"bucket": BUCKET_ARN, "roleArn": ROLE_ARN})
fs_id = fs["fileSystemId"]
fs_arn = fs["fileSystemArn"]
try:
s, _ = _req("POST", _resource_tags_path(fs_arn), {
"tags": [{"key": "Scope", "value": "filesystem"}],
})
assert s == 200
s, listed = _req("GET", _resource_tags_path(fs_arn))
assert s == 200
assert {t["key"]: t["value"] for t in listed["tags"]} == {"Scope": "filesystem"}
s, ap = _req("PUT", "/access-points", {"fileSystemId": fs_id})
assert s == 200
ap_arn = ap["accessPointArn"]
s, _ = _req("POST", _resource_tags_path(ap_arn), {
"tags": [{"key": "Scope", "value": "accesspoint"}],
})
assert s == 200
s, listed = _req("GET", _resource_tags_path(ap_arn))
assert s == 200
assert {t["key"]: t["value"] for t in listed["tags"]} == {"Scope": "accesspoint"}
s, _ = _req("DELETE", _resource_tags_path(ap_arn), query={"tagKeys": ["Scope"]})
assert s == 200
s, listed = _req("GET", _resource_tags_path(ap_arn))
assert listed["tags"] == []
finally:
_req("DELETE", f"/file-systems/{fs_id}")
def test_resource_tags_reject_out_of_scope_arns_before_touching_tags():
s, fs = _req("PUT", "/file-systems", {"bucket": BUCKET_ARN, "roleArn": ROLE_ARN})
fs_id = fs["fileSystemId"]
try:
s, _ = _req("POST", f"/resource-tags/{fs_id}", {
"tags": [{"key": "Keep", "value": "true"}],
})
assert s == 200
bad_arns = [
"arn:nope",
f"arn:aws-cn:s3files:us-east-1:000000000000:file-system/{fs_id}",
f"arn:aws:s3:us-east-1:000000000000:file-system/{fs_id}",
f"arn:aws:s3files:us-west-2:000000000000:file-system/{fs_id}",
f"arn:aws:s3files:us-east-1:111111111111:file-system/{fs_id}",
f"arn:aws:s3files:us-east-1:000000000000:mount-target/{fs_id}",
"arn:aws:s3files:us-east-1:000000000000:file-system/fs-nothex",
f"arn:aws:s3files:us-east-1:000000000000:file-system/{fs_id}/access-point/fs-nothex",
]
for arn in bad_arns:
for method, body, query in (
("POST", {"tags": [{"key": "Bad", "value": "false"}]}, None),
("DELETE", None, {"tagKeys": ["Keep"]}),
("GET", None, None),
):
s, response = _req(method, _resource_tags_path(arn), body=body, query=query)
assert s == 400, (method, arn, response)
assert response.get("__type") == "ValidationException"
missing = "arn:aws:s3files:us-east-1:000000000000:file-system/fs-deadbeefdeadbeefdea"
s, response = _req("GET", _resource_tags_path(missing))
assert s == 404
assert response.get("__type") == "ResourceNotFoundException"
s, listed = _req("GET", f"/resource-tags/{fs_id}")
assert s == 200
assert {t["key"]: t["value"] for t in listed["tags"]} == {"Keep": "true"}
finally:
_req("DELETE", f"/file-systems/{fs_id}")
# ---------------------------------------------------------------------------
# Multi-tenancy
# ---------------------------------------------------------------------------
def test_account_isolation_for_file_systems():
a, b = "111111111111", "222222222222"
s, fs = _req("PUT", "/file-systems",
{"bucket": BUCKET_ARN, "roleArn": ROLE_ARN}, account=a)
fs_id = fs["fileSystemId"]
try:
s, listed_a = _req("GET", "/file-systems", account=a)
s, listed_b = _req("GET", "/file-systems", account=b)
ids_a = {f["fileSystemId"] for f in listed_a["fileSystems"]}
ids_b = {f["fileSystemId"] for f in listed_b["fileSystems"]}
assert fs_id in ids_a
assert fs_id not in ids_b
s, body = _req("GET", f"/file-systems/{fs_id}", account=b)
assert s == 404
assert body.get("__type") == "ResourceNotFoundException"
s, body = _req("DELETE", f"/file-systems/{fs_id}", account=b)
assert s == 404
finally:
_req("DELETE", f"/file-systems/{fs_id}", account=a)
# ---------------------------------------------------------------------------
# Pagination
# ---------------------------------------------------------------------------
def test_list_file_systems_pagination_walks_all_items():
created = []
try:
for _ in range(7):
_, fs = _req("PUT", "/file-systems",
{"bucket": BUCKET_ARN, "roleArn": ROLE_ARN})
created.append(fs["fileSystemId"])
seen = []
token = None
for _ in range(10): # safety bound; real loop terminates by None
q = {"maxResults": 3}
if token:
q["nextToken"] = token
s, page = _req("GET", "/file-systems", query=q)
assert s == 200
assert len(page["fileSystems"]) <= 3
seen.extend(f["fileSystemId"] for f in page["fileSystems"])
token = page.get("nextToken")
if not token:
break
else:
raise AssertionError("pagination did not terminate")
assert set(created).issubset(set(seen))
# No duplicates across pages.
assert len(seen) == len(set(seen))
finally:
for fs_id in created:
_req("DELETE", f"/file-systems/{fs_id}")
# ---------------------------------------------------------------------------
# ARN-form resourceId acceptance
# ---------------------------------------------------------------------------
def test_body_parameter_accepts_full_arn_form():
"""AWS shapes accept either a bare ID (`fs-xxx`) or a full ARN for
`fileSystemId` request fields. Verify the ARN form is normalized so
downstream lookups match the bare-ID storage key.
Path-parameter ARNs are not exercised: ASGI delivers the path already
URL-decoded, which collides with the `/` inside the ARN. Real SDKs
typically pass the bare ID in the URI and only use the ARN form in the
JSON body, which is the case covered here.
"""
s, fs = _req("PUT", "/file-systems", {"bucket": BUCKET_ARN, "roleArn": ROLE_ARN})
fs_id = fs["fileSystemId"]
fs_arn = fs["fileSystemArn"]
try:
# CreateMountTarget with the ARN form of fileSystemId.
s, mt = _req("PUT", "/mount-targets", {
"fileSystemId": fs_arn,
"subnetId": "subnet-12345678",
})
assert s == 200, mt
assert mt["fileSystemId"] == fs_id # normalized back to bare ID
_req("DELETE", f"/mount-targets/{mt['mountTargetId']}")
# CreateAccessPoint with the ARN form too.
s, ap = _req("PUT", "/access-points", {"fileSystemId": fs_arn})
assert s == 200, ap
assert ap["fileSystemId"] == fs_id
_req("DELETE", f"/access-points/{ap['accessPointId']}")
finally:
_req("DELETE", f"/file-systems/{fs_id}")