use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.
the class JwtProxySecureServerExposerTest method shouldExposeSecureServersWithNewJwtProxyServicePort.
@Test
public void shouldExposeSecureServersWithNewJwtProxyServicePort() throws Exception {
// given
ServicePort machineServicePort = new ServicePort();
machineServicePort.setTargetPort(new IntOrString(8080));
machineServicePort.setProtocol("TCP");
Map<String, ServerConfig> servers = ImmutableMap.of("server1", new ServerConfigImpl("8080/tcp", "http", "/api", ImmutableMap.of("secure", "true")), "server2", new ServerConfigImpl("8080/tcp", "ws", "/connect", ImmutableMap.of("secure", "true")));
ServicePort jwtProxyServicePort = new ServicePort();
doReturn(jwtProxyServicePort).when(jwtProxyProvisioner).expose(any(), any(), anyString(), anyString(), any(), anyString(), anyBoolean(), any());
when(jwtProxyProvisioner.getServiceName()).thenReturn(JWT_PROXY_SERVICE_NAME);
when(externalServerExposer.getStrategyConformingServers(eq(servers))).thenReturn(servers);
// when
secureServerExposer.expose(k8sEnv, null, MACHINE_NAME, MACHINE_SERVICE_NAME, null, machineServicePort, servers);
// then
verify(jwtProxyProvisioner).expose(eq(k8sEnv), any(), anyString(), eq(MACHINE_SERVICE_NAME), eq(machineServicePort), eq("TCP"), eq(false), any());
verify(externalServerExposer).expose(eq(k8sEnv), eq(MACHINE_NAME), eq(JWT_PROXY_SERVICE_NAME), isNull(), eq(jwtProxyServicePort), eq(servers));
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.
the class JwtProxySecureServerExposerTest method shouldUseMultiHostStrategyForSubdomainRequiringServers.
@Test
public void shouldUseMultiHostStrategyForSubdomainRequiringServers() throws Exception {
// given
ServicePort machineServicePort = new ServicePort();
machineServicePort.setTargetPort(new IntOrString(8080));
machineServicePort.setProtocol("TCP");
Map<String, ServerConfig> servers = ImmutableMap.of("server1", new ServerConfigImpl("8080/tcp", "http", "/api", ImmutableMap.of("secure", "true")), "server2", new ServerConfigImpl("8080/tcp", "ws", "/connect", ImmutableMap.of("secure", "true")));
Map<String, ServerConfig> conformingServers = Collections.singletonMap("server1", servers.get("server1"));
Map<String, ServerConfig> subdomainServers = Collections.singletonMap("server2", servers.get("server2"));
ServicePort jwtProxyServicePort = new ServicePort();
doReturn(jwtProxyServicePort).when(jwtProxyProvisioner).expose(any(), any(), anyString(), anyString(), any(), anyString(), anyBoolean(), any());
when(jwtProxyProvisioner.getServiceName()).thenReturn(JWT_PROXY_SERVICE_NAME);
when(externalServerExposer.getStrategyConformingServers(eq(servers))).thenReturn(conformingServers);
when(externalServerExposer.getServersRequiringSubdomain(eq(servers))).thenReturn(subdomainServers);
// when
secureServerExposer.expose(k8sEnv, null, MACHINE_NAME, MACHINE_SERVICE_NAME, null, machineServicePort, servers);
// then
verify(jwtProxyProvisioner).expose(eq(k8sEnv), any(), anyString(), eq(MACHINE_SERVICE_NAME), eq(machineServicePort), eq("TCP"), eq(false), any());
verify(jwtProxyProvisioner).expose(eq(k8sEnv), any(), anyString(), eq(MACHINE_SERVICE_NAME), eq(machineServicePort), eq("TCP"), eq(true), any());
verify(externalServerExposer).expose(eq(k8sEnv), eq(MACHINE_NAME), eq(JWT_PROXY_SERVICE_NAME), isNull(), eq(jwtProxyServicePort), eq(conformingServers));
verify(externalServerExposer).expose(eq(k8sEnv), eq(MACHINE_NAME), eq(JWT_PROXY_SERVICE_NAME), isNull(), eq(jwtProxyServicePort), eq(subdomainServers));
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.
the class KubernetesServerExposerTest method testExposeUniqueSecureServersWithOnlyMatchingServers.
@Test
public void testExposeUniqueSecureServersWithOnlyMatchingServers() throws InfrastructureException {
// https://github.com/eclipse/che/issues/16330
// given 2 servers which one of them is unique
ServerConfigImpl theiaSC = new ServerConfigImpl("3100/tcp", "https", null, ImmutableMap.of("internal", "false", "discoverable", "false", "secure", "true", "type", "ide"));
ServerConfigImpl webviewsSC = new ServerConfigImpl("3100/tcp", "https", null, ImmutableMap.of("internal", "false", "discoverable", "false", "unique", "true", "secure", "true", "type", "webview"));
Map<String, ServerConfigImpl> serversToExpose = ImmutableMap.of("theia", theiaSC, "webviews", webviewsSC);
// when
serverExposer.expose(serversToExpose);
// then expose is called twice with only one server each
ArgumentCaptor<Map<String, ServerConfig>> serversCaptor = ArgumentCaptor.forClass(Map.class);
verify(secureServerExposer, times(2)).expose(any(), any(), any(), any(), any(), any(), serversCaptor.capture());
for (Map<String, ServerConfig> captures : serversCaptor.getAllValues()) {
assertEquals(captures.size(), 1);
}
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.
the class CombinedSingleHostServerExposerTest method shouldExposeDevfileServersOnSubdomans.
@Test
public void shouldExposeDevfileServersOnSubdomans() {
// given
ServerConfig s1 = new ServerConfigImpl("1", "http", "/", emptyMap());
ServerConfig s2 = new ServerConfigImpl("2", "http", "/", singletonMap(REQUIRE_SUBDOMAIN, "false"));
ServerConfig s3 = new ServerConfigImpl("3", "http", "/", singletonMap(REQUIRE_SUBDOMAIN, "true"));
CombinedSingleHostServerExposer<KubernetesEnvironment> serverExposer = new CombinedSingleHostServerExposer<>(subdomainExposer, subpathExposer);
// when
serverExposer.expose(env, MACHINE, SERVICE, SERVER, PORT, Map.of("s1", s1, "s2", s2, "s3", s3));
// then
verify(subdomainExposer).expose(env, MACHINE, SERVICE, SERVER, PORT, Map.of("s3", s3));
verify(subpathExposer).expose(env, MACHINE, SERVICE, SERVER, PORT, Map.of("s1", s1, "s2", s2));
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.
the class DefaultHostExternalServiceExposureStrategyTest method shouldCreateSingleIngressForTwoNonUniqueServersWithTheSamePort.
@Test
public void shouldCreateSingleIngressForTwoNonUniqueServersWithTheSamePort() {
// given
ServerConfigImpl httpServerConfig = new ServerConfigImpl("8080/tcp", "http", "/api", ATTRIBUTES_MAP);
ServerConfigImpl wsServerConfig = new ServerConfigImpl("8080/tcp", "ws", "/connect", ATTRIBUTES_MAP);
ServicePort servicePort = new ServicePortBuilder().withName("server-8080").withPort(8080).withProtocol("TCP").withTargetPort(new IntOrString(8080)).build();
Map<String, ServerConfig> serversToExpose = ImmutableMap.of("http-server", httpServerConfig, "ws-server", wsServerConfig);
// when
externalServerExposer.expose(kubernetesEnvironment, MACHINE_NAME, SERVICE_NAME, null, servicePort, serversToExpose);
// then
assertEquals(kubernetesEnvironment.getIngresses().size(), 1);
assertThatExternalServerIsExposed(MACHINE_NAME, SERVICE_NAME, "http-server", servicePort, new ServerConfigImpl(httpServerConfig).withAttributes(ATTRIBUTES_MAP));
assertThatExternalServerIsExposed(MACHINE_NAME, SERVICE_NAME, "ws-server", servicePort, new ServerConfigImpl(wsServerConfig).withAttributes(ATTRIBUTES_MAP));
}
Aggregations