Skip to content

Commit 8470181

Browse files
jgoughhonourfish
authored andcommitted
update access policy func tests
Problem: A recent change to the archivist api requires confirmed subjects when creating an access policy This breaks the access policy functional tests Solution: Create confirmed subjects for use in the access policy functional tests Signed-off-by: Joe Gough <joe.gough@jitsuin.com>
1 parent 907e8be commit 8470181

2 files changed

Lines changed: 69 additions & 4 deletions

File tree

DEVELOPMENT.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ export TEST_AUTHTOKEN_FILENAME=credentials/authtoken
123123
task functests
124124
```
125125

126+
NOTE: For the access policy functional tests, two separate tenancy tokens are needed for successful test execution.
127+
Therefore add a another env variable for the second tenancy's auth token:
128+
129+
```
130+
export TEST_AUTHTOKEN_FILENAME_2=credentials/authtoken_tenant_2
131+
```
132+
126133
#### Testing Other Python Versions
127134

128135
##### Python 3.6

functests/execaccess_policies.py

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66
from os import environ
77
from unittest import TestCase
88
from uuid import uuid4
9+
from time import sleep
910

1011
from archivist.archivist import Archivist
1112

1213
# pylint: disable=fixme
1314
# pylint: disable=missing-docstring
1415
# pylint: disable=unused-variable
1516

17+
POLL_FREQUENCY = 10
18+
POLL_INTERVAL = 0.5
19+
20+
SELF_SUBJECT = "subjects/00000000-0000-0000-0000-000000000000"
21+
1622
DISPLAY_NAME = "AccessPolicy display name"
1723
PROPS = {
1824
"display_name": DISPLAY_NAME,
@@ -40,10 +46,7 @@
4046

4147
ACCESS_PERMISSIONS = [
4248
{
43-
"subjects": [
44-
"subjects/6a951b62-0a26-4c22-a886-1082297b063b",
45-
"subjects/a24306e5-dc06-41ba-a7d6-2b6b3e1df48d",
46-
],
49+
"subjects": [], # empty subjects for now, will be populated in test setup
4750
"behaviours": ["Attachments", "RecordEvidence"],
4851
"include_attributes": [
4952
"arc_display_name",
@@ -55,6 +58,52 @@
5558
]
5659

5760

61+
def poll_subject_confirmed(arch, identity):
62+
"""
63+
polls for the subject to be confirmed for POLL_FREQUENCY every POLL_INTERVAL.
64+
65+
:raises: AsssertionError if the subject is not confirmed within the polling window.
66+
"""
67+
68+
for x in range(POLL_FREQUENCY):
69+
subject = arch.subjects.read(identity)
70+
71+
if subject["confirmation_status"] == "CONFIRMED":
72+
return
73+
74+
sleep(POLL_INTERVAL)
75+
76+
raise AssertionError(f"subject: {subject['identity']} is not confirmed.")
77+
78+
79+
def reciprocal_subjects(arch_1, arch_2):
80+
"""
81+
creates reciprocal subjects for arch 1 and arch 2.
82+
83+
Returns the id's of the imported subjects as a tuple
84+
"""
85+
self_subject_1 = arch_1.subjects.read(SELF_SUBJECT)
86+
self_subject_2 = arch_2.subjects.read(SELF_SUBJECT)
87+
88+
subject_1 = arch_1.subjects.create(
89+
"org2_subject",
90+
self_subject_2["wallet_pub_key"],
91+
self_subject_2["tessera_pub_key"],
92+
)
93+
94+
subject_2 = arch_2.subjects.create(
95+
"org1_subject",
96+
self_subject_1["wallet_pub_key"],
97+
self_subject_1["tessera_pub_key"],
98+
)
99+
100+
# check the subjects are confirmed
101+
poll_subject_confirmed(arch_1, subject_1["identity"])
102+
poll_subject_confirmed(arch_2, subject_2["identity"])
103+
104+
return subject_1, subject_2
105+
106+
58107
class TestAccessPolicies(TestCase):
59108
"""
60109
Test Archivist AccessPolicies Create method
@@ -66,9 +115,18 @@ def setUp(self):
66115
with open(environ["TEST_AUTHTOKEN_FILENAME"], encoding="utf-8") as fd:
67116
auth = fd.read().strip()
68117
self.arch = Archivist(environ["TEST_ARCHIVIST"], auth, verify=False)
118+
119+
with open(environ["TEST_AUTHTOKEN_FILENAME_2"], encoding="utf-8") as fd:
120+
auth_2 = fd.read().strip()
121+
self.arch_2 = Archivist(environ["TEST_ARCHIVIST"], auth_2, verify=False)
122+
69123
self.props = deepcopy(PROPS)
70124
self.props["display_name"] = f"{DISPLAY_NAME} {uuid4()}"
71125

126+
# now get reciprocal subjects
127+
self.subject_id = reciprocal_subjects(self.arch, self.arch_2)[0]
128+
ACCESS_PERMISSIONS[0]["subjects"] = [self.subject_id["identity"]]
129+
72130
def test_access_policies_create(self):
73131
"""
74132
Test access_policy creation

0 commit comments

Comments
 (0)