additional gswauth functional tests
These tests cover account registration and de-registration user creation/delete, and listing of both account and user Change-Id: Ie622daccfc8e2d2fb45565952a99d7d832ce1189 Signed-off-by: Thiago da Silva <thiago@redhat.com> Reviewed-on: http://review.gluster.org/6212 Reviewed-by: Luis Pabon <lpabon@redhat.com> Tested-by: Luis Pabon <lpabon@redhat.com>
This commit is contained in:
parent
9f8d2e61a7
commit
0c34fa6085
@ -747,6 +747,7 @@ class Swauth(object):
|
||||
account = req.path_info_pop()
|
||||
if req.path_info or not account or account[0] == '.':
|
||||
return HTTPBadRequest(request=req)
|
||||
|
||||
# Ensure the container in the main auth account exists (this
|
||||
# container represents the new account)
|
||||
path = quote('/v1/%s/%s' % (self.auth_account, account))
|
||||
|
@ -15,6 +15,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
try:
|
||||
import simplejson as json
|
||||
except ImportError:
|
||||
import json
|
||||
import unittest
|
||||
from nose import SkipTest
|
||||
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
||||
@ -36,7 +40,7 @@ class TestGSWauth(unittest.TestCase):
|
||||
return {'X-Auth-Admin-User': config['admin_user'],
|
||||
'X-Auth-Admin-Key': config['admin_key']}
|
||||
|
||||
def _check_test_account_does_not_exist(self):
|
||||
def _check_test_account_is_not_registered(self):
|
||||
# check account exists
|
||||
path = '%sv2/%s' % (config['auth_prefix'], config['account'])
|
||||
|
||||
@ -47,7 +51,7 @@ class TestGSWauth(unittest.TestCase):
|
||||
resp = conn.getresponse()
|
||||
self.assertTrue(resp.status == 404)
|
||||
|
||||
def _create_test_account(self):
|
||||
def _register_test_account(self):
|
||||
# create account in swauth (not a swift account)
|
||||
# This current version only supports one account per volume
|
||||
# and the account name is the same as the volume name
|
||||
@ -61,9 +65,9 @@ class TestGSWauth(unittest.TestCase):
|
||||
resp = conn.getresponse()
|
||||
self.assertTrue(resp.status == 201)
|
||||
|
||||
def _delete_test_account(self):
|
||||
def _deregister_test_account(self):
|
||||
# delete account in swauth (not a swift account)
|
||||
# @see _create_test_account
|
||||
# @see _register_test_account
|
||||
path = '%sv2/%s' % (config['auth_prefix'], config['account'])
|
||||
headers = self._get_admin_headers()
|
||||
headers.update({'Content-Length': '0'})
|
||||
@ -72,15 +76,31 @@ class TestGSWauth(unittest.TestCase):
|
||||
resp = conn.getresponse()
|
||||
self.assertTrue(resp.status == 204)
|
||||
|
||||
def test_add_account(self):
|
||||
self._check_test_account_does_not_exist()
|
||||
self._create_test_account()
|
||||
self._delete_test_account()
|
||||
def test_register_account(self):
|
||||
# check and register account
|
||||
self._check_test_account_is_not_registered()
|
||||
self._register_test_account()
|
||||
|
||||
try:
|
||||
# list account
|
||||
path = '%sv2/%s' % (config['auth_prefix'], config['account'])
|
||||
headers = self._get_admin_headers()
|
||||
conn = http_connect(config['auth_host'], config['auth_port'],
|
||||
'GET', path, headers)
|
||||
resp = conn.getresponse()
|
||||
body = resp.read()
|
||||
info = json.loads(body)
|
||||
self.assertEqual(info['account_id'], 'AUTH_test')
|
||||
self.assertTrue(resp.status == 200)
|
||||
|
||||
finally:
|
||||
# de-register account
|
||||
self._deregister_test_account()
|
||||
|
||||
def test_add_user(self):
|
||||
# check and create account
|
||||
self._check_test_account_does_not_exist()
|
||||
self._create_test_account()
|
||||
# check and register account
|
||||
self._check_test_account_is_not_registered()
|
||||
self._register_test_account()
|
||||
|
||||
# create user
|
||||
path = '%sv2/%s/%s' % (config['auth_prefix'], config['account'],
|
||||
@ -93,3 +113,27 @@ class TestGSWauth(unittest.TestCase):
|
||||
path, headers)
|
||||
resp = conn.getresponse()
|
||||
self.assertTrue(resp.status == 201)
|
||||
|
||||
try:
|
||||
# list user
|
||||
headers = self._get_admin_headers()
|
||||
conn = http_connect(config['auth_host'], config['auth_port'],
|
||||
'GET', path, headers)
|
||||
resp = conn.getresponse()
|
||||
body = resp.read()
|
||||
self.assertEqual(body, '{"groups": [{"name": "test:tester"}, {"name":'
|
||||
' "test"}, {"name": ".admin"}], "auth": "plaintext:testing"}')
|
||||
self.assertTrue(resp.status == 200)
|
||||
|
||||
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()
|
||||
|
@ -53,6 +53,31 @@ fail()
|
||||
quit "$1"
|
||||
}
|
||||
|
||||
run_generic_tests()
|
||||
{
|
||||
# clean up gsmetadata dir
|
||||
gswauth_cleanup
|
||||
|
||||
#swauth-prep
|
||||
sudo_env swauth-prep -K swauthkey || fail "Unable to prep gswauth"
|
||||
sudo_env swauth-add-user -K swauthkey -a test tester testing || fail "Unable to add user test"
|
||||
sudo_env swauth-add-user -K swauthkey -a test2 tester2 testing2 || fail "Unable to add user test2"
|
||||
sudo_env swauth-add-user -K swauthkey test tester3 testing3 || fail "Unable to add user test3"
|
||||
|
||||
nosetests -v --exe \
|
||||
--with-xunit \
|
||||
--xunit-file functional_tests/gluster-swift-gswauth-generic-functional-TC-report.xml \
|
||||
--with-html-output \
|
||||
--html-out-file functional_tests/gluster-swift-gswauth-generic-functional-result.html \
|
||||
test/functional || fail "Functional tests failed"
|
||||
nosetests -v --exe \
|
||||
--with-xunit \
|
||||
--xunit-file functional_tests/gluster-swift-gswauth-functionalnosetests-TC-report.xml \
|
||||
--with-html-output \
|
||||
--html-out-file functional_tests/gluster-swift-gswauth-functionalnosetests-result.html \
|
||||
test/functionalnosetests || fail "Functional-nose tests failed"
|
||||
}
|
||||
|
||||
### MAIN ###
|
||||
|
||||
# Only run if there is no configuration in the system
|
||||
@ -90,27 +115,7 @@ nosetests -v --exe \
|
||||
--html-out-file functional_tests/gluster-swift-gswauth-functional-result.html \
|
||||
test/functional_auth/gswauth || fail "Functional gswauth test failed"
|
||||
|
||||
# clean up gsmetadata dir
|
||||
gswauth_cleanup
|
||||
|
||||
#swauth-prep
|
||||
sudo_env swauth-prep -K swauthkey || fail "Unable to prep gswauth"
|
||||
sudo_env swauth-add-user -K swauthkey -a test tester testing || fail "Unable to add user test"
|
||||
sudo_env swauth-add-user -K swauthkey -a test2 tester2 testing2 || fail "Unable to add user test2"
|
||||
sudo_env swauth-add-user -K swauthkey test tester3 testing3 || fail "Unable to add user test3"
|
||||
|
||||
nosetests -v --exe \
|
||||
--with-xunit \
|
||||
--xunit-file functional_tests/gluster-swift-gswauth-generic-functional-TC-report.xml \
|
||||
--with-html-output \
|
||||
--html-out-file functional_tests/gluster-swift-gswauth-generic-functional-result.html \
|
||||
test/functional || fail "Functional tests failed"
|
||||
nosetests -v --exe \
|
||||
--with-xunit \
|
||||
--xunit-file functional_tests/gluster-swift-gswauth-functionalnosetests-TC-report.xml \
|
||||
--with-html-output \
|
||||
--html-out-file functional_tests/gluster-swift-gswauth-functionalnosetests-result.html \
|
||||
test/functionalnosetests || fail "Functional-nose tests failed"
|
||||
run_generic_tests
|
||||
|
||||
cleanup
|
||||
exit 0
|
||||
|
Loading…
Reference in New Issue
Block a user