|
| 1 | +from doctest import debug |
| 2 | + |
1 | 3 | import pytest |
2 | 4 |
|
| 5 | +from pathlib import Path |
| 6 | + |
3 | 7 | from container_ci_suite.container_lib import ContainerTestLib, PodmanCLIWrapper |
| 8 | +from container_ci_suite.utils import get_file_content |
4 | 9 |
|
5 | 10 | from conftest import VARS |
6 | 11 |
|
| 12 | +test_fips = VARS.TEST_DIR / "test-fips" |
| 13 | + |
| 14 | + |
| 15 | +def build_s2i_app(app_path: Path) -> ContainerTestLib: |
| 16 | + container_lib = ContainerTestLib(VARS.IMAGE_NAME) |
| 17 | + app_name = app_path.name |
| 18 | + s2i_app = container_lib.build_as_df( |
| 19 | + app_path=app_path, |
| 20 | + s2i_args=f"--pull-policy=never {container_lib.build_s2i_npm_variables()}", |
| 21 | + src_image=VARS.IMAGE_NAME, |
| 22 | + dst_image=f"{VARS.IMAGE_NAME}-{app_name}" |
| 23 | + ) |
| 24 | + return s2i_app |
| 25 | + |
7 | 26 |
|
8 | 27 | class TestNodeJSAppContainer: |
9 | 28 |
|
@@ -55,3 +74,45 @@ def test_dockerfiles(self, dockerfile): |
55 | 74 | url=cip, |
56 | 75 | expected_output="Node.js Crud Application" |
57 | 76 | ) |
| 77 | + |
| 78 | + |
| 79 | +class TestNodeJSFipsContainer: |
| 80 | + def setup_method(self): |
| 81 | + self.s2i_fips = build_s2i_app(test_fips) |
| 82 | + |
| 83 | + def teardown_method(self): |
| 84 | + self.s2i_fips.cleanup() |
| 85 | + |
| 86 | + def test_nodejs_fips_mode(self): |
| 87 | + if VARS.OS == "rhel8": |
| 88 | + pytest.skip("Do not execute on RHEL8") |
| 89 | + is_fips_enabled = 0 |
| 90 | + fips_enabled_file = Path("/proc/sys/crypto/fips_enabled") |
| 91 | + if fips_enabled_file.exists(): |
| 92 | + is_fips_enabled = int(get_file_content(fips_enabled_file)) |
| 93 | + if is_fips_enabled == 1: |
| 94 | + fips_result = PodmanCLIWrapper.podman_run_command_and_remove( |
| 95 | + cid_file_name=f"{VARS.IMAGE_NAME}-{self.s2i_fips.app_name}", |
| 96 | + cmd="node test.js", |
| 97 | + return_output=False, |
| 98 | + ) |
| 99 | + assert fips_result == 1 |
| 100 | + else: |
| 101 | + fips_mode = PodmanCLIWrapper.podman_run_command_and_remove( |
| 102 | + cid_file_name=f"{VARS.IMAGE_NAME}-{self.s2i_fips.app_name}", |
| 103 | + cmd="node test.js", |
| 104 | + return_output=False, |
| 105 | + ) |
| 106 | + assert fips_mode == 0 |
| 107 | + |
| 108 | + def test_run_fips_app_application(self): |
| 109 | + is_fips_enabled = 0 |
| 110 | + fips_enabled_file = Path("/proc/sys/crypto/fips_enabled") |
| 111 | + if fips_enabled_file.exists(): |
| 112 | + is_fips_enabled = int(get_file_content(fips_enabled_file)) |
| 113 | + if is_fips_enabled == 1: |
| 114 | + assert self.s2i_fips.create_container( |
| 115 | + cid_file_name=self.s2i_fips.app_name, |
| 116 | + container_args="--user 100001" |
| 117 | + ) |
| 118 | + assert self.s2i_fips.get_cid(cid_file_name=self.s2i_fips.app_name) |
0 commit comments