66from os import environ
77from unittest import TestCase
88from uuid import uuid4
9+ from time import sleep
910
1011from 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+
1622DISPLAY_NAME = "AccessPolicy display name"
1723PROPS = {
1824 "display_name" : DISPLAY_NAME ,
4046
4147ACCESS_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" ,
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+
58107class 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