Test encryption during update

This commit is contained in:
Christoph Strobl
2022-11-16 10:12:33 +01:00
parent 4b8ac4d249
commit 73aeb7a425

View File

@@ -60,6 +60,7 @@ import org.springframework.data.mongodb.core.convert.MongoCustomConversions.Mong
import org.springframework.data.mongodb.core.convert.MongoValueConverter;
import org.springframework.data.mongodb.core.mapping.Encrypted;
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.data.mongodb.fle.FLETests.Config;
import org.springframework.data.mongodb.util.BsonUtils;
import org.springframework.data.util.Lazy;
@@ -151,6 +152,30 @@ public class FLETests {
assertThat(byWallet).isNull();
}
@Test
void theUpdateStuff() {
Person person = new Person();
person.id = "id-1";
person.name = "p1-name";
template.save(person);
Document savedDocument = template.execute(Person.class, collection -> {
return collection.find(new Document()).first();
});
System.out.println("saved: " + savedDocument.toJson());
template.update(Person.class).matching(where("id").is(person.id)).apply(Update.update("ssn", "secret-value")).first();
savedDocument = template.execute(Person.class, collection -> {
return collection.find(new Document()).first();
});
System.out.println("updated: " + savedDocument.toJson());
assertThat(savedDocument.get("ssn")).isInstanceOf(Binary.class);
}
@Test
void altKeyDetection(@Autowired ClientEncryption clientEncryption) throws InterruptedException {