2020-09-29 08:32:41 +00:00
|
|
|
"""Test Controllers"""
|
2020-10-14 18:21:47 +00:00
|
|
|
from os import environ
|
|
|
|
from unittest import skipUnless
|
|
|
|
|
2020-09-29 08:32:41 +00:00
|
|
|
import yaml
|
|
|
|
from django.test import TestCase
|
|
|
|
|
|
|
|
from passbook.flows.models import Flow
|
2020-11-04 09:54:44 +00:00
|
|
|
from passbook.outposts.models import KubernetesServiceConnection, Outpost, OutpostType
|
2020-10-16 09:28:54 +00:00
|
|
|
from passbook.providers.proxy.controllers.kubernetes import ProxyKubernetesController
|
2020-09-29 08:32:41 +00:00
|
|
|
from passbook.providers.proxy.models import ProxyProvider
|
|
|
|
|
|
|
|
|
2020-10-14 18:21:47 +00:00
|
|
|
@skipUnless("PB_TEST_K8S" in environ, "Kubernetes test cluster required")
|
2020-09-29 08:32:41 +00:00
|
|
|
class TestControllers(TestCase):
|
|
|
|
"""Test Controllers"""
|
|
|
|
|
2020-10-14 18:21:47 +00:00
|
|
|
def test_kubernetes_controller_static(self):
|
2020-09-29 08:32:41 +00:00
|
|
|
"""Test Kubernetes Controller"""
|
|
|
|
provider: ProxyProvider = ProxyProvider.objects.create(
|
|
|
|
name="test",
|
|
|
|
internal_host="http://localhost",
|
|
|
|
external_host="http://localhost",
|
|
|
|
authorization_flow=Flow.objects.first(),
|
|
|
|
)
|
2020-11-04 13:02:29 +00:00
|
|
|
service_connection = KubernetesServiceConnection.objects.first()
|
2020-09-29 08:32:41 +00:00
|
|
|
outpost: Outpost = Outpost.objects.create(
|
|
|
|
name="test",
|
|
|
|
type=OutpostType.PROXY,
|
2020-11-04 09:54:44 +00:00
|
|
|
service_connection=service_connection,
|
2020-09-29 08:32:41 +00:00
|
|
|
)
|
|
|
|
outpost.providers.add(provider)
|
|
|
|
outpost.save()
|
|
|
|
|
2020-11-04 09:54:44 +00:00
|
|
|
controller = ProxyKubernetesController(outpost, service_connection)
|
2020-09-29 08:32:41 +00:00
|
|
|
manifest = controller.get_static_deployment()
|
2020-10-19 12:55:25 +00:00
|
|
|
self.assertEqual(len(list(yaml.load_all(manifest, Loader=yaml.SafeLoader))), 4)
|
2020-10-14 18:21:47 +00: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(),
|
|
|
|
)
|
2020-11-04 13:02:29 +00:00
|
|
|
service_connection = KubernetesServiceConnection.objects.first()
|
2020-10-14 18:21:47 +00:00
|
|
|
outpost: Outpost = Outpost.objects.create(
|
|
|
|
name="test",
|
|
|
|
type=OutpostType.PROXY,
|
2020-11-04 09:54:44 +00:00
|
|
|
service_connection=service_connection,
|
2020-10-14 18:21:47 +00:00
|
|
|
)
|
|
|
|
outpost.providers.add(provider)
|
|
|
|
outpost.save()
|
|
|
|
|
2020-11-04 09:54:44 +00:00
|
|
|
controller = ProxyKubernetesController(outpost, service_connection)
|
2020-10-16 20:22:15 +00:00
|
|
|
controller.up()
|
2020-10-19 12:55:25 +00:00
|
|
|
controller.down()
|