use of org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl in project che-server by eclipse-che.
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.workspace.server.model.impl.ServerConfigImpl in project che-server by eclipse-che.
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.workspace.server.model.impl.ServerConfigImpl in project che-server by eclipse-che.
the class KubernetesServerExposerTest method shouldAddAdditionalContainerPortWhenThereIsTheSameButWithDifferentProtocol.
@Test
public void shouldAddAdditionalContainerPortWhenThereIsTheSameButWithDifferentProtocol() throws Exception {
// given
ServerConfigImpl udpServerConfig = new ServerConfigImpl("8080/udp", "udp", "/api", ATTRIBUTES_MAP);
Map<String, ServerConfigImpl> serversToExpose = ImmutableMap.of("server", udpServerConfig);
container.setPorts(new ArrayList<>(singletonList(new ContainerPortBuilder().withName("port-8080").withContainerPort(8080).withProtocol("TCP").build())));
// when
serverExposer.expose(serversToExpose);
// then
assertEquals(container.getPorts().size(), 2);
assertEquals(container.getPorts().get(1).getContainerPort(), new Integer(8080));
assertEquals(container.getPorts().get(1).getProtocol(), "UDP");
assertThatExternalServerIsExposed(MACHINE_NAME, "udp", 8080, "server", new ServerConfigImpl(udpServerConfig).withAttributes(ATTRIBUTES_MAP));
}
use of org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl in project che-server by eclipse-che.
the class KubernetesServerExposerTest method shouldExposeContainerPortAndCreateServiceAndForServerWhenTwoServersHasTheSamePort.
@Test
public void shouldExposeContainerPortAndCreateServiceAndForServerWhenTwoServersHasTheSamePort() throws Exception {
// given
ServerConfigImpl httpServerConfig = new ServerConfigImpl("8080/tcp", "http", "/api", ATTRIBUTES_MAP);
ServerConfigImpl wsServerConfig = new ServerConfigImpl("8080/tcp", "ws", "/connect", ATTRIBUTES_MAP);
Map<String, ServerConfigImpl> serversToExpose = ImmutableMap.of("http-server", httpServerConfig, "ws-server", wsServerConfig);
// when
serverExposer.expose(serversToExpose);
// then
assertEquals(kubernetesEnvironment.getServices().size(), 1);
assertThatExternalServersAreExposed(MACHINE_NAME, "tcp", 8080, ImmutableMap.of("http-server", new ServerConfigImpl(httpServerConfig).withAttributes(ATTRIBUTES_MAP), "ws-server", new ServerConfigImpl(wsServerConfig).withAttributes(ATTRIBUTES_MAP)));
}
use of org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl in project che-server by eclipse-che.
the class KubernetesServerExposerTest method shouldExposeTcpContainerPortsAndCreateServiceAndForServerWhenProtocolIsMissedInPort.
@Test
public void shouldExposeTcpContainerPortsAndCreateServiceAndForServerWhenProtocolIsMissedInPort() throws Exception {
// given
ServerConfigImpl httpServerConfig = new ServerConfigImpl("8080", "http", "/api", ATTRIBUTES_MAP);
Map<String, ServerConfigImpl> serversToExpose = ImmutableMap.of("http-server", httpServerConfig);
// when
serverExposer.expose(serversToExpose);
// then
assertEquals(kubernetesEnvironment.getServices().size(), 1);
assertThatExternalServerIsExposed(MACHINE_NAME, "TCP", 8080, "http-server", new ServerConfigImpl(httpServerConfig).withAttributes(ATTRIBUTES_MAP));
}
Aggregations