Best Python code snippet using tempest_python
test_container_acl_negative.py
Source:test_container_acl_negative.py
...41 def test_write_object_without_using_creds(self):42 # trying to create object with empty headers43 # X-Auth-Token is not provided44 object_name = data_utils.rand_name(name='Object')45 self.object_client.auth_provider.set_alt_auth_data(46 request_part='headers',47 auth_data=None48 )49 self.assertRaises(lib_exc.Unauthorized,50 self.object_client.create_object,51 self.container_name, object_name, 'data', headers={})52 @test.attr(type=['negative'])53 @test.idempotent_id('af85af0b-a025-4e72-a90e-121babf55720')54 def test_delete_object_without_using_creds(self):55 # create object56 object_name = data_utils.rand_name(name='Object')57 resp, _ = self.object_client.create_object(self.container_name,58 object_name, 'data')59 # trying to delete object with empty headers60 # X-Auth-Token is not provided61 self.object_client.auth_provider.set_alt_auth_data(62 request_part='headers',63 auth_data=None64 )65 self.assertRaises(lib_exc.Unauthorized,66 self.object_client.delete_object,67 self.container_name, object_name)68 @test.attr(type=['negative'])69 @test.idempotent_id('63d84e37-55a6-42e2-9e5f-276e60e26a00')70 def test_write_object_with_non_authorized_user(self):71 # attempt to upload another file using non-authorized user72 # User provided token is forbidden. ACL are not set73 object_name = data_utils.rand_name(name='Object')74 # trying to create object with non-authorized user75 self.object_client.auth_provider.set_alt_auth_data(76 request_part='headers',77 auth_data=self.test_auth_data78 )79 self.assertRaises(lib_exc.Forbidden,80 self.object_client.create_object,81 self.container_name, object_name, 'data', headers={})82 @test.attr(type=['negative'])83 @test.idempotent_id('abf63359-be52-4feb-87dd-447689fc77fd')84 def test_read_object_with_non_authorized_user(self):85 # attempt to read object using non-authorized user86 # User provided token is forbidden. ACL are not set87 object_name = data_utils.rand_name(name='Object')88 resp, _ = self.object_client.create_object(89 self.container_name, object_name, 'data')90 self.assertHeaders(resp, 'Object', 'PUT')91 # trying to get object with non authorized user token92 self.object_client.auth_provider.set_alt_auth_data(93 request_part='headers',94 auth_data=self.test_auth_data95 )96 self.assertRaises(lib_exc.Forbidden,97 self.object_client.get_object,98 self.container_name, object_name)99 @test.attr(type=['negative'])100 @test.idempotent_id('7343ac3d-cfed-4198-9bb0-00149741a492')101 def test_delete_object_with_non_authorized_user(self):102 # attempt to delete object using non-authorized user103 # User provided token is forbidden. ACL are not set104 object_name = data_utils.rand_name(name='Object')105 resp, _ = self.object_client.create_object(106 self.container_name, object_name, 'data')107 self.assertHeaders(resp, 'Object', 'PUT')108 # trying to delete object with non-authorized user token109 self.object_client.auth_provider.set_alt_auth_data(110 request_part='headers',111 auth_data=self.test_auth_data112 )113 self.assertRaises(lib_exc.Forbidden,114 self.object_client.delete_object,115 self.container_name, object_name)116 @test.attr(type=['negative'])117 @test.idempotent_id('9ed01334-01e9-41ea-87ea-e6f465582823')118 def test_read_object_without_rights(self):119 # attempt to read object using non-authorized user120 # update X-Container-Read metadata ACL121 cont_headers = {'X-Container-Read': 'badtenant:baduser'}122 resp_meta, body = self.container_client.update_container_metadata(123 self.container_name, metadata=cont_headers,124 metadata_prefix='')125 self.assertHeaders(resp_meta, 'Container', 'POST')126 # create object127 object_name = data_utils.rand_name(name='Object')128 resp, _ = self.object_client.create_object(self.container_name,129 object_name, 'data')130 self.assertHeaders(resp, 'Object', 'PUT')131 # Trying to read the object without rights132 self.object_client.auth_provider.set_alt_auth_data(133 request_part='headers',134 auth_data=self.test_auth_data135 )136 self.assertRaises(lib_exc.Forbidden,137 self.object_client.get_object,138 self.container_name, object_name)139 @test.attr(type=['negative'])140 @test.idempotent_id('a3a585a7-d8cf-4b65-a1a0-edc2b1204f85')141 def test_write_object_without_rights(self):142 # attempt to write object using non-authorized user143 # update X-Container-Write metadata ACL144 cont_headers = {'X-Container-Write': 'badtenant:baduser'}145 resp_meta, body = self.container_client.update_container_metadata(146 self.container_name, metadata=cont_headers,147 metadata_prefix='')148 self.assertHeaders(resp_meta, 'Container', 'POST')149 # Trying to write the object without rights150 self.object_client.auth_provider.set_alt_auth_data(151 request_part='headers',152 auth_data=self.test_auth_data153 )154 object_name = data_utils.rand_name(name='Object')155 self.assertRaises(lib_exc.Forbidden,156 self.object_client.create_object,157 self.container_name,158 object_name, 'data', headers={})159 @test.attr(type=['negative'])160 @test.idempotent_id('8ba512ad-aa6e-444e-b882-2906a0ea2052')161 def test_write_object_without_write_rights(self):162 # attempt to write object using non-authorized user163 # update X-Container-Read and X-Container-Write metadata ACL164 tenant_name = self.os_operator.credentials.tenant_name165 username = self.os_operator.credentials.username166 cont_headers = {'X-Container-Read':167 tenant_name + ':' + username,168 'X-Container-Write': ''}169 resp_meta, body = self.container_client.update_container_metadata(170 self.container_name, metadata=cont_headers,171 metadata_prefix='')172 self.assertHeaders(resp_meta, 'Container', 'POST')173 # Trying to write the object without write rights174 self.object_client.auth_provider.set_alt_auth_data(175 request_part='headers',176 auth_data=self.test_auth_data177 )178 object_name = data_utils.rand_name(name='Object')179 self.assertRaises(lib_exc.Forbidden,180 self.object_client.create_object,181 self.container_name,182 object_name, 'data', headers={})183 @test.attr(type=['negative'])184 @test.idempotent_id('b4e366f8-f185-47ab-b789-df4416f9ecdb')185 def test_delete_object_without_write_rights(self):186 # attempt to delete object using non-authorized user187 # update X-Container-Read and X-Container-Write metadata ACL188 tenant_name = self.os_operator.credentials.tenant_name189 username = self.os_operator.credentials.username190 cont_headers = {'X-Container-Read':191 tenant_name + ':' + username,192 'X-Container-Write': ''}193 resp_meta, body = self.container_client.update_container_metadata(194 self.container_name, metadata=cont_headers,195 metadata_prefix='')196 self.assertHeaders(resp_meta, 'Container', 'POST')197 # create object198 object_name = data_utils.rand_name(name='Object')199 resp, _ = self.object_client.create_object(self.container_name,200 object_name, 'data')201 self.assertHeaders(resp, 'Object', 'PUT')202 # Trying to delete the object without write rights203 self.object_client.auth_provider.set_alt_auth_data(204 request_part='headers',205 auth_data=self.test_auth_data206 )207 self.assertRaises(lib_exc.Forbidden,208 self.object_client.delete_object,209 self.container_name,...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!