cubefs

Форк
0
/
test_bucket_policy.py 
58 строк · 2.1 Кб
1
# Copyright 2020 The CubeFS Authors.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
# implied. See the License for the specific language governing
13
# permissions and limitations under the License.
14

15
# -*- coding: utf-8 -*-
16

17
import env
18
import json
19
from base import S3TestCase, get_env_s3_client
20

21
POLICY = '{' \
22
         '"Version": "2012-10-17", ' \
23
         '"Statement": [{ ' \
24
         '"Sid": "id-1",' \
25
         '"Effect": "Allow",' \
26
         '"Principal": {"AWS": ["arn:aws:iam::123456789012:root"]}, ' \
27
         '"Action": ["s3:PutObject"], ' \
28
         '"Resource": ["arn:aws:s3:::' + env.BUCKET + '/*" ] ' \
29
         '}]}'
30

31

32
class PolicyTest(S3TestCase):
33
    s3 = None
34

35
    def __init__(self, case):
36
        super(PolicyTest, self).__init__(case)
37
        self.s3 = get_env_s3_client()
38

39
    def test_policy_set(self):
40
        # Get bucket policy configuration
41
        try:
42
            result=self.s3.get_bucket_policy(Bucket=env.BUCKET)
43
        except Exception as e:
44
            self.assert_client_error(error=e, expect_status_code=404)
45
        # Put bucket policy configuration
46
        self.assert_result_status_code(
47
            result=self.s3.put_bucket_policy(Bucket=env.BUCKET, Policy=POLICY), status_code=204)
48
        # Get bucket policy configuration
49
        self.assert_get_bucket_policy_result(
50
            result=self.s3.get_bucket_policy(Bucket=env.BUCKET), policy=json.loads(POLICY))
51
        # Delete bucket policy configuration
52
        self.assert_result_status_code(
53
            result=self.s3.delete_bucket_policy(Bucket=env.BUCKET), status_code=204)
54
        # Get bucket policy configuration
55
        try:
56
            result=self.s3.get_bucket_policy(Bucket=env.BUCKET)
57
        except Exception as e:
58
            self.assert_client_error(error=e, expect_status_code=404)
59

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.