Skip to content

Commit 5d5e474

Browse files
christophstroblmp911de
authored andcommitted
Fix missing precision value when creating encryption settings.
Original pull request: #4993 Closes: #4989
1 parent fca17fc commit 5d5e474

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/schema/QueryCharacteristics.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,12 @@ public Document toDocument() {
253253
target.append("min", valueRange.getLowerBound().getValue().orElse((T) BsonNull.VALUE)).append("max",
254254
valueRange.getUpperBound().getValue().orElse((T) BsonNull.VALUE));
255255
}
256+
if (precision != null) {
257+
target.append("precision", precision);
258+
}
256259
if (sparsity != null) {
257260
target.append("sparsity", sparsity);
258261
}
259-
260262
return target;
261263
}
262264
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/encryption/MongoQueryableEncryptionCollectionCreationTests.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.junit.jupiter.params.ParameterizedTest;
3232
import org.junit.jupiter.params.provider.Arguments;
3333
import org.junit.jupiter.params.provider.MethodSource;
34-
3534
import org.springframework.beans.factory.annotation.Autowired;
3635
import org.springframework.context.annotation.Configuration;
3736
import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration;
@@ -84,7 +83,7 @@ void beforeEach() {
8483
template.dropCollection(COLLECTION_NAME);
8584
}
8685

87-
@ParameterizedTest // GH-4185
86+
@ParameterizedTest // GH-4185, GH-4989
8887
@MethodSource("collectionOptions")
8988
public void createsCollectionWithEncryptedFieldsCorrectly(CollectionOptions collectionOptions) {
9089

@@ -103,23 +102,33 @@ public void createsCollectionWithEncryptedFieldsCorrectly(CollectionOptions coll
103102
.containsEntry("bsonType", "long") //
104103
.containsEntry("queries", List.of(Document.parse(
105104
"{'queryType': 'range', 'contention': { '$numberLong' : '0' }, 'min': { '$numberLong' : '-1' }, 'max': { '$numberLong' : '1' }}")));
105+
106+
assertThat(fields.get(2)).containsEntry("path", "encryptedDouble") //
107+
.containsEntry("bsonType", "double") //
108+
.containsEntry("queries", List.of(Document.parse(
109+
"{'queryType': 'range', 'contention': { '$numberLong' : '1' }, 'min': { '$numberDouble' : '-1.123' }, 'max': { '$numberDouble' : '1.123' }, 'precision': { '$numberInt' : '5'}}")));
106110
}
107111

108112
private static Stream<Arguments> collectionOptions() {
109113

110114
BsonBinary key1 = new BsonBinary(UUID.randomUUID(), UuidRepresentation.STANDARD);
111115
BsonBinary key2 = new BsonBinary(UUID.randomUUID(), UuidRepresentation.STANDARD);
116+
BsonBinary key3 = new BsonBinary(UUID.randomUUID(), UuidRepresentation.STANDARD);
112117

113118
CollectionOptions manualOptions = CollectionOptions.encryptedCollection(options -> options //
114119
.queryable(encrypted(int32("encryptedInt")).keys(key1), range().min(5).max(100).contention(1)) //
115120
.queryable(encrypted(JsonSchemaProperty.int64("nested.encryptedLong")).keys(key2),
116-
range().min(-1L).max(1L).contention(0)));
121+
range().min(-1L).max(1L).contention(0)) //
122+
.queryable(encrypted(JsonSchemaProperty.float64("encryptedDouble")).keys(key3),
123+
range().min(-1.123D).max(1.123D).precision(5).contention(1)));
117124

118125
CollectionOptions schemaOptions = CollectionOptions.encryptedCollection(MongoJsonSchema.builder()
119126
.property(
120127
queryable(encrypted(int32("encryptedInt")).keyId(key1), List.of(range().min(5).max(100).contention(1))))
121128
.property(queryable(encrypted(int64("nested.encryptedLong")).keyId(key2),
122129
List.of(range().min(-1L).max(1L).contention(0))))
130+
.property(queryable(encrypted(float64("encryptedDouble")).keyId(key3),
131+
List.of(range().min(-1.123D).max(1.123D).precision(5).contention(1))))
123132
.build());
124133

125134
return Stream.of(Arguments.of(manualOptions), Arguments.of(schemaOptions));

0 commit comments

Comments
 (0)