-
Notifications
You must be signed in to change notification settings - Fork 4
Fix potential null pointer exceptions #159
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
Changes from 4 commits
63d003d
5877ccd
508ed33
68762ab
c09a092
28fd822
9c4a3fb
96c1978
19cd698
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.ironcorelabs.tenantsecurity.kms.v1; | ||
|
|
||
| abstract class NullParsingValidator { | ||
| /** | ||
| * Throws an IllegalArgumentException if any of the fields were parsed as null. | ||
| */ | ||
| abstract void ensureNoNullsOrThrow() throws IllegalArgumentException; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.ironcorelabs.tenantsecurity.kms.v1; | ||
|
|
||
| class VoidSecurityEventResponse extends NullParsingValidator { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should comment this class I think. At first I wasn't sure why we'd want this, so I definitely won't remember in the future.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ended up going a different way with it. I made an overload of |
||
| @Override | ||
| void ensureNoNullsOrThrow() throws IllegalArgumentException {} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.ironcorelabs.tenantsecurity.kms.v1; | ||
|
|
||
| import java.io.StringReader; | ||
| import org.testng.annotations.Test; | ||
| import com.google.api.client.json.JsonObjectParser; | ||
| import com.google.api.client.json.gson.GsonFactory; | ||
|
|
||
| @Test(groups = {"unit"}) | ||
| public class JsonParsingTest { | ||
| static JsonObjectParser parser = new JsonObjectParser(new GsonFactory()); | ||
|
|
||
| @Test(expectedExceptions = IllegalArgumentException.class) | ||
| void batchKeysAreEmpty() throws Exception { | ||
| String json = "{}"; | ||
| BatchWrappedDocumentKeys type = parser.<BatchWrappedDocumentKeys>parseAndClose( | ||
| new StringReader(json), BatchWrappedDocumentKeys.class); | ||
| type.ensureNoNullsOrThrow(); | ||
| } | ||
|
|
||
| @Test(expectedExceptions = IllegalArgumentException.class) | ||
| void derivedKeyResponseIsEmpty() throws Exception { | ||
| String json = "{}"; | ||
| DeriveKeyResponse type = | ||
| parser.<DeriveKeyResponse>parseAndClose(new StringReader(json), DeriveKeyResponse.class); | ||
| type.ensureNoNullsOrThrow(); | ||
|
|
||
| } | ||
|
|
||
| @Test(expectedExceptions = IllegalArgumentException.class) | ||
| void unwrappedDocumentKeyErrors() throws Exception { | ||
| String json = "{}"; | ||
| UnwrappedDocumentKey type = parser.<UnwrappedDocumentKey>parseAndClose(new StringReader(json), | ||
| UnwrappedDocumentKey.class); | ||
| type.ensureNoNullsOrThrow(); | ||
| } | ||
|
|
||
| @Test(expectedExceptions = IllegalArgumentException.class) | ||
| void wrappedDocumentKeyErrors() throws Exception { | ||
| String json = "{}"; | ||
| WrappedDocumentKey type = | ||
| parser.<WrappedDocumentKey>parseAndClose(new StringReader(json), WrappedDocumentKey.class); | ||
| type.ensureNoNullsOrThrow(); | ||
| } | ||
|
|
||
| @Test(expectedExceptions = IllegalArgumentException.class) | ||
| void rekeyedDocumentKeyIsNull() throws Exception { | ||
| String json = "{}"; | ||
| RekeyedDocumentKey type = | ||
| parser.<RekeyedDocumentKey>parseAndClose(new StringReader(json), RekeyedDocumentKey.class); | ||
| type.ensureNoNullsOrThrow(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/bin/bash | ||
| # Be sure to set API_KEY, TENANT_ID, and NEW_TENANT_ID env vars | ||
| cd "${0%/*/*}" # set the current directory to the one above this script | ||
| mvn -Dsuite=test-suites/test-all test |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> | ||
|
|
||
| <suite name="allTests"> | ||
| <test name="allTests"> | ||
| <groups> | ||
| <run> | ||
| <include name="unit" /> | ||
| <include name="local-integration" /> | ||
| <include name="dev-integration" /> | ||
| <include name="local-batch-integration" /> | ||
| <include name="local-deterministic" /> | ||
| </run> | ||
| </groups> | ||
| <packages> | ||
| <package name=".*" /> | ||
| </packages> | ||
| </test> | ||
| </suite> |
Uh oh!
There was an error while loading. Please reload this page.