-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#73 add ssh git container for authentication tests
- Loading branch information
1 parent
244d0c8
commit b28a47f
Showing
12 changed files
with
172 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...in/src/test/kotlin/io/github/simonhauck/release/plugin/ReleasePluginAuthenticationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package io.github.simonhauck.release.plugin | ||
|
||
import io.github.simonhauck.release.testdriver.GitTestCommandService | ||
import io.github.simonhauck.release.testdriver.ReleasePluginTestDriver | ||
import io.github.simonhauck.release.testdriver.assertIsOk | ||
import io.github.simonhauck.release.testdriver.getTestResourceFile | ||
import java.io.File | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.io.TempDir | ||
import org.testcontainers.containers.BindMode | ||
import org.testcontainers.containers.ExecConfig | ||
import org.testcontainers.containers.GenericContainer | ||
import org.testcontainers.utility.DockerImageName | ||
|
||
internal class ReleasePluginAuthenticationTest { | ||
|
||
@TempDir private lateinit var tmpDir: File | ||
|
||
private val testDriver = ReleasePluginTestDriver() | ||
|
||
@Test | ||
fun `test Git server container`() { | ||
|
||
val publicKeyContent = getTestResourceFile("ssh-key/id_rsa.pub").readText() | ||
val privateKey = getTestResourceFile("ssh-key/id_rsa") | ||
|
||
val serverWorkDir = tmpDir.resolve("server").apply { mkdirs() } | ||
val authorizedKeyFile = | ||
serverWorkDir.resolve("authorized_keys").apply { writeText(publicKeyContent) } | ||
|
||
val gitRepoMount = serverWorkDir.resolve("mount").apply { mkdirs() } | ||
|
||
val gitServer = | ||
GenericContainer(DockerImageName.parse("rockstorm/git-server")) | ||
.withExposedPorts(22) | ||
.withFileSystemBind( | ||
authorizedKeyFile.canonicalPath, | ||
"/home/git/.ssh/authorized_keys", | ||
BindMode.READ_WRITE, | ||
) | ||
.withFileSystemBind(gitRepoMount.canonicalPath, "/srv/git", BindMode.READ_WRITE) | ||
.withEnv(mapOf("SSH_AUTH_METHODS" to "publickey")) | ||
.withCommand("/usr/sbin/sshd", "-D", "-e") | ||
|
||
gitServer.start() | ||
|
||
gitServer | ||
.execInContainer( | ||
ExecConfig.builder() | ||
.command(arrayOf("chmod", "600", "/home/git/.ssh/authorized_keys")) | ||
.build() | ||
) | ||
.apply { | ||
println(stdout) | ||
println(stderr) | ||
} | ||
|
||
gitServer | ||
.execInContainer( | ||
ExecConfig.builder() | ||
.command(arrayOf("git", "init", "--bare", "/srv/git/your-repo.git")) | ||
.user("git") | ||
.workDir("/home/git") | ||
.build() | ||
) | ||
.apply { | ||
println(stdout) | ||
println(stderr) | ||
} | ||
|
||
val port = gitServer.firstMappedPort | ||
val host = gitServer.host | ||
|
||
println("Port: $port") | ||
println("Host: $host") | ||
|
||
println(privateKey.canonicalFile) | ||
val api = | ||
GitTestCommandService( | ||
tmpDir, | ||
privateKey.canonicalFile, | ||
disableStrictHostKeyChecking = true, | ||
) | ||
|
||
try { | ||
api.clone("ssh://git@${host}:${port}/srv/git/your-repo.git", "client2").assertIsOk() | ||
} finally { | ||
gitServer.stop() | ||
} | ||
// Add your test logic here | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
release-plugin/src/test/kotlin/io/github/simonhauck/release/testdriver/ResourceUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.github.simonhauck.release.testdriver | ||
|
||
import java.io.File | ||
import java.nio.file.Paths | ||
|
||
|
||
fun getTestResourceFile(resource: String): File { | ||
return Paths.get("src/test/resources").resolve(resource).toFile() | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn | ||
NhAAAAAwEAAQAAAYEA7+LxU9/FDVrgn7gtuBaoRkb+nU06KZIMqN8MQxtSfrDCWX+V42Gd | ||
F4zJz19dEN6LEmeVVsYBq0g5MBqgt3MMh1Q174vbX6+5b45tZsXDZsgjCxt1ptQ4yuYKsb | ||
mtqAjQO6prfZQCCSNW0UdZjYMSxD0Ssw8XtND5YDnd9f5mCq2J2eh2Qd5KW2B/C+BNMg/d | ||
qoMib6Wk1HcQgsBzoothawOj20OE82a54qFRrN7Oy7a5BHvjdlNqi4agiaZDJMzd8Znfi5 | ||
6YueVGzgkgBRkEZK+RYwQ5jxnhy9LBBxiqilYRXYqABJLByOrbh8rK7z3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paS9sajd51zatX3 | ||
CfnmCJ6Oo2f5fJAAAAA2dpdAECAwQFBgc= | ||
-----END OPENSSH PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDv4vFT38UNWuCfuC24FqhGRv6dTTopkgyo3wxDG1J+sMJZf5XjYZ0XjMnPX10Q3osSZ5VWxgGrSDkwGqC3cwyHVDXvi9tfr7lvjm1mxcNmyCMLG3Wm1DjK5gqxua2oCNA7qmt9lAIJI1bRR1mNgxLEPRKzDxe00PlgOd31/mYKrYnZ6HZB3kpbYH8L4E0yD92qgyJvpaTUdxCCwHOii2FrA6PbQ4TzZrnioVGs3s7LtrkEe+N2U2qLhqCJpkMkzN3xmd+Lnpi55UbOCSAFGQRkr5FjBDmPGeHL0sEHGKqKVhFdioAEksHI6tuHysrvPeeTNeTAV9ft6/E3KGdrgQ6NKAIjFFP5pFi0WBjGh2jAIfITtlR5lSsvfiFv0wrzwAAOydmKdQ6V3Mi6GoSzg+tXcBMRitYdQIt9lDFFVLyviiY0MMpUvT1sVhwzGdDRgEVIm7SR5gcZ19BjhMyU1R2+I0UjkfQlV+bx9ZzmiGhvlDFznU05U2ELwcECyjoYAqE= git |