policy: test get object tagging with conditionals

Signed-off-by: Abhishek Lekshmanan <abhishek@suse.com>
This commit is contained in:
Abhishek Lekshmanan 2018-01-17 10:56:26 +01:00
parent 5167af2e73
commit 3511eabc5c

View file

@ -9479,3 +9479,59 @@ def test_bucket_policy_get_obj_existing_tag():
res = new_conn.make_request("GET",bucket.name, 'invalidtag')
eq(res.status, 403)
@attr(resource='object')
@attr(method='get')
@attr(operation='Test ExistingObjectTag conditional on get object tagging')
@attr(assertion='success')
@attr('tagging')
@attr('bucket-policy')
def test_bucket_policy_get_obj_tagging_existing_tag():
bucket = _create_keys(keys=['publictag','privatetag','invalidtag'])
tag_conditional = {"StringEquals": {
"s3:ExistingObjectTag/security" : "public"
}}
resource = _make_arn_resource("{}/{}".format(bucket.name, "*"))
policy_document = make_json_policy("s3:GetObjectTagging",
resource,
conditions=tag_conditional)
bucket.set_policy(policy_document)
input_tagset = S3TestTagSet()
input_tagset.add_tag('security','public')
input_tagset.add_tag('foo','bar')
input_tagset2 = S3TestTagSet()
input_tagset2.add_tag('security','private')
input_tagset3 = S3TestTagSet()
input_tagset3.add_tag('security1','public')
res = _put_obj_tags(bucket, 'publictag', input_tagset.to_xml())
eq(res.status, 200)
res = _put_obj_tags(bucket, 'privatetag', input_tagset2.to_xml())
eq(res.status, 200)
res = _put_obj_tags(bucket, 'invalidtag', input_tagset3.to_xml())
eq(res.status, 200)
new_conn = _get_alt_connection()
res = new_conn.make_request("GET",bucket.name, 'publictag', query_args='tagging')
eq(res.status, 200)
# A get object itself should fail since we allowed only GetObjectTagging
res = new_conn.make_request("GET",bucket.name, 'publictag')
eq(res.status, 403)
res = new_conn.make_request("GET",bucket.name, 'privatetag', query_args='tagging')
eq(res.status, 403)
res = new_conn.make_request("GET",bucket.name, 'invalidtag', query_args='tagging')
eq(res.status, 403)