From 0ac1ba7e26d2d6394a0e4d96e7104f636eedaa1e Mon Sep 17 00:00:00 2001 From: Paul Lodronio Date: Tue, 7 May 2013 11:15:35 -0500 Subject: [PATCH] added malformed json tests these tests are all being skipped because the code being tested is broken bug #1177969 Change-Id: Iaf3c09bfda01b5ad883e9859906f831a3b2b5337 --- reddwarf/tests/api/mgmt/malformed_json.py | 204 ++++++++++++++++++++++ run_tests.py | 1 + 2 files changed, 205 insertions(+) create mode 100644 reddwarf/tests/api/mgmt/malformed_json.py diff --git a/reddwarf/tests/api/mgmt/malformed_json.py b/reddwarf/tests/api/mgmt/malformed_json.py new file mode 100644 index 0000000000..e1d92ce56d --- /dev/null +++ b/reddwarf/tests/api/mgmt/malformed_json.py @@ -0,0 +1,204 @@ +from proboscis import test +from proboscis.asserts import * +from proboscis import after_class +from proboscis import before_class +from proboscis.asserts import Check +from reddwarf.tests.config import CONFIG +from reddwarfclient import exceptions +import json +import requests + +from reddwarf.tests.util.users import Requirements +from reddwarf.tests.util import create_dbaas_client +from reddwarf.tests.util import poll_until +from nose.plugins.skip import SkipTest + + +@test(groups=["dbaas.api.mgmt.malformed_json"]) +class MalformedJson(object): + + @before_class + def setUp(self): + self.reqs = Requirements(is_admin=False) + self.user = CONFIG.users.find_user(self.reqs) + self.dbaas = create_dbaas_client(self.user) + self.instance = self.dbaas.instances.create( + name="qe_instance", + flavor_id=1, + volume={"size": 1}, + databases=[{"name": "firstdb", "character_set": "latin2", + "collate": "latin2_general_ci"}]) + + @after_class + def tearDown(self): + self.dbaas.instances.delete(self.instance) + + @test + def test_bad_instance_data(self): + raise SkipTest("Please see Launchpad Bug #1177969") + try: + self.dbaas.instances.create("bad_instance", 3, 3, + databases="foo", + users="bar") + except Exception as e: + resp, body = self.dbaas.client.last_response + httpCode = resp.status + assert_true(httpCode == 400, + "Create instance failed with code %s, exception %s" + % (httpCode, e)) + + @test + def test_bad_database_data(self): + raise SkipTest("Please see Launchpad Bug #1177969") + _bad_db_data = "{foo}" + try: + self.dbaas.databases.create(self.instance.id, _bad_db_data) + except Exception as e: + resp, body = self.dbaas.client.last_response + httpCode = resp.status + assert_true(httpCode == 400, + "Create database failed with code %s, exception %s" + % (httpCode, e)) + + @test + def test_bad_user_data(self): + _user = [] + _user_name = "F343jasdf" + _user.append({"name12": _user_name, + "password12": "password"}) + try: + self.dbaas.users.create(self.instance.id, _user) + except Exception as e: + resp, body = self.dbaas.client.last_response + httpCode = resp.status + assert_true(httpCode == 400, + "Create user failed with code %s, exception %s" + % (httpCode, e)) + + @test + def test_bad_resize_instance_data(self): + raise SkipTest("Please see Launchpad Bug #1177969") + + def _check_instance_status(): + inst = self.dbaas.instances.get(self.instance) + if inst.status == "ACTIVE": + return True + else: + return False + poll_until(_check_instance_status) + try: + self.dbaas.instances.resize_instance(self.instance.id, "bad data") + except Exception as e: + resp, body = self.dbaas.client.last_response + httpCode = resp.status + assert_true(httpCode == 400, + "Resize instance failed with code %s, exception %s" + % (httpCode, e)) + + @test + def test_bad_resize_vol_data(self): + def _check_instance_status(): + inst = self.dbaas.instances.get(self.instance) + if inst.status == "ACTIVE": + return True + else: + return False + poll_until(_check_instance_status) + try: + self.dbaas.instances.resize_volume(self.instance.id, "bad data") + except Exception as e: + resp, body = self.dbaas.client.last_response + httpCode = resp.status + assert_true(httpCode == 400, + "Resize instance failed with code %s, exception %s" + % (httpCode, e)) + + @test + def test_bad_change_user_password(self): + users = [{"name": ""}] + + def _check_instance_status(): + inst = self.dbaas.instances.get(self.instance) + if inst.status == "ACTIVE": + return True + else: + return False + poll_until(_check_instance_status) + try: + self.dbaas.users.change_passwords(self.instance, users) + except Exception as e: + resp, body = self.dbaas.client.last_response + httpCode = resp.status + assert_true(httpCode == 400, + "Change usr/passwd failed with code %s, exception %s" % + (httpCode, e)) + + @test + def test_bad_grant_user_access(self): + dbs = [] + + def _check_instance_status(): + inst = self.dbaas.instances.get(self.instance) + if inst.status == "ACTIVE": + return True + else: + return False + poll_until(_check_instance_status) + try: + self.dbaas.users.grant(self.instance, self.user, dbs) + except Exception as e: + resp, body = self.dbaas.client.last_response + httpCode = resp.status + assert_true(httpCode == 400, + "Grant user access failed with code %s, exception %s" % + (httpCode, e)) + + @test + def test_bad_revoke_user_access(self): + db = "" + + def _check_instance_status(): + inst = self.dbaas.instances.get(self.instance) + if inst.status == "ACTIVE": + return True + else: + return False + poll_until(_check_instance_status) + try: + self.dbaas.users.revoke(self.instance, self.user, db) + except Exception as e: + resp, body = self.dbaas.client.last_response + httpCode = resp.status + assert_true(httpCode == 404, + "Revoke user access failed w/code %s, exception %s" % + (httpCode, e)) + + @test + def test_bad_body_flavorid_create_instance(self): + raise SkipTest("Please see Launchpad Bug #1177969") + flavorId = ["?"] + try: + self.dbaas.instances.create("test_instance", + flavorId, + 2) + except Exception as e: + resp, body = self.dbaas.client.last_response + httpCode = resp.status + assert_true(httpCode == 400, + "Create instance failed with code %s, exception %s" % + (httpCode, e)) + + @test + def test_bad_body_volsize_create_instance(self): + raise SkipTest("Please see Launchpad Bug #1177969") + volsize = ("h3ll0") + try: + self.dbaas.instances.create("test_instance", + "1", + volsize) + except Exception as e: + resp, body = self.dbaas.client.last_response + httpCode = resp.status + assert_true(httpCode == 400, + "Create instance failed with code %s, exception %s" % + (httpCode, e)) diff --git a/run_tests.py b/run_tests.py index fd971e0cbe..9ab5d4f403 100644 --- a/run_tests.py +++ b/run_tests.py @@ -141,6 +141,7 @@ if __name__ == "__main__": from reddwarf.tests.api.mgmt import instances from reddwarf.tests.api.mgmt import instances_actions from reddwarf.tests.api.mgmt import storage + from reddwarf.tests.api.mgmt import malformed_json except Exception as e: print("Run tests failed: %s" % e) traceback.print_exc()