From 77f2ab719c50b27b4aeca4d7cbd4b1398337ed78 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Thu, 31 Oct 2024 22:39:09 +0100 Subject: sftp: Let a selection of tests use private key authentication Tests switch between password authentication and private key authentication depending on the hash of the method name. It's a fairly even spread. Update the docker config, it never wanted a pem file, it wanted a ssh-rsa format public key. --- .../java/org/the_jk/cleversync/sftp/SftpTreeTest.kt | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'libs/sftp/src/test/java/org') diff --git a/libs/sftp/src/test/java/org/the_jk/cleversync/sftp/SftpTreeTest.kt b/libs/sftp/src/test/java/org/the_jk/cleversync/sftp/SftpTreeTest.kt index b6b2236..da654a1 100644 --- a/libs/sftp/src/test/java/org/the_jk/cleversync/sftp/SftpTreeTest.kt +++ b/libs/sftp/src/test/java/org/the_jk/cleversync/sftp/SftpTreeTest.kt @@ -7,7 +7,9 @@ import org.junit.After import org.junit.AfterClass import org.junit.Before import org.junit.BeforeClass +import org.junit.Rule import org.junit.Test +import org.junit.rules.TestName import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config @@ -23,11 +25,27 @@ import java.util.concurrent.TimeUnit @Config(manifest=Config.NONE) @RunWith(RobolectricTestRunner::class) class SftpTreeTest : TreeAbstractTest() { + @get:Rule + val testName = TestName() + @Before fun setUpTest() { assertThat(shareDir.listFiles()).isEmpty() - val credentials = SftpCredentials.SftpPasswordCredentials("user", "notverysecret") + val credentials: SftpCredentials + // Test both password and key authentication + // "Stable" as it depends on the hashCode of the test method name + if (testName.methodName.hashCode() % 2 == 0) { + credentials = + SftpCredentials.SftpPasswordCredentials("user", "notverysecret") + } else { + val private = File(dockerDir, "user_private.pem") + credentials = SftpCredentials.SftpKeyCredentials( + "user", + private.readBytes(), + "notsecret", + ) + } tree = SftpTreeFactory.modifiableTree(uri, credentials).getOrThrow() } -- cgit v1.2.3-70-g09d2