From dcad44869f95ee03fe7e62e1129cc90c550d5a11 Mon Sep 17 00:00:00 2001 From: Yaroslava Lukoyanova Date: Thu, 16 May 2024 10:12:02 +0300 Subject: [PATCH] Updated test_s3_bucket_policy according to 1.5 --- .../services/s3_gate/test_s3_policy.py | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pytest_tests/testsuites/services/s3_gate/test_s3_policy.py b/pytest_tests/testsuites/services/s3_gate/test_s3_policy.py index a0d4c1a7..7a46b0a9 100644 --- a/pytest_tests/testsuites/services/s3_gate/test_s3_policy.py +++ b/pytest_tests/testsuites/services/s3_gate/test_s3_policy.py @@ -1,7 +1,9 @@ +import json import os import allure import pytest +from botocore.exceptions import ClientError from frostfs_testlib import reporter from frostfs_testlib.s3 import S3ClientWrapper, VersioningStatus from frostfs_testlib.steps.cli.container import search_container_by_name @@ -87,23 +89,24 @@ class TestS3GatePolicy(ClusterTestBase): @allure.title("Bucket policy (s3_client={s3_client})") def test_s3_bucket_policy(self, s3_client: S3ClientWrapper): - with reporter.step("Create bucket with default policy"): + with reporter.step("Create bucket"): bucket = s3_client.create_bucket() s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED) with reporter.step("GetBucketPolicy"): - s3_client.get_bucket_policy(bucket) + with pytest.raises((RuntimeError, ClientError)): + s3_client.get_bucket_policy(bucket) with reporter.step("Put new policy"): custom_policy = f"file://{os.getcwd()}/pytest_tests/resources/files/bucket_policy.json" custom_policy = { - "Version": "2008-10-17", + "Version": "2012-10-17", "Id": "aaaa-bbbb-cccc-dddd", "Statement": [ { "Sid": "AddPerm", "Effect": "Allow", - "Principal": {"AWS": "*"}, + "Principal": "*", "Action": ["s3:GetObject"], "Resource": [f"arn:aws:s3:::{bucket}/*"], } @@ -112,8 +115,16 @@ class TestS3GatePolicy(ClusterTestBase): s3_client.put_bucket_policy(bucket, custom_policy) with reporter.step("GetBucketPolicy"): - policy_1 = s3_client.get_bucket_policy(bucket) - print(policy_1) + returned_policy = json.loads(s3_client.get_bucket_policy(bucket)) + + assert returned_policy == custom_policy, "Wrong policy was received" + + with reporter.step("Delete the policy"): + s3_client.delete_bucket_policy(bucket) + + with reporter.step("GetBucketPolicy"): + with pytest.raises((RuntimeError, ClientError)): + s3_client.get_bucket_policy(bucket) @allure.title("Bucket CORS (s3_client={s3_client})") def test_s3_cors(self, s3_client: S3ClientWrapper):