Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ slf4j = "2.0.17"
tink = "1.20.0"
kyber = "2.0.1"
jbcrypt = "1.0.2"
junit4 = "4.13.2"
junitVintage = "6.0.2"
junit = "6.0.2"
mockk = "1.14.9"
logback = "1.5.29"
Expand All @@ -31,8 +29,6 @@ slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
tink = { module = "com.google.crypto.tink:tink", version.ref = "tink" }
kyber = { module = "asia.hombre:kyber", version.ref = "kyber" }
jbcrypt = { module = "org.connectbot:jbcrypt", version.ref = "jbcrypt" }
junit = { module = "junit:junit", version.ref = "junit4" }
junit-vintage-engine = { module = "org.junit.vintage:junit-vintage-engine", version.ref = "junitVintage" }
logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit" }
Expand Down
2 changes: 0 additions & 2 deletions sshlib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ dependencies {
implementation(libs.jbcrypt)

// Unit tests
testImplementation(libs.junit)
testImplementation(kotlin("test"))
testImplementation(libs.kotlinx.coroutines.test)
testImplementation(libs.mockk)
testRuntimeOnly(libs.junit.vintage.engine)

// Integration test dependencies
testImplementation(libs.junit.jupiter.api)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import org.connectbot.sshlib.protocol.SshAgentcRequestIdentities
import org.connectbot.sshlib.protocol.SshAgentcSignRequest
import org.connectbot.sshlib.protocol.createByteString
import org.connectbot.sshlib.protocol.toByteArray
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertArrayEquals
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import java.nio.ByteBuffer

class AgentProtocolTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package org.connectbot.sshlib

import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Test

class AgentProviderTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.connectbot.sshlib

import org.junit.Test
import org.junit.jupiter.api.Test
import java.util.Base64
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.connectbot.sshlib

import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.jupiter.api.Test
import java.io.File
import java.util.Base64
import kotlin.test.assertFalse
Expand Down
9 changes: 6 additions & 3 deletions sshlib/src/test/kotlin/org/connectbot/sshlib/SshKeysTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

package org.connectbot.sshlib

import org.junit.Test
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertNotNull
import kotlin.test.assertTrue

Expand Down Expand Up @@ -113,9 +114,11 @@ class SshKeysTest {
assertEquals("EC", keyPair.public.algorithm)
}

@Test(expected = SshException::class)
@Test
fun `decodePemPrivateKey invalid data throws`() {
SshKeys.decodePemPrivateKey("not a valid key")
assertFailsWith<SshException> {
SshKeys.decodePemPrivateKey("not a valid key")
}
}

@Test
Expand Down
21 changes: 14 additions & 7 deletions sshlib/src/test/kotlin/org/connectbot/sshlib/SshSigningTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import org.connectbot.sshlib.crypto.SignatureEntry
import org.connectbot.sshlib.crypto.SignatureVerifier
import org.connectbot.sshlib.protocol.SshPublicKey
import org.connectbot.sshlib.protocol.SshSignature
import org.junit.Test
import org.junit.jupiter.api.Test
import java.security.KeyPairGenerator
import java.security.spec.ECGenParameterSpec
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import kotlin.test.assertNotEquals
import kotlin.test.assertTrue
Expand Down Expand Up @@ -98,10 +99,12 @@ class SshSigningTest {
assertTrue(pubKey.publicKeyBlob.isNotEmpty())
}

@Test(expected = SshException::class)
@Test
fun `sign with unknown algorithm throws`() {
val keyData = readKey("ed25519_unencrypted")
SshSigning.sign("unknown-algorithm", keyData, null, "data".toByteArray())
assertFailsWith<SshException> {
SshSigning.sign("unknown-algorithm", keyData, null, "data".toByteArray())
}
}

private fun loadKeyPair(keyResource: String, passphrase: String? = null): java.security.KeyPair {
Expand Down Expand Up @@ -153,11 +156,13 @@ class SshSigningTest {
assertEquals(fromPrivate, authPubKey)
}

@Test(expected = SshException::class)
@Test
fun `encodePublicKey unsupported key type throws`() {
val kpg = KeyPairGenerator.getInstance("DSA")
kpg.initialize(2048)
SshSigning.encodePublicKey(kpg.generateKeyPair())
assertFailsWith<SshException> {
SshSigning.encodePublicKey(kpg.generateKeyPair())
}
}

@Test
Expand Down Expand Up @@ -232,10 +237,12 @@ class SshSigningTest {
assertTrue(sigEntry.algorithm.verify(parsedPubKey, parsedSig, data))
}

@Test(expected = SshException::class)
@Test
fun `signWithKeyPair unknown algorithm throws`() {
val keyPair = loadKeyPair("ed25519_unencrypted")
SshSigning.signWithKeyPair("unknown-algorithm", keyPair, "data".toByteArray())
assertFailsWith<SshException> {
SshSigning.signWithKeyPair("unknown-algorithm", keyPair, "data".toByteArray())
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.connectbot.sshlib

import org.junit.Test
import org.junit.jupiter.api.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertArrayEquals
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class ForwardingChannelTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import io.mockk.coEvery
import io.mockk.mockk
import io.mockk.slot
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class SessionChannelTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.readFully
import kotlinx.coroutines.test.runTest
import org.connectbot.sshlib.Socks5Authenticator
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Test
import java.nio.ByteBuffer

class Socks5HandlerTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package org.connectbot.sshlib.crypto

import org.junit.Assert.assertArrayEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertArrayEquals
import org.junit.jupiter.api.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertFalse

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package org.connectbot.sshlib.crypto

import org.connectbot.sshlib.transport.TransportException
import org.junit.Assert.assertArrayEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertArrayEquals
import org.junit.jupiter.api.Test
import java.nio.ByteBuffer
import kotlin.test.assertFailsWith

Expand Down Expand Up @@ -166,7 +166,7 @@ class AesGcmCipherTest {
val result = encryptor.encrypt(packetLength, plaintext)
val decrypted = decryptor.decrypt(packetLength, result.ciphertext, result.tag)

assertArrayEquals("Packet $i failed", plaintext, decrypted)
assertArrayEquals(plaintext, decrypted, "Packet $i failed")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package org.connectbot.sshlib.crypto

import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertSame
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class AlgorithmsTest {

Expand Down Expand Up @@ -124,8 +124,8 @@ class AlgorithmsTest {
fun `CipherEntry defaults contain all entries`() {
for (entry in CipherEntry.entries) {
assertTrue(
"${entry.sshName} not found in defaultString",
CipherEntry.defaultString.contains(entry.sshName)
CipherEntry.defaultString.contains(entry.sshName),
"${entry.sshName} not found in defaultString"
)
}
}
Expand Down Expand Up @@ -189,8 +189,8 @@ class AlgorithmsTest {
fun `MacEntry defaults contain all entries`() {
for (entry in MacEntry.entries) {
assertTrue(
"${entry.sshName} not found in defaultString",
MacEntry.defaultString.contains(entry.sshName)
MacEntry.defaultString.contains(entry.sshName),
"${entry.sshName} not found in defaultString"
)
}
}
Expand Down Expand Up @@ -266,8 +266,8 @@ class AlgorithmsTest {
fun `KexEntry defaultString contains all default entries`() {
for (entry in KexEntry.defaults) {
assertTrue(
"${entry.sshName} not found in defaultString",
KexEntry.defaultString.contains(entry.sshName)
KexEntry.defaultString.contains(entry.sshName),
"${entry.sshName} not found in defaultString"
)
}
}
Expand Down Expand Up @@ -306,8 +306,8 @@ class AlgorithmsTest {
fun `SignatureEntry defaults contain all entries`() {
for (entry in SignatureEntry.entries) {
assertTrue(
"${entry.sshName} not found in defaultString",
SignatureEntry.defaultString.contains(entry.sshName)
SignatureEntry.defaultString.contains(entry.sshName),
"${entry.sshName} not found in defaultString"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.connectbot.sshlib.crypto

import org.connectbot.sshlib.transport.TransportException
import org.junit.Test
import org.junit.jupiter.api.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.connectbot.sshlib.crypto

import org.connectbot.sshlib.SshException
import org.junit.Test
import org.junit.jupiter.api.Test
import java.math.BigInteger
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package org.connectbot.sshlib.crypto

import org.connectbot.sshlib.SshException
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertArrayEquals
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.math.BigInteger
import kotlin.test.assertFailsWith

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.connectbot.sshlib.crypto

import org.connectbot.sshlib.SshException
import org.junit.Test
import org.junit.jupiter.api.Test
import java.math.BigInteger
import java.security.KeyFactory
import java.security.KeyPairGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.connectbot.sshlib.crypto

import org.connectbot.sshlib.SshException
import org.junit.Test
import org.junit.jupiter.api.Test
import java.math.BigInteger
import java.security.KeyFactory
import java.security.KeyPairGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.connectbot.sshlib.crypto

import org.connectbot.sshlib.SshException
import org.junit.Test
import org.junit.jupiter.api.Test
import java.math.BigInteger
import java.security.KeyPairGenerator
import java.security.interfaces.ECPublicKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.connectbot.sshlib.crypto
import io.kaitai.struct.ByteBufferKaitaiStream
import org.connectbot.sshlib.protocol.SshPublicKey
import org.connectbot.sshlib.protocol.SshSignature
import org.junit.Test
import org.junit.jupiter.api.Test
import java.io.ByteArrayOutputStream
import java.io.DataOutputStream
import java.math.BigInteger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.connectbot.sshlib.crypto
import io.kaitai.struct.ByteBufferKaitaiStream
import org.connectbot.sshlib.protocol.SshPublicKey
import org.connectbot.sshlib.protocol.SshSignature
import org.junit.Test
import org.junit.jupiter.api.Test
import java.io.ByteArrayOutputStream
import java.io.DataOutputStream
import java.security.KeyPairGenerator
Expand Down
Loading
Loading