Search in sources :

Example 1 with ServiceExposureStrategyProvider

use of org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ServiceExposureStrategyProvider in project devspaces-images by redhat-developer.

the class PassThroughProxyProvisionerTest method shouldConfigureProxyWithExcludes.

// PassThroughProxyProvisioner shares much of the codebase with the JwtProxyProvisioner. We only
// test the different behavior here, while the majority of the tests are present in the
// JwtProxyProvisionerTest
@Test
public void shouldConfigureProxyWithExcludes() throws Exception {
    // given
    KubernetesEnvironment k8sEnv = KubernetesEnvironment.builder().build();
    JwtProxyConfigBuilderFactory configBuilderFactory = mock(JwtProxyConfigBuilderFactory.class);
    JwtProxyConfigBuilder configBuilder = mock(JwtProxyConfigBuilder.class);
    when(configBuilderFactory.create(any())).thenReturn(configBuilder);
    ServiceExposureStrategyProvider exposureStrategyProvider = mock(ServiceExposureStrategyProvider.class);
    when(exposureStrategyProvider.get()).thenReturn(mock(ExternalServiceExposureStrategy.class));
    when(exposureStrategyProvider.getMultiHostStrategy()).thenReturn(mock(ExternalServiceExposureStrategy.class));
    PassThroughProxyProvisioner passThroughProxyProvisioner = new PassThroughProxyProvisioner(configBuilderFactory, exposureStrategyProvider, new CookiePathStrategy(MULTI_HOST_STRATEGY), new MultiHostCookiePathStrategy(), "eclipse/che-jwtproxy", "10m", "128mb", "0.02", "0.5", "Always", runtimeId);
    Map<String, String> attrs = new HashMap<>();
    ServerConfig.setCookiesAuthEnabled(attrs, true);
    ServerConfig.setSecure(attrs, true);
    ServerConfigImpl server1 = new ServerConfigImpl("4401/tcp", "http", "/", attrs);
    ServicePort port = new ServicePort();
    port.setTargetPort(new IntOrString(8080));
    // when
    passThroughProxyProvisioner.expose(k8sEnv, podWithName(), "machine", "terminal", port, "TCP", false, ImmutableMap.of("server1", server1));
    // then
    verify(configBuilder).addVerifierProxy(eq(4400), eq("http://terminal:8080"), eq(singleton("/")), eq(false), eq("/"), isNull());
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) HashMap(java.util.HashMap) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceExposureStrategyProvider(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ServiceExposureStrategyProvider) JwtProxyConfigBuilderFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.factory.JwtProxyConfigBuilderFactory) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) ExternalServiceExposureStrategy(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ExternalServiceExposureStrategy) Test(org.testng.annotations.Test)

Example 2 with ServiceExposureStrategyProvider

use of org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ServiceExposureStrategyProvider in project che-server by eclipse-che.

the class PassThroughProxyProvisionerTest method shouldConfigureProxyWithExcludes.

// PassThroughProxyProvisioner shares much of the codebase with the JwtProxyProvisioner. We only
// test the different behavior here, while the majority of the tests are present in the
// JwtProxyProvisionerTest
@Test
public void shouldConfigureProxyWithExcludes() throws Exception {
    // given
    KubernetesEnvironment k8sEnv = KubernetesEnvironment.builder().build();
    JwtProxyConfigBuilderFactory configBuilderFactory = mock(JwtProxyConfigBuilderFactory.class);
    JwtProxyConfigBuilder configBuilder = mock(JwtProxyConfigBuilder.class);
    when(configBuilderFactory.create(any())).thenReturn(configBuilder);
    ServiceExposureStrategyProvider exposureStrategyProvider = mock(ServiceExposureStrategyProvider.class);
    when(exposureStrategyProvider.get()).thenReturn(mock(ExternalServiceExposureStrategy.class));
    when(exposureStrategyProvider.getMultiHostStrategy()).thenReturn(mock(ExternalServiceExposureStrategy.class));
    PassThroughProxyProvisioner passThroughProxyProvisioner = new PassThroughProxyProvisioner(configBuilderFactory, exposureStrategyProvider, new CookiePathStrategy(MULTI_HOST_STRATEGY), new MultiHostCookiePathStrategy(), "eclipse/che-jwtproxy", "10m", "128mb", "0.02", "0.5", "Always", runtimeId);
    Map<String, String> attrs = new HashMap<>();
    ServerConfig.setCookiesAuthEnabled(attrs, true);
    ServerConfig.setSecure(attrs, true);
    ServerConfigImpl server1 = new ServerConfigImpl("4401/tcp", "http", "/", attrs);
    ServicePort port = new ServicePort();
    port.setTargetPort(new IntOrString(8080));
    // when
    passThroughProxyProvisioner.expose(k8sEnv, podWithName(), "machine", "terminal", port, "TCP", false, ImmutableMap.of("server1", server1));
    // then
    verify(configBuilder).addVerifierProxy(eq(4400), eq("http://terminal:8080"), eq(singleton("/")), eq(false), eq("/"), isNull());
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) HashMap(java.util.HashMap) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceExposureStrategyProvider(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ServiceExposureStrategyProvider) JwtProxyConfigBuilderFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.factory.JwtProxyConfigBuilderFactory) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) ExternalServiceExposureStrategy(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ExternalServiceExposureStrategy) Test(org.testng.annotations.Test)

Aggregations

IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)2 HashMap (java.util.HashMap)2 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)2 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)2 ExternalServiceExposureStrategy (org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ExternalServiceExposureStrategy)2 ServiceExposureStrategyProvider (org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ServiceExposureStrategyProvider)2 JwtProxyConfigBuilderFactory (org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.factory.JwtProxyConfigBuilderFactory)2 Test (org.testng.annotations.Test)2