-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46293 from Malandril/mongo-tls-registry
Allow mongo client to be configured by a tls registry
- Loading branch information
Showing
9 changed files
with
189 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...ions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/MongoTlsRegistryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package io.quarkus.mongodb; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.DisabledOnOs; | ||
import org.junit.jupiter.api.condition.OS; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.mongodb.client.MongoClient; | ||
|
||
import de.flapdoodle.embed.mongo.commands.MongodArguments; | ||
import de.flapdoodle.embed.mongo.transitions.ImmutableMongod; | ||
import de.flapdoodle.reverse.transitions.Start; | ||
import io.quarkus.mongodb.reactive.ReactiveMongoClient; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.certs.Format; | ||
import io.smallrye.certs.junit5.Certificate; | ||
import io.smallrye.certs.junit5.Certificates; | ||
|
||
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "Tests don't pass on windows CI") | ||
@Certificates(baseDir = MongoTlsRegistryTest.BASEDIR, certificates = { | ||
@Certificate(name = "mongo-cert", formats = Format.PEM, client = true) | ||
}) | ||
public class MongoTlsRegistryTest extends MongoTestBase { | ||
static final String BASEDIR = "target/certs"; | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(MongoTestBase.class)) | ||
.withConfigurationResource("tls-mongoclient.properties"); | ||
private static final Path BASEPATH = Path.of(BASEDIR); | ||
private final Path serverCertPath = Path.of(BASEDIR, "mongo-cert.crt"); | ||
private final Path serverKeyPath = Path.of(BASEDIR, "mongo-cert.key"); | ||
private final Path serverCaPath = Path.of(BASEDIR, "mongo-cert-server-ca.crt"); | ||
private final Path serverCertKeyPath = Path.of(BASEDIR, "mongo-certkey.pem"); | ||
@Inject | ||
MongoClient client; | ||
@Inject | ||
ReactiveMongoClient reactiveClient; | ||
|
||
@AfterEach | ||
void cleanup() { | ||
if (reactiveClient != null) { | ||
reactiveClient.close(); | ||
} | ||
if (client != null) { | ||
client.close(); | ||
} | ||
} | ||
|
||
@Override | ||
protected ImmutableMongod addExtraConfig(ImmutableMongod mongo) { | ||
try (var fos = Files.newOutputStream(serverCertKeyPath)) { | ||
Files.copy(serverCertPath, fos); | ||
Files.copy(serverKeyPath, fos); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return mongo.withMongodArguments(Start.to(mongo.mongodArguments().destination()) | ||
.initializedWith(MongodArguments.builder() | ||
.putArgs("--tlsCertificateKeyFile", serverCertKeyPath.toAbsolutePath().toString()) | ||
.putArgs("--tlsMode", "requireTLS") | ||
.putArgs("--tlsCAFile", serverCaPath.toAbsolutePath().toString()) | ||
.build())); | ||
|
||
} | ||
|
||
@Test | ||
public void testClientWorksWithTls() { | ||
assertThat(client.listDatabaseNames().first()).isNotEmpty(); | ||
assertThat(reactiveClient.listDatabases().collect().first().await().indefinitely()).isNotEmpty(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
extensions/mongodb-client/deployment/src/test/resources/tls-mongoclient.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
quarkus.mongodb.connection-string=mongodb://127.0.0.1:27018 | ||
quarkus.mongodb.tls-configuration-name=mongo | ||
quarkus.tls.mongo.key-store.pem.0.cert=target/certs/mongo-cert-client.crt | ||
quarkus.tls.mongo.key-store.pem.0.key=target/certs/mongo-cert-client.key | ||
quarkus.tls.mongo.trust-store.pem.certs=target/certs/mongo-cert-client-ca.crt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters