From 53fda6b5e0a95096be4df673f800df494d174f01 Mon Sep 17 00:00:00 2001 From: Thiago da Silva Date: Mon, 4 Nov 2013 15:41:38 -0500 Subject: new user related gswauth functional tests New tests around account and user modifications Testing password changes and invalid admin rights porting changes to havana branch Change-Id: I2e867c2bb3ed10f375cc3f20fa66506e2cdd96e6 Reviewed-on: http://review.gluster.org/6223 Reviewed-by: Luis Pabon Tested-by: Luis Pabon Signed-off-by: Thiago da Silva Reviewed-on: http://review.gluster.org/6260 --- test/functional_auth/gswauth/test_gswauth.py | 128 +++++++++++++++++++++++++-- 1 file changed, 120 insertions(+), 8 deletions(-) diff --git a/test/functional_auth/gswauth/test_gswauth.py b/test/functional_auth/gswauth/test_gswauth.py index f14ff8a..30ecfeb 100644 --- a/test/functional_auth/gswauth/test_gswauth.py +++ b/test/functional_auth/gswauth/test_gswauth.py @@ -28,14 +28,6 @@ config = get_config('func_test') class TestGSWauth(unittest.TestCase): - def setUp(self): - #TODO - None - - def tearDown(self): - #TODO - None - def _get_admin_headers(self): return {'X-Auth-Admin-User': config['admin_user'], 'X-Auth-Admin-Key': config['admin_key']} @@ -137,3 +129,123 @@ class TestGSWauth(unittest.TestCase): finally: # de-register account self._deregister_test_account() + + def test_register_invalid_account(self): + # invalid account + path = '%sv2/%s' % (config['auth_prefix'], '.test') + headers = self._get_admin_headers() + headers.update({'Content-Length': '0'}) + conn = http_connect(config['auth_host'], config['auth_port'], 'PUT', + path, headers) + resp = conn.getresponse() + self.assertTrue(resp.status == 400) + + def test_add_invalid_user(self): + path = '%sv2/%s/%s' % (config['auth_prefix'], config['account'], + '.invaliduser') + headers = self._get_admin_headers() + headers.update({'X-Auth-User-Key': config['password'], + 'Content-Length': '0', + 'X-Auth-User-Admin': 'true'}) + conn = http_connect(config['auth_host'], config['auth_port'], 'PUT', + path, headers) + resp = conn.getresponse() + self.assertTrue(resp.status == 400) + + def test_register_account_without_admin_rights(self): + path = '%sv2/%s' % (config['auth_prefix'], config['account']) + headers = {'X-Auth-Admin-User': config['admin_user']} + headers.update({'Content-Length': '0'}) + conn = http_connect(config['auth_host'], config['auth_port'], 'PUT', + path, headers) + resp = conn.getresponse() + self.assertTrue(resp.status == 403) + + def test_change_user_password(self): + # check and register account + self._check_test_account_is_not_registered() + self._register_test_account() + + try: + # create user + path = '%sv2/%s/%s' % (config['auth_prefix'], config['account'], + config['username']) + headers = self._get_admin_headers() + headers.update({'X-Auth-User-Key': config['password'], + 'Content-Length': '0', + 'X-Auth-User-Admin': 'true'}) + conn = http_connect(config['auth_host'], config['auth_port'], 'PUT', + path, headers) + resp = conn.getresponse() + print "resp creating user %s" % resp.status + self.assertTrue(resp.status == 201) + + # change password + path = '%sv2/%s/%s' % (config['auth_prefix'], config['account'], + config['username']) + headers = self._get_admin_headers() + headers.update({'X-Auth-User-Key': 'newpassword', + 'Content-Length': '0', + 'X-Auth-User-Admin': 'true'}) + conn = http_connect(config['auth_host'], config['auth_port'], 'PUT', + path, headers) + resp = conn.getresponse() + print "resp changing password %s" % resp.status + self.assertTrue(resp.status == 201) + finally: + try: + # delete user + headers = self._get_admin_headers() + conn = http_connect(config['auth_host'], config['auth_port'], + 'DELETE', path, headers) + resp = conn.getresponse() + self.assertTrue(resp.status == 204) + + finally: + # de-register account + self._deregister_test_account() + + def test_change_user_password_without_admin_rights(self): + # check and register account + self._check_test_account_is_not_registered() + self._register_test_account() + + try: + # create user + path = '%sv2/%s/%s' % (config['auth_prefix'], config['account'], + config['username']) + headers = self._get_admin_headers() + headers.update({'X-Auth-User-Key': config['password'], + 'Content-Length': '0', + 'X-Auth-User-Admin': 'true'}) + conn = http_connect(config['auth_host'], config['auth_port'], 'PUT', + path, headers) + resp = conn.getresponse() + print "resp creating user %s" % resp.status + self.assertTrue(resp.status == 201) + + # attempt to change password + path = '%sv2/%s/%s' % (config['auth_prefix'], config['account'], + config['username']) + headers = self._get_admin_headers() + headers.update({'X-Auth-User-Key': 'newpassword', + 'Content-Length': '0', + 'X-Auth-Admin-Key': config['password'], + 'X-Auth-User-Admin': 'true'}) + conn = http_connect(config['auth_host'], config['auth_port'], 'PUT', + path, headers) + resp = conn.getresponse() + self.assertTrue(resp.status == 403) + + finally: + try: + # delete user + headers = self._get_admin_headers() + conn = http_connect(config['auth_host'], config['auth_port'], + 'DELETE', path, headers) + resp = conn.getresponse() + self.assertTrue(resp.status == 204) + + finally: + # de-register account + self._deregister_test_account() -- cgit