mirror of
https://github.com/ceph/s3-tests.git
synced 2024-11-25 03:47:22 +00:00
refactor raw GET tests
urllib2 is no longer necessary. We will use urlparse instead to get the path and query components of the uri.
This commit is contained in:
parent
e4d78eccbb
commit
76f78c0bb8
1 changed files with 34 additions and 39 deletions
|
@ -14,7 +14,7 @@ import socket
|
||||||
import ssl
|
import ssl
|
||||||
|
|
||||||
from httplib import HTTPConnection, HTTPSConnection
|
from httplib import HTTPConnection, HTTPSConnection
|
||||||
from urllib2 import urlopen, HTTPError
|
from urlparse import urlparse
|
||||||
|
|
||||||
from nose.tools import eq_ as eq
|
from nose.tools import eq_ as eq
|
||||||
from nose.plugins.attrib import attr
|
from nose.plugins.attrib import attr
|
||||||
|
@ -784,17 +784,21 @@ def _setup_request(bucket_acl=None, object_acl=None):
|
||||||
return (bucket, key)
|
return (bucket, key)
|
||||||
|
|
||||||
|
|
||||||
def _make_request(method, bucket, key):
|
def _make_request(method, bucket, key, body=None, authenticated=False):
|
||||||
|
if authenticated:
|
||||||
|
url = key.generate_url(100000, method=method)
|
||||||
|
o = urlparse(url)
|
||||||
|
path = o.path + '?' + o.query
|
||||||
|
else:
|
||||||
|
path = '/{bucket}/{obj}'.format(bucket=key.bucket.name, obj=key.name)
|
||||||
|
|
||||||
if s3.main.is_secure:
|
if s3.main.is_secure:
|
||||||
class_ = HTTPSConnection
|
class_ = HTTPSConnection
|
||||||
else:
|
else:
|
||||||
class_ = HTTPConnection
|
class_ = HTTPConnection
|
||||||
|
|
||||||
c = class_(s3.main.host, s3.main.port, strict=True)
|
c = class_(s3.main.host, s3.main.port, strict=True)
|
||||||
|
c.request(method, path, body=body)
|
||||||
url = '/{bucket}/{obj}'.format(bucket=key.bucket.name, obj=key.name)
|
|
||||||
print url
|
|
||||||
c.request(method, url)
|
|
||||||
res = c.getresponse()
|
res = c.getresponse()
|
||||||
|
|
||||||
print res.status, res.reason
|
print res.status, res.reason
|
||||||
|
@ -830,6 +834,7 @@ def test_object_raw_get_object_gone():
|
||||||
# a private bucket should not affect reading or writing to a bucket
|
# a private bucket should not affect reading or writing to a bucket
|
||||||
def test_object_raw_get_bucket_acl():
|
def test_object_raw_get_bucket_acl():
|
||||||
(bucket, key) = _setup_request('private', 'public-read')
|
(bucket, key) = _setup_request('private', 'public-read')
|
||||||
|
|
||||||
res = _make_request('GET', bucket, key)
|
res = _make_request('GET', bucket, key)
|
||||||
eq(res.status, 200)
|
eq(res.status, 200)
|
||||||
eq(res.reason, 'OK')
|
eq(res.reason, 'OK')
|
||||||
|
@ -837,53 +842,43 @@ def test_object_raw_get_bucket_acl():
|
||||||
|
|
||||||
def test_object_raw_get_object_acl():
|
def test_object_raw_get_object_acl():
|
||||||
(bucket, key) = _setup_request('public-read', 'private')
|
(bucket, key) = _setup_request('public-read', 'private')
|
||||||
|
|
||||||
res = _make_request('GET', bucket, key)
|
res = _make_request('GET', bucket, key)
|
||||||
eq(res.status, 403)
|
eq(res.status, 403)
|
||||||
eq(res.reason, 'Forbidden')
|
eq(res.reason, 'Forbidden')
|
||||||
|
|
||||||
|
|
||||||
def _make_request_authenticated(key):
|
|
||||||
url = key.generate_url(100000)
|
|
||||||
print url
|
|
||||||
|
|
||||||
try:
|
|
||||||
res = urlopen(url)
|
|
||||||
(code, msg) = (res.code, res.msg)
|
|
||||||
except HTTPError as e:
|
|
||||||
(code, msg) = (e.code, e.msg)
|
|
||||||
|
|
||||||
print code, msg
|
|
||||||
return (code, msg)
|
|
||||||
|
|
||||||
|
|
||||||
# 403 TimeTooSkewed
|
# 403 TimeTooSkewed
|
||||||
@attr('fails_on_dho')
|
@attr('fails_on_dho')
|
||||||
@attr('fails_on_rgw')
|
@attr('fails_on_rgw')
|
||||||
def test_object_raw_authenticated():
|
def test_object_raw_authenticated():
|
||||||
(_, key) = _setup_request('public-read', 'public-read')
|
(bucket, key) = _setup_request('public-read', 'public-read')
|
||||||
(code, msg) = _make_request_authenticated(key)
|
|
||||||
eq(code, 200)
|
res = _make_request('GET', bucket, key, authenticated=True)
|
||||||
eq(msg, 'OK')
|
eq(res.status, 200)
|
||||||
|
eq(res.reason, 'OK')
|
||||||
|
|
||||||
|
|
||||||
# 403 TimeTooSkewed
|
# 403 TimeTooSkewed
|
||||||
@attr('fails_on_dho')
|
@attr('fails_on_dho')
|
||||||
@attr('fails_on_rgw')
|
@attr('fails_on_rgw')
|
||||||
def test_object_raw_authenticated_bucket_acl():
|
def test_object_raw_authenticated_bucket_acl():
|
||||||
(_, key) = _setup_request('private', 'public-read')
|
(bucket, key) = _setup_request('private', 'public-read')
|
||||||
(code, msg) = _make_request_authenticated(key)
|
|
||||||
eq(code, 200)
|
res = _make_request('GET', bucket, key, authenticated=True)
|
||||||
eq(msg, 'OK')
|
eq(res.status, 200)
|
||||||
|
eq(res.reason, 'OK')
|
||||||
|
|
||||||
|
|
||||||
# 403 TimeTooSkewed
|
# 403 TimeTooSkewed
|
||||||
@attr('fails_on_dho')
|
@attr('fails_on_dho')
|
||||||
@attr('fails_on_rgw')
|
@attr('fails_on_rgw')
|
||||||
def test_object_raw_authenticated_object_acl():
|
def test_object_raw_authenticated_object_acl():
|
||||||
(_, key) = _setup_request('public-read', 'private')
|
(bucket, key) = _setup_request('public-read', 'private')
|
||||||
(code, msg) = _make_request_authenticated(key)
|
|
||||||
eq(code, 200)
|
res = _make_request('GET', bucket, key, authenticated=True)
|
||||||
eq(msg, 'OK')
|
eq(res.status, 200)
|
||||||
|
eq(res.reason, 'OK')
|
||||||
|
|
||||||
|
|
||||||
# 403 TimeTooSkewed
|
# 403 TimeTooSkewed
|
||||||
|
@ -894,21 +889,21 @@ def test_object_raw_authenticated_bucket_gone():
|
||||||
key.delete()
|
key.delete()
|
||||||
bucket.delete()
|
bucket.delete()
|
||||||
|
|
||||||
(code, msg) = _make_request_authenticated(key)
|
res = _make_request('GET', bucket, key, authenticated=True)
|
||||||
eq(code, 404)
|
eq(res.status, 404)
|
||||||
eq(msg, 'Not Found')
|
eq(res.reason, 'Not Found')
|
||||||
|
|
||||||
|
|
||||||
# 403 TimeTooSkewed
|
# 403 TimeTooSkewed
|
||||||
@attr('fails_on_dho')
|
@attr('fails_on_dho')
|
||||||
@attr('fails_on_rgw')
|
@attr('fails_on_rgw')
|
||||||
def test_object_raw_authenticated_object_gone():
|
def test_object_raw_authenticated_object_gone():
|
||||||
(_, key) = _setup_request('public-read', 'public-read')
|
(bucket, key) = _setup_request('public-read', 'public-read')
|
||||||
key.delete()
|
key.delete()
|
||||||
|
|
||||||
(code, msg) = _make_request_authenticated(key)
|
res = _make_request('GET', bucket, key, authenticated=True)
|
||||||
eq(code, 404)
|
eq(res.status, 404)
|
||||||
eq(msg, 'Not Found')
|
eq(res.reason, 'Not Found')
|
||||||
|
|
||||||
|
|
||||||
def check_bad_bucket_name(name):
|
def check_bad_bucket_name(name):
|
||||||
|
|
Loading…
Reference in a new issue