@@ -342,6 +342,94 @@ def test_reader_state_with_invalid_native_pointer(self):
342342 with self .assertRaises (Error ):
343343 reader .json ()
344344
345+ def test_reader_is_embedded (self ):
346+ """Test the is_embedded method returns correct values for embedded and remote manifests."""
347+
348+ # Test with a fixture which has an embedded manifest
349+ with open (self .testPath , "rb" ) as file :
350+ reader = Reader ("image/jpeg" , file )
351+ self .assertTrue (reader .is_embedded ())
352+ reader .close ()
353+
354+ # Test with cloud.jpg fixture which has a remote manifest (not embedded)
355+ cloud_fixture_path = os .path .join (self .data_dir , "cloud.jpg" )
356+ with Reader ("image/jpeg" , cloud_fixture_path ) as reader :
357+ self .assertFalse (reader .is_embedded ())
358+
359+ def test_sign_and_read_is_not_embedded (self ):
360+ """Test the is_embedded method returns correct values for remote manifests."""
361+
362+ with open (os .path .join (self .data_dir , "es256_certs.pem" ), "rb" ) as cert_file :
363+ certs = cert_file .read ()
364+ with open (os .path .join (self .data_dir , "es256_private.key" ), "rb" ) as key_file :
365+ key = key_file .read ()
366+
367+ # Create signer info and signer
368+ signer_info = C2paSignerInfo (
369+ alg = b"es256" ,
370+ sign_cert = certs ,
371+ private_key = key ,
372+ ta_url = b"http://timestamp.digicert.com"
373+ )
374+ signer = Signer .from_info (signer_info )
375+
376+ # Define a simple manifest
377+ manifest_definition = {
378+ "claim_generator" : "python_test" ,
379+ "claim_generator_info" : [{
380+ "name" : "python_test" ,
381+ "version" : "0.0.1" ,
382+ }],
383+ "format" : "image/jpeg" ,
384+ "title" : "Python Test Image" ,
385+ "ingredients" : [],
386+ "assertions" : [
387+ {
388+ "label" : "c2pa.actions" ,
389+ "data" : {
390+ "actions" : [
391+ {
392+ "action" : "c2pa.opened"
393+ }
394+ ]
395+ }
396+ }
397+ ]
398+ }
399+
400+ # Create a temporary directory for the signed file
401+ with tempfile .TemporaryDirectory () as temp_dir :
402+ temp_file_path = os .path .join (temp_dir , "signed_test_file_no_embed.jpg" )
403+
404+ with open (self .testPath , "rb" ) as file :
405+ builder = Builder (manifest_definition )
406+ # Direct the Builder not to embed the manifest into the asset
407+ builder .set_no_embed ()
408+
409+
410+ with open (temp_file_path , "wb" ) as temp_file :
411+ manifest_data = builder .sign (
412+ signer , "image/jpeg" , file , temp_file )
413+
414+ with Reader ("image/jpeg" , temp_file_path , manifest_data ) as reader :
415+ self .assertFalse (reader .is_embedded ())
416+
417+ def test_reader_get_remote_url (self ):
418+ """Test the get_remote_url method returns correct values for embedded and remote manifests."""
419+
420+ # Test get_remote_url for file with embedded manifest (should return None)
421+ with open (self .testPath , "rb" ) as file :
422+ reader = Reader ("image/jpeg" , file )
423+ self .assertIsNone (reader .get_remote_url ())
424+ reader .close ()
425+
426+ # Test remote manifest using cloud.jpg fixture which has a remote URL
427+ cloud_fixture_path = os .path .join (self .data_dir , "cloud.jpg" )
428+ with Reader ("image/jpeg" , cloud_fixture_path ) as reader :
429+ remote_url = reader .get_remote_url ()
430+ self .assertEqual (remote_url , "https://cai-manifests.adobe.com/manifests/adobe-urn-uuid-5f37e182-3687-462e-a7fb-573462780391" )
431+ self .assertFalse (reader .is_embedded ())
432+
345433 # TODO: Unskip once fixed configuration to read data is clarified
346434 # def test_read_cawg_data_file(self):
347435 # """Test reading C2PA metadata from C_with_CAWG_data.jpg file."""
0 commit comments