Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAVA-5767 Support $lookup in CSFLE and QE #1638

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"_id": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"keyMaterial": {
"$binary": {
"base64": "sHe0kz57YW7v8g9VP9sf/+K1ex4JqKc5rf/URX3n3p8XdZ6+15uXPaSayC6adWbNxkFskuMCOifDoTT+rkqMtFkDclOy884RuGGtUysq3X7zkAWYTKi8QAfKkajvVbZl2y23UqgVasdQu3OVBQCrH/xY00nNAs/52e958nVjBuzQkSb1T8pKJAyjZsHJ60+FtnfafDZSTAIBJYn7UWBCwQ==",
"subType": "00"
}
},
"creationDate": {
"$date": {
"$numberLong": "1648914851981"
}
},
"updateDate": {
"$date": {
"$numberLong": "1648914851981"
}
},
"status": {
"$numberInt": "0"
},
"masterKey": {
"provider": "local"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"properties": {
"csfle": {
"encrypt": {
"keyId": [
{
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
}
],
"bsonType": "string",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
}
}
},
"bsonType": "object"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"properties": {
"csfle2": {
"encrypt": {
"keyId": [
{
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
}
],
"bsonType": "string",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
}
}
},
"bsonType": "object"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"escCollection": "enxcol_.qe.esc",
"ecocCollection": "enxcol_.qe.ecoc",
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "qe",
"bsonType": "string",
"queries": {
"queryType": "equality",
"contention": 0
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"escCollection": "enxcol_.qe2.esc",
"ecocCollection": "enxcol_.qe2.ecoc",
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "qe2",
"bsonType": "string",
"queries": {
"queryType": "equality",
"contention": 0
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.mongodb.client.model.bulk;

import com.mongodb.MongoBaseInterfaceAssertions;
import com.mongodb.testing.MongoBaseInterfaceAssertions;
import org.junit.jupiter.api.Test;

class BaseClientDeleteOptionsTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.mongodb.client.model.bulk;

import com.mongodb.MongoBaseInterfaceAssertions;
import com.mongodb.testing.MongoBaseInterfaceAssertions;
import org.junit.jupiter.api.Test;

class BaseClientUpdateOptionsTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.mongodb.client.model.bulk;

import com.mongodb.MongoBaseInterfaceAssertions;
import com.mongodb.testing.MongoBaseInterfaceAssertions;
import org.junit.jupiter.api.Test;

final class BaseClientUpsertableWriteModelOptionsTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.mongodb.client.model.bulk;

import com.mongodb.MongoBaseInterfaceAssertions;
import com.mongodb.testing.MongoBaseInterfaceAssertions;
import org.junit.jupiter.api.Test;

final class BaseClientWriteModelOptionsTest {
Expand Down
43 changes: 43 additions & 0 deletions driver-core/src/test/unit/com/mongodb/testing/MongoAssertions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2008-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.mongodb.testing;

import org.junit.jupiter.api.function.Executable;
import org.opentest4j.AssertionFailedError;

import static org.junit.jupiter.api.Assertions.assertThrows;

public final class MongoAssertions {

private MongoAssertions() {
//NOP
}

public static <T extends Throwable> void assertCause(
final Class<T> expectedCause, final String expectedMessageFragment, final Executable e) {
Throwable cause = assertThrows(Throwable.class, e);
while (cause.getCause() != null) {
cause = cause.getCause();
}
if (!cause.getMessage().contains(expectedMessageFragment)) {
throw new AssertionFailedError("Unexpected message: " + cause.getMessage(), cause);
}
if (!expectedCause.isInstance(cause)) {
throw new AssertionFailedError("Unexpected cause: " + cause.getClass(), assertThrows(Throwable.class, e));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.mongodb;
package com.mongodb.testing;

import org.reflections.Reflections;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.mongodb.lang.Nullable;
import com.mongodb.reactivestreams.client.MongoClient;
import org.bson.BsonDocument;
import reactor.core.publisher.Mono;
import reactor.core.publisher.Flux;

import static com.mongodb.assertions.Assertions.notNull;
import static com.mongodb.reactivestreams.client.internal.TimeoutHelper.databaseWithTimeoutDeferred;
Expand All @@ -35,8 +35,8 @@ class CollectionInfoRetriever {
this.client = notNull("client", client);
}

public Mono<BsonDocument> filter(final String databaseName, final BsonDocument filter, @Nullable final Timeout operationTimeout) {
public Flux<BsonDocument> filter(final String databaseName, final BsonDocument filter, @Nullable final Timeout operationTimeout) {
return databaseWithTimeoutDeferred(client.getDatabase(databaseName), TIMEOUT_ERROR_MESSAGE, operationTimeout)
.flatMap(database -> Mono.from(database.listCollections(BsonDocument.class).filter(filter).first()));
.flatMapMany(database -> Flux.from(database.listCollections(BsonDocument.class).filter(filter)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,8 @@ private void collInfo(final MongoCryptContext cryptContext,
} else {
collectionInfoRetriever.filter(databaseName, cryptContext.getMongoOperation(), operationTimeout)
.contextWrite(sink.contextView())
.doOnSuccess(result -> {
if (result != null) {
cryptContext.addMongoOperationResult(result);
}
.doOnNext(result -> cryptContext.addMongoOperationResult(result))
.doOnComplete(() -> {
cryptContext.completeMongoOperation();
executeStateMachineWithSink(cryptContext, databaseName, sink, operationTimeout);
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2008-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.mongodb.reactivestreams.client;

import com.mongodb.ClientEncryptionSettings;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.vault.ClientEncryption;
import com.mongodb.reactivestreams.client.syncadapter.SyncClientEncryption;
import com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient;
import com.mongodb.reactivestreams.client.vault.ClientEncryptions;

public class ClientSideEncryption25LookupProseTests extends com.mongodb.client.ClientSideEncryption25LookupProseTests {

@Override
protected MongoClient createMongoClient(final MongoClientSettings settings) {
return new SyncMongoClient(MongoClients.create(settings));
}

@Override
protected ClientEncryption createClientEncryption(final ClientEncryptionSettings settings) {
return new SyncClientEncryption(ClientEncryptions.create(settings));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.mongodb.client.internal;

import com.mongodb.client.ListCollectionsIterable;
import com.mongodb.client.MongoClient;
import com.mongodb.internal.time.Timeout;
import com.mongodb.lang.Nullable;
Expand All @@ -33,9 +34,8 @@ class CollectionInfoRetriever {
this.client = notNull("client", client);
}

@Nullable
public BsonDocument filter(final String databaseName, final BsonDocument filter, @Nullable final Timeout operationTimeout) {
return databaseWithTimeout(client.getDatabase(databaseName), TIMEOUT_ERROR_MESSAGE,
operationTimeout).listCollections(BsonDocument.class).filter(filter).first();
public ListCollectionsIterable<BsonDocument> filter(final String databaseName, final BsonDocument filter, @Nullable final Timeout operationTimeout) {
return databaseWithTimeout(client.getDatabase(databaseName), TIMEOUT_ERROR_MESSAGE, operationTimeout)
.listCollections(BsonDocument.class).filter(filter);
}
}
9 changes: 6 additions & 3 deletions driver-sync/src/main/com/mongodb/client/internal/Crypt.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.mongodb.MongoClientException;
import com.mongodb.MongoException;
import com.mongodb.MongoInternalException;
import com.mongodb.client.ListCollectionsIterable;
import com.mongodb.client.MongoClient;
import com.mongodb.client.model.vault.DataKeyOptions;
import com.mongodb.client.model.vault.EncryptOptions;
Expand All @@ -41,6 +42,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Map;
import java.util.function.Supplier;

Expand Down Expand Up @@ -308,9 +310,10 @@ private void fetchCredentials(final MongoCryptContext cryptContext) {

private void collInfo(final MongoCryptContext cryptContext, final String databaseName, @Nullable final Timeout operationTimeout) {
try {
BsonDocument collectionInfo = assertNotNull(collectionInfoRetriever).filter(databaseName, cryptContext.getMongoOperation(), operationTimeout);
if (collectionInfo != null) {
cryptContext.addMongoOperationResult(collectionInfo);
ListCollectionsIterable<BsonDocument> results = assertNotNull(collectionInfoRetriever)
.filter(databaseName, cryptContext.getMongoOperation(), operationTimeout);
for (BsonDocument result : results.into(new ArrayList<>())) {
cryptContext.addMongoOperationResult(result);
}
cryptContext.completeMongoOperation();
} catch (Throwable t) {
Expand Down
Loading