[skip ci] fix test_configureSsh

This commit is contained in:
az 2023-03-26 21:56:59 +02:00
parent e35caca49a
commit 587e978d63

View file

@ -1,7 +1,9 @@
package org.domaindrivenarchitecture.provs.server.infrastructure
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.checkFile
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.deleteFile
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.fileContainsText
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
import org.domaindrivenarchitecture.provs.test.tags.ExtensiveContainerTest
import org.junit.jupiter.api.Assertions.assertTrue
@ -12,15 +14,21 @@ class SshKtTest {
fun test_configureSsh() {
// given
val p = defaultTestContainer()
val prov = defaultTestContainer()
prov.task {
aptInstall("openssh-server")
deleteFile(pathSshdHardeningConfig, sudo = true)
}
// when
val res = p.configureSsh()
prov.configureSsh()
// then
assertTrue(res.success)
assertTrue(p.fileContainsText("/etc/ssh/ssh_config","PasswordAuthentication no", sudo=true))
assertTrue(p.fileContainsText("/etc/ssh/sshd_config","PasswordAuthentication no", sudo=true))
assertTrue(p.checkFile("/etc/ssh/sshd_config.d/sshd_hardening.conf"))
// Note: result of method configureSsh might have status failure as restart ssh within docker is not possible,
// but files should have expected content
assertTrue(prov.fileContainsText("/etc/ssh/ssh_config","PasswordAuthentication no", sudo=true))
assertTrue(prov.fileContainsText("/etc/ssh/sshd_config","PasswordAuthentication no", sudo=true))
assertTrue(prov.checkFile("/etc/ssh/sshd_config.d/sshd_hardening.conf"))
}
}