-
Notifications
You must be signed in to change notification settings - Fork 1.5k
CSFLE auto encryption tests improvements #1788
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2fe7827
Support auto encryption in unified tests
rozza 1b253aa
Support CSFLE unified tests
rozza e4be78d
Update driver-sync/src/test/functional/com/mongodb/client/unified/Uni…
rozza da62912
PR update
rozza a44378d
Checkstyle fix
rozza 1908f18
Scala syncadapter implement all methods
rozza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
98 changes: 98 additions & 0 deletions
98
...-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncClientEncryption.scala
This file contains hidden or 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,98 @@ | ||
/* | ||
* 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 org.mongodb.scala.syncadapter | ||
|
||
import com.mongodb.ClusterFixture.TIMEOUT_DURATION | ||
import com.mongodb.client.model.{ CreateCollectionOptions, CreateEncryptedCollectionParams } | ||
import com.mongodb.client.model.vault.{ | ||
DataKeyOptions, | ||
EncryptOptions, | ||
RewrapManyDataKeyOptions, | ||
RewrapManyDataKeyResult | ||
} | ||
import com.mongodb.client.result.DeleteResult | ||
import com.mongodb.client.vault.{ ClientEncryption => JClientEncryption } | ||
import com.mongodb.client.{ MongoDatabase => JMongoDatabase } | ||
import org.bson.{ BsonBinary, BsonDocument, BsonValue } | ||
import org.bson.conversions.Bson | ||
import org.mongodb.scala.vault.ClientEncryption | ||
import reactor.core.publisher.Mono | ||
|
||
import java.util.Objects.requireNonNull | ||
|
||
case class SyncClientEncryption(wrapped: ClientEncryption) extends JClientEncryption { | ||
|
||
override def createDataKey(kmsProvider: String): BsonBinary = | ||
requireNonNull(Mono.from(wrapped.createDataKey(kmsProvider, new DataKeyOptions)).block(TIMEOUT_DURATION)) | ||
|
||
override def createDataKey(kmsProvider: String, dataKeyOptions: DataKeyOptions): BsonBinary = | ||
requireNonNull(Mono.from(wrapped.createDataKey(kmsProvider, dataKeyOptions)).block(TIMEOUT_DURATION)) | ||
|
||
override def encrypt(value: BsonValue, options: EncryptOptions): BsonBinary = | ||
requireNonNull(Mono.from(wrapped.encrypt(value, options)).block(TIMEOUT_DURATION)) | ||
|
||
override def encryptExpression(expression: Bson, options: EncryptOptions): BsonDocument = | ||
requireNonNull(Mono.from(wrapped | ||
.encryptExpression(expression.toBsonDocument, options)).block(TIMEOUT_DURATION).toBsonDocument) | ||
|
||
override def decrypt(value: BsonBinary): BsonValue = | ||
requireNonNull(Mono.from(wrapped.decrypt(value)).block(TIMEOUT_DURATION)) | ||
|
||
override def deleteKey(id: BsonBinary): DeleteResult = | ||
requireNonNull(Mono.from(wrapped.deleteKey(id)).block(TIMEOUT_DURATION)) | ||
|
||
override def getKey(id: BsonBinary): BsonDocument = Mono.from(wrapped.getKey(id)).block(TIMEOUT_DURATION) | ||
|
||
override def getKeys = new SyncFindIterable[BsonDocument](wrapped.keys) | ||
|
||
override def addKeyAltName(id: BsonBinary, keyAltName: String): BsonDocument = | ||
Mono.from(wrapped.addKeyAltName(id, keyAltName)).block(TIMEOUT_DURATION) | ||
|
||
override def removeKeyAltName(id: BsonBinary, keyAltName: String): BsonDocument = | ||
Mono.from(wrapped.removeKeyAltName(id, keyAltName)).block(TIMEOUT_DURATION) | ||
|
||
override def getKeyByAltName(keyAltName: String): BsonDocument = | ||
Mono.from(wrapped.getKeyByAltName(keyAltName)).block(TIMEOUT_DURATION) | ||
|
||
override def rewrapManyDataKey(filter: Bson): RewrapManyDataKeyResult = | ||
requireNonNull(Mono.from(wrapped.rewrapManyDataKey(filter)).block(TIMEOUT_DURATION)) | ||
|
||
override def rewrapManyDataKey(filter: Bson, options: RewrapManyDataKeyOptions): RewrapManyDataKeyResult = | ||
requireNonNull(Mono.from(wrapped.rewrapManyDataKey(filter, options)).block(TIMEOUT_DURATION)) | ||
|
||
override def createEncryptedCollection( | ||
database: JMongoDatabase, | ||
collectionName: String, | ||
createCollectionOptions: CreateCollectionOptions, | ||
createEncryptedCollectionParams: CreateEncryptedCollectionParams | ||
): BsonDocument = { | ||
database match { | ||
case syncMongoDatabase: SyncMongoDatabase => | ||
requireNonNull(Mono.from(wrapped.createEncryptedCollection( | ||
syncMongoDatabase.wrapped, | ||
collectionName, | ||
createCollectionOptions, | ||
createEncryptedCollectionParams | ||
)).block(TIMEOUT_DURATION)) | ||
case _ => throw new AssertionError(s"Unexpected database type: ${database.getClass}") | ||
} | ||
} | ||
|
||
override def close(): Unit = { | ||
wrapped.close() | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
21 changes: 21 additions & 0 deletions
21
driver-scala/src/integrationTest/scala/org/mongodb/scala/unified/ClientEncryptionTest.scala
This file contains hidden or 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,21 @@ | ||
/* | ||
* 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 org.mongodb.scala.unified | ||
|
||
object ClientEncryptionTest extends UnifiedTest { | ||
val directory = "client-side-encryption/tests/unified" | ||
} |
21 changes: 21 additions & 0 deletions
21
driver-scala/src/integrationTest/scala/org/mongodb/scala/unified/UnifiedCrudTest.scala
This file contains hidden or 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,21 @@ | ||
/* | ||
* 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 org.mongodb.scala.unified | ||
|
||
object UnifiedCrudTest extends UnifiedTest { | ||
val directory = "crud" | ||
} |
66 changes: 66 additions & 0 deletions
66
driver-scala/src/integrationTest/scala/org/mongodb/scala/unified/UnifiedTest.scala
This file contains hidden or 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,66 @@ | ||
/* | ||
* 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 org.mongodb.scala.unified | ||
|
||
import com.mongodb.client.gridfs.{ GridFSBucket => JGridFSBucket } | ||
import com.mongodb.client.unified.UnifiedTest.Language | ||
import com.mongodb.client.unified.{ UnifiedTest, UnifiedTest => JUnifiedTest } | ||
import com.mongodb.client.vault.{ ClientEncryption => JClientEncryption } | ||
import com.mongodb.client.{ MongoClient => JMongoClient, MongoDatabase => JMongoDatabase } | ||
import com.mongodb.reactivestreams.client.internal.vault.ClientEncryptionImpl | ||
import com.mongodb.{ ClientEncryptionSettings => JClientEncryptionSettings, MongoClientSettings } | ||
import org.junit.jupiter.api.TestInstance | ||
import org.junit.jupiter.api.TestInstance.Lifecycle | ||
import org.junit.jupiter.params.provider.Arguments | ||
import org.mongodb.scala.MongoClient | ||
import org.mongodb.scala.MongoClient.DEFAULT_CODEC_REGISTRY | ||
import org.mongodb.scala.syncadapter.{ SyncClientEncryption, SyncMongoClient } | ||
import org.mongodb.scala.vault.ClientEncryption | ||
|
||
import java.util | ||
|
||
@TestInstance(Lifecycle.PER_CLASS) | ||
abstract class UnifiedTest extends JUnifiedTest { | ||
|
||
val directory: String | ||
|
||
def data(): util.Collection[Arguments] = JUnifiedTest.getTestData(directory, true, Language.SCALA) | ||
|
||
override def createMongoClient(settings: MongoClientSettings): JMongoClient = | ||
SyncMongoClient(MongoClient(MongoClientSettings.builder(settings).codecRegistry(DEFAULT_CODEC_REGISTRY).build())) | ||
|
||
override def createGridFSBucket(database: JMongoDatabase): JGridFSBucket = | ||
throw new NotImplementedError("Not implemented") | ||
|
||
override def createClientEncryption( | ||
keyVaultClient: JMongoClient, | ||
clientEncryptionSettings: JClientEncryptionSettings | ||
): JClientEncryption = { | ||
keyVaultClient match { | ||
case client: SyncMongoClient => | ||
SyncClientEncryption(ClientEncryption(new ClientEncryptionImpl( | ||
client.wrapped.wrapped, | ||
clientEncryptionSettings | ||
))) | ||
case _ => throw new IllegalArgumentException(s"Invalid keyVaultClient type: ${keyVaultClient.getClass}") | ||
} | ||
} | ||
|
||
override protected def isReactive: Boolean = true | ||
|
||
override protected def getLanguage: Language = Language.SCALA | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Could we match the formatting used below for consistency, unless this is from Spotless auto-formatting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes thats a Spotless automatic change - occurs once the line reaches a certain limit.