summaryrefslogtreecommitdiff
path: root/libs/sftp
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
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')
-rw-r--r--libs/sftp/src/test/docker/docker-compose.yml2
-rw-r--r--libs/sftp/src/test/docker/user_public.pem9
-rw-r--r--libs/sftp/src/test/docker/user_public.ssh1
-rw-r--r--libs/sftp/src/test/java/org/the_jk/cleversync/sftp/SftpTreeTest.kt20
4 files changed, 21 insertions, 11 deletions
diff --git a/libs/sftp/src/test/docker/docker-compose.yml b/libs/sftp/src/test/docker/docker-compose.yml
index 973a942..d8321cd 100644
--- a/libs/sftp/src/test/docker/docker-compose.yml
+++ b/libs/sftp/src/test/docker/docker-compose.yml
@@ -6,7 +6,7 @@ services:
volumes:
- ./ssh_host_ed25519_key:/etc/ssh/ssh_host_ed25519_key
- ./ssh_host_rsa_key:/etc/ssh/ssh_host_rsa_key
- - ./user_public.pub:/home/user/.ssh/keys/id_rsa.pub:ro
+ - ./user_public.ssh:/home/user/.ssh/keys/id_rsa:ro
- ../../../build/test-share:/home/user/share
ports:
- "127.0.0.1:10022:22"
diff --git a/libs/sftp/src/test/docker/user_public.pem b/libs/sftp/src/test/docker/user_public.pem
deleted file mode 100644
index f0812d9..0000000
--- a/libs/sftp/src/test/docker/user_public.pem
+++ /dev/null
@@ -1,9 +0,0 @@
------BEGIN PUBLIC KEY-----
-MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4/t3pxBvR68V27NiEp76
-pKxlQWchdyScphxK0pC6sH9goQNOa8YH9pZjQ4ltrTiG4DkeAPG6THjT9sxq6VM7
-mBZkqfeuOdJk1XCE3i06QeUzT2O7XfMFkPllAedkSDKE+PnuiTZHl8LF7Xhx3gcV
-PgSLDs0oqR2NpOccG1gxIV0xQ49BIO/lyHumNN4xQ1WINheCkOQhdryJdVVjpUvm
-zAJ4BAs1daNAgY2shAFUuta+vO6vRT/viCyVo0YfkeQharCMGylv0H7sHzUb3SlR
-kGDci1l3X85LLbRX0JO4je+5sO7vr4ePRhGVNtGYpTldLBoM+Iu29ejnVzqBFieN
-ewIDAQAB
------END PUBLIC KEY-----
diff --git a/libs/sftp/src/test/docker/user_public.ssh b/libs/sftp/src/test/docker/user_public.ssh
new file mode 100644
index 0000000..ffceffc
--- /dev/null
+++ b/libs/sftp/src/test/docker/user_public.ssh
@@ -0,0 +1 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDj+3enEG9HrxXbs2ISnvqkrGVBZyF3JJymHErSkLqwf2ChA05rxgf2lmNDiW2tOIbgOR4A8bpMeNP2zGrpUzuYFmSp96450mTVcITeLTpB5TNPY7td8wWQ+WUB52RIMoT4+e6JNkeXwsXteHHeBxU+BIsOzSipHY2k5xwbWDEhXTFDj0Eg7+XIe6Y03jFDVYg2F4KQ5CF2vIl1VWOlS+bMAngECzV1o0CBjayEAVS61r687q9FP++ILJWjRh+R5CFqsIwbKW/QfuwfNRvdKVGQYNyLWXdfzksttFfQk7iN77mw7u+vh49GEZU20ZilOV0sGgz4i7b16OdXOoEWJ417
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()
}