Skip to content

Commit aea39be

Browse files
committed
CODEC-134: Add test to cover missed exception case in BCodec.java.
1 parent d0aebfd commit aea39be

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/test/java/org/apache/commons/codec/net/BCodecTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
* @version $Id$
3535
*/
3636
public class BCodecTest {
37+
private static final String[] BASE64_IMPOSSIBLE_CASES = {
38+
"ZE==",
39+
"ZmC=",
40+
"Zm9vYE==",
41+
"Zm9vYmC=",
42+
};
3743

3844
static final int SWISS_GERMAN_STUFF_UNICODE[] =
3945
{ 0x47, 0x72, 0xFC, 0x65, 0x7A, 0x69, 0x5F, 0x7A, 0xE4, 0x6D, 0xE4 };
@@ -148,4 +154,17 @@ public void testDecodeObjects() throws Exception {
148154
// Exception expected, test segment passes.
149155
}
150156
}
157+
158+
@Test
159+
public void testBase64ImpossibleSamples() {
160+
BCodec codec = new BCodec();
161+
for (String s : BASE64_IMPOSSIBLE_CASES) {
162+
try {
163+
codec.decode(s);
164+
fail();
165+
} catch (DecoderException ex) {
166+
// expected
167+
}
168+
}
169+
}
151170
}

0 commit comments

Comments
 (0)