Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/integration: Automate manual selinux test #1157

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions tests/integration/selinux/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
version: "3"
services:
web1:
container1:
image: busybox
command: httpd -f -p 80 -h /var/www/html
command: ["busybox", "sleep", "infinity"]
volumes:
- type: bind
source: ./docker-compose.yml
target: /var/www/html/index.html
source: ./host_test_text.txt
target: /test_text.txt
bind:
selinux: z
ports:
- "8080:80"

container2:
image: busybox
command: ["busybox", "sleep", "infinity"]
volumes:
- type: bind
source: ./host_test_text.txt
target: /test_text.txt
1 change: 1 addition & 0 deletions tests/integration/selinux/host_test_text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# There must be a source file in the host for volumes type: bind
58 changes: 58 additions & 0 deletions tests/integration/selinux/test_podman_compose_selinux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# SPDX-License-Identifier: GPL-2.0

import json
import os
import subprocess
import unittest

from tests.integration.test_utils import RunSubprocessMixin
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path


class TestPodmanCompose(unittest.TestCase, RunSubprocessMixin):
def test_selinux(self):
# test if when using volumes type:bind with selinux:z option, container ackquires a
# respective host:source:z mapping in CreateCommand list
compose_path = os.path.join(test_path(), "selinux", "docker-compose.yml")
try:
# change working directory to where docker-compose.yml file is so that containers can
# directly access host source file for mounting from that working directory
subprocess.run(
[
podman_compose_path(),
"-f",
compose_path,
"up",
"-d",
"container1",
"container2",
],
cwd=os.path.join(test_path(), 'selinux'),
)
out, _ = self.run_subprocess_assert_returncode([
"podman",
"inspect",
"selinux_container1_1",
])
inspect_out = json.loads(out)
create_command_list = inspect_out[0].get("Config", []).get("CreateCommand", {})
self.assertIn('./host_test_text.txt:/test_text.txt:z', create_command_list)

out, _ = self.run_subprocess_assert_returncode([
"podman",
"inspect",
"selinux_container2_1",
])
inspect_out = json.loads(out)
create_command_list = inspect_out[0].get("Config", []).get("CreateCommand", {})
self.assertIn('./host_test_text.txt:/test_text.txt', create_command_list)
finally:
out, _ = self.run_subprocess_assert_returncode([
podman_compose_path(),
"-f",
compose_path,
"down",
"-t",
"0",
])