diff --git a/swift/common/middleware/tempurl.py b/swift/common/middleware/tempurl.py index 83c4e7b..fe854c1 100644 --- a/swift/common/middleware/tempurl.py +++ b/swift/common/middleware/tempurl.py @@ -485,7 +485,7 @@ class TempURL(object): :returns: None for safe operations or swob.HTTPBadResponse if the request includes disallowed headers. """ - if env['REQUEST_METHOD'] in ('GET', 'HEAD', 'OPTIONS'): + if env['REQUEST_METHOD'] in ('GET', 'HEAD', 'OPTIONS', 'POST'): return for h in env: if h in self.disallowed_headers: diff --git a/test/functional/swift_test_client.py b/test/functional/swift_test_client.py index c93b2ea..c80db01 100644 --- a/test/functional/swift_test_client.py +++ b/test/functional/swift_test_client.py @@ -1000,3 +1000,26 @@ class File(Base): raise ResponseError(self.conn.response) self.md5 = self.compute_md5sum(six.StringIO(data)) return resp + + def post(self, hdrs=None, parms=None, cfg=None, return_resp=False): + if hdrs is None: + hdrs = {} + if parms is None: + parms = {} + if cfg is None: + cfg = {} + + headers = self.make_headers(cfg=cfg) + headers.update(hdrs) + + self.conn.make_request('POST', self.path, hdrs=headers, + parms=parms, cfg=cfg) + + if self.conn.response.status not in (201, 202): + raise ResponseError(self.conn.response, 'POST', + self.conn.make_path(self.path)) + + if return_resp: + return self.conn.response + + return True diff --git a/test/functional/tests.py b/test/functional/tests.py index 06cf125..d336a67 100644 --- a/test/functional/tests.py +++ b/test/functional/tests.py @@ -2957,6 +2957,30 @@ class TestTempurl(Base): else: self.fail('request did not error') + # try again using a tempurl POST to an already created object + new_obj.write('', {}, parms=put_parms, cfg={'no_auth_token': True}) + expires = int(time.time()) + 86400 + sig = self.tempurl_sig( + 'POST', expires, self.env.conn.make_path(new_obj.path), + self.env.tempurl_key) + post_parms = {'temp_url_sig': sig, + 'temp_url_expires': str(expires)} + # pointer to non-existent container + new_obj.post({'x-object-manifest': '%s/foo' % 'some_randon_container'}, + parms=post_parms, cfg={'no_auth_token': True}) + try: + info = new_obj.info(parms=post_parms, cfg={'no_auth_token': True}) + except ResponseError as e: + self.assertEqual(e.status, 404) + else: + self.fail('Expected a 404') + + # pointer to existing comtainer + new_obj.post({'x-object-manifest': '%s/foo' % other_container}, + parms=post_parms, cfg={'no_auth_token': True}) + info = new_obj.info(parms=post_parms, cfg={'no_auth_token': True}) + self.assertTrue('x_object_manifest' in info) + def test_HEAD(self): expires = int(time.time()) + 86400 sig = self.tempurl_sig(