|
10 | 10 | from localstack.utils.strings import short_uid |
11 | 11 | from localstack.utils.urls import localstack_host |
12 | 12 |
|
13 | | -# TODO: this fails in CI, not sure why yet |
14 | | -# s3_control_endpoint = f"http://s3-control.{localstack_host()}" |
15 | 13 | s3_control_endpoint = f"https://{localstack_host().host_and_port()}" |
16 | 14 |
|
17 | 15 |
|
@@ -421,3 +419,152 @@ def test_access_point_pagination( |
421 | 419 |
|
422 | 420 | list_by_bucket = s3control_client.list_access_points(AccountId=account_id, Bucket=bucket_1) |
423 | 421 | snapshot.match("list-by-bucket", list_by_bucket) |
| 422 | + |
| 423 | + |
| 424 | +@markers.snapshot.skip_snapshot_verify( |
| 425 | + paths=[ |
| 426 | + # FIXME: this needs to be updated in the serializer, see https://github.com/localstack/localstack/pull/9730 |
| 427 | + "$..HostId", |
| 428 | + ] |
| 429 | +) |
| 430 | +class TestS3ControlTagging: |
| 431 | + @markers.aws.validated |
| 432 | + def test_tag_lifecycle( |
| 433 | + self, s3_bucket, s3control_client, snapshot, account_id, s3control_snapshot |
| 434 | + ): |
| 435 | + bucket_arn = f"arn:aws:s3:::{s3_bucket}" |
| 436 | + |
| 437 | + list_tags_before = s3control_client.list_tags_for_resource( |
| 438 | + AccountId=account_id, |
| 439 | + ResourceArn=bucket_arn, |
| 440 | + ) |
| 441 | + snapshot.match("list-tags-before", list_tags_before) |
| 442 | + |
| 443 | + tag_resource = s3control_client.tag_resource( |
| 444 | + AccountId=account_id, |
| 445 | + ResourceArn=bucket_arn, |
| 446 | + Tags=[ |
| 447 | + {"Key": "key1", "Value": "value1"}, |
| 448 | + {"Key": "key2", "Value": "value2"}, |
| 449 | + ], |
| 450 | + ) |
| 451 | + snapshot.match("tag-resource", tag_resource) |
| 452 | + |
| 453 | + list_tags_1 = s3control_client.list_tags_for_resource( |
| 454 | + AccountId=account_id, |
| 455 | + ResourceArn=bucket_arn, |
| 456 | + ) |
| 457 | + snapshot.match("list-tags-1", list_tags_1) |
| 458 | + |
| 459 | + tag_resource_after_update = s3control_client.tag_resource( |
| 460 | + AccountId=account_id, ResourceArn=bucket_arn, Tags=[{"Key": "key3", "Value": "value3"}] |
| 461 | + ) |
| 462 | + snapshot.match("tag-resource-after-update", tag_resource_after_update) |
| 463 | + |
| 464 | + list_tags_after_update = s3control_client.list_tags_for_resource( |
| 465 | + AccountId=account_id, |
| 466 | + ResourceArn=bucket_arn, |
| 467 | + ) |
| 468 | + snapshot.match("list-tags-after-update", list_tags_after_update) |
| 469 | + |
| 470 | + untag_resource = s3control_client.untag_resource( |
| 471 | + AccountId=account_id, ResourceArn=bucket_arn, TagKeys=["key3"] |
| 472 | + ) |
| 473 | + snapshot.match("untag-resource", untag_resource) |
| 474 | + |
| 475 | + list_tags_after_untag = s3control_client.list_tags_for_resource( |
| 476 | + AccountId=account_id, |
| 477 | + ResourceArn=bucket_arn, |
| 478 | + ) |
| 479 | + snapshot.match("list-tags-after-untag", list_tags_after_untag) |
| 480 | + |
| 481 | + untag_resource_idempotent = s3control_client.untag_resource( |
| 482 | + AccountId=account_id, ResourceArn=bucket_arn, TagKeys=["key3"] |
| 483 | + ) |
| 484 | + snapshot.match("untag-resource-idempotent", untag_resource_idempotent) |
| 485 | + |
| 486 | + @markers.aws.validated |
| 487 | + def test_tag_resource_validation( |
| 488 | + self, s3_bucket, s3control_client_no_validation, account_id, snapshot, s3control_snapshot |
| 489 | + ): |
| 490 | + bucket_arn = f"arn:aws:s3:::{s3_bucket}" |
| 491 | + |
| 492 | + with pytest.raises(ClientError) as e: |
| 493 | + s3control_client_no_validation.tag_resource( |
| 494 | + AccountId=account_id, |
| 495 | + ResourceArn=bucket_arn, |
| 496 | + Tags=[{"Key": None, "Value": "value1"}], |
| 497 | + ) |
| 498 | + snapshot.match("tags-key-none", e.value.response) |
| 499 | + |
| 500 | + with pytest.raises(ClientError) as e: |
| 501 | + s3control_client_no_validation.tag_resource( |
| 502 | + AccountId=account_id, |
| 503 | + ResourceArn=bucket_arn, |
| 504 | + Tags=[{"Key": "key1", "Value": None}], |
| 505 | + ) |
| 506 | + snapshot.match("tags-value-none", e.value.response) |
| 507 | + |
| 508 | + with pytest.raises(ClientError) as e: |
| 509 | + s3control_client_no_validation.tag_resource( |
| 510 | + AccountId=account_id, |
| 511 | + ResourceArn=bucket_arn, |
| 512 | + Tags=[{"Key": "aws:test", "Value": "value1"}], |
| 513 | + ) |
| 514 | + snapshot.match("tags-key-aws-prefix", e.value.response) |
| 515 | + |
| 516 | + with pytest.raises(ClientError) as e: |
| 517 | + s3control_client_no_validation.tag_resource( |
| 518 | + AccountId=account_id, |
| 519 | + ResourceArn=bucket_arn, |
| 520 | + Tags=[ |
| 521 | + {"Key": "key1", "Value": "value1"}, |
| 522 | + {"Key": "key1", "Value": "value1"}, |
| 523 | + ], |
| 524 | + ) |
| 525 | + snapshot.match("tags-key-aws-duplicated-key", e.value.response) |
| 526 | + |
| 527 | + with pytest.raises(ClientError) as e: |
| 528 | + s3control_client_no_validation.tag_resource( |
| 529 | + AccountId=account_id, |
| 530 | + ResourceArn=bucket_arn, |
| 531 | + Tags=[{"Key": "test", "Value": "value1,value2"}], |
| 532 | + ) |
| 533 | + snapshot.match("tags-key-aws-bad-value", e.value.response) |
| 534 | + |
| 535 | + with pytest.raises(ClientError) as e: |
| 536 | + s3control_client_no_validation.tag_resource( |
| 537 | + AccountId=account_id, |
| 538 | + ResourceArn=bucket_arn, |
| 539 | + Tags=[{"Key": "test,test2", "Value": "value1"}], |
| 540 | + ) |
| 541 | + snapshot.match("tags-key-aws-bad-key", e.value.response) |
| 542 | + |
| 543 | + @markers.aws.validated |
| 544 | + def test_tag_operation_no_bucket( |
| 545 | + self, s3_bucket, s3control_client, account_id, snapshot, s3control_snapshot |
| 546 | + ): |
| 547 | + bucket_arn = f"arn:aws:s3:::{short_uid()}-{short_uid()}" |
| 548 | + |
| 549 | + with pytest.raises(ClientError) as e: |
| 550 | + s3control_client.tag_resource( |
| 551 | + AccountId=account_id, |
| 552 | + ResourceArn=bucket_arn, |
| 553 | + Tags=[{"Key": "key1", "Value": "value1"}], |
| 554 | + ) |
| 555 | + snapshot.match("tag-resource-no-exist", e.value.response) |
| 556 | + |
| 557 | + with pytest.raises(ClientError) as e: |
| 558 | + s3control_client.untag_resource( |
| 559 | + AccountId=account_id, |
| 560 | + ResourceArn=bucket_arn, |
| 561 | + TagKeys=["key1"], |
| 562 | + ) |
| 563 | + snapshot.match("untag-resource-no-exist", e.value.response) |
| 564 | + |
| 565 | + with pytest.raises(ClientError) as e: |
| 566 | + s3control_client.list_tags_for_resource( |
| 567 | + AccountId=account_id, |
| 568 | + ResourceArn=bucket_arn, |
| 569 | + ) |
| 570 | + snapshot.match("list-resource-tags-no-exist", e.value.response) |
0 commit comments