Skip to content

Fix missing precision value when creating encryption settings. #4993

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Fix missing precision value when creating encryption settings.
  • Loading branch information
christophstrobl committed Jun 4, 2025
commit 2f761372a62dafd34c8bb724777671ca9757025d
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,12 @@ public Document toDocument() {
target.append("min", valueRange.getLowerBound().getValue().orElse((T) BsonNull.VALUE)).append("max",
valueRange.getUpperBound().getValue().orElse((T) BsonNull.VALUE));
}
if (precision != null) {
target.append("precision", precision);
}
if (sparsity != null) {
target.append("sparsity", sparsity);
}

return target;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration;
Expand Down Expand Up @@ -84,7 +83,7 @@ void beforeEach() {
template.dropCollection(COLLECTION_NAME);
}

@ParameterizedTest // GH-4185
@ParameterizedTest // GH-4185, GH-4989
@MethodSource("collectionOptions")
public void createsCollectionWithEncryptedFieldsCorrectly(CollectionOptions collectionOptions) {

Expand All @@ -103,23 +102,33 @@ public void createsCollectionWithEncryptedFieldsCorrectly(CollectionOptions coll
.containsEntry("bsonType", "long") //
.containsEntry("queries", List.of(Document.parse(
"{'queryType': 'range', 'contention': { '$numberLong' : '0' }, 'min': { '$numberLong' : '-1' }, 'max': { '$numberLong' : '1' }}")));

assertThat(fields.get(2)).containsEntry("path", "encryptedDouble") //
.containsEntry("bsonType", "double") //
.containsEntry("queries", List.of(Document.parse(
"{'queryType': 'range', 'contention': { '$numberLong' : '1' }, 'min': { '$numberDouble' : '-1.123' }, 'max': { '$numberDouble' : '1.123' }, 'precision': { '$numberInt' : '5'}}")));
}

private static Stream<Arguments> collectionOptions() {

BsonBinary key1 = new BsonBinary(UUID.randomUUID(), UuidRepresentation.STANDARD);
BsonBinary key2 = new BsonBinary(UUID.randomUUID(), UuidRepresentation.STANDARD);
BsonBinary key3 = new BsonBinary(UUID.randomUUID(), UuidRepresentation.STANDARD);

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

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

return Stream.of(Arguments.of(manualOptions), Arguments.of(schemaOptions));
Expand Down