From 921fda2d91b8a6c301b3ad8c8fe76eb1da1d4123 Mon Sep 17 00:00:00 2001 From: az Date: Tue, 31 Jan 2023 19:06:09 +0100 Subject: [PATCH] [skip ci] update DesktopServiceKtTest.kt --- Dockerfile | 5 ++- build.gradle | 2 +- .../desktop/domain/DesktopServiceKtTest.kt | 33 +++++++++---------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 944a9e1..2181d03 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,10 +3,9 @@ FROM ubuntu:latest ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get -y install apt-utils sudo -RUN useradd -m testuser && echo "testuserpw:testuser" | chpasswd && adduser testuser sudo -RUN echo "testuser ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/testuser -RUN useradd testuser2 && echo "testuser2pw:testuser2" | chpasswd && adduser testuser2 sudo +RUN useradd -m testuser && echo "testuser:testuserpw" | chpasswd && adduser testuser sudo +RUN echo "testuser ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/testuser USER testuser CMD /bin/bash diff --git a/build.gradle b/build.gradle index 81fd7bd..80dd125 100644 --- a/build.gradle +++ b/build.gradle @@ -71,7 +71,7 @@ dependencies { api("org.jetbrains.kotlinx:kotlinx-serialization-core:1.3.2") api("org.jetbrains.kotlinx:kotlinx-cli:0.3.4") - api('com.charleskorn.kaml:kaml:0.43.0') + api('com.charleskorn.kaml:kaml:0.49.0') api("org.slf4j:slf4j-api:1.7.36") api('ch.qos.logback:logback-classic:1.2.11') diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopServiceKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopServiceKtTest.kt index 7a2f6a7..a00e7cc 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopServiceKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopServiceKtTest.kt @@ -3,47 +3,46 @@ package org.domaindrivenarchitecture.provs.desktop.domain import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig import org.domaindrivenarchitecture.provs.framework.core.ProgressType import org.domaindrivenarchitecture.provs.framework.core.Prov +import org.domaindrivenarchitecture.provs.framework.core.docker.provideContainer import org.domaindrivenarchitecture.provs.framework.core.local import org.domaindrivenarchitecture.provs.framework.core.processors.ContainerStartMode import org.domaindrivenarchitecture.provs.framework.core.processors.ContainerUbuntuHostProcessor import org.domaindrivenarchitecture.provs.framework.core.remote +import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.deleteFile import org.domaindrivenarchitecture.provs.test.defaultTestContainer -import org.domaindrivenarchitecture.provs.test.defaultTestContainerName -import org.domaindrivenarchitecture.provs.test.tags.ContainerTest import org.domaindrivenarchitecture.provs.test.tags.ExtensiveContainerTest -import org.domaindrivenarchitecture.provs.test.testDockerWithSudo +import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test internal class DesktopServiceKtTest { - @ContainerTest + @ExtensiveContainerTest fun provisionLocalDesktop_fails_if_user_cannot_sudo_without_password() { // given - local().cmd( "sudo docker exec -it --user testuser2 provs-test-no-pw /bin/bash" ) + val containerName = "prov-test-sudo-no-pw" + local().provideContainer(containerName, "ubuntu_plus_user") val prov = Prov.newInstance( ContainerUbuntuHostProcessor( - "prov-test-no-pw", + containerName, startMode = ContainerStartMode.USE_RUNNING_ELSE_CREATE, sudo = true, dockerImage = "ubuntu_plus_user" ), progressType = ProgressType.NONE ) - + prov.deleteFile("/etc/sudoers.de/testuser", sudo = true) // remove no password required // when - // in order to test DesktopType.OFFICE: fix installing libreoffice for a fresh container as it hangs the first time but succeeds 2nd time - val res = prov.provisionDesktop( - DesktopType.BASIC, - gitUserName = "testuser", - gitEmail = "testuser@test.org", - onlyModules = null - ) - - // then - assertTrue(res.success) + Assertions.assertThrows(Exception::class.java) { + prov.provisionDesktop( + DesktopType.BASIC, + gitUserName = "testuser", + gitEmail = "testuser@test.org", + onlyModules = null + ) + } } @ExtensiveContainerTest