Skip to content

Commit 57ee8dd

Browse files
bertysentryclaude
andcommitted
Issue #91: check that . and .. are skipped and the SFTP client closed when listing subfolders
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e24ff44 commit 57ee8dd

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎src/test/java/org/metricshub/ssh/SSHClientTest.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,8 @@ void testListFiles() throws Exception {
739739
.when(mock.ls("/"))
740740
.thenReturn(
741741
Arrays.asList(
742+
entry(".", DIRECTORY),
743+
entry("..", DIRECTORY),
742744
entry("top.txt", REGULAR_FILE, 1, 10),
743745
entry("sub", DIRECTORY),
744746
entry("sublink", SYMBOLIC_LINK)
@@ -753,8 +755,12 @@ void testListFiles() throws Exception {
753755
Arrays.asList("/top.txt", "/sub/nested.log"),
754756
paths(authenticatedClient().listFiles("/", null, true))
755757
);
756-
// A symbolic link to a directory is never descended into
757-
Mockito.verify(mockedConstruction.constructed().get(0), Mockito.never()).ls("/sublink");
758+
final SFTPv3Client sftpClient = mockedConstruction.constructed().get(0);
759+
// Neither "." nor ".." nor a symbolic link to a directory is descended into
760+
Mockito.verify(sftpClient, Mockito.never()).ls("/.");
761+
Mockito.verify(sftpClient, Mockito.never()).ls("/..");
762+
Mockito.verify(sftpClient, Mockito.never()).ls("/sublink");
763+
Mockito.verify(sftpClient).close();
758764
}
759765

760766
// The SFTP client is closed when the listing fails

0 commit comments

Comments
 (0)