Skip to content
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

Fix NPE when user identity is null for SDK v1 #264

Merged
merged 3 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public static Record toRecordV1(final DynamodbEvent.DynamodbStreamRecord record)
.withEventSource(record.getEventSource())
.withEventVersion(record.getEventVersion())
.withUserIdentity(
DynamodbIdentityTransformer.toIdentityV1(record.getUserIdentity())
record.getUserIdentity() != null
? DynamodbIdentityTransformer.toIdentityV1(record.getUserIdentity())
: null
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ public static StreamRecord toStreamRecordV1(final com.amazonaws.services.lambda.
DynamodbAttributeValueTransformer.toAttributeValueMapV1(streamRecord.getKeys())
)
.withNewImage(
DynamodbAttributeValueTransformer.toAttributeValueMapV1(streamRecord.getNewImage())
streamRecord.getNewImage() != null
? DynamodbAttributeValueTransformer.toAttributeValueMapV1(streamRecord.getNewImage())
: null
)
.withOldImage(
DynamodbAttributeValueTransformer.toAttributeValueMapV1(streamRecord.getOldImage())
streamRecord.getOldImage() != null
? DynamodbAttributeValueTransformer.toAttributeValueMapV1(streamRecord.getOldImage())
: null
)
.withSequenceNumber(streamRecord.getSequenceNumber())
.withSizeBytes(streamRecord.getSizeBytes())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.amazonaws.services.dynamodbv2.model.OperationType;
import com.amazonaws.services.dynamodbv2.model.Record;
import com.amazonaws.services.lambda.runtime.events.DynamodbEvent;
import com.amazonaws.services.lambda.runtime.events.transformers.v1.DynamodbEventTransformer;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -49,4 +50,14 @@ public void testToRecordV1() {
Assertions.assertEquals(record_v1, convertedRecord);
}

@Test
public void testToRecordV1WhenUserIdentityIsNull() {
DynamodbEvent.DynamodbStreamRecord record = record_event.clone();
record.setUserIdentity(null);

Assertions.assertDoesNotThrow(() -> {
com.amazonaws.services.lambda.runtime.events.transformers.v1.dynamodb.DynamodbRecordTransformer.toRecordV1(record);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,24 @@ public void testToStreamRecordV1() {
StreamRecord convertedStreamRecord = DynamodbStreamRecordTransformer.toStreamRecordV1(streamRecord_event);
Assertions.assertEquals(streamRecord_v1, convertedStreamRecord);
}

@Test
public void testToStreamRecordV1WhenOldImageIsNull() {
com.amazonaws.services.lambda.runtime.events.models.dynamodb.StreamRecord streamRecord = streamRecord_event.clone();
streamRecord.setOldImage(null);

Assertions.assertDoesNotThrow(() -> {
com.amazonaws.services.lambda.runtime.events.transformers.v1.dynamodb.DynamodbStreamRecordTransformer.toStreamRecordV1(streamRecord);
});
}

@Test
public void testToStreamRecordV1WhenNewImageIsNull() {
com.amazonaws.services.lambda.runtime.events.models.dynamodb.StreamRecord streamRecord = streamRecord_event.clone();
streamRecord.setNewImage(null);

Assertions.assertDoesNotThrow(() -> {
com.amazonaws.services.lambda.runtime.events.transformers.v1.dynamodb.DynamodbStreamRecordTransformer.toStreamRecordV1(streamRecord);
});
}
}