summaryrefslogtreecommitdiff
path: root/libs/sftp/src/test/java/org/the_jk/cleversync
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2024-10-31 22:39:09 +0100
committerJoel Klinghed <the_jk@spawned.biz>2024-10-31 22:40:33 +0100
commit77f2ab719c50b27b4aeca4d7cbd4b1398337ed78 (patch)
tree299be1dec867f10921dcae726c5fa332f8fd859f /libs/sftp/src/test/java/org/the_jk/cleversync
parent284a09b19bc3be8849fc71acd0ad407c43ec7380 (diff)
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.
Diffstat (limited to 'libs/sftp/src/test/java/org/the_jk/cleversync')
-rw-r--r--libs/sftp/src/test/java/org/the_jk/cleversync/sftp/SftpTreeTest.kt20
1 files changed, 19 insertions, 1 deletions
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()
}