swauth: .token objects are now split into 16 containers
This commit is contained in:
@@ -174,7 +174,8 @@ class Swauth(object):
|
|||||||
if expires < time():
|
if expires < time():
|
||||||
groups = None
|
groups = None
|
||||||
if not groups:
|
if not groups:
|
||||||
path = quote('/v1/%s/.token/%s' % (self.auth_account, token))
|
path = quote('/v1/%s/.token%s/%s' %
|
||||||
|
(self.auth_account, token[-1], token))
|
||||||
resp = self.make_request(env, 'GET', path).get_response(self.app)
|
resp = self.make_request(env, 'GET', path).get_response(self.app)
|
||||||
if resp.status_int // 100 != 2:
|
if resp.status_int // 100 != 2:
|
||||||
return None
|
return None
|
||||||
@@ -331,8 +332,14 @@ class Swauth(object):
|
|||||||
if resp.status_int // 100 != 2:
|
if resp.status_int // 100 != 2:
|
||||||
raise Exception('Could not create the main auth account: %s %s' %
|
raise Exception('Could not create the main auth account: %s %s' %
|
||||||
(path, resp.status))
|
(path, resp.status))
|
||||||
for container in ('.token', '.account_id'):
|
path = quote('/v1/%s/.account_id' % self.auth_account)
|
||||||
path = quote('/v1/%s/%s' % (self.auth_account, container))
|
resp = self.make_request(req.environ, 'PUT',
|
||||||
|
path).get_response(self.app)
|
||||||
|
if resp.status_int // 100 != 2:
|
||||||
|
raise Exception('Could not create container: %s %s' %
|
||||||
|
(path, resp.status))
|
||||||
|
for container in xrange(16):
|
||||||
|
path = quote('/v1/%s/.token%x' % (self.auth_account, container))
|
||||||
resp = self.make_request(req.environ, 'PUT',
|
resp = self.make_request(req.environ, 'PUT',
|
||||||
path).get_response(self.app)
|
path).get_response(self.app)
|
||||||
if resp.status_int // 100 != 2:
|
if resp.status_int // 100 != 2:
|
||||||
@@ -845,8 +852,8 @@ class Swauth(object):
|
|||||||
(path, resp.status))
|
(path, resp.status))
|
||||||
candidate_token = resp.headers.get('x-object-meta-auth-token')
|
candidate_token = resp.headers.get('x-object-meta-auth-token')
|
||||||
if candidate_token:
|
if candidate_token:
|
||||||
path = quote('/v1/%s/.token/%s' % (self.auth_account,
|
path = quote('/v1/%s/.token%s/%s' %
|
||||||
candidate_token))
|
(self.auth_account, candidate_token[-1], candidate_token))
|
||||||
resp = self.make_request(req.environ, 'DELETE',
|
resp = self.make_request(req.environ, 'DELETE',
|
||||||
path).get_response(self.app)
|
path).get_response(self.app)
|
||||||
if resp.status_int // 100 != 2 and resp.status_int != 404:
|
if resp.status_int // 100 != 2 and resp.status_int != 404:
|
||||||
@@ -952,8 +959,8 @@ class Swauth(object):
|
|||||||
token = None
|
token = None
|
||||||
candidate_token = resp.headers.get('x-object-meta-auth-token')
|
candidate_token = resp.headers.get('x-object-meta-auth-token')
|
||||||
if candidate_token:
|
if candidate_token:
|
||||||
path = quote('/v1/%s/.token/%s' % (self.auth_account,
|
path = quote('/v1/%s/.token%s/%s' %
|
||||||
candidate_token))
|
(self.auth_account, candidate_token[-1], candidate_token))
|
||||||
resp = self.make_request(req.environ, 'GET',
|
resp = self.make_request(req.environ, 'GET',
|
||||||
path).get_response(self.app)
|
path).get_response(self.app)
|
||||||
if resp.status_int // 100 == 2:
|
if resp.status_int // 100 == 2:
|
||||||
@@ -980,7 +987,8 @@ class Swauth(object):
|
|||||||
# Generate new token
|
# Generate new token
|
||||||
token = '%stk%s' % (self.reseller_prefix, uuid4().hex)
|
token = '%stk%s' % (self.reseller_prefix, uuid4().hex)
|
||||||
# Save token info
|
# Save token info
|
||||||
path = quote('/v1/%s/.token/%s' % (self.auth_account, token))
|
path = quote('/v1/%s/.token%s/%s' %
|
||||||
|
(self.auth_account, token[-1], token))
|
||||||
resp = self.make_request(req.environ, 'PUT', path,
|
resp = self.make_request(req.environ, 'PUT', path,
|
||||||
json.dumps({'account': account, 'user': user,
|
json.dumps({'account': account, 'user': user,
|
||||||
'account_id': account_id,
|
'account_id': account_id,
|
||||||
@@ -1042,7 +1050,8 @@ class Swauth(object):
|
|||||||
if expires < time():
|
if expires < time():
|
||||||
groups = None
|
groups = None
|
||||||
if not groups:
|
if not groups:
|
||||||
path = quote('/v1/%s/.token/%s' % (self.auth_account, token))
|
path = quote('/v1/%s/.token%s/%s' %
|
||||||
|
(self.auth_account, token[-1], token))
|
||||||
resp = self.make_request(req.environ, 'GET',
|
resp = self.make_request(req.environ, 'GET',
|
||||||
path).get_response(self.app)
|
path).get_response(self.app)
|
||||||
if resp.status_int // 100 != 2:
|
if resp.status_int // 100 != 2:
|
||||||
|
|||||||
@@ -826,20 +826,22 @@ class TestAuth(unittest.TestCase):
|
|||||||
self.assertEquals(self.test_auth.app.calls, 7)
|
self.assertEquals(self.test_auth.app.calls, 7)
|
||||||
|
|
||||||
def test_prep_success(self):
|
def test_prep_success(self):
|
||||||
self.test_auth.app = FakeApp(iter([
|
list_to_iter = [
|
||||||
# PUT of .auth account
|
# PUT of .auth account
|
||||||
('201 Created', {}, ''),
|
('201 Created', {}, ''),
|
||||||
# PUT of .token container
|
|
||||||
('201 Created', {}, ''),
|
|
||||||
# PUT of .account_id container
|
# PUT of .account_id container
|
||||||
('201 Created', {}, '')]))
|
('201 Created', {}, '')]
|
||||||
|
# PUT of .token* containers
|
||||||
|
for x in xrange(16):
|
||||||
|
list_to_iter.append(('201 Created', {}, ''))
|
||||||
|
self.test_auth.app = FakeApp(iter(list_to_iter))
|
||||||
resp = Request.blank('/auth/v2/.prep',
|
resp = Request.blank('/auth/v2/.prep',
|
||||||
environ={'REQUEST_METHOD': 'POST'},
|
environ={'REQUEST_METHOD': 'POST'},
|
||||||
headers={'X-Auth-Admin-User': '.super_admin',
|
headers={'X-Auth-Admin-User': '.super_admin',
|
||||||
'X-Auth-Admin-Key': 'supertest'}
|
'X-Auth-Admin-Key': 'supertest'}
|
||||||
).get_response(self.test_auth)
|
).get_response(self.test_auth)
|
||||||
self.assertEquals(resp.status_int, 204)
|
self.assertEquals(resp.status_int, 204)
|
||||||
self.assertEquals(self.test_auth.app.calls, 3)
|
self.assertEquals(self.test_auth.app.calls, 18)
|
||||||
|
|
||||||
def test_prep_bad_method(self):
|
def test_prep_bad_method(self):
|
||||||
resp = Request.blank('/auth/v2/.prep',
|
resp = Request.blank('/auth/v2/.prep',
|
||||||
|
|||||||
Reference in New Issue
Block a user