Skip to content

Commit

Permalink
Fixes merge to 1.6.x (#564)
Browse files Browse the repository at this point in the history
* merged #503 from master to 1.6.x
cherry-pick 2638299

Feat/#502 consul integrate test (#503)

* Fixed the scope caching error

* Added dependence of container test into pom

* Moved the test cases to server module

* Enhanced the registry test with testContainer.

* Migrate consul container test to integration folder

* Reverted unnecessary change

* Changed name

* Disable the integration test for mvn clean install

* Removed unused line

* -now integration test will copy the config under its own integration folder to the target folder
-CURD some config files due to fix test cases (those were not configured correctly in previous versions)

* -move integration plugins to integration-test profile
-test configs will be generated either from integration folder or under test folder depends on the profile, cannot include both because file with same name will have only one copy under config directory in phase "generate-test-sources".
-when run mvn clean install will as usual, when run mvn clean install -P integration-test will execute integration tests

* fixes the typo

# Conflicts:
#	pom.xml

* Fix/#519 keystore fall back (#525)

* Fixed the scope caching error

* Fix keystore and truststore fall back

* Fixed keystore and truststore fall back

* Removed incorrect/unnecessary log message

* Added comments

* Created TlsUtil to support load keystore/truststore

* Added test cases
  • Loading branch information
BalloonWen authored and stevehu committed Jul 10, 2019
1 parent 12e6b9c commit aa38241
Show file tree
Hide file tree
Showing 27 changed files with 619 additions and 56 deletions.
24 changes: 3 additions & 21 deletions client/src/main/java/com/networknt/client/Http2Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import com.networknt.monad.Failure;
import com.networknt.monad.Result;
import com.networknt.utility.ModuleRegistry;
import com.networknt.utility.TlsUtil;
import io.undertow.UndertowOptions;
import io.undertow.client.*;
import com.networknt.client.http.*;
Expand Down Expand Up @@ -406,25 +407,6 @@ public Result populateHeader(ClientRequest request, String authToken, String cor
return result;
}



private static KeyStore loadKeyStore(final String name, final char[] password) throws IOException {
final InputStream stream = Config.getInstance().getInputStreamFromFile(name);
if(stream == null) {
throw new RuntimeException("Could not load keystore");
}
try {
KeyStore loadedKeystore = KeyStore.getInstance("JKS");
loadedKeystore.load(stream, password);

return loadedKeystore;
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException e) {
throw new IOException(String.format("Unable to load KeyStore %s", name), e);
} finally {
IoUtils.safeClose(stream);
}
}

/**
* default method for creating ssl context. trustedNames config is not used.
*
Expand Down Expand Up @@ -465,7 +447,7 @@ public static SSLContext createSSLContext(String trustedNamesGroupKey) throws IO
}
if (keyStoreName != null && keyStorePass != null) {
String keyPass = (String) ClientConfig.get().getSecretConfig().get(SecretConstants.CLIENT_KEY_PASS);
KeyStore keyStore = loadKeyStore(keyStoreName, keyStorePass.toCharArray());
KeyStore keyStore = TlsUtil.loadKeyStore(keyStoreName, keyStorePass.toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keyPass.toCharArray());
keyManagers = keyManagerFactory.getKeyManagers();
Expand All @@ -492,7 +474,7 @@ public static SSLContext createSSLContext(String trustedNamesGroupKey) throws IO
if(logger.isInfoEnabled()) logger.info("Loading trust store from config at " + Encode.forJava(trustStoreName));
}
if (trustStoreName != null && trustStorePass != null) {
KeyStore trustStore = loadKeyStore(trustStoreName, trustStorePass.toCharArray());
KeyStore trustStore = TlsUtil.loadTrustStore(trustStoreName, trustStorePass.toCharArray());
TLSConfig tlsConfig = TLSConfig.create(tlsMap, trustedNamesGroupKey);

TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
Expand Down
Binary file added client/src/test/resources/config/client.keystore
Binary file not shown.
Binary file added client/src/test/resources/config/client.truststore
Binary file not shown.
4 changes: 1 addition & 3 deletions config/src/main/java/com/networknt/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Iterator;
Expand Down Expand Up @@ -61,7 +60,6 @@
*/
public abstract class Config {
public static final String LIGHT_4J_CONFIG_DIR = "light-4j-config-dir";
public static final String CENTRALIZED_MANAGEMENT = "values";

protected Config() {
}
Expand Down Expand Up @@ -437,7 +435,7 @@ private InputStream getConfigStream(String configFilename, String path) {
logger.info("Unable to load config " + Encode.forJava(configFilename) + ". Looking for the same file name with extension yaml...");
} else if (configFilename.endsWith(CONFIG_EXT_YAML)) {
logger.info("Unable to load config " + Encode.forJava(configFilename) + ". Looking for the same file name with extension json...");
} else {
} else if (configFilename.endsWith(CONFIG_EXT_JSON)) {
System.out.println("Unable to load config '" + Encode.forJava(configFilename.substring(0, configFilename.indexOf("."))) + "' with extension yml, yaml and json from external config, application config and module config. Please ignore this message if you are sure that your application is not using this config file.");
}
return null;
Expand Down
120 changes: 106 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<version.nexus-staging-maven>1.6.8</version.nexus-staging-maven>
<version.maven-source>3.0.1</version.maven-source>
<version.maven-surefire>3.0.0-M3</version.maven-surefire>
<version.maven-failsafe>2.22.0</version.maven-failsafe>
<!--<version.maven-release>2.5.3</version.maven-release>-->
<version.maven-javadoc>3.1.0</version.maven-javadoc>
<version.jacoco>0.8.3</version.jacoco>
Expand All @@ -111,6 +112,9 @@
<version.error_prone_core>2.0.15</version.error_prone_core>
<version.lifecycle-mapping>1.0.0</version.lifecycle-mapping>
<version.maven-gpg>1.6</version.maven-gpg>
<version.testcontainers>1.8.0</version.testcontainers>
<skip.unit.tests>false</skip.unit.tests>
<matched.test.resources>**/*</matched.test.resources>
</properties>

<modules>
Expand Down Expand Up @@ -607,6 +611,12 @@
<version>${version.httpclient}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${version.testcontainers}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -617,17 +627,18 @@
<resource>
<filtering>false</filtering>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>**/*.keystore</exclude>
<exclude>**/*.truststore</exclude>
</excludes>
</resource>
</resources>
<testResources>
<testResource>
<filtering>false</filtering>
<directory>${basedir}/src/test/resources</directory>
<includes>
<include>**/*</include>
<include>${matched.test.resources}</include>
</includes>
</testResource>
</testResources>
Expand Down Expand Up @@ -693,23 +704,24 @@
<version>${version.maven-surefire}</version>
</dependency>
</dependencies>
<configuration>
<!-- Skips unit tests if the value of skip.unit.tests property is true -->
<skipTests>${skip.unit.tests}</skipTests>
<!-- Excludes integration tests when unit tests are run -->
<excludes>
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.maven-surefire}</version>
<version>${version.maven-failsafe}</version>
<configuration>
<encoding>UTF-8</encoding>
<forkCount>0</forkCount>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down Expand Up @@ -886,6 +898,12 @@
<profiles>
<profile>
<id>dev</id>
<properties>
<!--
Only unit tests are run when the development profile is active
-->
<skip.unit.tests>false</skip.unit.tests>
</properties>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -956,6 +974,80 @@
</plugins>
</build>
</profile>
<!-- The Configuration of the integration-test profile -->
<profile>
<id>integration-test</id>
<properties>
<!--
Only integration tests are run when the integration-test profile is active
-->
<skip.unit.tests>true</skip.unit.tests>
<!--to include nothing for regular unit resources-->
<matched.test.resources>a^</matched.test.resources>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.maven-surefire}</version>
<executions>
<!--
Invokes both the integration-test and the verify goals of the
Failsafe Maven plugin
-->
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!--
Skips integration tests if the value of skip.integration.tests
property is true
-->
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${version.build-helper-maven}</version>
<executions>
<execution>
<id>add-integration-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/src/integration/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-resource</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<!-- Don't forget <directory> label -->
<directory>${project.basedir}/src/integration/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>jdk8</id>
<activation>
Expand Down
5 changes: 5 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit aa38241

Please sign in to comment.