簡體   English   中英

AWS Device Farm - Mongo SSL 證書異常

[英]AWS Device Farm - Mongo SSL Certificate Exception

好的,我正在嘗試在 AWS Device Farm 上運行我的 Gradle-Java 測試項目,方法是壓縮我的整個項目,選擇“使用 Appium Node.js 構建”選項,然后運行: ./gradlew test --tests MyTestRunner --debug但是當我嘗試通過 URI 連接 MongoDB 時出現下一個錯誤: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.

我可以在我的本地機器上建立連接。 這是我的方法:

public static void connectToMongo(){
    String uri = "mongodb+srv://user:pass@server";
    MongoClient client = MongoClients.create(uri);
    MongoDatabase database = client.getDatabase("database");
    MongoCollection<Document> myCollection = database.getCollection("collection");
    Document document = myCollection.find(
        eq("email", "myEmail")
    ).first();
    System.out.println(document.get("state").toString());
}

我正在使用下一個工具:

  • JDK 1.8.0_211
  • Gradle 6.5

這些是我的依賴項:

dependencies {
    compile 'org.mongodb:mongodb-driver-sync:4.5.0'
    compile group:'io.cucumber', name:'cucumber-java', version:'4.2.0'
    compile group:'io.cucumber', name:'cucumber-junit', version:'4.2.0'
    compile group: 'com.github.javafaker', name: 'javafaker', version: '1.0.2'
}

我嘗試了接下來的事情:

  • 向 URI 添加選項: mongodb+srv://user:pass@server?ssl=true&invalidHostNameAllowed=true
  • 將更高的 jdk 版本添加到 zip( jdk-17.0.2corretto-11.0.8 ),並通過將其添加到 build.gradle 來強制運行: compileJava.options.fork=true compileJava.options.forkOptions.executable='jdk-17.0.2/bin/javac'
  • 復制我的本地 jdk cacerts 並添加 gradle.properties:systemProp.javax.net.ssl.trustStore=cacerts systemProp.javax.net.ssl.trustStorePassword systemProp.javax.net.ssl.trustStore=cacerts systemProp.javax.net.ssl.trustStorePassword=changeit
  • 更改 mongo-driver 依賴項: compile 'org.mongodb:mongodb-driver-sync:4.0.5' compile 'org.mongodb:mongodb-driver-sync:4.5.0' implementation group:'org.mongodb',name:'mongo-java-driver',version:'3.12.11'

完整堆疊: 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@64a30f91. Client view of cluster state is {type=XXXXXX, servers=[{address=XXXXXX:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}, caused by {sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}, caused by {sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}}, {address=XXXXXX:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}, caused by {sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}, caused by {sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}}, {address=XXXXXX:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}, caused by {sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}, caused by {sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}}] 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.internal.connection.BaseCluster.createTimeoutException(BaseCluster.java:403) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.internal.connection.BaseCluster.selectServer(BaseCluster.java:118) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.internal.connection.AbstractMultiServerCluster.selectServer(AbstractMultiServerCluster.java:54) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:149) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:98) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:278) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:182) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.client.internal.FindIterableImpl.first(FindIterableImpl.java:189) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@64a30f91. Client view of cluster state is {type=XXXXXX, servers=[{address=XXXXXX:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}, caused by {sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}, caused by {sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}}, {address=XXXXXX:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}, caused by {sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}, caused by {sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}}, {address=XXXXXX:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}, caused by {sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}, caused by {sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target}}] 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.internal.connection.BaseCluster.createTimeoutException(BaseCluster.java:403) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.internal.connection.BaseCluster.selectServer(BaseCluster.java:118) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.internal.connection.AbstractMultiServerCluster.selectServer(AbstractMultiServerCluster.java:54) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:149) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:98) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:278) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:182) 2022-04-25T23:11:47.423+0000 [DEBUG] [TestEventLogger] at com.mongodb.client.internal.FindIterableImpl.first(FindIterableImpl.java:189)

解決了。 出現此問題是由於 AWS Device Farm 上的 jdk 版本過時:jdk1.8.0_65

對於尋求修復的人:為了解決這個問題,我在項目 zip 中包含了 jdk1.8.0_241,並更改了 env JAVA_HOME: export JAVA_HOME="$DEVICEFARM_TEST_PACKAGE_PATH/MyProject/jdk1.8.0_241"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM