2020-09-29 09:32:41 +01:00
|
|
|
"""Test Controllers"""
|
2020-10-14 19:21:47 +01:00
|
|
|
from os import environ
|
|
|
|
from unittest import skipUnless
|
|
|
|
|
2020-09-29 09:32:41 +01:00
|
|
|
import yaml
|
|
|
|
from django.test import TestCase
|
|
|
|
|
|
|
|
from passbook.flows.models import Flow
|
|
|
|
from passbook.outposts.models import Outpost, OutpostDeploymentType, OutpostType
|
2020-10-16 10:28:54 +01:00
|
|
|
from passbook.providers.proxy.controllers.kubernetes import ProxyKubernetesController
|
2020-09-29 09:32:41 +01:00
|
|
|
from passbook.providers.proxy.models import ProxyProvider
|
|
|
|
|
|
|
|
|
2020-10-14 19:21:47 +01:00
|
|
|
@skipUnless("PB_TEST_K8S" in environ, "Kubernetes test cluster required")
|
2020-09-29 09:32:41 +01:00
|
|
|
class TestControllers(TestCase):
|
|
|
|
"""Test Controllers"""
|
|
|
|
|
2020-10-14 19:21:47 +01:00
|
|
|
def test_kubernetes_controller_static(self):
|
2020-09-29 09:32:41 +01:00
|
|
|
"""Test Kubernetes Controller"""
|
|
|
|
provider: ProxyProvider = ProxyProvider.objects.create(
|
|
|
|
name="test",
|
|
|
|
internal_host="http://localhost",
|
|
|
|
external_host="http://localhost",
|
|
|
|
authorization_flow=Flow.objects.first(),
|
|
|
|
)
|
|
|
|
outpost: Outpost = Outpost.objects.create(
|
|
|
|
name="test",
|
|
|
|
type=OutpostType.PROXY,
|
2020-10-14 19:21:47 +01:00
|
|
|
deployment_type=OutpostDeploymentType.KUBERNETES,
|
2020-09-29 09:32:41 +01:00
|
|
|
)
|
|
|
|
outpost.providers.add(provider)
|
|
|
|
outpost.save()
|
|
|
|
|
2020-10-14 19:21:47 +01:00
|
|
|
controller = ProxyKubernetesController(outpost.pk)
|
2020-09-29 09:32:41 +01:00
|
|
|
manifest = controller.get_static_deployment()
|
|
|
|
self.assertEqual(len(list(yaml.load_all(manifest, Loader=yaml.SafeLoader))), 3)
|
2020-10-14 19:21:47 +01:00
|
|
|
|
|
|
|
def test_kubernetes_controller_deploy(self):
|
|
|
|
"""Test Kubernetes Controller"""
|
|
|
|
provider: ProxyProvider = ProxyProvider.objects.create(
|
|
|
|
name="test",
|
|
|
|
internal_host="http://localhost",
|
|
|
|
external_host="http://localhost",
|
|
|
|
authorization_flow=Flow.objects.first(),
|
|
|
|
)
|
|
|
|
outpost: Outpost = Outpost.objects.create(
|
|
|
|
name="test",
|
|
|
|
type=OutpostType.PROXY,
|
|
|
|
deployment_type=OutpostDeploymentType.KUBERNETES,
|
|
|
|
)
|
|
|
|
outpost.providers.add(provider)
|
|
|
|
outpost.save()
|
|
|
|
|
|
|
|
controller = ProxyKubernetesController(outpost.pk)
|
2020-10-16 21:22:15 +01:00
|
|
|
controller.up()
|