Skip to content

Commit 485bdf7

Browse files
committed
PyTest suite test_container_ssl.py was removed.
The whole suite was added to test_container_httpd_s2i.py. Also building new image is called by new function. Now each class use this function. Check of SSL should pass with proper response. Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent 7c08055 commit 485bdf7

File tree

5 files changed

+66
-95
lines changed

5 files changed

+66
-95
lines changed

2.4-micro/test/test_container_ssl.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

2.4/test/test_container_ssl.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/test_container_httpd.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23
import re
34
import tempfile
45

@@ -7,7 +8,11 @@
78
import pytest
89

910
from container_ci_suite.container_lib import ContainerTestLib
10-
from container_ci_suite.utils import ContainerTestLibUtils
11+
from container_ci_suite.utils import ContainerTestLibUtils, check_variables
12+
13+
14+
if not check_variables():
15+
sys.exit(1)
1116

1217

1318
TEST_DIR = Path(__file__).parent.absolute()

test/test_container_httpd_s2i.py

Lines changed: 60 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,44 @@
11
import os
2+
import sys
23
import time
34
import tempfile
45

56
from pathlib import Path
67

78
from container_ci_suite.container_lib import ContainerTestLib
8-
from container_ci_suite.utils import ContainerTestLibUtils
9+
from container_ci_suite.utils import ContainerTestLibUtils, check_variables
910
from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper
1011

12+
if not check_variables():
13+
sys.exit(1)
1114

1215
TEST_DIR = Path(__file__).parent.absolute()
1316
VERSION = os.getenv("VERSION")
14-
OS = os.getenv("TARGET")
17+
OS = os.getenv("OS").lower()
1518
IMAGE_NAME = os.getenv("IMAGE_NAME")
1619

1720

1821
pre_init_test_app = TEST_DIR / "pre-init-test-app"
1922
sample_test_app = TEST_DIR / "sample-test-app"
23+
self_cert_test = TEST_DIR / "self-signed-ssl"
24+
25+
26+
def build_s2i_app(app_path: Path) -> ContainerTestLib:
27+
container_lib = ContainerTestLib(IMAGE_NAME)
28+
app_name = app_path.name
29+
s2i_app = container_lib.build_as_df(
30+
app_path=app_path,
31+
s2i_args="--pull-policy=never",
32+
src_image=IMAGE_NAME,
33+
dst_image=f"{IMAGE_NAME}-{app_name}"
34+
)
35+
return s2i_app
2036

2137

2238
class TestHttpdS2IPreInitContainer:
2339

2440
def setup_method(self):
25-
self.container_lib = ContainerTestLib(IMAGE_NAME)
26-
print(self.container_lib)
27-
app_name = pre_init_test_app.name
28-
print(app_name)
29-
self.s2i_app = self.container_lib.build_as_df(
30-
app_path=pre_init_test_app,
31-
s2i_args="--pull-policy=never",
32-
src_image=IMAGE_NAME,
33-
dst_image=f"{IMAGE_NAME}-{app_name}"
34-
)
41+
self.s2i_app = build_s2i_app(pre_init_test_app)
3542

3643
def teardown_method(self):
3744
self.s2i_app.cleanup()
@@ -50,14 +57,7 @@ def test_run_pre_init_test(self):
5057
class TestHttpdS2ISampleAppContainer:
5158

5259
def setup_method(self):
53-
self.ci = ContainerTestLib(IMAGE_NAME)
54-
app_name = sample_test_app.name
55-
self.s2i_app = self.ci.build_as_df(
56-
app_path=sample_test_app,
57-
s2i_args="--pull-policy=never",
58-
src_image=IMAGE_NAME,
59-
dst_image=f"{IMAGE_NAME}-{app_name}"
60-
)
60+
self.s2i_app = build_s2i_app(sample_test_app)
6161

6262
def teardown_method(self):
6363
self.s2i_app.cleanup()
@@ -82,25 +82,18 @@ def test_sample_app(self):
8282
class TestHttpdCertAgeContainer:
8383

8484
def setup_method(self):
85-
self.ci = ContainerTestLib(IMAGE_NAME)
86-
app_name = sample_test_app.name
87-
self.s2i_app = self.ci.build_as_df(
88-
app_path=sample_test_app,
89-
s2i_args="--pull-policy=never",
90-
src_image=IMAGE_NAME,
91-
dst_image=f"{IMAGE_NAME}-{app_name}"
92-
)
85+
self.s2i_app = build_s2i_app(sample_test_app)
9386

9487
def teardown_method(self):
9588
self.s2i_app.cleanup()
9689

97-
"""
98-
This tests checks whether the certificate was freshly generated after the image
99-
We need to make sure the certificate is generated no sooner than in assemble phase,
100-
because shipping the same certs in the image would make it easy to exploit
101-
Let's see how old the certificate is and compare with how old the image is
102-
"""
10390
def test_cert_age(self):
91+
"""
92+
This tests checks whether the certificate was freshly generated after the image
93+
We need to make sure the certificate is generated no sooner than in assemble phase,
94+
because shipping the same certs in the image would make it easy to exploit
95+
Let's see how old the certificate is and compare with how old the image is
96+
"""
10497
assert self.s2i_app.create_container(cid_file_name=self.s2i_app.app_name, container_args="--user 1000")
10598
image_age_s = PodmanCLIWrapper.podman_inspect(
10699
field="{{.Created}}", src_image=IMAGE_NAME
@@ -132,4 +125,36 @@ def test_cert_age(self):
132125
# Testing presence and permissions of the generated certificate
133126
assert PodmanCLIWrapper.podman_exec_shell_command(
134127
cid_file_name=cid, cmd="ls -l \\$HTTPD_TLS_CERT_PATH/localhost.key"
135-
)
128+
)
129+
130+
class TestHttpdS2ISslSelfSignedAppContainer:
131+
132+
def setup_method(self):
133+
self.s2i_app = build_s2i_app(self_cert_test)
134+
135+
def teardown_method(self):
136+
self.s2i_app.cleanup()
137+
138+
def test_self_cert_test(self):
139+
"""
140+
Test s2i use case #3 - using own ssl certs
141+
Since we built the candidate image locally, we don't want S2I attempt to pull
142+
it from Docker hub
143+
"""
144+
self.s2i_app.set_new_image(image_name=f"{IMAGE_NAME}-{self.s2i_app.app_name}")
145+
assert self.s2i_app.create_container(cid_file_name=self.s2i_app.app_name, container_args="--user 1000")
146+
cip = self.s2i_app.get_cip(cid_file_name=self.s2i_app.app_name)
147+
assert cip
148+
assert self.s2i_app.test_response(url=cip, expected_code=200, expected_output="SSL test works")
149+
assert self.s2i_app.test_response(url=f"https://{cip}", port=8443, expected_output="SSL test works")
150+
server_cmd = f"openssl s_client -showcerts -servername {cip} -connect {cip}:8443 2>/dev/null"
151+
server_output = ContainerTestLibUtils.run_command(cmd=server_cmd)
152+
certificate_dir = tempfile.mkdtemp(prefix="/tmp/server_cert_dir")
153+
with open(Path(certificate_dir) / "output", mode="wt+") as f:
154+
f.write(server_output)
155+
server_cert = ContainerTestLibUtils.run_command(
156+
cmd=f"openssl x509 -inform pem -noout -text -in {Path(certificate_dir)}/output"
157+
)
158+
config_cmd = f"openssl x509 -in {TEST_DIR}/{self.s2i_app.app_name}/httpd-ssl/certs/server-cert-selfsigned.pem -inform pem -noout -text"
159+
config_cert = ContainerTestLibUtils.run_command(cmd=config_cmd)
160+
assert server_cert == config_cert

test/test_container_ssl.py

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)