@@ -788,6 +788,82 @@ def test_sign_file(self):
788788 # Clean up the temporary directory
789789 shutil .rmtree (temp_dir )
790790
791+ def test_sign_extensionless_jpg_file (self ):
792+ """Test signing a file using the sign_file method."""
793+ # Create a temporary directory for the test
794+ temp_dir = tempfile .mkdtemp ()
795+ try :
796+ # Use the extensionless jpg from the test files
797+ extensionless_dir = os .path .join (FIXTURES_DIR , "extensionless-files" )
798+ source_path = os .path .join (extensionless_dir , "jpg" )
799+
800+ output_path = os .path .join (temp_dir , "signed_output.jpg" )
801+
802+ # Use the sign_file method
803+ builder = Builder (self .manifestDefinition )
804+ result , manifest_bytes = builder .sign_file (
805+ source_path = source_path ,
806+ dest_path = output_path ,
807+ signer = self .signer
808+ )
809+
810+ # Verify the output file was created
811+ self .assertTrue (os .path .exists (output_path ))
812+
813+ # Verify we got both result and manifest bytes
814+ self .assertIsInstance (result , int )
815+ self .assertIsInstance (manifest_bytes , bytes )
816+ self .assertGreater (len (manifest_bytes ), 0 )
817+
818+ # Read the signed file and verify the manifest
819+ with open (output_path , "rb" ) as file :
820+ reader = Reader ("image/jpeg" , file )
821+ json_data = reader .json ()
822+ self .assertIn ("Python Test" , json_data )
823+ self .assertNotIn ("validation_status" , json_data )
824+
825+ finally :
826+ # Clean up the temporary directory
827+ shutil .rmtree (temp_dir )
828+
829+ def test_sign_extensionless_svg_file (self ):
830+ """Test signing an extensionless SVG file using the sign_file method."""
831+ # Create a temporary directory for the test
832+ temp_dir = tempfile .mkdtemp ()
833+ try :
834+ # Use the extensionless svg from the test files
835+ extensionless_dir = os .path .join (FIXTURES_DIR , "extensionless-files" )
836+ source_path = os .path .join (extensionless_dir , "svg" )
837+
838+ output_path = os .path .join (temp_dir , "signed_output.svg" )
839+
840+ # Use the sign_file method
841+ builder = Builder (self .manifestDefinition )
842+ result , manifest_bytes = builder .sign_file (
843+ source_path = source_path ,
844+ dest_path = output_path ,
845+ signer = self .signer
846+ )
847+
848+ # Verify the output file was created
849+ self .assertTrue (os .path .exists (output_path ))
850+
851+ # Verify we got both result and manifest bytes
852+ self .assertIsInstance (result , int )
853+ self .assertIsInstance (manifest_bytes , bytes )
854+ self .assertGreater (len (manifest_bytes ), 0 )
855+
856+ # Read the signed file and verify the manifest
857+ with open (output_path , "rb" ) as file :
858+ reader = Reader ("image/svg+xml" , file )
859+ json_data = reader .json ()
860+ self .assertIn ("Python Test" , json_data )
861+ self .assertNotIn ("validation_status" , json_data )
862+
863+ finally :
864+ # Clean up the temporary directory
865+ shutil .rmtree (temp_dir )
866+
791867 def test_sign_file_callback_signer (self ):
792868 """Test signing a file using the sign_file method."""
793869
@@ -1201,6 +1277,7 @@ def error_callback_signer(data: bytes) -> bytes:
12011277 finally :
12021278 shutil .rmtree (temp_dir )
12031279
1280+
12041281class TestStream (unittest .TestCase ):
12051282 def setUp (self ):
12061283 # Create a temporary file for testing
0 commit comments