-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for the
ubi-hardening-extras
Docker images.
- Loading branch information
Showing
10 changed files
with
233 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__ |
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,27 @@ | ||
# Copyright 2023 The MathWorks, Inc. | ||
|
||
""" | ||
Module for testing the "icewm" image | ||
""" | ||
|
||
from utils import basetest | ||
import unittest | ||
|
||
|
||
class IcewmTest(basetest.TestCase): | ||
""" | ||
Test class to build a Docker image from the "icewm" one and test the resulting image | ||
""" | ||
|
||
def test_packages_present(self): | ||
"""Test that the icewm-* packages are installed""" | ||
packages = ["icewm", "icewm-data", "icewm-themes"] | ||
for name in packages: | ||
with self.subTest(packagename=name): | ||
self.assertTrue(self.host.package(name).is_installed) | ||
|
||
|
||
################################################################################## | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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,25 @@ | ||
# Copyright 2023 The MathWorks, Inc. | ||
|
||
""" | ||
Module for testing the "novnc" image | ||
""" | ||
|
||
from utils import basetest | ||
import unittest | ||
|
||
|
||
class NoVncTest(basetest.TestCase): | ||
""" | ||
Test class to build a Docker image from the "novnc" one and test the resulting image | ||
""" | ||
dockerfile = "Dockerfile.novnc" | ||
|
||
def test_can_launch(self): | ||
"""Test that the launch.sh executable exists""" | ||
self.assertTrue(self.host.file("/tmp/novnc/utils/launch.sh").exists) | ||
|
||
|
||
################################################################################## | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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,4 @@ | ||
# Copyright 2023 The MathWorks, Inc. | ||
|
||
docker>=6.1.2 | ||
pytest-testinfra>=9.0 |
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,30 @@ | ||
# Copyright 2023 The MathWorks, Inc. | ||
|
||
""" | ||
Module for testing the "tigervnc" image | ||
""" | ||
|
||
from utils import basetest | ||
import unittest | ||
|
||
|
||
class TigerVncTest(basetest.TestCase): | ||
""" | ||
Test class to build a Docker image from the "tigervnc" one and test the resulting image | ||
""" | ||
|
||
def test_packages_present(self): | ||
"""Test that the tigervnc_* packages are installed""" | ||
packages = [ | ||
"tigervnc-server-minimal", | ||
"tigervnc-license", | ||
] | ||
for name in packages: | ||
with self.subTest(packagename=name): | ||
self.assertTrue(self.host.package(name).is_installed) | ||
|
||
|
||
################################################################################## | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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,23 @@ | ||
# Copyright 2023 The MathWorks, Inc. | ||
|
||
ARG BASE_REGISTRY=redhat | ||
ARG BASE_IMAGE=ubi8 | ||
ARG BASE_TAG=8.8 | ||
ARG IMAGE_UNDER_TEST | ||
|
||
FROM ${IMAGE_UNDER_TEST} AS image-under-test | ||
|
||
# install the RPM packages contained in the $TAR_IMAGE into a redhat-ubi image | ||
|
||
FROM ${BASE_REGISTRY}/${BASE_IMAGE}:${BASE_TAG} | ||
|
||
ARG RPM_INSTALL=/tmp | ||
|
||
COPY --from=image-under-test *.rpm.tar.gz ${RPM_INSTALL} | ||
|
||
RUN cd ${RPM_INSTALL} && \ | ||
ls *.rpm.tar.gz | xargs -n 1 tar -xvzf && \ | ||
dnf install -y --nodocs *.rpm --nogpgcheck && \ | ||
dnf -y clean all && \ | ||
rm -rf /var/cache/dnf && \ | ||
rm -rf ${RPM_INSTALL} |
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,15 @@ | ||
# Copyright 2023 The MathWorks, Inc. | ||
|
||
ARG BASE_REGISTRY=redhat | ||
ARG BASE_IMAGE=ubi8 | ||
ARG BASE_TAG=8.8 | ||
ARG IMAGE_UNDER_TEST=novnc | ||
|
||
FROM ${IMAGE_UNDER_TEST} AS image-under-test | ||
|
||
FROM ${BASE_REGISTRY}/${BASE_IMAGE}:${BASE_TAG} | ||
|
||
COPY --from=image-under-test *.tar.gz /tmp | ||
|
||
RUN mkdir /tmp/novnc/ && \ | ||
tar -xzf /tmp/novnc.tar.gz --directory /tmp/novnc/ --no-same-owner --no-same-permissions |
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,50 @@ | ||
# Copyright 2023 The MathWorks, Inc. | ||
|
||
import testinfra | ||
import docker | ||
import unittest | ||
import pathlib | ||
import os | ||
|
||
|
||
class TestCase(unittest.TestCase): | ||
"""Base test class""" | ||
|
||
# default parameters (can be overridden in derived test classes) | ||
buildargs = {"IMAGE_UNDER_TEST": os.getenv("IMAGE_NAME")} | ||
dockerfile = "Dockerfile" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
""" | ||
Build a Docker image from the Dockerfile contained in this directory. | ||
To choose which image use as a base image, set the buildargs "IMAGE_UNDER_TEST" | ||
""" | ||
cls.client = docker.from_env() | ||
cls.image, _ = cls.client.images.build( | ||
path=str(pathlib.Path(__file__).parent.resolve()), | ||
buildargs=cls.buildargs, | ||
dockerfile=cls.dockerfile, | ||
rm=True, | ||
) | ||
|
||
def setUp(self): | ||
"""Run the docker container. Equivalent to | ||
'docker run --rm -i -d DOCKER_IMAGE ' | ||
""" | ||
self.container = self.client.containers.run( | ||
image=self.image.id, detach=True, stdin_open=True | ||
) | ||
self.host = testinfra.get_host("docker://" + self.container.id) | ||
|
||
def tearDown(self): | ||
"""Stop and remove the container.""" | ||
self.container.stop() | ||
self.container.remove() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
"""Remove the image and the client.""" | ||
cls.client.images.remove(cls.image.id, force=True) | ||
cls.client.close() |
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,30 @@ | ||
# Copyright 2023 The MathWorks, Inc. | ||
|
||
""" | ||
Module for testing the "xterm" image | ||
""" | ||
|
||
from utils import basetest | ||
import unittest | ||
|
||
|
||
class XtermVncTest(basetest.TestCase): | ||
""" | ||
Test class to build a Docker image from the "xterm" one and test the resulting image | ||
""" | ||
|
||
def test_packages_present(self): | ||
"""Test that the xterm-* packages are installed""" | ||
packages = [ | ||
"xterm", | ||
"xterm-resize", | ||
] | ||
for name in packages: | ||
with self.subTest(packagename=name): | ||
self.assertTrue(self.host.package(name).is_installed) | ||
|
||
|
||
################################################################################## | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |