mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-29 23:32:14 +00:00
Some tests for Base64 encoding.
This commit is contained in:
parent
59a07175a6
commit
45d938566c
@ -484,8 +484,8 @@ public final class Base64 {
|
|||||||
* @since 1.3
|
* @since 1.3
|
||||||
*/
|
*/
|
||||||
private static int decode4to3(
|
private static int decode4to3(
|
||||||
byte[] source, int srcOffset,
|
final byte[] source, final int srcOffset,
|
||||||
byte[] destination, int destOffset, int options ) {
|
final byte[] destination, final int destOffset, final int options ) {
|
||||||
|
|
||||||
// Lots of error checking and exception throwing
|
// Lots of error checking and exception throwing
|
||||||
if( source == null ){
|
if( source == null ){
|
||||||
@ -570,7 +570,7 @@ public final class Base64 {
|
|||||||
* @return decoded data
|
* @return decoded data
|
||||||
* @throws IllegalArgumentException If bogus characters exist in source data
|
* @throws IllegalArgumentException If bogus characters exist in source data
|
||||||
*/
|
*/
|
||||||
private static byte[] decode( byte[] source, int off, int len, int options ) {
|
private static byte[] decode(final byte[] source, final int off, final int len, final int options ) {
|
||||||
|
|
||||||
// Lots of error checking and exception throwing
|
// Lots of error checking and exception throwing
|
||||||
if( source == null ){
|
if( source == null ){
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
package org.springframework.security.crypto.codec;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luke Taylor
|
||||||
|
*/
|
||||||
|
public class Base64Tests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isBase64ReturnsTrueForValidBase64() {
|
||||||
|
new Base64(); // unused
|
||||||
|
|
||||||
|
assertTrue(Base64.isBase64(new byte[]{ (byte)'A',(byte)'B',(byte)'C',(byte)'D'}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isBase64ReturnsFalseForInvalidBase64() throws Exception {
|
||||||
|
// Include invalid '`' character
|
||||||
|
assertFalse(Base64.isBase64(new byte[]{ (byte)'A',(byte)'B',(byte)'C',(byte)'`'}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = NullPointerException.class)
|
||||||
|
public void isBase64RejectsNull() {
|
||||||
|
Base64.isBase64(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void isBase64RejectsInvalidLength() {
|
||||||
|
Base64.isBase64(new byte[]{ (byte)'A'});
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user