/** * Verifies that a Hono server will bind to the default insecure port only * when using a default configuration with the insecure port being enabled. */ @Test public void checkInsecureOnlyPort() { // GIVEN a default configuration with insecure port being enabled but no key store being set final ServiceConfigProperties configProperties = new ServiceConfigProperties(); configProperties.setInsecurePortEnabled(true); // WHEN using this configuration to determine the server's port configuration final AbstractServiceBase<ServiceConfigProperties> server = createService(configProperties); final Future<Void> portConfigurationTracker = server.checkPortConfiguration(); // THEN the server will bind to the default insecure port only assertTrue(portConfigurationTracker.succeeded()); assertFalse(server.isSecurePortEnabled()); assertTrue(server.isInsecurePortEnabled()); assertThat(server.getInsecurePort(), is(INSECURE_PORT_NR)); }
/** * Verifies that a Hono server will bind to both the default insecure and secure ports * when using a default configuration with the insecure port being enabled and the * key store property being set. */ @Test public void checkBothPortsOpen() { // GIVEN a default configuration with insecure port being enabled and a key store being set. final ServiceConfigProperties configProperties = new ServiceConfigProperties(); configProperties.setInsecurePortEnabled(true); configProperties.setKeyStorePath(PREFIX_KEY_PATH + "/honoKeyStore.p12"); // WHEN using this configuration to determine the server's port configuration final AbstractServiceBase<ServiceConfigProperties> server = createService(configProperties); final Future<Void> portConfigurationTracker = server.checkPortConfiguration(); // THEN the server will bind to both the default insecure and secure ports assertTrue(portConfigurationTracker.succeeded()); assertTrue(server.isSecurePortEnabled()); assertThat(server.getPort(), is(PORT_NR)); assertTrue(server.isInsecurePortEnabled()); assertThat(server.getInsecurePort(), is(INSECURE_PORT_NR)); }
/** * Verifies that a Hono server will bind to a configured insecure port only * when using a default configuration with the insecure port property being set. */ @Test public void checkInsecureOnlyPortExplicitlySet() { // GIVEN a default configuration with insecure port being set to a specific port. final ServiceConfigProperties configProperties = new ServiceConfigProperties(); configProperties.setInsecurePortEnabled(true); configProperties.setInsecurePort(8888); // WHEN using this configuration to determine the server's port configuration final AbstractServiceBase<ServiceConfigProperties> server = createService(configProperties); final Future<Void> portConfigurationTracker = server.checkPortConfiguration(); // THEN the server will bind to the configured insecure port only assertTrue(portConfigurationTracker.succeeded()); assertFalse(server.isSecurePortEnabled()); assertTrue(server.isInsecurePortEnabled()); assertThat(server.getInsecurePort(), is(8888)); }