def test_add_attribute(self): """ ACCOUNT (REST): add/get/delete attribute.""" mw = [] headers1 = {'X-Rucio-Account': 'root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} r1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers1, expect_errors=True) assert_equal(r1.status, 200) token = str(r1.header('X-Rucio-Auth-Token')) acntusr = account_name_generator() headers2 = {'X-Rucio-Auth-Token': str(token)} data = dumps({'type': 'USER'}) r2 = TestApp(account_app.wsgifunc(*mw)).post('/' + acntusr, headers=headers2, params=data, expect_errors=True) assert_equal(r2.status, 201) key = account_name_generator() value = "true" data = dumps({'key': key, 'value': value}) r3 = TestApp(account_app.wsgifunc(*mw)).post('/{0}/attr/{1}'.format(acntusr, key), headers=headers2, params=data, expect_errors=True) assert_equal(r3.status, 201) r4 = TestApp(account_app.wsgifunc(*mw)).get('/' + acntusr + '/attr/', headers=headers2, expect_errors=True) assert_equal(r4.status, 200) r5 = TestApp(account_app.wsgifunc(*mw)).delete('/{0}/attr/{1}'.format(acntusr, key), headers=headers2, params=data, expect_errors=True) assert_equal(r5.status, 200)
def test_list_scope(self): """ SCOPE (REST): send a GET list all scopes for one account """ mw = [] headers1 = {'X-Rucio-Account': 'root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} r1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers1, expect_errors=True) assert_equal(r1.status, 200) token = str(r1.header('X-Rucio-Auth-Token')) tmp_val = account_name_generator() headers2 = {'Rucio-Type': 'user', 'X-Rucio-Account': 'root', 'X-Rucio-Auth-Token': str(token)} data = dumps({'type': 'USER'}) r2 = TestApp(account_app.wsgifunc(*mw)).post('/%s' % tmp_val, headers=headers2, params=data, expect_errors=True) assert_equal(r2.status, 201) headers3 = {'X-Rucio-Auth-Token': str(token)} for scope in self.scopes: data = dumps({}) r3 = TestApp(account_app.wsgifunc(*mw)).post('/%s/scopes/%s' % (tmp_val, scope), headers=headers3, params=data, expect_errors=True) assert_equal(r3.status, 201) r4 = TestApp(account_app.wsgifunc(*mw)).get('/%s/scopes/' % tmp_val, headers=headers3, expect_errors=True) assert_equal(r4.status, 200) svr_list = loads(r4.body) for scope in self.scopes: assert_in(scope, svr_list)
def test_create_user_failure(self): """ ACCOUNT (REST): send a POST with an existing user to test the error case """ mw = [] headers1 = {'X-Rucio-Account': 'root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} r1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers1, expect_errors=True) assert_equal(r1.status, 200) token = str(r1.header('X-Rucio-Auth-Token')) headers = {'X-Rucio-Auth-Token': str(token)} data = dumps({'type': 'USER'}) r1 = TestApp(account_app.wsgifunc(*mw)).post('/jdoe', headers=headers, params=data, expect_errors=True) r1 = TestApp(account_app.wsgifunc(*mw)).post('/jdoe', headers=headers, params=data, expect_errors=True) assert_equal(r1.status, 409)
def test_get_user_success(self): """ ACCOUNT (REST): send a GET to retrieve the infos of the new user """ mw = [] headers1 = {'X-Rucio-Account': 'root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} r1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers1, expect_errors=True) assert_equal(r1.status, 200) token = str(r1.header('X-Rucio-Auth-Token')) acntusr = account_name_generator() headers2 = {'X-Rucio-Auth-Token': str(token)} data = dumps({'type': 'USER'}) r2 = TestApp(account_app.wsgifunc(*mw)).post('/' + acntusr, headers=headers2, params=data, expect_errors=True) assert_equal(r2.status, 201) headers3 = {'X-Rucio-Auth-Token': str(token)} r3 = TestApp(account_app.wsgifunc(*mw)).get('/' + acntusr, headers=headers3, expect_errors=True) body = loads(r3.body) assert_equal(body['account'], acntusr) assert_equal(r3.status, 200)
def test_scope_success(self): """ SCOPE (REST): send a POST to create a new account and scope """ mw = [] headers1 = {'X-Rucio-Account': 'root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} r1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers1, expect_errors=True) assert_equal(r1.status, 200) token = str(r1.header('X-Rucio-Auth-Token')) headers2 = {'X-Rucio-Auth-Token': str(token)} acntusr = account_name_generator() data = dumps({'type': 'USER'}) r2 = TestApp(account_app.wsgifunc(*mw)).post('/' + acntusr, headers=headers2, params=data, expect_errors=True) assert_equal(r2.status, 201) headers3 = {'X-Rucio-Auth-Token': str(token)} scopeusr = scope_name_generator() r3 = TestApp(account_app.wsgifunc(*mw)).post('/%s/scopes/%s' % (acntusr, scopeusr), headers=headers3, expect_errors=True) assert_equal(r3.status, 201)
def test_del_user_failure(self): """ ACCOUNT (REST): send a DELETE with a wrong user to test the error """ mw = [] headers1 = {'X-Rucio-Account': 'root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} r1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers1, expect_errors=True) assert_equal(r1.status, 200) token = str(r1.header('X-Rucio-Auth-Token')) headers2 = {'X-Rucio-Auth-Token': str(token)} r2 = TestApp(account_app.wsgifunc(*mw)).delete('/wronguser', headers=headers2, expect_errors=True) assert_equal(r2.status, 404)
def test_whoami_account(self): """ ACCOUNT (REST): Test the whoami method.""" mw = [] headers1 = {'X-Rucio-Account': 'root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} r1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers1, expect_errors=True) assert_equal(r1.status, 200) token = str(r1.header('X-Rucio-Auth-Token')) headers2 = {'X-Rucio-Auth-Token': str(token)} r2 = TestApp(account_app.wsgifunc(*mw)).get('/whoami', headers=headers2, expect_errors=True) assert_equal(r2.status, 303)
def test_list_scope_no_scopes(self): """ SCOPE (REST): send a GET list all scopes for one account without scopes """ mw = [] headers1 = {'X-Rucio-Account': 'root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} r1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers1, expect_errors=True) assert_equal(r1.status, 200) token = str(r1.header('X-Rucio-Auth-Token')) headers2 = {'X-Rucio-Auth-Token': str(token)} acntusr = account_name_generator() data = dumps({'type': 'USER'}) r2 = TestApp(account_app.wsgifunc(*mw)).post('/' + acntusr, headers=headers2, params=data, expect_errors=True) assert_equal(r2.status, 201) headers3 = {'X-Rucio-Auth-Token': str(token)} r4 = TestApp(account_app.wsgifunc(*mw)).get('/%(acntusr)s/scopes/' % locals(), headers=headers3, params=data, expect_errors=True) assert_equal(r4.status, 404) assert_equal(r4.header('ExceptionClass'), 'ScopeNotFound')
def test_scope_failure(self): """ SCOPE (REST): send a POST to create a new scope for a not existing account to test the error""" mw = [] headers1 = {'X-Rucio-Account': 'root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} r1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers1, expect_errors=True) assert_equal(r1.status, 200) token = str(r1.header('X-Rucio-Auth-Token')) headers2 = {'X-Rucio-Auth-Token': str(token)} scopeusr = scope_name_generator() # NOQA acntusr = account_name_generator() # NOQA r2 = TestApp(account_app.wsgifunc(*mw)).post('/%(scopeusr)s/scopes/%(scopeusr)s' % locals(), headers=headers2, expect_errors=True) assert_equal(r2.status, 404)
def test_create_user_non_json_body(self): """ ACCOUNT (REST): send a POST with a non json body""" mw = [] headers = {'X-Rucio-Account': 'root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} r = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers, expect_errors=True) assert_equal(r.status, 200) token = str(r.header('X-Rucio-Auth-Token')) headers = {'X-Rucio-Auth-Token': str(token)} data = {'type': 'USER'} ret = TestApp(account_app.wsgifunc(*mw)).post('/testuser', headers=headers, params=data, expect_errors=True) assert_equal(ret.header('ExceptionClass'), 'ValueError') assert_equal(ret.normal_body, 'ValueError: cannot decode json parameter dictionary') assert_equal(ret.status, 400)
def test_del_user_success(self): """ ACCOUNT (REST): send a DELETE to disable the new user """ mw = [] headers1 = {'X-Rucio-Account': 'root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} r1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers1, expect_errors=True) assert_equal(r1.status, 200) token = str(r1.header('X-Rucio-Auth-Token')) acntusr = account_name_generator() headers2 = {'X-Rucio-Auth-Token': str(token)} data = dumps({'type': 'USER'}) r2 = TestApp(account_app.wsgifunc(*mw)).post('/' + acntusr, headers=headers2, params=data, expect_errors=True) assert_equal(r2.status, 201) headers3 = {'X-Rucio-Auth-Token': str(token)} r3 = TestApp(account_app.wsgifunc(*mw)).delete('/' + acntusr, headers=headers3, expect_errors=True) assert_equal(r3.status, 200) headers4 = {'X-Rucio-Auth-Token': str(token)} r4 = TestApp(account_app.wsgifunc(*mw)).get('/' + acntusr, headers=headers4, expect_errors=True) body = loads(r4.body) assert_true(body['status'] == AccountStatus.DELETED.description) assert_equal(r3.status, 200)
def test_create_user_not_json_dict(self): """ ACCOUNT (REST): send a POST with a non dictionary json body""" mw = [] headers = {'X-Rucio-Account': 'root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} r = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers, expect_errors=True) assert_equal(r.status, 200) token = str(r.header('X-Rucio-Auth-Token')) headers = {'X-Rucio-Auth-Token': str(token)} data = dumps(('account', 'account')) r = TestApp(account_app.wsgifunc(*mw)).post('/testaccount', headers=headers, params=data, expect_errors=True) assert_equal(r.header('ExceptionClass'), 'TypeError') assert_equal(r.normal_body, "TypeError: body must be a json dictionary") assert_equal(r.status, 400)
def test_create_user_missing_parameter(self): """ ACCOUNT (REST): send a POST with a missing parameter""" mw = [] headers = {'X-Rucio-Account': 'root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} r = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers, expect_errors=True) assert_equal(r.status, 200) token = str(r.header('X-Rucio-Auth-Token')) headers = {'X-Rucio-Auth-Token': str(token)} data = dumps({}) ret = TestApp(account_app.wsgifunc(*mw)).post('/account', headers=headers, params=data, expect_errors=True) assert_equal(ret.header('ExceptionClass'), 'KeyError') assert_equal(ret.normal_body, "KeyError: \'type\' not defined") assert_equal(ret.status, 400)
def test_list_scope_account_not_found(self): """ SCOPE (REST): send a GET list all scopes for a not existing account """ mw = [] headers1 = {'X-Rucio-Account': 'root', 'X-Rucio-Username': '******', 'X-Rucio-Password': '******'} r1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass', headers=headers1, expect_errors=True) assert_equal(r1.status, 200) token = str(r1.header('X-Rucio-Auth-Token')) headers3 = {'X-Rucio-Auth-Token': str(token)} r3 = TestApp(account_app.wsgifunc(*mw)).get('/testaccount/scopes', headers=headers3, expect_errors=True) assert_equal(r3.status, 404) assert_equal(r3.header('ExceptionClass'), 'AccountNotFound')