Skip to content

Commit 0856e27

Browse files
committed
test/integration: Automate manual selinux test
Signed-off-by: Monika Kairaityte <[email protected]>
1 parent 7c61f24 commit 0856e27

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-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 @@
1+
# There must be a source file in the host for volumes type: bind
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 test_selinux(self):
14+
# test if when using volumes type:bind with selinux:z option, container ackquires a
15+
# respective host:source:z mapping in CreateCommand list
16+
# change working directory to where docker-compose.yml file is so that containers can
17+
# directly access host source file for mounting from that working directory
18+
os.chdir(os.path.join(test_path(), 'selinux'))
19+
try:
20+
self.run_subprocess_assert_returncode([
21+
podman_compose_path(),
22+
"up",
23+
"-d",
24+
"container1",
25+
"container2",
26+
])
27+
28+
out, _ = self.run_subprocess_assert_returncode([
29+
"podman",
30+
"inspect",
31+
"selinux_container1_1",
32+
])
33+
inspect_out = json.loads(out)
34+
create_command_list = inspect_out[0].get("Config", {}).get("CreateCommand", {})
35+
self.assertIn('./host_test_text.txt:/test_text.txt:z', create_command_list)
36+
37+
out, _ = self.run_subprocess_assert_returncode([
38+
"podman",
39+
"inspect",
40+
"selinux_container2_1",
41+
])
42+
inspect_out = json.loads(out)
43+
create_command_list = inspect_out[0].get("Config", {}).get("CreateCommand", {})
44+
self.assertIn('./host_test_text.txt:/test_text.txt', create_command_list)
45+
finally:
46+
out, _ = self.run_subprocess_assert_returncode([
47+
podman_compose_path(),
48+
"down",
49+
"-t",
50+
"0",
51+
])

0 commit comments

Comments
 (0)