DefaultIsServicePortSecureResolver { boolean resolve(Input input) { final String securedLabelValue = input.getServiceLabels().getOrDefault("secured", "false"); if (TRUTHY_STRINGS.contains(securedLabelValue)) { if (log.isDebugEnabled()) { log.debug("Considering service with name: " + input.getServiceName() + " and port " + input.getPort() + " is secure since the service contains a true value for the 'secured' label"); } return true; } final String securedAnnotationValue = input.getServiceAnnotations().getOrDefault("secured", "false"); if (TRUTHY_STRINGS.contains(securedAnnotationValue)) { if (log.isDebugEnabled()) { log.debug("Considering service with name: " + input.getServiceName() + " and port " + input.getPort() + " is secure since the service contains a true value for the 'secured' annotation"); } return true; } if (input.getPort() != null && this.properties.getKnownSecurePorts().contains(input.getPort())) { if (log.isDebugEnabled()) { log.debug("Considering service with name: " + input.getServiceName() + " and port " + input.getPort() + " is secure due to the port being a known https port"); } return true; } return false; } DefaultIsServicePortSecureResolver(KubernetesDiscoveryProperties properties);   }
@Test public void testPortNumbersOnly() { final KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(); properties.getKnownSecurePorts().add(12345); final DefaultIsServicePortSecureResolver sut = new DefaultIsServicePortSecureResolver(properties); assertThat(sut.resolve(new DefaultIsServicePortSecureResolver.Input(null, "dummy"))).isFalse(); assertThat(sut.resolve(new DefaultIsServicePortSecureResolver.Input(8080, "dummy"))).isFalse(); assertThat(sut.resolve(new DefaultIsServicePortSecureResolver.Input(1234, "dummy"))).isFalse(); assertThat(sut.resolve(new DefaultIsServicePortSecureResolver.Input(443, "dummy"))).isTrue(); assertThat(sut.resolve(new DefaultIsServicePortSecureResolver.Input(8443, "dummy"))).isTrue(); assertThat(sut.resolve(new DefaultIsServicePortSecureResolver.Input(12345, "dummy"))).isTrue(); }
@Test public void testLabelsAndAnnotations() { final DefaultIsServicePortSecureResolver sut = new DefaultIsServicePortSecureResolver( new KubernetesDiscoveryProperties()); assertThat( sut.resolve(new DefaultIsServicePortSecureResolver.Input(8080, "dummy", new HashMap<String, String>() { { put("secured", "true"); put("other", "value"); } }, new HashMap<>()))).isTrue(); assertThat( sut.resolve(new DefaultIsServicePortSecureResolver.Input(1234, "dummy", new HashMap<String, String>() { { put("other", "value"); put("secured", "1"); } }, new HashMap<>()))).isTrue(); assertThat(sut.resolve(new DefaultIsServicePortSecureResolver.Input(4321, "dummy", new HashMap<>(), new HashMap<String, String>() { { put("other1", "value1"); put("secured", "yes"); put("other2", "value2"); } }))).isTrue(); }