-
Notifications
You must be signed in to change notification settings - Fork 71
fix : NPE if reading record without a signature fields #152
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
216150e
fix : NPE if reading record without a signature fields
e1dd0a4
Merge branch 'master' into master
bhuvangu 94b0355
Fix code formatting
e4c2a95
Add integration test for missing signature fields in document.
fbbe055
Updated decrypt logic to be less nested.
b9816f0
Add IT test for missing "MaterialDesc" fields.
c5d3354
Fix code format.
fe0b48c
Remove unwanted if condition and add better unit tests.
7808be0
Rename Test class to better represent the intent.
3a2cf4f
Fix Unit test
0ea193c
Remove `if` condition which throw a new error.
13de830
Rename IT class to be better
e2807d8
Rename unit test method to be better
9fde1f0
Correct formatting
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...va/com/amazonaws/services/dynamodbv2/mapper/integration/MissingSignatureFieldsITCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except | ||
* in compliance with the License. A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package com.amazonaws.services.dynamodbv2.mapper.integration; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.encryption.DoNotTouch; | ||
import com.amazonaws.services.dynamodbv2.mapper.encryption.StringAttributeTestClass; | ||
import com.amazonaws.services.dynamodbv2.mapper.encryption.TestDynamoDBMapperFactory; | ||
import com.amazonaws.services.dynamodbv2.model.AttributeValue; | ||
import com.amazonaws.services.dynamodbv2.model.PutItemRequest; | ||
import java.util.HashMap; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
/** Test reading of document which does not contain signature field. */ | ||
public class MissingSignatureFieldsITCase extends DynamoDBMapperCryptoIntegrationTestBase { | ||
bhuvangu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private static final String ORIGINAL_NAME_ATTRIBUTE = "originalName"; | ||
bhuvangu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private static final String STRING_ATTRIBUTE = "stringAttribute"; | ||
private static final List<Map<String, AttributeValue>> attrs = new LinkedList<>(); | ||
|
||
// Test data | ||
static { | ||
for (int i = 0; i < 5; i++) { | ||
Map<String, AttributeValue> attr = new HashMap<String, AttributeValue>(); | ||
attr.put(KEY_NAME, new AttributeValue().withS("" + startKey++)); | ||
attr.put(STRING_ATTRIBUTE, new AttributeValue().withS("" + startKey++)); | ||
attr.put(ORIGINAL_NAME_ATTRIBUTE, new AttributeValue().withS("" + startKey++)); | ||
attrs.add(attr); | ||
} | ||
} | ||
|
||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
DynamoDBMapperCryptoIntegrationTestBase.setUp(); | ||
for (Map<String, AttributeValue> attr : attrs) { | ||
dynamo.putItem(new PutItemRequest(TABLE_NAME, attr)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testLoadWithMissingSignatureFields() { | ||
DynamoDBMapper util = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo); | ||
|
||
for (Map<String, AttributeValue> attr : attrs) { | ||
AllDoNotTouchTable load = util.load(AllDoNotTouchTable.class, attr.get(KEY_NAME).getS()); | ||
assertEquals(load.getKey(), attr.get(KEY_NAME).getS()); | ||
assertEquals(load.getStringAttribute(), attr.get(STRING_ATTRIBUTE).getS()); | ||
} | ||
} | ||
|
||
@Test(expectedExceptions = DynamoDBMappingException.class) | ||
public void testLoadWithBadMissingSignatureFields() { | ||
bhuvangu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo) | ||
.load(StringAttributeTestClass.class, attrs.get(0).get(KEY_NAME).getS()); | ||
bhuvangu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@DynamoDBTable(tableName = "aws-java-sdk-util-crypto") | ||
public static final class AllDoNotTouchTable { | ||
bhuvangu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private String key; | ||
|
||
private String stringAttribute; | ||
|
||
@DynamoDBHashKey | ||
@DoNotTouch | ||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public void setKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
@DynamoDBAttribute | ||
@DoNotTouch | ||
public String getStringAttribute() { | ||
return stringAttribute; | ||
} | ||
|
||
public void setStringAttribute(String stringAttribute) { | ||
this.stringAttribute = stringAttribute; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
AllDoNotTouchTable that = (AllDoNotTouchTable) o; | ||
return key.equals(that.key) && stringAttribute.equals(that.stringAttribute); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.