Skip to content

Commit 5c8bed0

Browse files
committed
test/integration: Automate manual selinux test
Signed-off-by: Monika Kairaityte <[email protected]>
1 parent a54f0fa commit 5c8bed0

File tree

2 files changed

+80
-7
lines changed

2 files changed

+80
-7
lines changed
+11-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
version: "3"
22
services:
3-
web1:
3+
container1:
44
image: busybox
5-
command: httpd -f -p 80 -h /var/www/html
5+
command: ["busybox", "sleep", "infinity"]
66
volumes:
77
- type: bind
8-
source: ./docker-compose.yml
9-
target: /var/www/html/index.html
8+
source: ./host_test_text.txt
9+
target: /test_text.txt
1010
bind:
1111
selinux: z
12-
ports:
13-
- "8080:80"
14-
12+
container2:
13+
image: busybox
14+
command: ["busybox", "sleep", "infinity"]
15+
volumes:
16+
- type: bind
17+
source: ./host_test_text.txt
18+
target: /test_text.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
import json
4+
import os
5+
import unittest
6+
7+
from tests.integration.test_utils import RunSubprocessMixin
8+
from tests.integration.test_utils import podman_compose_path
9+
from tests.integration.test_utils import test_path
10+
11+
12+
class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin):
13+
def setUp(self):
14+
# there must be a source file in the host for volumes type: bind
15+
head, tail = os.path.split(podman_compose_path())
16+
self.path_to_host_test_file = head + "/host_test_text.txt"
17+
self.run_subprocess(["touch", self.path_to_host_test_file])
18+
19+
def tearDown(self):
20+
self.run_subprocess(["rm", self.path_to_host_test_file])
21+
22+
def test_selinux(self):
23+
# test if when using volumes type:bind with selinux:z option, container ackquires a
24+
# respective host:source:z mapping in CreateCommand list
25+
compose_path = os.path.join(test_path(), "selinux", "docker-compose.yml")
26+
try:
27+
self.run_subprocess_assert_returncode([
28+
podman_compose_path(),
29+
"-f",
30+
compose_path,
31+
"up",
32+
"-d",
33+
"container1",
34+
])
35+
(
36+
self.run_subprocess_assert_returncode([
37+
podman_compose_path(),
38+
"-f",
39+
compose_path,
40+
"up",
41+
"-d",
42+
"container2",
43+
]),
44+
)
45+
46+
out, _ = self.run_subprocess_assert_returncode([
47+
"podman",
48+
"inspect",
49+
"selinux_container1_1",
50+
])
51+
inspect_out = json.loads(out)
52+
create_command_map = inspect_out[0].get("Config", {}).get("CreateCommand", {})
53+
self.assertIn('./host_test_text.txt:/test_text.txt:z', create_command_map)
54+
55+
out, _ = self.run_subprocess_assert_returncode([
56+
"podman",
57+
"inspect",
58+
"selinux_container2_1",
59+
])
60+
inspect_out = json.loads(out)
61+
create_command_map = inspect_out[0].get("Config", {}).get("CreateCommand", {})
62+
self.assertNotIn('./host_test_text.txt:/test_text.txt:z', create_command_map)
63+
finally:
64+
out, _ = self.run_subprocess_assert_returncode([
65+
podman_compose_path(),
66+
"-f",
67+
compose_path,
68+
"down",
69+
])

0 commit comments

Comments
 (0)