From 587e978d6366df88c42e3c5e2e605da90ac12486 Mon Sep 17 00:00:00 2001 From: az Date: Sun, 26 Mar 2023 21:56:59 +0200 Subject: [PATCH] [skip ci] fix test_configureSsh --- .../provs/server/infrastructure/SshKtTest.kt | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/SshKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/SshKtTest.kt index 4863ae6..63ec68d 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/SshKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/SshKtTest.kt @@ -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")) } } \ No newline at end of file