-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
267abe1
commit 50a3d3e
Showing
2 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
50 changes: 50 additions & 0 deletions
50
src/test/java/com/fasterxml/jackson/databind/deser/jdk/BaseDecodingTest.java
This file contains 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,50 @@ | ||
package com.fasterxml.jackson.databind.deser.jdk; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.exc.InputMismatchException; | ||
|
||
// Mostly for [databind#1425]; not in optimal place (as it also has | ||
// tree-access tests), but has to do for now | ||
public class BaseDecodingTest extends BaseMapTest | ||
{ | ||
private final ObjectMapper MAPPER = objectMapper(); | ||
|
||
private final byte[] HELLO_BYTES = "hello".getBytes(StandardCharsets.UTF_8); | ||
private final String BASE64_HELLO = "aGVsbG8="; | ||
|
||
// for [databind#1425] | ||
public void testInvalidBase64() throws Exception | ||
{ | ||
byte[] b = MAPPER.readValue(quote(BASE64_HELLO), byte[].class); | ||
assertEquals(HELLO_BYTES, b); | ||
|
||
_testInvalidBase64(MAPPER, BASE64_HELLO+"!"); | ||
_testInvalidBase64(MAPPER, BASE64_HELLO+"!!"); | ||
} | ||
|
||
private void _testInvalidBase64(ObjectMapper mapper, String value) throws Exception | ||
{ | ||
// First, use data-binding | ||
try { | ||
MAPPER.readValue(quote(value), byte[].class); | ||
fail("Should not pass"); | ||
} catch (InputMismatchException e) { | ||
verifyException(e, "Failed to decode"); | ||
verifyException(e, "as base64"); | ||
verifyException(e, "Illegal character '!'"); | ||
} | ||
|
||
// and then tree model | ||
JsonNode tree = mapper.readTree(String.format("{\"foo\":\"%s\"}", value)); | ||
JsonNode nodeValue = tree.get("foo"); | ||
try { | ||
/*byte[] b =*/ nodeValue.binaryValue(); | ||
fail("Should not pass"); | ||
} catch (InputMismatchException e) { | ||
verifyException(e, "Can not access contents of TextNode as binary"); | ||
verifyException(e, "Illegal character '!'"); | ||
} | ||
} | ||
} |