Browse Source

Add test using combination of Encrypted and Queryable

issue/4185-light
Christoph Strobl 9 months ago
parent
commit
a522bb9e06
No known key found for this signature in database
GPG Key ID: E6054036D0C37A4B
  1. 29
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MappingMongoJsonSchemaCreatorUnitTests.java

29
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MappingMongoJsonSchemaCreatorUnitTests.java

@ -39,6 +39,7 @@ import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.data.mongodb.core.mapping.FieldType; import org.springframework.data.mongodb.core.mapping.FieldType;
import org.springframework.data.mongodb.core.mapping.MongoId; import org.springframework.data.mongodb.core.mapping.MongoId;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext; import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.core.mapping.Queryable;
import org.springframework.data.mongodb.core.mapping.RangeEncrypted; import org.springframework.data.mongodb.core.mapping.RangeEncrypted;
import org.springframework.data.mongodb.core.schema.JsonSchemaObject.Type; import org.springframework.data.mongodb.core.schema.JsonSchemaObject.Type;
import org.springframework.data.mongodb.core.schema.JsonSchemaProperty; import org.springframework.data.mongodb.core.schema.JsonSchemaProperty;
@ -284,35 +285,45 @@ class MappingMongoJsonSchemaCreatorUnitTests {
.containsEntry("properties.domainTypeValue", Document.parse("{'encrypt': {'bsonType': 'object' } }")); .containsEntry("properties.domainTypeValue", Document.parse("{'encrypt': {'bsonType': 'object' } }"));
} }
@Test // GH-4454 @Test // GH-4185
void qeRangeEncryptedProperties() { void qeRangeEncryptedProperties() {
MongoJsonSchema schema = MongoJsonSchemaCreator.create() // MongoJsonSchema schema = MongoJsonSchemaCreator.create() //
.filter(MongoJsonSchemaCreator.encryptedOnly()) // filter non encrypted fields .filter(MongoJsonSchemaCreator.encryptedOnly()) // filter non encrypted fields
.createSchemaFor(RangeEncryptedRoot.class); .createSchemaFor(QueryableEncryptedRoot.class);
String expectedForInt = """ String expectedForInt = """
{ 'encrypt' : { { 'encrypt' : {
'algorithm' : 'Range', 'algorithm' : 'Range',
'bsonType' : 'int', 'bsonType' : 'int',
'queries' : [ 'queries' : [
{ 'contention' : { '$numberLong' : '0' }, 'max' : 200, 'min' : 0, 'queryType' : 'range', 'sparsity' : 1, 'trimFactor' : 1 } { 'queryType' : 'range', 'contention' : { '$numberLong' : '0' }, 'max' : 200, 'min' : 0, 'sparsity' : 1, 'trimFactor' : 1 }
]
}}""";
String expectedForRootLong = """
{ 'encrypt' : {
'algorithm' : 'Range',
'bsonType' : 'long',
'queries' : [
{ 'queryType' : 'range', contention : { '$numberLong' : '0' }, 'sparsity' : 0 }
] ]
}}"""; }}""";
String expectedForLong = """ String expectedForNestedLong = """
{ 'encrypt' : { { 'encrypt' : {
'algorithm' : 'Range', 'algorithm' : 'Range',
'bsonType' : 'long', 'bsonType' : 'long',
'queries' : [ 'queries' : [
{ contention : { '$numberLong' : '1' }, 'max' : { '$numberLong' : '1' }, 'min' : { '$numberLong' : '-1' }, 'queryType' : 'range', 'sparsity' : 1, 'trimFactor' : 1 } { 'queryType' : 'range', contention : { '$numberLong' : '1' }, 'max' : { '$numberLong' : '1' }, 'min' : { '$numberLong' : '-1' }, 'sparsity' : 1, 'trimFactor' : 1 }
] ]
}}"""; }}""";
assertThat(schema.schemaDocument()) // assertThat(schema.schemaDocument()) //
.doesNotContainKey("properties.unencrypted") // .doesNotContainKey("properties.unencrypted") //
.containsEntry("properties.encryptedInt", Document.parse(expectedForInt)) .containsEntry("properties.encryptedInt", Document.parse(expectedForInt))
.containsEntry("properties.nested.properties.encrypted_long", Document.parse(expectedForLong)); .containsEntry("properties.encryptedLong", Document.parse(expectedForRootLong))
.containsEntry("properties.nested.properties.encrypted_long", Document.parse(expectedForNestedLong));
} }
@ -728,13 +739,17 @@ class MappingMongoJsonSchemaCreatorUnitTests {
@Encrypted SomeDomainType domainTypeValue; @Encrypted SomeDomainType domainTypeValue;
} }
static class RangeEncryptedRoot { static class QueryableEncryptedRoot {
String unencrypted; String unencrypted;
@RangeEncrypted(contentionFactor = 0L, rangeOptions = "{ 'min': 0, 'max': 200, 'trimFactor': 1, 'sparsity': 1}") // @RangeEncrypted(contentionFactor = 0L, rangeOptions = "{ 'min': 0, 'max': 200, 'trimFactor': 1, 'sparsity': 1}") //
Integer encryptedInt; Integer encryptedInt;
@Encrypted(algorithm = "Range")
@Queryable(contentionFactor = 0L, queryType = "range", queryAttributes = "{ 'sparsity': 0 }") //
Long encryptedLong;
NestedRangeEncrypted nested; NestedRangeEncrypted nested;
} }

Loading…
Cancel
Save