Skip to content

Commit

Permalink
Avoid NullPointerException in RouteTlsProvisioner (eclipse-che#18224)
Browse files Browse the repository at this point in the history
* Avoid NullPointerException in RouteTlsProvisioner

Signed-off-by: Sergii Kabashniuk <skabashniuk@redhat.com>
  • Loading branch information
skabashnyuk authored Oct 30, 2020
1 parent f60fced commit ba6ae09
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
package org.eclipse.che.workspace.infrastructure.openshift.provision;

import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.putAnnotations;
import static org.eclipse.che.workspace.infrastructure.kubernetes.provision.TlsProvisioner.getSecureProtocol;

import io.fabric8.openshift.api.model.Route;
Expand Down Expand Up @@ -73,8 +74,7 @@ private void useSecureProtocolForServers(final Route route) {
servers.values().forEach(s -> s.setProtocol(getSecureProtocol(s.getProtocol())));

Map<String, String> annotations = Annotations.newSerializer().servers(servers).annotations();

route.getMetadata().getAnnotations().putAll(annotations);
putAnnotations(route.getMetadata(), annotations);
}

private void enableTls(final Route route) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,27 @@ public void provisionTlsForRoutes() throws Exception {
assertEquals(servers.get("ws-server").getProtocol(), "wss");
}

@Test
public void shouldNotThrowNPE() throws Exception {
// given
RouteTlsProvisioner tlsProvisioner = new RouteTlsProvisioner(true);

final Map<String, Route> routes = new HashMap<>();
Route route =
new RouteBuilder()
.withNewMetadata()
.withName("name")
.endMetadata()
.withNewSpec()
.endSpec()
.build();
routes.put("route", route);
when(osEnv.getRoutes()).thenReturn(routes);

// when
tlsProvisioner.provision(osEnv, runtimeIdentity);
}

private Route createRoute(String name, Map<String, ServerConfigImpl> servers) {
return new RouteBuilder()
.withNewMetadata()
Expand Down

0 comments on commit ba6ae09

Please sign in to comment.