aboutsummaryrefslogtreecommitdiffstats
path: root/moon_cache/tests/unit_python/mock_repo
diff options
context:
space:
mode:
Diffstat (limited to 'moon_cache/tests/unit_python/mock_repo')
-rw-r--r--moon_cache/tests/unit_python/mock_repo/__init__.py12
-rw-r--r--moon_cache/tests/unit_python/mock_repo/data.py306
-rw-r--r--moon_cache/tests/unit_python/mock_repo/urls.py174
3 files changed, 492 insertions, 0 deletions
diff --git a/moon_cache/tests/unit_python/mock_repo/__init__.py b/moon_cache/tests/unit_python/mock_repo/__init__.py
new file mode 100644
index 00000000..1856aa2c
--- /dev/null
+++ b/moon_cache/tests/unit_python/mock_repo/__init__.py
@@ -0,0 +1,12 @@
+# Software Name: MOON
+
+# Version: 5.4
+
+# SPDX-FileCopyrightText: Copyright (c) 2018-2020 Orange and its contributors
+# SPDX-License-Identifier: Apache-2.0
+
+# This software is distributed under the 'Apache License 2.0',
+# the text of which is available at 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+# or see the "LICENSE" file for more details.
+
+
diff --git a/moon_cache/tests/unit_python/mock_repo/data.py b/moon_cache/tests/unit_python/mock_repo/data.py
new file mode 100644
index 00000000..ff5e25a8
--- /dev/null
+++ b/moon_cache/tests/unit_python/mock_repo/data.py
@@ -0,0 +1,306 @@
+# Software Name: MOON
+
+# Version: 5.4
+
+# SPDX-FileCopyrightText: Copyright (c) 2018-2020 Orange and its contributors
+# SPDX-License-Identifier: Apache-2.0
+
+# This software is distributed under the 'Apache License 2.0',
+# the text of which is available at 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+# or see the "LICENSE" file for more details.
+
+
+
+shared_ids = {
+ "policy": {
+ "policy_id_1": "policy_id_1",
+ "policy_id_2": "policy_id_2",
+ "policy_id_3": "policy_id_3",
+ "policy_id_invalid_response": "policy_id_invalid_response"
+ },
+ "category": {
+ "category_id_1": "category_id_1",
+ "invalid_category_id_1": " invalid_category_id_1"
+ },
+ "perimeter": {
+ "perimeter_id_1": "subject_id_1",
+ "perimeter_id_2": "object_id_1",
+ "perimeter_id_3": "action_id_1"
+ },
+ "meta_rule": {
+ "meta_rule_id_1": "meta_rule_id_1",
+ "meta_rule_id_2": "meta_rule_id_2"
+ },
+ "rule": {
+ "rule_id_1": "rule_id_2",
+ "rule_id_2": "rule_id_2"
+ },
+ "model": {
+ "model_id_1": "model_id_1"
+ },
+ "subject": {
+ "subject_id_1": "subject_id_1",
+ "invalid_subject_id": "invalid_subject_id",
+ "invalid_category_id": "invalid_category_id",
+ "invalid_assignment_id": "invalid_assignment_id"
+ },
+ "object": {
+ "object_id_1": "object_id_1",
+ "invalid_object_id": "invalid_object_id",
+ "invalid_category_id": "invalid_category_id",
+ "invalid_assignment_id": "invalid_assignment_id"
+ },
+ "action": {
+ "action_id_1": "action_id_1",
+ "invalid_action_id": "invalid_action_id",
+ "invalid_category_id": "invalid_category_id",
+ "invalid_assignment_id": "invalid_assignment_id"
+ }
+}
+
+pdp_mock = {
+ "pdp_id1": {
+ "name": "...",
+ "security_pipeline": ["policy_id_1", "policy_id_2"],
+ "vim_project_id": "vim_project_id1",
+ "description": "...",
+ }
+}
+
+meta_rules_mock = {
+ shared_ids["meta_rule"]["meta_rule_id_1"]: {
+ "name": "meta_rule1",
+ "algorithm": "name of the meta rule algorithm",
+ "subject_categories": ["subject_category_id1",
+ "subject_category_id2"],
+ "object_categories": ["object_category_id1"],
+ "action_categories": ["action_category_id1"]
+ },
+ shared_ids["meta_rule"]["meta_rule_id_2"]: {
+ "name": "name of the meta rules2",
+ "algorithm": "name of the meta rule algorithm",
+ "subject_categories": ["subject_category_id1",
+ "subject_category_id2"],
+ "object_categories": ["object_category_id1"],
+ "action_categories": ["action_category_id1"]
+ }
+}
+
+policies_mock = {
+ shared_ids["policy"]["policy_id_1"]: {
+ "name": "test_policy1",
+ "model_id": shared_ids["model"]["model_id_1"],
+ "genre": "authz",
+ "description": "test",
+ },
+ shared_ids["policy"]["policy_id_2"]: {
+ "name": "test_policy2",
+ "model_id": shared_ids["model"]["model_id_1"],
+ "genre": "authz",
+ "description": "test",
+ }
+}
+
+subject_mock = {
+ shared_ids["policy"]["policy_id_1"]: {
+ "subject_id": {
+ "name": "subject_name",
+ "vim_id": "vim_project_id1",
+ "description": "a description"
+ }
+ },
+ shared_ids["policy"]["policy_id_invalid_response"]: {
+ "subject_id": {
+ "name": "subject_name",
+ "vim_id": "vim_project_id1",
+ "description": "a description"
+ }
+ }
+
+}
+
+subject_assignment_mock = {
+ shared_ids["subject"]["subject_id_1"]: {
+ "policy_id": shared_ids["policy"]["policy_id_1"],
+ "subject_id": "subject_id_1",
+ "category_id": shared_ids["category"]["category_id_1"],
+ "assignments": ["data_id_1, data_id_2"],
+ }
+}
+
+subject_assignment_mock_invalid_subject_id = {
+ shared_ids["subject"]["invalid_subject_id"]: {
+ "policy_id": shared_ids["policy"]["policy_id_1"],
+ "subject_id_invalid": "subject_id_1",
+ "category_id": shared_ids["category"]["category_id_1"],
+ "assignments": ["data_id_1, data_id_2"],
+ }
+}
+
+subject_assignment_mock_invalid_category_id = {
+ shared_ids["subject"]["invalid_category_id"]: {
+ "policy_id": shared_ids["policy"]["policy_id_1"],
+ "subject_id": "subject_id_1",
+ "category_id_invalid": shared_ids["category"]["category_id_1"],
+ "assignments": ["data_id_1, data_id_2"],
+ }
+}
+
+subject_assignment_mock_invalid_assignment_id = {
+ shared_ids["subject"]["invalid_assignment_id"]: {
+ "policy_id": shared_ids["policy"]["policy_id_1"],
+ "subject_id": "subject_id_1",
+ "category_id": shared_ids["category"]["category_id_1"],
+ "assignments_invalid": ["data_id_1, data_id_2"],
+ }
+}
+
+object_mock = {
+ shared_ids["policy"]["policy_id_1"]: {
+ "object_id": {
+ "name": "object_name",
+ "description": "a description"
+ }
+ }
+}
+
+object_assignment_mock = {
+ shared_ids["object"]["object_id_1"]: {
+ "policy_id": shared_ids["policy"]["policy_id_1"],
+ "object_id": "object_id_1",
+ "category_id": shared_ids["category"]["category_id_1"],
+ "assignments": ["data_id_1, data_id_2"]
+ }
+}
+
+object_assignment_mock_invalid_object_id = {
+ shared_ids["object"]["invalid_object_id"]: {
+ "policy_id": shared_ids["policy"]["policy_id_1"],
+ "object_id": "object_id_1",
+ "category_id": shared_ids["category"]["category_id_1"],
+ "assignments": ["data_id_1, data_id_2"]
+ }
+}
+
+object_assignment_mock_invalid_category_id = {
+ shared_ids["object"]["invalid_category_id"]: {
+ "policy_id": shared_ids["policy"]["policy_id_1"],
+ "object_id": "object_id_1",
+ "category_id": shared_ids["category"]["category_id_1"],
+ "assignments": ["data_id_1, data_id_2"]
+ }
+}
+
+object_assignment_mock_invalid_assignment_id = {
+ shared_ids["object"]["invalid_assignment_id"]: {
+ "policy_id": shared_ids["policy"]["policy_id_1"],
+ "object_id": "object_id_1",
+ "category_id": shared_ids["category"]["category_id_1"],
+ "assignments": ["data_id_1, data_id_2"]
+ }
+}
+
+action_mock = {
+ shared_ids["policy"]["policy_id_1"]: {
+ "action_id": {
+ "name": "action_name",
+ "description": "a description"
+ }
+ }
+}
+
+action_assignment_mock = {
+ shared_ids["action"]["action_id_1"]: {
+ "policy_id": shared_ids["policy"]["policy_id_1"],
+ "action_id": "action_id_1",
+ "category_id": shared_ids["category"]["category_id_1"],
+ "assignments": ["data_id_1, data_id_2"]
+ }
+}
+
+action_assignment_mock_invalid_action_id = {
+ shared_ids["action"]["invalid_action_id"]: {
+ "policy_id": shared_ids["policy"]["policy_id_1"],
+ "action_id": "action_id_1",
+ "category_id": shared_ids["category"]["category_id_1"],
+ "assignments": ["data_id_1, data_id_2"]
+ }
+}
+
+action_assignment_mock_invalid_category_id = {
+ shared_ids["action"]["invalid_category_id"]: {
+ "policy_id": shared_ids["policy"]["policy_id_1"],
+ "action_id": "action_id_1",
+ "category_id": shared_ids["category"]["category_id_1"],
+ "assignments": ["data_id_1, data_id_2"]
+ }
+}
+
+action_assignment_mock_invalid_assignment_id = {
+ shared_ids["action"]["invalid_assignment_id"]: {
+ "policy_id": shared_ids["policy"]["policy_id_1"],
+ "action_id": "action_id_1",
+ "category_id": shared_ids["category"]["category_id_1"],
+ "assignments": ["data_id_1, data_id_2"]
+ }
+}
+
+
+models_mock = {
+ shared_ids["model"]["model_id_1"]: {
+ "name": "test_model",
+ "description": "test",
+ "meta_rules": [shared_ids["meta_rule"]["meta_rule_id_1"]]
+ }
+}
+
+rules_mock = {
+ "rules": {
+ "meta_rule_id": shared_ids["meta_rule"]["meta_rule_id_1"],
+ shared_ids["rule"]["rule_id_1"]: {
+ "rule": ["subject_data_id1",
+ "object_data_id1",
+ "action_data_id1"],
+ "instructions": (
+ {"decision": "grant"},
+ # "grant" to immediately exit,
+ # "continue" to wait for the result of next policy
+ # "deny" to deny the request
+ )
+ },
+ shared_ids["rule"]["rule_id_2"]: {
+ "rule": ["subject_data_id2",
+ "object_data_id2",
+ "action_data_id2"],
+ "instructions": (
+ {
+ "update": {
+ "operation": "add",
+ # operations may be "add" or "delete"
+ "target": "rbac:role:admin"
+ # add the role admin to the current user
+ }
+ },
+ {"chain": {"name": "rbac"}}
+ # chain with the policy named rbac
+ )
+ }
+ }
+}
+
+pipelines_mock = {
+ "policy_id_1": {
+ "starttime": 1548688120.3931532,
+ "port": 20000,
+ "server_ip": "127.0.0.1",
+ "status": "up",
+ "log": "/tmp/moon_policy_id_1.log"
+ },
+ "policy_id_2": {
+ "starttime": 1548688120.3931532,
+ "port": 20001,
+ "server_ip": "127.0.0.1",
+ "status": "up",
+ "log": "/tmp/moon_policy_id_2.log"
+ }
+}
diff --git a/moon_cache/tests/unit_python/mock_repo/urls.py b/moon_cache/tests/unit_python/mock_repo/urls.py
new file mode 100644
index 00000000..4b6d5133
--- /dev/null
+++ b/moon_cache/tests/unit_python/mock_repo/urls.py
@@ -0,0 +1,174 @@
+# Software Name: MOON
+
+# Version: 5.4
+
+# SPDX-FileCopyrightText: Copyright (c) 2018-2020 Orange and its contributors
+# SPDX-License-Identifier: Apache-2.0
+
+# This software is distributed under the 'Apache License 2.0',
+# the text of which is available at 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+# or see the "LICENSE" file for more details.
+
+
+import mock_repo.data as data_mock
+
+
+def register_model_any(m, conf, module_name, mocked_data, key=None):
+ if key is None:
+ key = module_name
+ m.register_uri(
+ 'GET', '{}/{}'.format(conf['management']['url'],
+ module_name),
+
+ json={key: mocked_data}
+ )
+
+
+def register_policy_any(m, conf, policy_id, module_name, mocked_data, key=None):
+ if key is None:
+ key = module_name
+ m.register_uri(
+ 'GET', '{}/{}/{}/{}'.format(conf['management']['url'],
+ 'policies',
+ policy_id,
+ module_name),
+ json={key: mocked_data}
+ )
+
+
+def register_policy(m, conf, policy_id, mocked_data):
+ m.register_uri(
+ 'GET', '{}/{}/{}'.format(conf['management']['url'],
+ 'policies',
+ policy_id),
+ json={"policies": mocked_data}
+ )
+
+
+def register_pipelines(m, conf):
+ m.register_uri(
+ 'GET', 'http://127.0.0.1:20000/pipelines/policy_id_1',
+ json={'pipelines': data_mock.pipelines_mock}
+ )
+
+
+def register_slaves(m, conf):
+ m.register_uri(
+ 'GET', 'http://127.0.0.1:10000/pipelines',
+ json={'pipelines': data_mock.pipelines_mock}
+ )
+
+
+def register_pdp(m, conf):
+ register_model_any(m, conf, 'pdp', data_mock.pdp_mock, 'pdps')
+
+
+def register_meta_rules(m, conf):
+ register_model_any(m, conf, 'meta_rules', data_mock.meta_rules_mock)
+
+
+def register_policies(m, conf):
+ for _policy_id in data_mock.policies_mock:
+ register_policy(m, conf, _policy_id, data_mock.policies_mock[_policy_id])
+ register_model_any(m, conf, 'policies', data_mock.policies_mock)
+
+
+def register_models(m, conf):
+ register_model_any(m, conf, 'models', data_mock.models_mock)
+
+
+def register_policy_subject(m, conf, policy_id):
+ register_policy_any(m, conf, policy_id, 'subjects', data_mock.subject_mock[policy_id])
+
+
+def register_policy_subject_invalid_response(m, conf, policy_id):
+ register_policy_any(m, conf, policy_id, 'subjects', data_mock.subject_mock[policy_id],
+ 'subjects_invalid_key')
+
+
+def register_policy_object(m, conf, policy_id):
+ register_policy_any(m, conf, policy_id, 'objects', data_mock.object_mock[policy_id])
+
+
+def register_policy_object_invalid_response(m, conf, policy_id):
+ register_policy_any(m, conf, policy_id, 'objects', data_mock.subject_mock[policy_id],
+ 'objects_invalid_key')
+
+
+def register_policy_action(m, conf, policy_id):
+ register_policy_any(m, conf, policy_id, 'actions', data_mock.action_mock[policy_id])
+
+
+def register_policy_action_invalid_response(m, conf, policy_id):
+ register_policy_any(m, conf, policy_id, 'actions', data_mock.subject_mock[policy_id],
+ 'actions_invalid_key')
+
+
+def register_policy_subject_assignment_list(m, conf, policy_id):
+ register_policy_any(m, conf, policy_id, 'subject_assignments',
+ data_mock.subject_assignment_mock)
+
+
+def register_policy_object_assignment_list(m, conf, policy_id):
+ register_policy_any(m, conf, policy_id, 'object_assignments',
+ data_mock.object_assignment_mock)
+
+
+def register_policy_action_assignment_list(m, conf, policy_id):
+ register_policy_any(m, conf, policy_id, 'action_assignments',
+ data_mock.action_assignment_mock)
+
+
+def register_policy_subject_assignment(m, conf, policy_id, perimeter_id):
+ m.register_uri(
+ 'GET', '{}/{}/{}/subject_assignments/{}'.format(conf['management']['url'],
+ 'policies',
+ policy_id,
+ perimeter_id),
+ json={'subject_assignments': data_mock.subject_assignment_mock}
+ )
+
+
+def register_policy_object_assignment(m, conf, policy_id, perimeter_id):
+ m.register_uri(
+ 'GET', '{}/{}/{}/object_assignments/{}'.format(conf['management']['url'],
+ 'policies',
+ policy_id,
+ perimeter_id),
+ json={'object_assignments': data_mock.object_assignment_mock}
+ )
+
+
+def register_policy_action_assignment(m, conf, policy_id, perimeter_id):
+ m.register_uri(
+ 'GET', '{}/{}/{}/action_assignments/{}'.format(conf['management']['url'],
+ 'policies',
+ policy_id,
+ perimeter_id),
+ json={'action_assignments': data_mock.action_assignment_mock}
+ )
+
+
+def register_rules(m, conf, policy_id):
+ register_policy_any(m, conf, policy_id, 'rules', data_mock.rules_mock)
+
+
+def register_attributes(m, conf):
+ m.register_uri(
+ 'GET', 'http://127.0.0.1:8000/attributes/mode',
+ json={
+ 'attributes': {
+ 'id': 'mode', 'value': 'build', 'values': ['build', 'run'], 'default': 'run'
+ }
+ }
+ )
+ m.register_uri(
+ 'GET', 'http://127.0.0.1:8000/attributes',
+ json={
+ 'attributes': {
+ 'mode': {
+ 'id': 'mode', 'value': 'build', 'values': ['build', 'run'], 'default': 'run'}
+ }
+ }
+ )
+