aboutsummaryrefslogtreecommitdiffstats
path: root/python_moonutilities/tests/unit_python/mock_repo/urls.py
blob: 4170213ce3829879062f6fe81178016a73c7f118 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import mock_repo.components_utilities as comp_util
import mock_repo.data as data_mock


def register_components(m):
    for component in data_mock.components:
        m.register_uri(
            'GET', 'http://consul:8500/v1/kv/{}'.format(component),
            json=[{'Key': component, 'Value': comp_util.get_b64_conf(component)}]
        )
    m.register_uri(
        'GET', 'http://consul:8500/v1/kv/components/port_start',
        json=[{'Key': 'port_start', 'Value': comp_util.get_b64_conf("components/port_start")}]
    )
    m.register_uri(
        'GET', 'http://consul:8500/v1/kv/plugins?recurse=true',
        json=[
            {
                "LockIndex": 0,
                "Key": "plugins/authz",
                "Flags": 0,
                "Value": "eyJjb250YWluZXIiOiAid3Vrb25nc3VuL21vb25fYXV0aHo6djQuMyIsICJwb3J0IjogODA4MX0=",
                "CreateIndex": 14,
                "ModifyIndex": 656
            }
        ],
    )
    m.register_uri(
        'PUT', 'http://consul:8500/v1/kv/components/port_start',
        json=[]
    )

    m.register_uri(
        'GET', 'http://consul:8500/v1/kv/components?recurse=true',
        json=[
            {"Key": key, "Value": comp_util.get_b64_conf(key)} for key in data_mock.components
        ],
        # json={'Key': "components", 'Value': get_b64_comp_util.CONF("components")}
    )


def register_keystone(m):
    m.register_uri(
        'POST', 'http://keystone:5000/v3/auth/tokens',
        headers={'X-Subject-Token': "111111111"}
    )
    m.register_uri(
        'DELETE', 'http://keystone:5000/v3/auth/tokens',
        headers={'X-Subject-Token': "111111111"}
    )
    m.register_uri(
        'POST', 'http://keystone:5000/v3/users?name=testuser&domain_id=default',
        json={"users": {}}
    )
    m.register_uri(
        'GET', 'http://keystone:5000/v3/users?name=testuser&domain_id=default',
        json={"users": {}}
    )
    m.register_uri(
        'POST', 'http://keystone:5000/v3/users/',
        json={"users": [{
            "id": "1111111111111"
        }]}
    )

def register_model_any(m, module_name, mocked_data, key=None):
    if key is None:
        key = module_name
    m.register_uri(
        'GET', 'http://{}:{}/{}'.format(comp_util.CONF['components']['manager']['hostname'],
                                        comp_util.CONF['components']['manager']['port'], module_name),

        json={key: mocked_data}
    )

def register_policy_any(m, policy_id, module_name, mocked_data, key=None):
    if key is None:
        key = module_name
    m.register_uri(
        'GET', 'http://{}:{}/{}/{}/{}'.format(comp_util.CONF['components']['manager']['hostname'],
                                                    comp_util.CONF['components']['manager']['port'], 'policies',
                                                    policy_id, module_name),
        json={key: mocked_data}
    )

def register_pdp(m):
    register_model_any(m, 'pdp', data_mock.pdp_mock,'pdps')

def register_meta_rules(m):
    register_model_any(m, 'meta_rules',data_mock.meta_rules_mock)

def register_policies(m):
    register_model_any(m, 'policies', data_mock.policies_mock)


def register_models(m):
    register_model_any(m, 'models', data_mock.models_mock)

def register_policy_subject(m, policy_id):
    register_policy_any(m, policy_id, 'subjects', data_mock.subject_mock[policy_id])


def register_policy_subject_invalid_response(m, policy_id):
    register_policy_any(m, policy_id, 'subjects', data_mock.subject_mock[policy_id],'subjects_invalid_key')

def register_policy_object(m, policy_id):
    register_policy_any(m, policy_id, 'objects', data_mock.object_mock[policy_id])

def register_policy_object_invalid_response(m, policy_id):
    register_policy_any(m, policy_id, 'objects', data_mock.subject_mock[policy_id],'objects_invalid_key')

def register_policy_action(m, policy_id):
    register_policy_any(m, policy_id, 'actions', data_mock.action_mock[policy_id])

def register_policy_action_invalid_response(m, policy_id):
    register_policy_any(m, policy_id, 'actions', data_mock.subject_mock[policy_id],'actions_invalid_key')

def register_policy_subject_assignment_list(m, policy_id):
    register_policy_any(m, policy_id, 'subject_assignments', data_mock.subject_assignment_mock)

def register_policy_object_assignment_list(m, policy_id):
    register_policy_any(m, policy_id, 'object_assignments', data_mock.object_assignment_mock)


def register_policy_action_assignment_list(m, policy_id):
    register_policy_any(m, policy_id, 'action_assignments', data_mock.action_assignment_mock)

def register_policy_subject_assignment(m, policy_id, perimeter_id):
    m.register_uri(
        'GET', 'http://{}:{}/{}/{}/subject_assignments/{}'.format(comp_util.CONF['components']['manager']['hostname'],
                                                                  comp_util.CONF['components']['manager']['port'],
                                                                  'policies',
                                                                  policy_id,
                                                                  perimeter_id),
        json={'subject_assignments': data_mock.subject_assignment_mock}
    )

def register_policy_object_assignment(m, policy_id, perimeter_id):
    m.register_uri(
        'GET', 'http://{}:{}/{}/{}/object_assignments/{}'.format(comp_util.CONF['components']['manager']['hostname'],
                                                                 comp_util.CONF['components']['manager']['port'],
                                                                 'policies',
                                                                 policy_id,
                                                                 perimeter_id),
        json={'object_assignments': data_mock.object_assignment_mock}
    )

def register_policy_action_assignment(m, policy_id, perimeter_id):
    m.register_uri(
        'GET', 'http://{}:{}/{}/{}/action_assignments/{}'.format(comp_util.CONF['components']['manager']['hostname'],
                                                                 comp_util.CONF['components']['manager']['port'],
                                                                 'policies',
                                                                 policy_id,
                                                                 perimeter_id),
        json={'action_assignments': data_mock.action_assignment_mock}
    )

def register_rules(m, policy_id):
    register_policy_any(m, policy_id, 'rules', data_mock.rules_mock)

# def register_pods(m):
#     m.register_uri(
#         'GET', 'http://{}:{}/pods'.format(comp_util.CONF['components']['orchestrator']['hostname'],
#                                               comp_util.CONF['components']['orchestrator']['port']),
#         json={'pods': data_mock.pods_mock}
#     )