Skip to content
This repository was archived by the owner on May 25, 2025. It is now read-only.
Closed
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
1 change: 1 addition & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ jobs:
java-version: 11
- uses: gradle/wrapper-validation-action@v1
- uses: gradle/gradle-build-action@v2
- run: bash os-integration-test/setup-sshd.sh
- run: ./gradlew build
23 changes: 7 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@ allprojects {
group = 'org.hidetake'
version = System.getenv('VERSION') ?: 'SNAPSHOT'

afterEvaluate {
tasks.withType(Test) {
finalizedBy ':testReport'
testReport.reportOn binaryResultsDirectory
reports.html.required = false
reports.junitXml.destination = file("${rootProject.buildDir}/test-results")
}
}

plugins.withType(JavaPlugin) {
dependencies {
testImplementation 'junit:junit:4.11'
testImplementation 'org.spockframework:spock-core:2.3-groovy-3.0'
testImplementation platform("org.spockframework:spock-bom:2.3-groovy-3.0")
testImplementation "org.spockframework:spock-core"
testImplementation "org.spockframework:spock-junit4"
testRuntimeOnly 'ch.qos.logback:logback-classic:1.4.5'
}
}
}

task testReport(type: TestReport) {
description 'Generates test report for all projects'
destinationDirectory = file("$buildDir/reports")
test {
useJUnitPlatform()
}
}
}
27 changes: 18 additions & 9 deletions cli/src/test/groovy/org/hidetake/groovy/ssh/MainDryRunSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package org.hidetake.groovy.ssh

import com.jcraft.jsch.JSchException
import org.hidetake.groovy.ssh.test.server.SshServerMock
import org.junit.Rule
import org.junit.ClassRule
import org.junit.rules.TemporaryFolder
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll

import static org.hidetake.groovy.ssh.test.server.FilenameUtils.toUnixPath

class MainDryRunSpec extends Specification {

@Shared
Expand All @@ -17,18 +19,25 @@ class MainDryRunSpec extends Specification {

PrintStream stdout

@Rule
@Shared @ClassRule
TemporaryFolder temporaryFolder

def setupSpec() {
int port = SshServerMock.pickUpFreePort()
script = "ssh.run {" +
"session(host: 'localhost'," +
" port: $port," +
" user: 'someuser'," +
" password: 'somepassword')" +
"{ execute('somecommand') { println 'Q6zLyqR1MKANtYJ4' } }" +
"}"
def knownHostsFile = temporaryFolder.newFile() << "[localhost]:${port} dummy"
script = """\
ssh.run {
session(
host: 'localhost',
port: ${port},
knownHosts: new File('${toUnixPath(knownHostsFile.path)}'),
user: 'someuser',
password: 'somepassword'
) {
execute('somecommand') { println 'Q6zLyqR1MKANtYJ4' }
}
}
"""
}

def setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package org.hidetake.groovy.ssh.connection
import org.hidetake.groovy.ssh.core.Proxy
import org.hidetake.groovy.ssh.core.ProxyType

import static org.hidetake.groovy.ssh.core.ProxyType.SOCKS

/**
* Basic validation and defaults for proxied connections created by {@link ConnectionManager}.
*
Expand Down
10 changes: 10 additions & 0 deletions os-integration-test/etc/ssh/id_ecdsa_pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABDXw8+TMm
PD/3Ucw/UBXMWeAAAAEAAAAAEAAABoAAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlz
dHAyNTYAAABBBOrnnc2zLhs1gnsU5EmpRoZjhVWwPZb/UG04SfxgE6o1aujA5i89L4fHSr
R6Qwkmede88PQb9wzo7pOy7pOhO7MAAADAHSwb0T4JGfAZH2nPL3YV052PfBDMdAkS80qg
0QMrejOQTMZKz1rGz8BIgqlXXLdxlO/fmUqBbE0L1D5zYfh1aeC3Iqyuuf/FxBFwW4waCL
qidfrGPWS4ASg3huzfuOxgCxJWObk6cYZEXzVrxKCbRxHx8W+Uvr0lsS/pQ5KAuRg+FuDA
5XZbU+n5tS6U8tcBWbce4GAOMbgTzYZisInJhM57v6pdK++UWK8s2Mj0xPHBpNtd+9Evc5
AYcUruE4iL
-----END OPENSSH PRIVATE KEY-----
1 change: 1 addition & 0 deletions os-integration-test/etc/ssh/id_ecdsa_pass.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOrnnc2zLhs1gnsU5EmpRoZjhVWwPZb/UG04SfxgE6o1aujA5i89L4fHSrR6Qwkmede88PQb9wzo7pOy7pOhO7M= codespace@codespaces-7f1977
27 changes: 0 additions & 27 deletions os-integration-test/etc/ssh/id_rsa

This file was deleted.

1 change: 0 additions & 1 deletion os-integration-test/etc/ssh/id_rsa.pub

This file was deleted.

30 changes: 0 additions & 30 deletions os-integration-test/etc/ssh/id_rsa_pass

This file was deleted.

1 change: 0 additions & 1 deletion os-integration-test/etc/ssh/id_rsa_pass.pub

This file was deleted.

21 changes: 0 additions & 21 deletions os-integration-test/etc/ssh/ssh_host_dsa_key

This file was deleted.

1 change: 0 additions & 1 deletion os-integration-test/etc/ssh/ssh_host_dsa_key.pub

This file was deleted.

27 changes: 0 additions & 27 deletions os-integration-test/etc/ssh/ssh_host_rsa_key

This file was deleted.

1 change: 0 additions & 1 deletion os-integration-test/etc/ssh/ssh_host_rsa_key.pub

This file was deleted.

10 changes: 0 additions & 10 deletions os-integration-test/run-sshd.sh

This file was deleted.

18 changes: 18 additions & 0 deletions os-integration-test/setup-sshd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -eux

sudo systemctl status sshd

install_host_key () {
sudo cp "os-integration-test/etc/ssh/$1" "/etc/ssh/$1"
sudo chmod 600 "/etc/ssh/$1"
}

install_host_key ssh_host_ecdsa_key
install_host_key ssh_host_ed25519_key

mkdir -p ~/.ssh
cat os-integration-test/etc/ssh/*.pub > ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

sudo systemctl restart sshd
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,18 @@ class Fixture {
host = 'localhost'
port = 22
user = 'tester'
identity = new File("etc/ssh/id_rsa")
identity = new File("etc/ssh/id_ecdsa")
knownHosts = addHostKey(new File("build/known_hosts"))
}
}
service.remotes {
DefaultWithECDSAKey {
host = service.remotes.Default.host
port = service.remotes.Default.port
user = service.remotes.Default.user
identity = new File("etc/ssh/id_ecdsa")
knownHosts = service.remotes.Default.knownHosts
}
DefaultWithPassphrase {
host = service.remotes.Default.host
port = service.remotes.Default.port
user = service.remotes.Default.user
knownHosts = service.remotes.Default.knownHosts

identity = new File("etc/ssh/id_rsa_pass")
identity = new File("etc/ssh/id_ecdsa_pass")
passphrase = 'gradle'
}
DefaultWithOpenSSHKnownHosts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,7 @@ class UserAuthenticationSpec extends Specification {
ssh.settings.extensions.add(UserManagementExtension)
}

def 'should authenticate by ECDSA key'() {
given:
def x = randomInt()
def y = randomInt()

when:
def r = ssh.run {
session(ssh.remotes.DefaultWithECDSAKey) {
execute "expr $x + $y"
}
} as int

then:
r == (x + y)
}

def 'should authenticate by pass-phrased RSA key'() {
def 'should authenticate by pass-phrased key'() {
given:
def x = randomInt()
def y = randomInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import groovy.util.logging.Slf4j
import org.apache.sshd.common.keyprovider.KeyPairProvider
import org.apache.sshd.server.SshServer

import static org.apache.sshd.common.keyprovider.KeyPairProvider.SSH_DSS
import static org.apache.sshd.common.keyprovider.KeyPairProvider.ECDSA_SHA2_NISTP256
import static org.hidetake.groovy.ssh.test.server.HostKeyFixture.keyPairProvider

/**
Expand All @@ -15,7 +15,7 @@ import static org.hidetake.groovy.ssh.test.server.HostKeyFixture.keyPairProvider
@Slf4j
class SshServerMock {

static SshServer setUpLocalhostServer(KeyPairProvider provider = keyPairProvider(SSH_DSS)) {
static SshServer setUpLocalhostServer(KeyPairProvider provider = keyPairProvider(ECDSA_SHA2_NISTP256)) {
SshServer.setUpDefaultServer().with {
host = 'localhost'
port = pickUpFreePort()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package org.hidetake.groovy.ssh.test.server
class UserKeyFixture {

static enum KeyType {
rsa,
rsa_pass,
ecdsa
ecdsa,
ecdsa_pass
}

static privateKey(KeyType keyType = KeyType.rsa) {
static privateKey(KeyType keyType = KeyType.ecdsa) {
new File(UserKeyFixture.getResource("/id_$keyType").file)
}

static publicKey(KeyType keyType = KeyType.rsa) {
static publicKey(KeyType keyType = KeyType.ecdsa) {
new File(UserKeyFixture.getResource("/id_${keyType}.pub").file)
}

Expand Down
Loading