@@ -930,6 +930,73 @@ extension IntegrationSuite {
930930 }
931931 }
932932
933+ func testUnixSocketIntoGuest( ) async throws {
934+ let id = " test-unixsocket-into-guest "
935+
936+ let bs = try await bootstrap ( id)
937+
938+ let hostSocketPath = try createHostUnixSocket ( )
939+
940+ let buffer = BufferWriter ( )
941+ let container = try LinuxContainer ( id, rootfs: bs. rootfs, vmm: bs. vmm) { config in
942+ config. process. arguments = [ " sleep " , " 100 " ]
943+ config. sockets = [
944+ UnixSocketConfiguration (
945+ source: URL ( filePath: hostSocketPath) ,
946+ destination: URL ( filePath: " /tmp/test.sock " ) ,
947+ direction: . into
948+ )
949+ ]
950+ config. bootlog = bs. bootlog
951+ }
952+
953+ do {
954+ try await container. create ( )
955+ try await container. start ( )
956+
957+ // Execute ls -l to check the socket exists and is indeed a socket
958+ let lsExec = try await container. exec ( " ls-socket " ) { config in
959+ config. arguments = [ " ls " , " -l " , " /tmp/test.sock " ]
960+ config. stdout = buffer
961+ }
962+
963+ try await lsExec. start ( )
964+ let status = try await lsExec. wait ( )
965+ try await lsExec. delete ( )
966+
967+ guard status. exitCode == 0 else {
968+ throw IntegrationError . assert ( msg: " ls command failed with status \( status) " )
969+ }
970+
971+ guard let output = String ( data: buffer. data, encoding: . utf8) else {
972+ throw IntegrationError . assert ( msg: " failed to convert ls output to UTF8 " )
973+ }
974+
975+ // Socket files in ls -l output start with 's'
976+ guard output. hasPrefix ( " s " ) else {
977+ throw IntegrationError . assert (
978+ msg: " expected socket file (starting with 's'), got: \( output) " )
979+ }
980+
981+ try await container. kill ( SIGKILL)
982+ try await container. wait ( )
983+ try await container. stop ( )
984+ } catch {
985+ try ? await container. stop ( )
986+ throw error
987+ }
988+ }
989+
990+ private func createHostUnixSocket( ) throws -> String {
991+ let dir = FileManager . default. uniqueTemporaryDirectory ( create: true )
992+ let socketPath = dir. appendingPathComponent ( " test.sock " ) . path
993+
994+ let socket = try Socket ( type: UnixType ( path: socketPath) )
995+ try socket. listen ( )
996+
997+ return socketPath
998+ }
999+
9331000 private func createMountDirectory( ) throws -> URL {
9341001 let dir = FileManager . default. uniqueTemporaryDirectory ( create: true )
9351002 try " hello " . write ( to: dir. appendingPathComponent ( " hi.txt " ) , atomically: true , encoding: . utf8)
0 commit comments