This commit is contained in:
commit
db82325ed7
216 files changed
+33718
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import unittest
|
||||
import uuid
|
||||
from runtime import Service, deployment_manifest, network_policy, branding_config
|
||||
|
||||
|
||||
class RuntimeTests(unittest.TestCase):
|
||||
def test_powered_by_footer_only_uses_html_substitution(self):
|
||||
config=branding_config(3000,{'hostedFooterEnabled':'true','hostedFooterText':'由 WebUp Cloud 提供服务','hostedFooterLink':'https://webup.run'})
|
||||
self.assertIn('sub_filter',config)
|
||||
self.assertIn('proxy_pass http://127.0.0.1:3000',config)
|
||||
self.assertIn('proxy_set_header Upgrade',config)
|
||||
self.assertNotIn('sub_filter_types application/json',config)
|
||||
self.assertIsNone(branding_config(3000,{'hostedFooterEnabled':'false'}))
|
||||
|
||||
def test_footer_text_is_escaped(self):
|
||||
config=branding_config(3000,{'hostedFooterEnabled':'true','hostedFooterText':"<script>alert('$x')</script>",'hostedFooterLink':'https://webup.run'})
|
||||
self.assertNotIn('<script>',config)
|
||||
self.assertNotIn('$x',config)
|
||||
|
||||
def test_oci_runtime_is_non_root_and_health_checked(self):
|
||||
service = Service(id=uuid.uuid4(), name="api", image="example.invalid/app:v1", command=[], environment={"KEY": "value"}, port=3000, cpu_millis=250, memory_mb=256, replicas=2, health_path="/health")
|
||||
spec = deployment_manifest(uuid.uuid4().hex, uuid.uuid4().hex, service)["spec"]
|
||||
pod = spec["template"]["spec"]
|
||||
self.assertEqual(2, spec["replicas"])
|
||||
self.assertFalse(pod["automountServiceAccountToken"])
|
||||
self.assertTrue(pod["securityContext"]["runAsNonRoot"])
|
||||
self.assertEqual("gvisor", pod["runtimeClassName"])
|
||||
self.assertIn("startupProbe", pod["containers"][0])
|
||||
self.assertIn("secretRef", pod["containers"][0]["envFrom"][0])
|
||||
self.assertNotIn("hostPath", str(pod))
|
||||
|
||||
def test_project_network_does_not_allow_other_projects(self):
|
||||
project = uuid.uuid4().hex
|
||||
policy = network_policy(project)["spec"]
|
||||
self.assertEqual(project, policy["podSelector"]["matchLabels"]["platform/project"])
|
||||
self.assertEqual(project, policy["ingress"][0]["from"][0]["podSelector"]["matchLabels"]["platform/project"])
|
||||
self.assertIn("169.254.0.0/16", policy["egress"][2]["to"][0]["ipBlock"]["except"])
|
||||
Reference in new issue
Block a user