/** * Verifies that a Hono server will bind to the default port only * when using a default configuration with only the key store property being set. */ @Test public void checkSecurePortAutoSelect() { // GIVEN a configuration with a key store set final ServiceConfigProperties configProperties = new ServiceConfigProperties(); configProperties.setKeyStorePath(PREFIX_KEY_PATH + "/honoKeyStore.p12"); // WHEN using this configuration to determine the server's port configuration // secure port config: no port set -> secure IANA port selected final AbstractServiceBase<ServiceConfigProperties> server = createService(configProperties); final Future<Void> portConfigurationTracker = server.checkPortConfiguration(); // THEN the default secure port is selected and no insecure port will be opened assertTrue(portConfigurationTracker.succeeded()); assertTrue(server.isSecurePortEnabled()); assertThat(server.getPort(), is(PORT_NR)); assertFalse(server.isInsecurePortEnabled()); }
/** * 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 the configured secure port only * when using a default configuration with only the key store and the port property being set. */ @Test public void checkSecurePortExplicitlySet() { // GIVEN a configuration with a key store and a secure port being set final ServiceConfigProperties configProperties = new ServiceConfigProperties(); configProperties.setKeyStorePath(PREFIX_KEY_PATH + "/honoKeyStore.p12"); configProperties.setPort(8989); // WHEN using this configuration to determine the server's port configuration // secure port config: explicit port set -> port used final AbstractServiceBase<ServiceConfigProperties> server = createService(configProperties); final Future<Void> portConfigurationTracker = server.checkPortConfiguration(); // THEN the configured port is used and no insecure port will be opened assertTrue(portConfigurationTracker.succeeded()); assertTrue(server.isSecurePortEnabled()); assertThat(server.getPort(), is(8989)); assertFalse(server.isInsecurePortEnabled()); }