Browse Source

switch tests

issue/4185-light
Christoph Strobl 9 months ago
parent
commit
6e9a184299
No known key found for this signature in database
GPG Key ID: E6054036D0C37A4B
  1. 17
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/schema/IdentifiableJsonSchemaProperty.java
  2. 48
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/schema/MongoJsonSchemaUnitTests.java

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

@ -24,6 +24,7 @@ import java.util.UUID; @@ -24,6 +24,7 @@ import java.util.UUID;
import org.bson.Document;
import org.springframework.data.domain.Range;
import org.springframework.data.mongodb.core.EncryptionAlgorithms;
import org.springframework.data.mongodb.core.schema.QueryCharacteristics.QueryCharacteristic;
import org.springframework.data.mongodb.core.schema.TypedJsonSchemaObject.ArrayJsonSchemaObject;
import org.springframework.data.mongodb.core.schema.TypedJsonSchemaObject.BooleanJsonSchemaObject;
@ -1117,13 +1118,25 @@ public class IdentifiableJsonSchemaProperty<T extends JsonSchemaObject> implemen @@ -1117,13 +1118,25 @@ public class IdentifiableJsonSchemaProperty<T extends JsonSchemaObject> implemen
return new EncryptedJsonSchemaProperty(target);
}
/**
* Create new instance of {@link EncryptedJsonSchemaProperty} with {@literal Range} encryption, wrapping the given
* {@link JsonSchemaProperty target}.
*
* @param target must not be {@literal null}.
* @return new instance of {@link EncryptedJsonSchemaProperty}.
* @since 4.5
*/
public static EncryptedJsonSchemaProperty rangeEncrypted(JsonSchemaProperty target) {
return new EncryptedJsonSchemaProperty(target).algorithm(EncryptionAlgorithms.RANGE);
}
/**
* Use {@literal AEAD_AES_256_CBC_HMAC_SHA_512-Random} algorithm.
*
* @return new instance of {@link EncryptedJsonSchemaProperty}.
*/
public EncryptedJsonSchemaProperty aead_aes_256_cbc_hmac_sha_512_random() {
return algorithm("AEAD_AES_256_CBC_HMAC_SHA_512-Random");
return algorithm(EncryptionAlgorithms.AEAD_AES_256_CBC_HMAC_SHA_512_Random);
}
/**
@ -1132,7 +1145,7 @@ public class IdentifiableJsonSchemaProperty<T extends JsonSchemaObject> implemen @@ -1132,7 +1145,7 @@ public class IdentifiableJsonSchemaProperty<T extends JsonSchemaObject> implemen
* @return new instance of {@link EncryptedJsonSchemaProperty}.
*/
public EncryptedJsonSchemaProperty aead_aes_256_cbc_hmac_sha_512_deterministic() {
return algorithm("AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic");
return algorithm(EncryptionAlgorithms.AEAD_AES_256_CBC_HMAC_SHA_512_Deterministic);
}
/**

48
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/schema/MongoJsonSchemaUnitTests.java

@ -15,26 +15,23 @@ @@ -15,26 +15,23 @@
*/
package org.springframework.data.mongodb.core.schema;
import static java.util.Arrays.asList;
import static org.springframework.data.mongodb.core.schema.JsonSchemaProperty.*;
import static org.springframework.data.mongodb.test.util.Assertions.*;
import static org.springframework.data.mongodb.core.schema.IdentifiableJsonSchemaProperty.EncryptedJsonSchemaProperty.rangeEncrypted;
import static org.springframework.data.mongodb.core.schema.JsonSchemaProperty.encrypted;
import static org.springframework.data.mongodb.core.schema.JsonSchemaProperty.number;
import static org.springframework.data.mongodb.core.schema.JsonSchemaProperty.queryable;
import static org.springframework.data.mongodb.core.schema.JsonSchemaProperty.string;
import static org.springframework.data.mongodb.test.util.Assertions.assertThat;
import static org.springframework.data.mongodb.test.util.Assertions.assertThatIllegalArgumentException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import org.bson.BsonArray;
import org.bson.BsonDocument;
import org.bson.BsonInt32;
import org.bson.BsonInt64;
import org.bson.BsonNull;
import org.bson.BsonString;
import org.bson.Document;
import org.bson.json.JsonWriterSettings;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.mongodb.core.schema.IdentifiableJsonSchemaProperty.QueryableJsonSchemaProperty;
/**
* Unit tests for {@link MongoJsonSchema}.
@ -120,27 +117,16 @@ class MongoJsonSchemaUnitTests { @@ -120,27 +117,16 @@ class MongoJsonSchemaUnitTests {
QueryCharacteristics characteristics = new QueryCharacteristics();
characteristics.addQuery(QueryCharacteristics.range().contention(0).trimFactor(1).sparsity(1).min(0).max(200));
QueryableJsonSchemaProperty property = queryable(encrypted(number("mypath")), characteristics);
//Document document = MongoJsonSchema.builder().property(property).build().schemaDocument();
Document document = property.toDocument();
System.out.println(document.toJson(JsonWriterSettings.builder().indent(true).build()));
BsonDocument encryptedFields = new BsonDocument().append("fields",
new BsonArray(asList(
new BsonDocument("keyId", BsonNull.VALUE).append("path", new BsonString("encryptedInt"))
.append("bsonType", new BsonString("int"))
.append("queries",
new BsonDocument("queryType", new BsonString("range")).append("contention", new BsonInt64(0L))
.append("trimFactor", new BsonInt32(1)).append("sparsity", new BsonInt64(1))
.append("min", new BsonInt32(0)).append("max", new BsonInt32(200))),
new BsonDocument("keyId", BsonNull.VALUE).append("path", new BsonString("encryptedLong"))
.append("bsonType", new BsonString("long")).append("queries",
new BsonDocument("queryType", new BsonString("range")).append("contention", new BsonInt64(0L))
.append("trimFactor", new BsonInt32(1)).append("sparsity", new BsonInt64(1))
.append("min", new BsonInt64(1000)).append("max", new BsonInt64(9999))))));
MongoJsonSchema schema = MongoJsonSchema.builder().properties( //
queryable(rangeEncrypted(number("ssn")), characteristics)).build();
assertThat(schema.toDocument()).isEqualTo(new Document("$jsonSchema",
new Document("type", "object").append("properties",
new Document("ssn",
new Document("encrypt",
new Document("bsonType", "long").append("algorithm", "Range").append("queries",
List.of(new Document("contention", 0L).append("trimFactor", 1).append("sparsity", 1L)
.append("queryType", "range").append("min", 0).append("max", 200))))))));
}
@Test // DATAMONGO-1835

Loading…
Cancel
Save