summaryrefslogtreecommitdiffstats
path: root/test/functional/test_account.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/test_account.py')
-rwxr-xr-xtest/functional/test_account.py135
1 files changed, 80 insertions, 55 deletions
diff --git a/test/functional/test_account.py b/test/functional/test_account.py
index 30a8e74..57bbe6b 100755
--- a/test/functional/test_account.py
+++ b/test/functional/test_account.py
@@ -15,12 +15,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import unittest
+import unittest2
import json
from uuid import uuid4
-from nose import SkipTest
-from string import letters
+from unittest2 import SkipTest
+from string import ascii_letters
+from six.moves import range
from swift.common.middleware.acl import format_acl
from test.functional import check_response, retry, requires_acls, \
@@ -28,7 +29,15 @@ from test.functional import check_response, retry, requires_acls, \
import test.functional as tf
-class TestAccount(unittest.TestCase):
+def setUpModule():
+ tf.setup_package()
+
+
+def tearDownModule():
+ tf.teardown_package()
+
+
+class TestAccount(unittest2.TestCase):
def setUp(self):
self.max_meta_count = load_constraint('max_meta_count')
@@ -88,22 +97,22 @@ class TestAccount(unittest.TestCase):
self.assertEqual(resp.status, 204)
resp = retry(head)
resp.read()
- self.assert_(resp.status in (200, 204), resp.status)
- self.assertEqual(resp.getheader('x-account-meta-test'), None)
+ self.assertIn(resp.status, (200, 204))
+ self.assertIsNone(resp.getheader('x-account-meta-test'))
resp = retry(get)
resp.read()
- self.assert_(resp.status in (200, 204), resp.status)
- self.assertEqual(resp.getheader('x-account-meta-test'), None)
+ self.assertIn(resp.status, (200, 204))
+ self.assertIsNone(resp.getheader('x-account-meta-test'))
resp = retry(post, 'Value')
resp.read()
self.assertEqual(resp.status, 204)
resp = retry(head)
resp.read()
- self.assert_(resp.status in (200, 204), resp.status)
+ self.assertIn(resp.status, (200, 204))
self.assertEqual(resp.getheader('x-account-meta-test'), 'Value')
resp = retry(get)
resp.read()
- self.assert_(resp.status in (200, 204), resp.status)
+ self.assertIn(resp.status, (200, 204))
self.assertEqual(resp.getheader('x-account-meta-test'), 'Value')
def test_invalid_acls(self):
@@ -118,7 +127,7 @@ class TestAccount(unittest.TestCase):
# needs to be an acceptable header size
num_keys = 8
max_key_size = load_constraint('max_header_size') / num_keys
- acl = {'admin': [c * max_key_size for c in letters[:num_keys]]}
+ acl = {'admin': [c * max_key_size for c in ascii_letters[:num_keys]]}
headers = {'x-account-access-control': format_acl(
version=2, acl_dict=acl)}
resp = retry(post, headers=headers, use_account=1)
@@ -126,7 +135,8 @@ class TestAccount(unittest.TestCase):
self.assertEqual(resp.status, 400)
# and again a touch smaller
- acl = {'admin': [c * max_key_size for c in letters[:num_keys - 1]]}
+ acl = {'admin': [c * max_key_size for c
+ in ascii_letters[:num_keys - 1]]}
headers = {'x-account-access-control': format_acl(
version=2, acl_dict=acl)}
resp = retry(post, headers=headers, use_account=1)
@@ -154,7 +164,7 @@ class TestAccount(unittest.TestCase):
resp = retry(post, headers, use_account=1)
resp.read()
self.assertEqual(resp.status, 400)
- self.assertEqual(resp.getheader('X-Account-Access-Control'), None)
+ self.assertIsNone(resp.getheader('X-Account-Access-Control'))
@requires_acls
def test_invalid_acl_values(self):
@@ -170,7 +180,7 @@ class TestAccount(unittest.TestCase):
resp = retry(post, headers=headers, use_account=1)
resp.read()
self.assertEqual(resp.status, 400)
- self.assertEqual(resp.getheader('X-Account-Access-Control'), None)
+ self.assertIsNone(resp.getheader('X-Account-Access-Control'))
@requires_acls
def test_read_only_acl(self):
@@ -189,7 +199,7 @@ class TestAccount(unittest.TestCase):
# cannot read account
resp = retry(get, use_account=3)
resp.read()
- self.assertEquals(resp.status, 403)
+ self.assertEqual(resp.status, 403)
# grant read access
acl_user = tf.swift_test_user[2]
@@ -203,9 +213,9 @@ class TestAccount(unittest.TestCase):
# read-only can read account headers
resp = retry(get, use_account=3)
resp.read()
- self.assert_(resp.status in (200, 204))
+ self.assertIn(resp.status, (200, 204))
# but not acls
- self.assertEqual(resp.getheader('X-Account-Access-Control'), None)
+ self.assertIsNone(resp.getheader('X-Account-Access-Control'))
# read-only can not write metadata
headers = {'x-account-meta-test': 'value'}
@@ -220,7 +230,7 @@ class TestAccount(unittest.TestCase):
self.assertEqual(resp.status, 204)
resp = retry(get, use_account=3)
resp.read()
- self.assert_(resp.status in (200, 204))
+ self.assertIn(resp.status, (200, 204))
self.assertEqual(resp.getheader('X-Account-Meta-Test'), 'value')
@requires_acls
@@ -240,7 +250,7 @@ class TestAccount(unittest.TestCase):
# cannot read account
resp = retry(get, use_account=3)
resp.read()
- self.assertEquals(resp.status, 403)
+ self.assertEqual(resp.status, 403)
# grant read-write access
acl_user = tf.swift_test_user[2]
@@ -254,9 +264,9 @@ class TestAccount(unittest.TestCase):
# read-write can read account headers
resp = retry(get, use_account=3)
resp.read()
- self.assert_(resp.status in (200, 204))
+ self.assertIn(resp.status, (200, 204))
# but not acls
- self.assertEqual(resp.getheader('X-Account-Access-Control'), None)
+ self.assertIsNone(resp.getheader('X-Account-Access-Control'))
# read-write can not write account metadata
headers = {'x-account-meta-test': 'value'}
@@ -281,7 +291,7 @@ class TestAccount(unittest.TestCase):
# cannot read account
resp = retry(get, use_account=3)
resp.read()
- self.assertEquals(resp.status, 403)
+ self.assertEqual(resp.status, 403)
# grant admin access
acl_user = tf.swift_test_user[2]
@@ -295,7 +305,7 @@ class TestAccount(unittest.TestCase):
# admin can read account headers
resp = retry(get, use_account=3)
resp.read()
- self.assert_(resp.status in (200, 204))
+ self.assertIn(resp.status, (200, 204))
# including acls
self.assertEqual(resp.getheader('X-Account-Access-Control'),
acl_json_str)
@@ -308,7 +318,7 @@ class TestAccount(unittest.TestCase):
self.assertEqual(resp.status, 204)
resp = retry(get, use_account=3)
resp.read()
- self.assert_(resp.status in (200, 204))
+ self.assertIn(resp.status, (200, 204))
self.assertEqual(resp.getheader('X-Account-Meta-Test'), value)
# admin can even revoke their own access
@@ -320,7 +330,7 @@ class TestAccount(unittest.TestCase):
# and again, cannot read account
resp = retry(get, use_account=3)
resp.read()
- self.assertEquals(resp.status, 403)
+ self.assertEqual(resp.status, 403)
@requires_acls
def test_protected_tempurl(self):
@@ -358,11 +368,11 @@ class TestAccount(unittest.TestCase):
# read-only tester3 can read account metadata
resp = retry(get, use_account=3)
resp.read()
- self.assert_(resp.status in (200, 204),
- 'Expected status in (200, 204), got %s' % resp.status)
+ self.assertIn(resp.status, (200, 204),
+ 'Expected status in (200, 204), got %s' % resp.status)
self.assertEqual(resp.getheader('X-Account-Meta-Test'), value)
# but not temp-url-key
- self.assertEqual(resp.getheader('X-Account-Meta-Temp-Url-Key'), None)
+ self.assertIsNone(resp.getheader('X-Account-Meta-Temp-Url-Key'))
# grant read-write access to tester3
acl_user = tf.swift_test_user[2]
@@ -376,11 +386,11 @@ class TestAccount(unittest.TestCase):
# read-write tester3 can read account metadata
resp = retry(get, use_account=3)
resp.read()
- self.assert_(resp.status in (200, 204),
- 'Expected status in (200, 204), got %s' % resp.status)
+ self.assertIn(resp.status, (200, 204),
+ 'Expected status in (200, 204), got %s' % resp.status)
self.assertEqual(resp.getheader('X-Account-Meta-Test'), value)
# but not temp-url-key
- self.assertEqual(resp.getheader('X-Account-Meta-Temp-Url-Key'), None)
+ self.assertIsNone(resp.getheader('X-Account-Meta-Temp-Url-Key'))
# grant admin access to tester3
acl_user = tf.swift_test_user[2]
@@ -394,8 +404,8 @@ class TestAccount(unittest.TestCase):
# admin tester3 can read account metadata
resp = retry(get, use_account=3)
resp.read()
- self.assert_(resp.status in (200, 204),
- 'Expected status in (200, 204), got %s' % resp.status)
+ self.assertIn(resp.status, (200, 204),
+ 'Expected status in (200, 204), got %s' % resp.status)
self.assertEqual(resp.getheader('X-Account-Meta-Test'), value)
# including temp-url-key
self.assertEqual(resp.getheader('X-Account-Meta-Temp-Url-Key'),
@@ -411,8 +421,8 @@ class TestAccount(unittest.TestCase):
self.assertEqual(resp.status, 204)
resp = retry(get, use_account=3)
resp.read()
- self.assert_(resp.status in (200, 204),
- 'Expected status in (200, 204), got %s' % resp.status)
+ self.assertIn(resp.status, (200, 204),
+ 'Expected status in (200, 204), got %s' % resp.status)
self.assertEqual(resp.getheader('X-Account-Meta-Temp-Url-Key'),
secret)
@@ -450,13 +460,13 @@ class TestAccount(unittest.TestCase):
use_account=1)
resp.read()
self.assertEqual(resp.status, 204)
- self.assertEqual(resp.getheader('X-Account-Access-Control'), None)
+ self.assertIsNone(resp.getheader('X-Account-Access-Control'))
# User1 can GET their own empty account
resp = retry(get, use_account=1)
resp.read()
self.assertEqual(resp.status // 100, 2)
- self.assertEqual(resp.getheader('X-Account-Access-Control'), None)
+ self.assertIsNone(resp.getheader('X-Account-Access-Control'))
# User2 can't GET User1's account
resp = retry(get, use_account=2, url_account=1)
@@ -500,7 +510,7 @@ class TestAccount(unittest.TestCase):
resp = retry(head, use_account=2, url_account=1)
resp.read()
self.assertEqual(resp.status, 204)
- self.assertEqual(resp.getheader('x-account-access-control'), None)
+ self.assertIsNone(resp.getheader('x-account-access-control'))
# User2 can PUT and DELETE a container
resp = retry(put, use_account=2, url_account=1,
@@ -525,7 +535,7 @@ class TestAccount(unittest.TestCase):
resp = retry(head, use_account=2, url_account=1)
resp.read()
self.assertEqual(resp.status, 204)
- self.assertEqual(resp.getheader('x-account-access-control'), None)
+ self.assertIsNone(resp.getheader('x-account-access-control'))
# User2 can't PUT a container
resp = retry(put, use_account=2, url_account=1,
@@ -563,13 +573,13 @@ class TestAccount(unittest.TestCase):
resp = retry(post, headers={'X-Account-Access-Control': '{}'})
resp.read()
self.assertEqual(resp.status, 204)
- self.assertEqual(resp.getheader('X-Account-Access-Control'), None)
+ self.assertIsNone(resp.getheader('X-Account-Access-Control'))
# User1 can GET their own empty account
resp = retry(get)
resp.read()
self.assertEqual(resp.status // 100, 2)
- self.assertEqual(resp.getheader('X-Account-Access-Control'), None)
+ self.assertIsNone(resp.getheader('X-Account-Access-Control'))
# User1 can POST non-empty data
acl_json = '{"admin":["bob"]}'
@@ -622,13 +632,13 @@ class TestAccount(unittest.TestCase):
resp = retry(post, headers={'X-Account-Access-Control': '{}'})
resp.read()
self.assertEqual(resp.status, 204)
- self.assertEqual(resp.getheader('X-Account-Access-Control'), None)
+ self.assertIsNone(resp.getheader('X-Account-Access-Control'))
# User1 can GET their own empty account
resp = retry(get)
resp.read()
self.assertEqual(resp.status // 100, 2)
- self.assertEqual(resp.getheader('X-Account-Access-Control'), None)
+ self.assertIsNone(resp.getheader('X-Account-Access-Control'))
# User1 can POST non-empty data
acl_json = '{"admin":["bob"]}'
@@ -688,17 +698,17 @@ class TestAccount(unittest.TestCase):
if (tf.web_front_end == 'integral'):
resp = retry(post, uni_key, '1')
resp.read()
- self.assertTrue(resp.status in (201, 204))
+ self.assertIn(resp.status, (201, 204))
resp = retry(head)
resp.read()
- self.assert_(resp.status in (200, 204), resp.status)
+ self.assertIn(resp.status, (200, 204))
self.assertEqual(resp.getheader(uni_key.encode('utf-8')), '1')
resp = retry(post, 'X-Account-Meta-uni', uni_value)
resp.read()
self.assertEqual(resp.status, 204)
resp = retry(head)
resp.read()
- self.assert_(resp.status in (200, 204), resp.status)
+ self.assertIn(resp.status, (200, 204))
self.assertEqual(resp.getheader('X-Account-Meta-uni'),
uni_value.encode('utf-8'))
if (tf.web_front_end == 'integral'):
@@ -707,7 +717,7 @@ class TestAccount(unittest.TestCase):
self.assertEqual(resp.status, 204)
resp = retry(head)
resp.read()
- self.assert_(resp.status in (200, 204), resp.status)
+ self.assertIn(resp.status, (200, 204))
self.assertEqual(resp.getheader(uni_key.encode('utf-8')),
uni_value.encode('utf-8'))
@@ -729,14 +739,14 @@ class TestAccount(unittest.TestCase):
self.assertEqual(resp.status, 204)
resp = retry(head)
resp.read()
- self.assert_(resp.status in (200, 204), resp.status)
+ self.assertIn(resp.status, (200, 204))
self.assertEqual(resp.getheader('x-account-meta-one'), '1')
resp = retry(post, 'X-Account-Meta-Two', '2')
resp.read()
self.assertEqual(resp.status, 204)
resp = retry(head)
resp.read()
- self.assert_(resp.status in (200, 204), resp.status)
+ self.assertIn(resp.status, (200, 204))
self.assertEqual(resp.getheader('x-account-meta-one'), '1')
self.assertEqual(resp.getheader('x-account-meta-two'), '2')
@@ -790,13 +800,13 @@ class TestAccount(unittest.TestCase):
resp = retry(post, headers)
headers = {}
- for x in xrange(self.max_meta_count):
+ for x in range(self.max_meta_count):
headers['X-Account-Meta-%d' % x] = 'v'
resp = retry(post, headers)
resp.read()
self.assertEqual(resp.status, 204)
headers = {}
- for x in xrange(self.max_meta_count + 1):
+ for x in range(self.max_meta_count + 1):
headers['X-Account-Meta-%d' % x] = 'v'
resp = retry(post, headers)
resp.read()
@@ -827,14 +837,29 @@ class TestAccount(unittest.TestCase):
resp = retry(post, headers)
resp.read()
self.assertEqual(resp.status, 204)
+ # this POST includes metadata size that is over limit
headers['X-Account-Meta-k'] = \
- 'v' * (self.max_meta_overall_size - size)
+ 'x' * (self.max_meta_overall_size - size)
+ resp = retry(post, headers)
+ resp.read()
+ self.assertEqual(resp.status, 400)
+ # this POST would be ok and the aggregate backend metadata
+ # size is on the border
+ headers = {'X-Account-Meta-k':
+ 'y' * (self.max_meta_overall_size - size - 1)}
+ resp = retry(post, headers)
+ resp.read()
+ self.assertEqual(resp.status, 204)
+ # this last POST would be ok by itself but takes the aggregate
+ # backend metadata size over limit
+ headers = {'X-Account-Meta-k':
+ 'z' * (self.max_meta_overall_size - size)}
resp = retry(post, headers)
resp.read()
self.assertEqual(resp.status, 400)
-class TestAccountInNonDefaultDomain(unittest.TestCase):
+class TestAccountInNonDefaultDomain(unittest2.TestCase):
def setUp(self):
if tf.skip or tf.skip2 or tf.skip_if_not_v3:
raise SkipTest('AUTH VERSION 3 SPECIFIC TEST')
@@ -859,8 +884,8 @@ class TestAccountInNonDefaultDomain(unittest.TestCase):
resp = retry(head, use_account=4)
resp.read()
self.assertEqual(resp.status, 204)
- self.assertTrue('X-Account-Project-Domain-Id' in resp.headers)
+ self.assertIn('X-Account-Project-Domain-Id', resp.headers)
if __name__ == '__main__':
- unittest.main()
+ unittest2.main()