refactor-git-trust #4
3 changed files with 27 additions and 15 deletions
|
@ -25,24 +25,11 @@ open class KnownHost protected constructor(val hostName: String, val hostKeys: L
|
||||||
)
|
)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
protected val values = listOf(KnownHost.GITHUB, KnownHost.GITLAB)
|
protected val values = listOf(GITHUB, GITLAB)
|
||||||
|
|
||||||
fun values(): List<KnownHost> {
|
fun values(): List<KnownHost> {
|
||||||
return values
|
return values
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun valueOf(value: String): KnownHost = valueOf(value, KnownHost.values)
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
protected fun valueOf(value: String, valueList: List<KnownHost>): KnownHost {
|
|
||||||
for (type in valueList) {
|
|
||||||
if (value.uppercase().equals(type.hostName)) {
|
|
||||||
return type
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw RuntimeException("No KnownHost found for value: $value")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import org.domaindrivenarchitecture.provs.framework.core.Prov
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.keys.base.addKnownHost
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.keys.base.addKnownHost
|
||||||
|
|
||||||
|
|
||||||
fun Prov.addKnownHosts(knownHosts: List<KnownHost> = defaultKnownHosts) = task {
|
fun Prov.addKnownHosts(knownHosts: List<KnownHost> = KnownHost.values()) = task {
|
||||||
for (knownHost in knownHosts) {
|
for (knownHost in knownHosts) {
|
||||||
with(knownHost) {
|
with(knownHost) {
|
||||||
addKnownHost(hostName, hostKeys, verifyKeys = true)
|
addKnownHost(hostName, hostKeys, verifyKeys = true)
|
||||||
|
|
|
@ -5,7 +5,9 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInsta
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.keys.base.KNOWN_HOSTS_FILE
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.keys.base.KNOWN_HOSTS_FILE
|
||||||
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
||||||
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Assertions.assertTrue
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
|
||||||
class KnownHostTest {
|
class KnownHostTest {
|
||||||
|
@ -25,5 +27,28 @@ class KnownHostTest {
|
||||||
// then
|
// then
|
||||||
assertTrue(res.success)
|
assertTrue(res.success)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Subclass of KnownHost for test knownHostSubclass_includes_additional_host
|
||||||
|
class KnownHostsSubclass(hostName: String, hostKeys: List<HostKey>): KnownHost(hostName, hostKeys) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val ANOTHER_HOST = KnownHostsSubclass("anotherhost.com", listOf("key1"))
|
||||||
|
|
||||||
|
fun values(): List<KnownHost> {
|
||||||
|
return values + ANOTHER_HOST
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun knownHostSubclass_includes_additional_host() {
|
||||||
|
// when
|
||||||
|
val hosts = KnownHostsSubclass.values()
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertTrue(hosts.size > 1)
|
||||||
|
assertEquals("key1", hosts.last().hostKeys[0])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue