Skip to content

Commit

Permalink
added test coverage for UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
agoston committed Dec 7, 2020
1 parent c6433c1 commit 67aadc1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/test/java/com/bol/system/EncryptSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void cleanDb() {
mongoTemplate.dropCollection(MyBean.class);
mongoTemplate.dropCollection(Person.class);
mongoTemplate.dropCollection(RenamedField.class);
mongoTemplate.dropCollection(PrimitiveField.class);
}

@Test
Expand Down Expand Up @@ -71,14 +72,18 @@ public void simpleEncryption() {
@Test
public void checkEncryptPrimitives() {
PrimitiveField bean = new PrimitiveField();
bean.id = UUID.randomUUID();
bean.primitiveInt = 1;
bean.encryptedPrimitiveInt = 2;
bean.data = new byte[]{1, 2, 3};
mongoTemplate.save(bean);

PrimitiveField fromDb = mongoTemplate.findOne(new Query(), PrimitiveField.class);

assertThat(fromDb.id).isEqualTo(bean.id);
assertThat(fromDb.primitiveInt).isEqualTo(bean.primitiveInt);
assertThat(fromDb.encryptedPrimitiveInt).isEqualTo(bean.encryptedPrimitiveInt);
assertThat(fromDb.data).isEqualTo(bean.data);

// FIXME: test for DB encoding of java primitives
}
Expand Down
22 changes: 21 additions & 1 deletion src/test/java/com/bol/system/model/PrimitiveField.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
package com.bol.system.model;

import com.bol.secure.Encrypted;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.util.UUID;

import static com.bol.system.model.PrimitiveField.MONGO_PRIMITIVEFIELD;
import static com.bol.system.model.RenamedField.MONGO_RENAMEDFIELD;

/*
> db.primitivefield.find().pretty();
{
"_id" : BinData(3,"m0jcj60kTHxdZZriPCPxuw=="),
"data" : BinData(0,"gIUv9oVQRNFDcialLXqdd/MiSrrkuSmOLmFr1M+x5hBk"),
"primitiveInt" : 1,
"encryptedPrimitiveInt" : BinData(0,"gCIePEAEVzZ8ymqz30WeSVCqkq3sLtk0Pc+6rjgMDaoO"),
"_class" : "com.bol.system.model.PrimitiveField"
}
*/
@Document(collection = MONGO_PRIMITIVEFIELD)
public class PrimitiveField {
public static final String MONGO_PRIMITIVEFIELD = "primitivefield";

// try using UUID as ID
@Id
public UUID id;

@Field
@Encrypted
public byte[] data;

@Field
public int primitiveInt;

Expand Down

0 comments on commit 67aadc1

Please sign in to comment.