aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuan HE <ruan.he@orange.com>2018-01-08 20:11:11 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-01-08 20:11:11 +0000
commitff82da77d0464292b45f41a935abd5e43a42986f (patch)
tree04b208e6a949671c157d26206b36e009fbf123ac
parent9e25cdc18d6a5013db876641ef0a151f34ff62c5 (diff)
parent272ad1b600710f06285a5da8803369cb3a6fa744 (diff)
Merge "Add tests to test_authz"
-rw-r--r--moon_authz/tests/unit_python/test_authz.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/moon_authz/tests/unit_python/test_authz.py b/moon_authz/tests/unit_python/test_authz.py
index 50493c9f..cf37cfdf 100644
--- a/moon_authz/tests/unit_python/test_authz.py
+++ b/moon_authz/tests/unit_python/test_authz.py
@@ -48,3 +48,44 @@ def test_user_not_allowed(context):
assert isinstance(data, dict)
assert "message" in data
assert data["message"] == "Cannot find subject user_not_allowed"
+
+
+def test_object_not_allowed(context):
+ import moon_authz.server
+ from python_moonutilities.context import Context
+ from python_moonutilities.cache import Cache
+ server = moon_authz.server.create_server()
+ client = server.app.test_client()
+ CACHE = Cache()
+ CACHE.update()
+ context['subject_name'] = "testuser"
+ context['object_name'] = "invalid"
+ _context = Context(context, CACHE)
+ req = client.post("/authz", data=pickle.dumps(_context))
+ assert req.status_code == 400
+ data = get_json(req.data)
+ assert data
+ assert isinstance(data, dict)
+ assert "message" in data
+ assert data["message"] == "Cannot find object invalid"
+
+
+def test_action_not_allowed(context):
+ import moon_authz.server
+ from python_moonutilities.context import Context
+ from python_moonutilities.cache import Cache
+ server = moon_authz.server.create_server()
+ client = server.app.test_client()
+ CACHE = Cache()
+ CACHE.update()
+ context['subject_name'] = "testuser"
+ context['object_name'] = "vm1"
+ context['action_name'] = "invalid"
+ _context = Context(context, CACHE)
+ req = client.post("/authz", data=pickle.dumps(_context))
+ assert req.status_code == 400
+ data = get_json(req.data)
+ assert data
+ assert isinstance(data, dict)
+ assert "message" in data
+ assert data["message"] == "Cannot find action invalid"