Boost up test coverage a bit
diff --git a/release-notes/CREDITS b/release-notes/CREDITS
index 4aaca26..bcb11a7 100644
--- a/release-notes/CREDITS
+++ b/release-notes/CREDITS
@@ -107,3 +107,8 @@
Kevin Gallardo (newkek@github)
* Reported #296: JsonParserSequence skips a token on a switched Parser
(2.8.0)
+
+Alex Yursha (AlexYursha@github)
+ * Contributed #312: Add `JsonProcessingException.clearLocation()` to allow clearing
+ possibly security-sensitive information
+ (2.9.0)
diff --git a/release-notes/VERSION b/release-notes/VERSION
index c9d34dc..cdb5e2e 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -17,6 +17,9 @@
2.9.0 (not yet released)
#304: Optimize `NumberOutput.outputLong()` method
+#312: Add `JsonProcessingException.clearLocation()` to allow clearing
+ possibly security-sensitive information
+ (contributed by Alex Y)
2.8.4 (14-Oct-2016)
diff --git a/src/main/java/com/fasterxml/jackson/core/JsonProcessingException.java b/src/main/java/com/fasterxml/jackson/core/JsonProcessingException.java
index fbaf4c7..23599b1 100644
--- a/src/main/java/com/fasterxml/jackson/core/JsonProcessingException.java
+++ b/src/main/java/com/fasterxml/jackson/core/JsonProcessingException.java
@@ -55,7 +55,10 @@
/**
* Method that allows to remove context information from this exception's message.
- * Useful when you are parsing security-sensitive data and don't want original data excerpts to be present in Jackson parser error messages.
+ * Useful when you are parsing security-sensitive data and don't want original data excerpts
+ * to be present in Jackson parser error messages.
+ *
+ * @since 2.9
*/
public void clearLocation() { _location = null; }
diff --git a/src/test/java/com/fasterxml/jackson/core/TestExceptions.java b/src/test/java/com/fasterxml/jackson/core/TestExceptions.java
index 0301b19..fbbb74f 100644
--- a/src/test/java/com/fasterxml/jackson/core/TestExceptions.java
+++ b/src/test/java/com/fasterxml/jackson/core/TestExceptions.java
@@ -16,6 +16,20 @@
String orig = exc.getOriginalMessage();
assertEquals("Foobar", orig);
assertTrue(msg.length() > orig.length());
+
+ // and another
+ JsonProcessingException exc2 = new JsonProcessingException("Second",
+ JsonLocation.NA, exc);
+ assertSame(exc, exc2.getCause());
+ exc2.clearLocation();
+ assertNull(exc2.getLocation());
+
+ // and yet with null
+ JsonProcessingException exc3 = new JsonProcessingException(exc);
+ assertNull(exc3.getOriginalMessage());
+ assertEquals("N/A", exc3.getMessage());
+
+ assertEquals("com.fasterxml.jackson.core.JsonProcessingException: N/A", exc3.toString());
}
// [core#198]
diff --git a/src/test/java/com/fasterxml/jackson/core/TestLocation.java b/src/test/java/com/fasterxml/jackson/core/TestLocation.java
new file mode 100644
index 0000000..d993129
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/core/TestLocation.java
@@ -0,0 +1,21 @@
+package com.fasterxml.jackson.core;
+
+public class TestLocation extends BaseTest
+{
+ public void testBasics()
+ {
+ JsonLocation loc1 = new JsonLocation("src", 10L, 10L, 1, 2);
+ JsonLocation loc2 = new JsonLocation(null, 10L, 10L, 3, 2);
+ assertEquals(loc1, loc1);
+ assertFalse(loc1.equals(null));
+ assertFalse(loc1.equals(loc2));
+ assertFalse(loc2.equals(loc1));
+
+ // don't care about what it is; should not compute to 0 with data above
+ assertTrue(loc1.hashCode() != 0);
+ assertTrue(loc2.hashCode() != 0);
+
+ assertEquals("[Source: src; line: 1, column: 2]", loc1.toString());
+ assertEquals("[Source: UNKNOWN; line: 3, column: 2]", loc2.toString());
+ }
+}
diff --git a/src/test/java/com/fasterxml/jackson/core/TestVersions.java b/src/test/java/com/fasterxml/jackson/core/TestVersions.java
index c7b6feb..865be6f 100644
--- a/src/test/java/com/fasterxml/jackson/core/TestVersions.java
+++ b/src/test/java/com/fasterxml/jackson/core/TestVersions.java
@@ -6,7 +6,7 @@
import com.fasterxml.jackson.core.util.BufferRecycler;
/**
- * Tests to verify [JACKSON-278]
+ * Tests to verify functioning of {@link Version} class.
*/
public class TestVersions extends com.fasterxml.jackson.core.BaseTest
{
@@ -22,6 +22,18 @@
jgen.close();
}
+ public void testMisc() {
+ Version unk = Version.unknownVersion();
+ assertEquals("0.0.0", unk.toString());
+ assertEquals("//0.0.0", unk.toFullString());
+ assertTrue(unk.equals(unk));
+
+ Version other = new Version(2, 8, 4, "",
+ "groupId", "artifactId");
+ assertEquals("2.8.4", other.toString());
+ assertEquals("groupId/artifactId/2.8.4", other.toFullString());
+ }
+
/*
/**********************************************************
/* Helper methods
diff --git a/src/test/java/com/fasterxml/jackson/core/base64/Base64CodecTest.java b/src/test/java/com/fasterxml/jackson/core/base64/Base64CodecTest.java
new file mode 100644
index 0000000..60c148e
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/core/base64/Base64CodecTest.java
@@ -0,0 +1,106 @@
+package com.fasterxml.jackson.core.base64;
+
+import org.junit.Assert;
+
+import com.fasterxml.jackson.core.*;
+
+public class Base64CodecTest
+ extends com.fasterxml.jackson.core.BaseTest
+{
+ public void testVariantAccess()
+ {
+ for (Base64Variant var : new Base64Variant[] {
+ Base64Variants.MIME,
+ Base64Variants.MIME_NO_LINEFEEDS,
+ Base64Variants.MODIFIED_FOR_URL,
+ Base64Variants.PEM
+ }) {
+ assertSame(var, Base64Variants.valueOf(var.getName()));
+ }
+
+ try {
+ Base64Variants.valueOf("foobar");
+ fail("Should not pass");
+ } catch (IllegalArgumentException e) {
+ verifyException(e, "No Base64Variant with name 'foobar'");
+ }
+ }
+
+ public void testProps()
+ {
+ Base64Variant std = Base64Variants.MIME;
+ // let's verify basic props of std cocec
+ assertEquals("MIME", std.getName());
+ assertEquals("MIME", std.toString());
+ assertTrue(std.usesPadding());
+ assertFalse(std.usesPaddingChar('X'));
+ assertEquals('=', std.getPaddingChar());
+ assertTrue(std.usesPaddingChar('='));
+ assertEquals((byte) '=', std.getPaddingByte());
+ assertEquals(76, std.getMaxLineLength());
+ }
+
+ public void testCharEncoding() throws Exception
+ {
+ Base64Variant std = Base64Variants.MIME;
+ assertEquals(Base64Variant.BASE64_VALUE_INVALID, std.decodeBase64Char('?'));
+ assertEquals(Base64Variant.BASE64_VALUE_INVALID, std.decodeBase64Char((int) '?'));
+ assertEquals(Base64Variant.BASE64_VALUE_INVALID, std.decodeBase64Char((char) 0xA0));
+ assertEquals(Base64Variant.BASE64_VALUE_INVALID, std.decodeBase64Char(0xA0));
+
+ assertEquals(Base64Variant.BASE64_VALUE_INVALID, std.decodeBase64Byte((byte) '?'));
+ assertEquals(Base64Variant.BASE64_VALUE_INVALID, std.decodeBase64Byte((byte) 0xA0));
+
+ assertEquals(0, std.decodeBase64Char('A'));
+ assertEquals(1, std.decodeBase64Char((int) 'B'));
+ assertEquals(2, std.decodeBase64Char((byte)'C'));
+
+ assertEquals(0, std.decodeBase64Byte((byte) 'A'));
+ assertEquals(1, std.decodeBase64Byte((byte) 'B'));
+ assertEquals(2, std.decodeBase64Byte((byte)'C'));
+
+ assertEquals('/', std.encodeBase64BitsAsChar(63));
+ assertEquals((byte) 'b', std.encodeBase64BitsAsByte(27));
+
+ String EXP_STR = "HwdJ";
+ int TRIPLET = 0x1F0749;
+ StringBuilder sb = new StringBuilder();
+ std.encodeBase64Chunk(sb, TRIPLET);
+ assertEquals(EXP_STR, sb.toString());
+
+ byte[] exp = EXP_STR.getBytes("UTF-8");
+ byte[] act = new byte[exp.length];
+ std.encodeBase64Chunk(TRIPLET, act, 0);
+ Assert.assertArrayEquals(exp, act);
+ }
+
+ public void testConvenienceMethods() throws Exception
+ {
+ Base64Variant std = Base64Variants.MIME;
+
+ byte[] input = new byte[] { 1, 2, 34, 127, -1 };
+ String encoded = std.encode(input, false);
+ byte[] decoded = std.decode(encoded);
+ Assert.assertArrayEquals(input, decoded);
+
+ assertEquals(quote(encoded), std.encode(input, true));
+ }
+
+ @SuppressWarnings("unused")
+ public void testErrors() throws Exception
+ {
+ try {
+ Base64Variant b = new Base64Variant("foobar", "xyz", false, '!', 24);
+ fail("Should not pass");
+ } catch (IllegalArgumentException iae) {
+ verifyException(iae, "length must be exactly");
+ }
+
+ try {
+ Base64Variants.MIME.decode("!@##@%$#%&*^(&)(*");
+ fail("Should not pass");
+ } catch (IllegalArgumentException iae) {
+ verifyException(iae, "Illegal character");
+ }
+ }
+}
diff --git a/src/test/java/com/fasterxml/jackson/core/base64/TestBase64Codec.java b/src/test/java/com/fasterxml/jackson/core/base64/TestBase64Codec.java
deleted file mode 100644
index 4b4b7b2..0000000
--- a/src/test/java/com/fasterxml/jackson/core/base64/TestBase64Codec.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.fasterxml.jackson.core.base64;
-
-import org.junit.Assert;
-
-import com.fasterxml.jackson.core.*;
-
-public class TestBase64Codec
- extends com.fasterxml.jackson.core.BaseTest
-{
- public void testProps()
- {
- Base64Variant std = Base64Variants.MIME;
- // let's verify basic props of std cocec
- assertEquals("MIME", std.getName());
- assertEquals("MIME", std.toString());
- assertTrue(std.usesPadding());
- assertFalse(std.usesPaddingChar('X'));
- assertEquals('=', std.getPaddingChar());
- assertTrue(std.usesPaddingChar('='));
- assertEquals((byte) '=', std.getPaddingByte());
- assertEquals(76, std.getMaxLineLength());
- }
-
- public void testCharEncoding() throws Exception
- {
- Base64Variant std = Base64Variants.MIME;
- assertEquals(Base64Variant.BASE64_VALUE_INVALID, std.decodeBase64Char('?'));
- assertEquals(Base64Variant.BASE64_VALUE_INVALID, std.decodeBase64Char((int) '?'));
- assertEquals(Base64Variant.BASE64_VALUE_INVALID, std.decodeBase64Char((byte) '?'));
-
- assertEquals(0, std.decodeBase64Char('A'));
- assertEquals(1, std.decodeBase64Char((int) 'B'));
- assertEquals(2, std.decodeBase64Char((byte)'C'));
-
- assertEquals('/', std.encodeBase64BitsAsChar(63));
- assertEquals((byte) 'b', std.encodeBase64BitsAsByte(27));
-
- String EXP_STR = "HwdJ";
- int TRIPLET = 0x1F0749;
- StringBuilder sb = new StringBuilder();
- std.encodeBase64Chunk(sb, TRIPLET);
- assertEquals(EXP_STR, sb.toString());
-
- byte[] exp = EXP_STR.getBytes("UTF-8");
- byte[] act = new byte[exp.length];
- std.encodeBase64Chunk(TRIPLET, act, 0);
- Assert.assertArrayEquals(exp, act);
- }
-
- @SuppressWarnings("unused")
- public void testErrors() throws Exception
- {
- try {
- Base64Variant b = new Base64Variant("foobar", "xyz", false, '!', 24);
- } catch (IllegalArgumentException iae) {
- verifyException(iae, "length must be exactly");
- }
- }
-}