-
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.
feat: Add tls registry to mongo client
- Loading branch information
Showing
9 changed files
with
184 additions
and
21 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
77 changes: 77 additions & 0 deletions
77
...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,77 @@ | ||
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.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.CertificateFiles; | ||
import io.smallrye.certs.Format; | ||
import io.smallrye.certs.junit5.Certificate; | ||
import io.smallrye.certs.junit5.Certificates; | ||
|
||
@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); | ||
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())); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Test | ||
public void testClientWorksWithTls() { | ||
assertThat(client.listDatabaseNames().first()).isNotEmpty(); | ||
assertThat(reactiveClient.listDatabases().collect().first().await().indefinitely()).isNotEmpty(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
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,6 @@ | ||
quarkus.mongodb.connection-string=mongodb://127.0.0.1:27018 | ||
quarkus.mongodb.tls=true | ||
quarkus.mongodb.tls-configuration-name=mongo | ||
quarkus.tls.mongo.trust-store.pem.certs=target/certs/mongo-cert-client-ca.crt | ||
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 |
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