RouteTlsProvisioner implements TlsProvisioner<OpenShiftEnvironment>,
        ConfigurationProvisioner<OpenShiftEnvironment> { @Override @Traced public void provision(OpenShiftEnvironment osEnv, RuntimeIdentity identity) { TracingTags.WORKSPACE_ID.set(identity::getWorkspaceId); if (!isTlsEnabled) { return; } final Set<Route> routes = new HashSet<>(osEnv.getRoutes().values()); for (Route route : routes) { useSecureProtocolForServers(route); enableTls(route); } } @Inject  RouteTlsProvisioner(@Named("che.infra.kubernetes.tls_enabled") boolean isTlsEnabled); @Override @Traced void provision(OpenShiftEnvironment osEnv, RuntimeIdentity identity);  }
@Test public void doNothingWhenTlsDisabled() throws Exception { RouteTlsProvisioner tlsProvisioner = new RouteTlsProvisioner(false); tlsProvisioner.provision(osEnv, runtimeIdentity); verify(osEnv, never()).getRoutes(); }
@Test public void provisionTlsForRoutes() throws Exception { RouteTlsProvisioner tlsProvisioner = new RouteTlsProvisioner(true); ServerConfigImpl httpServer = new ServerConfigImpl("8080/tpc", "http", "/api", emptyMap()); ServerConfigImpl wsServer = new ServerConfigImpl("8080/tpc", "ws", "/ws", emptyMap()); final Map<String, Route> routes = new HashMap<>(); Route route = createRoute("route", ImmutableMap.of("http-server", httpServer, "ws-server", wsServer)); routes.put("route", route); when(osEnv.getRoutes()).thenReturn(routes); tlsProvisioner.provision(osEnv, runtimeIdentity); assertEquals(route.getSpec().getTls().getTermination(), TERMINATION_EDGE); assertEquals( route.getSpec().getTls().getInsecureEdgeTerminationPolicy(), TERMINATION_POLICY_REDIRECT); Map<String, ServerConfigImpl> servers = Annotations.newDeserializer(route.getMetadata().getAnnotations()).servers(); assertEquals(servers.get("http-server").getProtocol(), "https"); assertEquals(servers.get("ws-server").getProtocol(), "wss"); }