Skip to content

Commit 1ecc6dd

Browse files
Merge pull request #51 from SalusaSecondus/issue-32
Force use of SaveBehavior.PUT or SaveBehavior.CLOBBER. Issue #32
2 parents c4fc260 + 4ab941e commit 1ecc6dd

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/main/java/com/amazonaws/services/dynamodbv2/datamodeling/AttributeEncryptor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838

3939
/**
4040
* Encrypts all non-key fields prior to storing them in DynamoDB.
41-
* <em>This must be used with @{link SaveBehavior#PUT} or @{link SaveBehavior#CLOBBER}. Use of
42-
* any other @{code SaveBehavior} can result in data-corruption.</em>
41+
* <em>This must be used with @{link SaveBehavior#PUT} or @{link SaveBehavior#CLOBBER}.</em>
4342
*
4443
* @author Greg Rubin
4544
*/
@@ -77,7 +76,8 @@ public Map<String, AttributeValue> transform(final Parameters<?> parameters) {
7776
// unmodified fields. Thus, upon untransform, the signature verification will fail as it won't cover all
7877
// expected fields.
7978
if (parameters.isPartialUpdate()) {
80-
LOG.error("Use of AttributeEncryptor without SaveBehavior.PUT or SaveBehavior.CLOBBER is an error " +
79+
throw new DynamoDBMappingException(
80+
"Use of AttributeEncryptor without SaveBehavior.PUT or SaveBehavior.CLOBBER is an error " +
8181
"and can result in data-corruption. This occured while trying to save " +
8282
parameters.getModelClass());
8383
}

src/test/java/com/amazonaws/services/dynamodbv2/datamodeling/AttributeEncryptorTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ public void fullEncryption() {
129129
assertNotNull(encryptedAttributes.get("stringValue").getB());
130130
}
131131

132+
@Test(expected = DynamoDBMappingException.class)
133+
public void rejectsPartialUpdate() {
134+
Parameters<BaseClass> params = FakeParameters.getInstance(BaseClass.class, attribs, null,
135+
TABLE_NAME, HASH_KEY, RANGE_KEY, true);
136+
encryptor.transform(params);
137+
}
138+
132139
@Test(expected = DynamoDBMappingException.class)
133140
public void fullEncryptionBadSignature() {
134141
Parameters<BaseClass> params = FakeParameters.getInstance(BaseClass.class, attribs, null,

0 commit comments

Comments
 (0)