aboutsummaryrefslogtreecommitdiffstats
path: root/moonv4/tests/test_policies.py
blob: 8f26d72d7a45d71c0a23d59a4a55df58179649db (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
from utils.policies import *
from utils.models import *


def test_policies():
    check_policy()
    policy_id = add_policy()
    check_policy(policy_id)
    delete_policy(policy_id)


def test_subjects():
    policy_id = add_policy()
    subject_id = add_subject()

    update_subject(subject_id=subject_id, policy_id=policy_id)

    check_subject(subject_id=subject_id, policy_id=policy_id)

    delete_subject(subject_id, policy_id=policy_id)
    delete_subject(subject_id)

    
def test_objects():
    policy_id = add_policy()
    object_id = add_object()

    update_object(object_id=object_id, policy_id=policy_id)
    check_object(object_id=object_id, policy_id=policy_id)

    delete_object(object_id=object_id, policy_id=policy_id)
    delete_object(object_id=object_id)

    
def test_actions():
    policy_id = add_policy()
    action_id = add_action()

    update_action(action_id=action_id, policy_id=policy_id)
    check_action(action_id=action_id, policy_id=policy_id)

    delete_action(action_id=action_id, policy_id=policy_id)
    delete_action(action_id=action_id)


def test_subject_data():
    policy_id = add_policy()

    model_id = add_model()

    update_policy(policy_id, model_id)

    meta_rule_id, subject_cat_id, object_cat_id, action_cat_id = add_categories_and_meta_rule()
    add_meta_rule_to_model(model_id, meta_rule_id)

    subject_data_id = add_subject_data(policy_id=policy_id, category_id=subject_cat_id)
    check_subject_data(policy_id=policy_id, data_id=subject_data_id, category_id=subject_cat_id)
    delete_subject_data(policy_id=policy_id, data_id=subject_data_id, category_id=subject_cat_id)


def test_object_data():
    policy_id = add_policy()

    model_id = add_model()

    update_policy(policy_id, model_id)

    meta_rule_id, object_cat_id, object_cat_id, action_cat_id = add_categories_and_meta_rule()
    add_meta_rule_to_model(model_id, meta_rule_id)

    object_data_id = add_object_data(policy_id=policy_id, category_id=object_cat_id)
    check_object_data(policy_id=policy_id, data_id=object_data_id, category_id=object_cat_id)
    delete_object_data(policy_id=policy_id, data_id=object_data_id, category_id=object_cat_id)


def test_action_data():
    policy_id = add_policy()

    model_id = add_model()

    update_policy(policy_id, model_id)

    meta_rule_id, action_cat_id, action_cat_id, action_cat_id = add_categories_and_meta_rule()
    add_meta_rule_to_model(model_id, meta_rule_id)

    action_data_id = add_action_data(policy_id=policy_id, category_id=action_cat_id)
    check_action_data(policy_id=policy_id, data_id=action_data_id, category_id=action_cat_id)
    delete_action_data(policy_id=policy_id, data_id=action_data_id, category_id=action_cat_id)


def test_assignments():
    policy_id = add_policy()

    model_id = add_model()

    update_policy(policy_id, model_id)

    meta_rule_id, subject_cat_id, object_cat_id, action_cat_id = add_categories_and_meta_rule()
    add_meta_rule_to_model(model_id, meta_rule_id)

    subject_data_id = add_subject_data(policy_id=policy_id, category_id=subject_cat_id)
    subject_data_id_bis = add_subject_data(policy_id=policy_id, category_id=subject_cat_id)
    object_data_id = add_object_data(policy_id=policy_id, category_id=object_cat_id)
    object_data_id_bis = add_object_data(policy_id=policy_id, category_id=object_cat_id)
    action_data_id = add_action_data(policy_id=policy_id, category_id=action_cat_id)
    action_data_id_bis = add_action_data(policy_id=policy_id, category_id=action_cat_id)

    subject_id = add_subject(policy_id)
    object_id = add_object(policy_id)
    action_id = add_action(policy_id)

    add_subject_assignments(policy_id, subject_id, subject_cat_id, subject_data_id)
    add_subject_assignments(policy_id, subject_id, subject_cat_id, subject_data_id_bis)
    add_object_assignments(policy_id, object_id, object_cat_id, object_data_id)
    add_object_assignments(policy_id, object_id, object_cat_id, object_data_id_bis)
    add_action_assignments(policy_id, action_id, action_cat_id, action_data_id)
    add_action_assignments(policy_id, action_id, action_cat_id, action_data_id_bis)

    check_subject_assignments(policy_id, subject_id, subject_cat_id, subject_data_id)
    check_subject_assignments(policy_id, subject_id, subject_cat_id, subject_data_id_bis)
    check_object_assignments(policy_id, object_id, object_cat_id, object_data_id)
    check_object_assignments(policy_id, object_id, object_cat_id, object_data_id_bis)
    check_action_assignments(policy_id, action_id, action_cat_id, action_data_id)
    check_action_assignments(policy_id, action_id, action_cat_id, action_data_id_bis)

    delete_subject_assignment(policy_id, subject_id, subject_cat_id, subject_data_id)
    delete_object_assignment(policy_id, object_id, object_cat_id, object_data_id)
    delete_action_assignment(policy_id, action_id, action_cat_id, action_data_id)


def test_rule():
    policy_id = add_policy()

    model_id = add_model()

    update_policy(policy_id, model_id)

    meta_rule_id, subject_cat_id, object_cat_id, action_cat_id = add_categories_and_meta_rule()
    add_meta_rule_to_model(model_id, meta_rule_id)

    subject_data_id = add_subject_data(policy_id=policy_id, category_id=subject_cat_id)
    object_data_id = add_object_data(policy_id=policy_id, category_id=object_cat_id)
    action_data_id = add_action_data(policy_id=policy_id, category_id=action_cat_id)

    subject_id = add_subject(policy_id)
    object_id = add_object(policy_id)
    action_id = add_action(policy_id)

    add_subject_assignments(policy_id, subject_id, subject_cat_id, subject_data_id)
    add_object_assignments(policy_id, object_id, object_cat_id, object_data_id)
    add_action_assignments(policy_id, action_id, action_cat_id, action_data_id)

    rule_id = add_rule(policy_id, meta_rule_id, [subject_data_id, object_data_id, action_data_id])
    check_rule(policy_id, meta_rule_id, rule_id, [subject_data_id, object_data_id, action_data_id])

    delete_rule(policy_id, rule_id)