Debian Codegraph @

tests/integration/secrets/test_podman_compose_secrets.py

raw symbols SCIP
1 # SPDX-License-Identifier: GPL-2.0
2
3 import os
4 import unittest
5 from subprocess import PIPE
6 from subprocess import Popen
7
8 from tests.integration.test_utils import RunSubprocessMixin
9 from tests.integration.test_utils import podman_compose_path
10 from tests.integration.test_utils import test_path
11
12
13 def compose_yaml_path() -> str:
14 return os.path.join(os.path.join(test_path(), "secrets"), "docker-compose.yaml")
15
16
17 class TestComposeNoSecrets(unittest.TestCase, RunSubprocessMixin):
18 created_secrets = [
19 "podman_compose_test_secret",
20 "podman_compose_test_secret_2",
21 "podman_compose_test_secret_3",
22 "podman_compose_test_secret_custom_name",
23 ]
24
25 def setUp(self) -> None:
26 for secret in self.created_secrets:
27 p = Popen(["podman", "secret", "create", secret, "-"], stdin=PIPE)
28 p.communicate(secret.encode('utf-8'))
29
30 def tearDown(self) -> None:
31 for secret in self.created_secrets:
32 self.run_subprocess_assert_returncode([
33 "podman",
34 "secret",
35 "rm",
36 f"{secret}",
37 ])
38
39 # test if secrets are saved and available in respective files of a container
40 def test_secrets(self) -> None:
41 try:
42 _, error, _ = self.run_subprocess(
43 [
44 podman_compose_path(),
45 "-f",
46 compose_yaml_path(),
47 "up",
48 "test",
49 ],
50 )
51
52 self.assertNotIn(
53 b'That is un-supported and a no-op and is ignored.',
54 error,
55 )
56 self.assertIn(
57 b'WARNING: Service test uses secret unused_params_warning with uid, '
58 + b'gid, or mode. These fields are not supported by this implementation '
59 + b'of the Compose file',
60 error,
61 )
62
63 output, _ = self.run_subprocess_assert_returncode(["podman", "logs", "secrets_test_1"])
64 expected_output = (
65 b'/run/secrets/custom_name:important-secret-is-important\n'
66 + b'/run/secrets/file_secret:important-secret-is-important\n'
67 + b'/run/secrets/podman_compose_test_secret:podman_compose_test_secret\n'
68 + b'/run/secrets/podman_compose_test_secret_3:podman_compose_test_secret_3\n'
69 + b'/run/secrets/unused_params_warning:important-secret-is-important\n'
70 + b'important-secret-is-important\n'
71 + b'podman_compose_test_secret\n'
72 )
73 self.assertEqual(expected_output, output)
74 finally:
75 self.run_subprocess_assert_returncode([
76 podman_compose_path(),
77 "-f",
78 compose_yaml_path(),
79 "down",
80 "-t",
81 "0",
82 ])