Commit 0d4ce557 authored by Alinga Yeung's avatar Alinga Yeung
Browse files

Story 1869. Added unit test for more than one users matching an email address.

parent e13e9805
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -580,7 +580,7 @@ public class LdapUserDAO<T extends Principal> extends LdapDAO
        {
            if (e.getResultCode() == ResultCode.SIZE_LIMIT_EXCEEDED)
            {
                String msg = "More than one User with email address " + emailAddress + " found";
                String msg = "More than one user with email address " + emailAddress + " found";
                logger.debug(msg);
                throw new UserNotFoundException(msg);
            }
@@ -608,7 +608,7 @@ public class LdapUserDAO<T extends Principal> extends LdapDAO
            {
                if (e.getResultCode() == ResultCode.SIZE_LIMIT_EXCEEDED)
                {
                    String msg = "More than one User with email address " + emailAddress + " found";
                    String msg = "More than one user with email address " + emailAddress + " found";
                    logger.debug(msg);
                    throw new UserNotFoundException(msg);
                }
+55 −23
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.security.AccessControlException;
import java.security.Principal;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Collection;
import java.util.Random;
@@ -397,20 +398,9 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest
        });
    }

    /**
     * Test of getUserByEmailAddress method, of class LdapUserDAO.
     */
    @Test
    public void testGetUserByEmailAddress() throws Exception
    {
        // create a user with the email attribute
        final String username = createUsername();
        final String emailAddress = username +"@canada.ca";
        final HttpPrincipal userID = new HttpPrincipal(username);
        final UserRequest<Principal> userRequest = createUserRequest(userID, emailAddress);
        addUser(userID, userRequest);
        
        try
    protected void testGetOneUserByEmailAddress(final String emailAddress,
            final String username) 
            throws PrivilegedActionException
    {
        // do as servops
        Subject servops = SSLUtil.createSubject(new File(SERVOPS_PEM));      
@@ -437,6 +427,48 @@ public class LdapUserDAOTest extends AbstractLdapDAOTest
            }
        });
    }
    
    /**
     * Test of getUserByEmailAddress method, of class LdapUserDAO.
     */
    @Test
    public void testGetUserByEmailAddress() throws Exception
    {
        // create a user with the email attribute
        final String username = createUsername();
        final String emailAddress = username +"@canada.ca";
        final HttpPrincipal userID = new HttpPrincipal(username);
        final UserRequest<Principal> userRequest = createUserRequest(userID, emailAddress);
        addUser(userID, userRequest);
        
        try
        {
            // case 1: only one user matches the email address
            testGetOneUserByEmailAddress(emailAddress, username);
            
            // create another user with the same email attribute
            final String username1 = createUsername();
            final HttpPrincipal userID1 = new HttpPrincipal(username1);
            final UserRequest<Principal> userRequest1 = createUserRequest(userID1, emailAddress);
            addUser(userID1, userRequest1);
            
            try
            {
                // case 2: two users match the email address
                testGetOneUserByEmailAddress(emailAddress, username);
            }
            catch (PrivilegedActionException pae)
            {
                Exception e = pae.getException();
                Throwable t = e.getCause();
                assertTrue(e.getCause() instanceof UserNotFoundException);
                assertTrue(e.getCause().getMessage().contains("More than one user"));
            }
            finally
            {
                deleteUser(userID1);
            }
        }
        finally
        {
            deleteUser(userID);