Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoet-jh committed Nov 6, 2023
1 parent 03b3ed3 commit 1d08b49
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import static org.eclipse.pass.deposit.transport.Transport.TRANSPORT_SERVER_PORT;
import static org.eclipse.pass.deposit.transport.Transport.TRANSPORT_USERNAME;
import static org.eclipse.pass.deposit.transport.sftp.SftpTransport.SFTP_BASE_DIRECTORY;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -42,6 +44,7 @@
import org.apache.sshd.sftp.client.SftpClient;
import org.apache.sshd.sftp.client.impl.DefaultSftpClientFactory;
import org.apache.sshd.sftp.server.SftpSubsystemFactory;
import org.eclipse.pass.deposit.DepositServiceRuntimeException;
import org.eclipse.pass.deposit.assembler.PackageStream;
import org.eclipse.pass.deposit.transport.TransportResponse;
import org.eclipse.pass.deposit.transport.TransportSession;
Expand Down Expand Up @@ -105,6 +108,35 @@ public void testCreateFile() {
verifyFileOnSftpServer(String.format("upload/test/%s/", dateDirName) + testFileName);
}

@Test
public void testCreateFile_Fail_MissingBaseDir() {
// GIVEN
Map<String, String> hints = Map.of(
TRANSPORT_SERVER_FQDN, "localhost",
TRANSPORT_SERVER_PORT, String.valueOf(sshd.getPort()),
TRANSPORT_USERNAME, "dummyUser",
TRANSPORT_PASSWORD, "dummyPass"
);
String testFileName = System.currentTimeMillis() + "package.tar.gz";
NullInputStream content = new NullInputStream(ONE_MIB);
PackageStream stream = mock(PackageStream.class);
PackageStream.Metadata streamMetadata = mock(PackageStream.Metadata.class);
when(stream.metadata()).thenReturn(streamMetadata);
when(streamMetadata.name()).thenReturn(testFileName);
when(stream.open()).thenReturn(content);

SftpTransport sftpTransport = new SftpTransport();
TransportSession transportSession = sftpTransport.open(hints);

// WHEN
DepositServiceRuntimeException ex = assertThrows(DepositServiceRuntimeException.class, () -> {
transportSession.send(stream, new HashMap<>());
});

// THEN
assertEquals("Sftp requires \"default-directory\" in protocol-binding", ex.getMessage());
}

private void verifyFileOnSftpServer(String path) {
try (SshClient sshClient = SshClient.setUpDefaultClient()) {
sshClient.start();
Expand Down

0 comments on commit 1d08b49

Please sign in to comment.