Skip to content

Commit 5e1be8b

Browse files
committed
Separated out integration tests
1 parent bc4da2e commit 5e1be8b

File tree

7 files changed

+135
-83
lines changed

7 files changed

+135
-83
lines changed

build.gradle

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import java.text.SimpleDateFormat
2+
import com.bmuschko.gradle.docker.tasks.container.*
3+
import com.bmuschko.gradle.docker.tasks.image.*
24

35
plugins {
46
id "java"
57
id "groovy"
68
id "jacoco"
79
id "osgi"
810
id "maven-publish"
11+
id "com.bmuschko.docker-remote-api" version "3.2.1"
912
id 'pl.allegro.tech.build.axion-release' version '1.8.1'
1013
id "com.github.hierynomus.license" version "0.12.1"
1114
id "com.jfrog.bintray" version "1.7"
@@ -125,6 +128,27 @@ sourcesJar {
125128
}
126129
}
127130

131+
configurations {
132+
integrationTestCompile.extendsFrom testCompile
133+
integrationTestRuntime.extendsFrom testRuntime
134+
}
135+
136+
sourceSets {
137+
integrationTest {
138+
groovy {
139+
compileClasspath += sourceSets.main.output + sourceSets.test.output
140+
runtimeClasspath += sourceSets.main.output + sourceSets.test.output
141+
srcDir file('src/itest/groovy')
142+
}
143+
resources.srcDir file('src/itest/resources')
144+
}
145+
}
146+
147+
task integrationTest(type: Test) {
148+
testClassesDirs = sourceSets.integrationTest.output.classesDirs
149+
classpath = sourceSets.integrationTest.runtimeClasspath
150+
}
151+
128152
tasks.withType(Test) {
129153
testLogging {
130154
exceptionFormat = 'full'
@@ -231,7 +255,30 @@ jacocoTestReport {
231255
}
232256

233257

234-
project.tasks.release.dependsOn(project.tasks.build)
258+
task buildItestImage(type: DockerBuildImage) {
259+
inputDir = file('src/itest/docker-image')
260+
tag = 'sshj/sshd-itest'
261+
}
262+
263+
task createItestContainer(type: DockerCreateContainer) {
264+
dependsOn buildItestImage
265+
targetImageId { buildItestImage.getImageId() }
266+
portBindings = ['2222:22']
267+
}
268+
269+
task startItestContainer(type: DockerStartContainer) {
270+
dependsOn createItestContainer
271+
targetContainerId { createItestContainer.getContainerId() }
272+
}
273+
274+
task stopItestContainer(type: DockerStopContainer) {
275+
targetContainerId { createItestContainer.getContainerId() }
276+
}
277+
278+
project.tasks.integrationTest.dependsOn(startItestContainer)
279+
project.tasks.integrationTest.finalizedBy(stopItestContainer)
280+
281+
project.tasks.release.dependsOn([project.tasks.integrationTest, project.tasks.build])
235282
project.tasks.release.finalizedBy(project.tasks.bintrayUpload)
236283
project.tasks.jacocoTestReport.dependsOn(project.tasks.test)
237284
project.tasks.check.dependsOn(project.tasks.jacocoTestReport)
File renamed without changes.

src/itest/docker-image/id_rsa.pub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAoZ9l6Tkm2aL1tSBy2yw4xU5s8BE9MfqS/4J7DzvsYJxF6oQmTIjmStuhH/CT7UjuDtKXdXZUsIhKtafiizxGO8kHSzKDeitpth2RSr8ddMzZKyD6RNs7MfsgjA3UTtrrSrCXEY6O43S2cnuJrWzkPxtwxaQ3zOvDbS2tiulzyq0VzYmuhA/a4CyuQtJBuu+P2oqmu6pU/VB6IzONpvBvYbNPsH1WDmP7zko5wHPihXPCliztspKxS4DRtOZ7BGXyvg44UmIy0Kf4jOkaBV/eCCA4qH7ZHz71/5ceMOpszPcNOEmLGGYhwI+P3OuGMpkrSAv1f8IY6R8spZNncP6UaQ== no-passphrase
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (C)2009 - SSHJ Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.hierynomus.sshj
17+
18+
import net.schmizz.sshj.DefaultConfig
19+
import net.schmizz.sshj.SSHClient
20+
import net.schmizz.sshj.transport.TransportException
21+
import net.schmizz.sshj.transport.verification.PromiscuousVerifier
22+
import net.schmizz.sshj.userauth.UserAuthException
23+
import spock.lang.Specification
24+
25+
class IntegrationSpec extends Specification {
26+
private static final int DOCKER_PORT = 2222;
27+
private static final String USERNAME = "sshj";
28+
private final static String SERVER_IP = System.getProperty("serverIP", "127.0.0.1");
29+
30+
def "should accept correct key"() {
31+
given:
32+
SSHClient sshClient = new SSHClient(new DefaultConfig())
33+
sshClient.addHostKeyVerifier("d3:6a:a9:52:05:ab:b5:48:dd:73:60:18:0c:3a:f0:a3") // test-containers/ssh_host_ecdsa_key's fingerprint
34+
35+
when:
36+
sshClient.connect(SERVER_IP, DOCKER_PORT)
37+
38+
then:
39+
sshClient.isConnected()
40+
}
41+
42+
def "should decline wrong key"() throws IOException {
43+
given:
44+
SSHClient sshClient = new SSHClient(new DefaultConfig())
45+
sshClient.addHostKeyVerifier("d4:6a:a9:52:05:ab:b5:48:dd:73:60:18:0c:3a:f0:a3")
46+
47+
when:
48+
sshClient.connect(SERVER_IP, DOCKER_PORT)
49+
50+
then:
51+
thrown(TransportException.class)
52+
}
53+
54+
def "should authenticate"() {
55+
given:
56+
SSHClient client = getConnectedClient()
57+
58+
when:
59+
client.authPublickey("sshj", "src/test/resources/id_rsa")
60+
61+
then:
62+
client.isAuthenticated()
63+
}
64+
65+
def "should not authenticate with wrong key"() {
66+
given:
67+
SSHClient client = getConnectedClient()
68+
69+
when:
70+
client.authPublickey("sshj", "src/test/resources/id_dsa")
71+
72+
then:
73+
thrown(UserAuthException.class)
74+
!client.isAuthenticated()
75+
}
76+
77+
private static SSHClient getConnectedClient() throws IOException {
78+
SSHClient sshClient = new SSHClient(new DefaultConfig());
79+
sshClient.addHostKeyVerifier(new PromiscuousVerifier());
80+
sshClient.connect(SERVER_IP, DOCKER_PORT);
81+
82+
return sshClient;
83+
}
84+
85+
86+
}

src/test/java/com/hierynomus/sshj/IntegrationTest.java

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)