Example #1
0
 def test_outpost_validaton(self):
     """Test Outpost validation"""
     valid = OutpostSerializer(
         data={
             "name": "foo",
             "type": OutpostType.PROXY,
             "config": default_outpost_config(),
             "providers": [
                 ProxyProvider.objects.create(
                     name="test", authorization_flow=create_test_flow()
                 ).pk
             ],
         }
     )
     self.assertTrue(valid.is_valid())
     invalid = OutpostSerializer(
         data={
             "name": "foo",
             "type": OutpostType.PROXY,
             "config": default_outpost_config(),
             "providers": [
                 LDAPProvider.objects.create(
                     name="test", authorization_flow=create_test_flow()
                 ).pk
             ],
         }
     )
     self.assertFalse(invalid.is_valid())
     self.assertIn("providers", invalid.errors)
Example #2
0
 def test_outpost_config(self):
     """Test Outpost's config field"""
     provider = ProxyProvider.objects.create(name="test", authorization_flow=create_test_flow())
     invalid = OutpostSerializer(data={"name": "foo", "providers": [provider.pk], "config": ""})
     self.assertFalse(invalid.is_valid())
     self.assertIn("config", invalid.errors)
     valid = OutpostSerializer(
         data={
             "name": "foo",
             "providers": [provider.pk],
             "config": default_outpost_config("foo"),
             "type": OutpostType.PROXY,
         }
     )
     self.assertTrue(valid.is_valid())
 def setUp(self):
     super().setUp()
     self.ssl_folder = mkdtemp()
     self.container = self._start_container(self.ssl_folder)
     # Ensure that local connection have been created
     outpost_local_connection()
     self.provider: ProxyProvider = ProxyProvider.objects.create(
         name="test",
         internal_host="http://localhost",
         external_host="http://localhost",
         authorization_flow=Flow.objects.create(
             name="foo",
             slug="foo",
             designation=FlowDesignation.AUTHORIZATION),
     )
     authentication_kp = CertificateKeyPair.objects.create(
         name="docker-authentication",
         # pylint: disable=consider-using-with
         certificate_data=open(f"{self.ssl_folder}/client/cert.pem",
                               encoding="utf8").read(),
         # pylint: disable=consider-using-with
         key_data=open(f"{self.ssl_folder}/client/key.pem",
                       encoding="utf8").read(),
     )
     verification_kp = CertificateKeyPair.objects.create(
         name="docker-verification",
         # pylint: disable=consider-using-with
         certificate_data=open(f"{self.ssl_folder}/client/ca.pem",
                               encoding="utf8").read(),
     )
     self.service_connection = DockerServiceConnection.objects.create(
         url="https://localhost:2376",
         tls_verification=verification_kp,
         tls_authentication=authentication_kp,
     )
     self.outpost: Outpost = Outpost.objects.create(
         name="test",
         type=OutpostType.PROXY,
         service_connection=self.service_connection,
         _config=default_outpost_config(self.live_server_url),
     )
     self.outpost.providers.add(self.provider)
     self.outpost.save()
Example #4
0
 def default_settings(self, request: Request) -> Response:
     """Global default outpost config"""
     host = self.request.build_absolute_uri("/")
     return Response({"config": default_outpost_config(host)})