test_notes.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. import pytest
  2. from render import Render
  3. @pytest.fixture
  4. def mock_values():
  5. return {
  6. "ix_context": {
  7. "app_metadata": {
  8. "name": "test_app",
  9. "title": "Test App",
  10. "train": "enterprise",
  11. }
  12. },
  13. "images": {
  14. "test_image": {
  15. "repository": "nginx",
  16. "tag": "latest",
  17. }
  18. },
  19. }
  20. def test_notes(mock_values):
  21. render = Render(mock_values)
  22. c1 = render.add_container("test_container", "test_image")
  23. c1.healthcheck.disable()
  24. output = render.render()
  25. assert (
  26. output["x-notes"]
  27. == """# Test App
  28. ## Security
  29. ### Container: [test_container]
  30. - Is running as unknown user
  31. - Is running as unknown group
  32. ## Bug Reports and Feature Requests
  33. If you find a bug in this app or have an idea for a new feature, please file an issue at
  34. https://ixsystems.atlassian.net
  35. """
  36. )
  37. def test_notes_on_non_enterprise_train(mock_values):
  38. mock_values["ix_context"]["app_metadata"]["train"] = "community"
  39. render = Render(mock_values)
  40. c1 = render.add_container("test_container", "test_image")
  41. c1.set_user(568, 568)
  42. c1.healthcheck.disable()
  43. output = render.render()
  44. assert (
  45. output["x-notes"]
  46. == """# Test App
  47. ## Bug Reports and Feature Requests
  48. If you find a bug in this app or have an idea for a new feature, please file an issue at
  49. https://github.com/truenas/apps
  50. """
  51. )
  52. def test_notes_with_warnings(mock_values):
  53. render = Render(mock_values)
  54. render.notes.add_warning("this is not properly configured. fix it now!")
  55. render.notes.add_warning("that is not properly configured. fix it later!")
  56. c1 = render.add_container("test_container", "test_image")
  57. c1.set_user(568, 568)
  58. c1.healthcheck.disable()
  59. output = render.render()
  60. assert (
  61. output["x-notes"]
  62. == """# Test App
  63. ## Warnings
  64. - this is not properly configured. fix it now!
  65. - that is not properly configured. fix it later!
  66. ## Bug Reports and Feature Requests
  67. If you find a bug in this app or have an idea for a new feature, please file an issue at
  68. https://ixsystems.atlassian.net
  69. """
  70. )
  71. def test_notes_with_deprecations(mock_values):
  72. render = Render(mock_values)
  73. render.notes.add_deprecation("this is will be removed later. fix it now!")
  74. render.notes.add_deprecation("that is will be removed later. fix it later!")
  75. c1 = render.add_container("test_container", "test_image")
  76. c1.set_user(568, 568)
  77. c1.healthcheck.disable()
  78. output = render.render()
  79. assert (
  80. output["x-notes"]
  81. == """# Test App
  82. ## Deprecations
  83. - this is will be removed later. fix it now!
  84. - that is will be removed later. fix it later!
  85. ## Bug Reports and Feature Requests
  86. If you find a bug in this app or have an idea for a new feature, please file an issue at
  87. https://ixsystems.atlassian.net
  88. """
  89. )
  90. def test_notes_with_body(mock_values):
  91. render = Render(mock_values)
  92. render.notes.set_body(
  93. """## Additional info
  94. Some info
  95. some other info.
  96. """
  97. )
  98. c1 = render.add_container("test_container", "test_image")
  99. c1.set_user(568, 568)
  100. c1.healthcheck.disable()
  101. output = render.render()
  102. assert (
  103. output["x-notes"]
  104. == """# Test App
  105. ## Additional info
  106. Some info
  107. some other info.
  108. ## Bug Reports and Feature Requests
  109. If you find a bug in this app or have an idea for a new feature, please file an issue at
  110. https://ixsystems.atlassian.net
  111. """
  112. )
  113. def test_notes_all(mock_values):
  114. render = Render(mock_values)
  115. render.notes.add_warning("this is not properly configured. fix it now!")
  116. render.notes.add_warning("that is not properly configured. fix it later!")
  117. render.notes.add_deprecation("this is will be removed later. fix it now!")
  118. render.notes.add_deprecation("that is will be removed later. fix it later!")
  119. render.notes.set_body(
  120. """## Additional info
  121. Some info
  122. some other info.
  123. """
  124. )
  125. c1 = render.add_container("test_container", "test_image")
  126. c1.healthcheck.disable()
  127. c1.set_privileged(True)
  128. c1.set_user(0, 0)
  129. c1.add_group(0)
  130. c1.set_ipc_mode("host")
  131. c1.set_pid_mode("host")
  132. c1.set_cgroup("host")
  133. c1.set_tty(True)
  134. c1.remove_security_opt("no-new-privileges")
  135. c1.restart.set_policy("on-failure", 1)
  136. c2 = render.add_container("test_container2", "test_image")
  137. c2.healthcheck.disable()
  138. c2.set_user(568, 568)
  139. c3 = render.add_container("test_container3", "test_image")
  140. c3.healthcheck.disable()
  141. c3.restart.set_policy("on-failure", 1)
  142. c3.set_user(568, 568)
  143. output = render.render()
  144. assert (
  145. output["x-notes"]
  146. == """# Test App
  147. ## Warnings
  148. - 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)
  149. - this is not properly configured. fix it now!
  150. - that is not properly configured. fix it later!
  151. ## Deprecations
  152. - this is will be removed later. fix it now!
  153. - that is will be removed later. fix it later!
  154. ## Security
  155. ### Container: [test_container]
  156. **This container is short-lived.**
  157. - Is running with privileged mode enabled
  158. - Is running as root user
  159. - Is running as root group
  160. - Is running with supplementary root group
  161. - Is running with host IPC namespace
  162. - Is running with host PID namespace
  163. - Is running with host cgroup namespace
  164. - Is running without [no-new-privileges] security option
  165. ## Additional info
  166. Some info
  167. some other info.
  168. ## Bug Reports and Feature Requests
  169. If you find a bug in this app or have an idea for a new feature, please file an issue at
  170. https://ixsystems.atlassian.net
  171. """ # noqa
  172. )