@@ -494,6 +494,44 @@ mod tests {
494494 AbsolutePathBuf :: new ( dir. path ( ) . join ( "archive.tar.gz" ) ) . unwrap ( )
495495 }
496496
497+ #[ tokio:: test]
498+ async fn extracts_zip_runtime_archives ( ) {
499+ use std:: io:: Write ;
500+
501+ use zip:: { CompressionMethod , ZipWriter , write:: SimpleFileOptions } ;
502+
503+ for compression in [ CompressionMethod :: Stored , CompressionMethod :: Deflated ] {
504+ let temp = TempDir :: new ( ) . unwrap ( ) ;
505+ let root = AbsolutePathBuf :: new ( temp. path ( ) . to_path_buf ( ) ) . unwrap ( ) ;
506+ let archive_path = root. join ( "node.zip" ) ;
507+ let target = root. join ( "extracted" ) ;
508+ let contents = b"mock node binary" ;
509+ let mut archive = ZipWriter :: new ( File :: create ( & archive_path) . unwrap ( ) ) ;
510+ let options = SimpleFileOptions :: default ( ) . compression_method ( compression) ;
511+ archive. add_directory ( "node-win-x64/" , options) . unwrap ( ) ;
512+ archive. start_file ( "node-win-x64/node.exe" , options) . unwrap ( ) ;
513+ archive. write_all ( contents) . unwrap ( ) ;
514+ archive. finish ( ) . unwrap ( ) ;
515+
516+ extract_archive ( & archive_path, & target, ArchiveFormat :: Zip ) . await . unwrap ( ) ;
517+
518+ assert_eq ! ( std:: fs:: read( target. join( "node-win-x64/node.exe" ) ) . unwrap( ) , contents) ;
519+ }
520+ }
521+
522+ #[ tokio:: test]
523+ async fn rejects_invalid_zip_runtime_archives ( ) {
524+ let temp = TempDir :: new ( ) . unwrap ( ) ;
525+ let root = AbsolutePathBuf :: new ( temp. path ( ) . to_path_buf ( ) ) . unwrap ( ) ;
526+ let archive_path = root. join ( "node.zip" ) ;
527+ std:: fs:: write ( & archive_path, b"not a ZIP archive" ) . unwrap ( ) ;
528+
529+ let result =
530+ extract_archive ( & archive_path, & root. join ( "extracted" ) , ArchiveFormat :: Zip ) . await ;
531+
532+ assert ! ( matches!( result, Err ( Error :: ExtractionFailed { .. } ) ) ) ;
533+ }
534+
497535 async fn read_request ( socket : & mut TcpStream ) -> String {
498536 let mut request = Vec :: new ( ) ;
499537 let mut buffer = [ 0 ; 1024 ] ;
0 commit comments