Example usage for org.apache.commons.codec.binary Base64 isBase64

List of usage examples for org.apache.commons.codec.binary Base64 isBase64

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Base64 isBase64.

Prototype

public static boolean isBase64(final byte[] arrayOctet) 

Source Link

Document

Tests a given byte array to see if it contains only valid characters within the Base64 alphabet.

Usage

From source file:uk.ac.cam.cl.dtg.segue.auth.SegueLocalAuthenticatorTest.java

/**
 * Verify that setOrChangeUsersPassword works with correct input and the
 * result is a user object with base64 encoded passwords and a secure salt.
 *///  www .  j a  v a  2 s  .  co m
@Test
public final void segueLocalAuthenticator_setOrChangeUsersPasswordValidPassword_passwordAndHashShouldBePopulatedAsBase64() {
    RegisteredUser someUser = new RegisteredUser();
    someUser.setEmail("test@test.com");
    someUser.setId(533L);
    String somePassword = "test5eguePassw0rd";
    replay(userDataManager);

    SegueLocalAuthenticator segueAuthenticator = new SegueLocalAuthenticator(this.userDataManager,
            this.propertiesLoader);

    try {
        segueAuthenticator.setOrChangeUsersPassword(someUser, somePassword);

        // user should now contain an appropriately hashedPassword and salt
        assertTrue(someUser.getPassword() != null);
        assertTrue(someUser.getSecureSalt() != null);

        // check that the password and salt are both in base64
        assertTrue(Base64.isBase64(someUser.getPassword()));
        assertTrue(Base64.isBase64(someUser.getSecureSalt()));

    } catch (InvalidPasswordException e) {
        fail("This should be a valid password");
    }
}