4141ALTERNATIVE_INGREDIENT_TEST_FILE = os .path .join (FIXTURES_DIR , "cloud.jpg" )
4242
4343
44- def load_test_settings_as_json ():
44+ def load_toml_test_settings_as_json ():
4545 """
4646 Load default trust configuration test settings from a
4747 TOML config file and return its content as JSON-compatible dict.
@@ -64,6 +64,29 @@ def load_test_settings_as_json():
6464
6565 return settings_data
6666
67+ def load_test_settings_json ():
68+ """
69+ Load default trust configuration test settings from a
70+ JSON config file and return its content as JSON-compatible dict.
71+ The return value is used to load settings.
72+
73+ Returns:
74+ dict: The parsed JSON content as a Python dictionary (JSON-compatible).
75+
76+ Raises:
77+ FileNotFoundError: If trust_config_test_settings.json is not found.
78+ json.JSONDecodeError: If the JSON file is malformed.
79+ """
80+ # Locate the file which contains default settings for tests
81+ tests_dir = os .path .dirname (os .path .abspath (__file__ ))
82+ settings_path = os .path .join (tests_dir , 'trust_config_test_settings.json' )
83+
84+ # Load the located default test settings
85+ with open (settings_path , 'r' ) as f :
86+ settings_data = json .load (f )
87+
88+ return settings_data
89+
6790
6891class TestC2paSdk (unittest .TestCase ):
6992 def test_sdk_version (self ):
@@ -146,6 +169,42 @@ def test_stream_read_get_validation_state(self):
146169 # Needs trust configuration to be set up to validate as Trusted, otherwise manifest is Invalid
147170 self .assertEqual (validation_state , "Invalid" )
148171
172+ def test_stream_read_get_validation_state_with_trust_config_from_toml (self ):
173+ # Run in a separate thread to isolate thread-local settings
174+ result = {}
175+ exception = {}
176+
177+ def read_with_trust_config ():
178+ try :
179+ # Load trust configuration from test_settings.toml
180+ settings_dict = load_toml_test_settings_as_json ()
181+
182+ # Apply the settings (including trust configuration)
183+ # Settings are thread-local, so they won't affect other tests
184+ # And that is why we also run the test in its own thread, so tests are isolated
185+ load_settings (settings_dict )
186+
187+ with open (self .testPath , "rb" ) as file :
188+ reader = Reader ("image/jpeg" , file )
189+ validation_state = reader .get_validation_state ()
190+ result ['validation_state' ] = validation_state
191+ except Exception as e :
192+ exception ['error' ] = e
193+
194+ # Create and start thread
195+ thread = threading .Thread (target = read_with_trust_config )
196+ thread .start ()
197+ thread .join ()
198+
199+ # Check for exceptions
200+ if 'error' in exception :
201+ raise exception ['error' ]
202+
203+ # Assertions run in main thread
204+ self .assertIsNotNone (result .get ('validation_state' ))
205+ # With trust configuration loaded, manifest is Trusted
206+ self .assertEqual (result .get ('validation_state' ), "Trusted" )
207+
149208 def test_stream_read_get_validation_state_with_trust_config (self ):
150209 # Run in a separate thread to isolate thread-local settings
151210 result = {}
@@ -154,7 +213,7 @@ def test_stream_read_get_validation_state_with_trust_config(self):
154213 def read_with_trust_config ():
155214 try :
156215 # Load trust configuration from test_settings.toml
157- settings_dict = load_test_settings_as_json ()
216+ settings_dict = load_test_settings_json ()
158217
159218 # Apply the settings (including trust configuration)
160219 # Settings are thread-local, so they won't affect other tests
@@ -1110,7 +1169,7 @@ def test_streams_sign_with_es256_alg_with_trust_config(self):
11101169 def sign_and_validate_with_trust_config ():
11111170 try :
11121171 # Load trust configuration from test_settings.toml
1113- settings_dict = load_test_settings_as_json ()
1172+ settings_dict = load_test_settings_json ()
11141173
11151174 # Apply the settings (including trust configuration)
11161175 # Settings are thread-local, so they won't affect other tests
@@ -1186,7 +1245,7 @@ def test_sign_with_ed25519_alg_with_trust_config(self):
11861245 def sign_and_validate_with_trust_config ():
11871246 try :
11881247 # Load trust configuration from test_settings.toml
1189- settings_dict = load_test_settings_as_json ()
1248+ settings_dict = load_test_settings_json ()
11901249
11911250 # Apply the settings (including trust configuration)
11921251 # Settings are thread-local, so they won't affect other tests
@@ -1328,7 +1387,7 @@ def test_sign_with_ps256_alg_2_with_trust_config(self):
13281387 def sign_and_validate_with_trust_config ():
13291388 try :
13301389 # Load trust configuration from test_settings.toml
1331- settings_dict = load_test_settings_as_json ()
1390+ settings_dict = load_test_settings_json ()
13321391
13331392 # Apply the settings (including trust configuration)
13341393 # Settings are thread-local, so they won't affect other tests
@@ -1407,7 +1466,7 @@ def test_archive_sign_with_trust_config(self):
14071466 def sign_and_validate_with_trust_config ():
14081467 try :
14091468 # Load trust configuration from test_settings.toml
1410- settings_dict = load_test_settings_as_json ()
1469+ settings_dict = load_test_settings_json ()
14111470
14121471 # Apply the settings (including trust configuration)
14131472 # Settings are thread-local, so they won't affect other tests
@@ -1480,7 +1539,7 @@ def test_archive_sign_with_added_ingredient_with_trust_config(self):
14801539 def sign_and_validate_with_trust_config ():
14811540 try :
14821541 # Load trust configuration from test_settings.toml
1483- settings_dict = load_test_settings_as_json ()
1542+ settings_dict = load_test_settings_json ()
14841543
14851544 # Apply the settings (including trust configuration)
14861545 # Settings are thread-local, so they won't affect other tests
@@ -1576,7 +1635,7 @@ def test_remote_sign_using_returned_bytes_V2_with_trust_config(self):
15761635 def sign_and_validate_with_trust_config ():
15771636 try :
15781637 # Load trust configuration from test_settings.toml
1579- settings_dict = load_test_settings_as_json ()
1638+ settings_dict = load_test_settings_json ()
15801639
15811640 # Apply the settings (including trust configuration)
15821641 # Settings are thread-local, so they won't affect other tests
0 commit comments