123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- import pytest
- from render import Render
- @pytest.fixture
- def mock_values():
- return {
- "ix_context": {
- "app_metadata": {
- "name": "test_app",
- "title": "Test App",
- "train": "enterprise",
- }
- },
- "images": {
- "test_image": {
- "repository": "nginx",
- "tag": "latest",
- }
- },
- }
- def test_notes(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- output = render.render()
- assert (
- output["x-notes"]
- == """# Test App
- ## Security
- ### Container: [test_container]
- - Is running as unknown user
- - Is running as unknown group
- ## Bug Reports and Feature Requests
- If you find a bug in this app or have an idea for a new feature, please file an issue at
- https://ixsystems.atlassian.net
- """
- )
- def test_notes_on_non_enterprise_train(mock_values):
- mock_values["ix_context"]["app_metadata"]["train"] = "community"
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.set_user(568, 568)
- c1.healthcheck.disable()
- output = render.render()
- assert (
- output["x-notes"]
- == """# Test App
- ## Bug Reports and Feature Requests
- If you find a bug in this app or have an idea for a new feature, please file an issue at
- https://github.com/truenas/apps
- """
- )
- def test_notes_with_warnings(mock_values):
- render = Render(mock_values)
- render.notes.add_warning("this is not properly configured. fix it now!")
- render.notes.add_warning("that is not properly configured. fix it later!")
- c1 = render.add_container("test_container", "test_image")
- c1.set_user(568, 568)
- c1.healthcheck.disable()
- output = render.render()
- assert (
- output["x-notes"]
- == """# Test App
- ## Warnings
- - this is not properly configured. fix it now!
- - that is not properly configured. fix it later!
- ## Bug Reports and Feature Requests
- If you find a bug in this app or have an idea for a new feature, please file an issue at
- https://ixsystems.atlassian.net
- """
- )
- def test_notes_with_deprecations(mock_values):
- render = Render(mock_values)
- render.notes.add_deprecation("this is will be removed later. fix it now!")
- render.notes.add_deprecation("that is will be removed later. fix it later!")
- c1 = render.add_container("test_container", "test_image")
- c1.set_user(568, 568)
- c1.healthcheck.disable()
- output = render.render()
- assert (
- output["x-notes"]
- == """# Test App
- ## Deprecations
- - this is will be removed later. fix it now!
- - that is will be removed later. fix it later!
- ## Bug Reports and Feature Requests
- If you find a bug in this app or have an idea for a new feature, please file an issue at
- https://ixsystems.atlassian.net
- """
- )
- def test_notes_with_body(mock_values):
- render = Render(mock_values)
- render.notes.set_body(
- """## Additional info
- Some info
- some other info.
- """
- )
- c1 = render.add_container("test_container", "test_image")
- c1.set_user(568, 568)
- c1.healthcheck.disable()
- output = render.render()
- assert (
- output["x-notes"]
- == """# Test App
- ## Additional info
- Some info
- some other info.
- ## Bug Reports and Feature Requests
- If you find a bug in this app or have an idea for a new feature, please file an issue at
- https://ixsystems.atlassian.net
- """
- )
- def test_notes_all(mock_values):
- render = Render(mock_values)
- render.notes.add_warning("this is not properly configured. fix it now!")
- render.notes.add_warning("that is not properly configured. fix it later!")
- render.notes.add_deprecation("this is will be removed later. fix it now!")
- render.notes.add_deprecation("that is will be removed later. fix it later!")
- render.notes.set_body(
- """## Additional info
- Some info
- some other info.
- """
- )
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- c1.set_privileged(True)
- c1.set_user(0, 0)
- c1.add_group(0)
- c1.set_ipc_mode("host")
- c1.set_pid_mode("host")
- c1.set_cgroup("host")
- c1.set_tty(True)
- c1.remove_security_opt("no-new-privileges")
- c1.restart.set_policy("on-failure", 1)
- c2 = render.add_container("test_container2", "test_image")
- c2.healthcheck.disable()
- c2.set_user(568, 568)
- c3 = render.add_container("test_container3", "test_image")
- c3.healthcheck.disable()
- c3.restart.set_policy("on-failure", 1)
- c3.set_user(568, 568)
- output = render.render()
- assert (
- output["x-notes"]
- == """# Test App
- ## Warnings
- - Container [test_container] is running with a TTY, Logs will not appear correctly in the UI due to an [upstream bug](https://github.com/docker/docker-py/issues/1394)
- - this is not properly configured. fix it now!
- - that is not properly configured. fix it later!
- ## Deprecations
- - this is will be removed later. fix it now!
- - that is will be removed later. fix it later!
- ## Security
- ### Container: [test_container]
- **This container is short-lived.**
- - Is running with privileged mode enabled
- - Is running as root user
- - Is running as root group
- - Is running with supplementary root group
- - Is running with host IPC namespace
- - Is running with host PID namespace
- - Is running with host cgroup namespace
- - Is running without [no-new-privileges] security option
- ## Additional info
- Some info
- some other info.
- ## Bug Reports and Feature Requests
- If you find a bug in this app or have an idea for a new feature, please file an issue at
- https://ixsystems.atlassian.net
- """ # noqa
- )
|