1 19 20 package org.apache.james.imapserver.handler.commands; 21 22 import org.apache.james.imapserver.ImapSessionState; 23 import org.apache.james.imapserver.ProtocolException; 24 25 26 27 public class LoginTest extends AbstractCommandTest 28 { 29 30 public void testValidUserStateNonAuth() throws ProtocolException { 31 mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.NON_AUTHENTICATED)); 32 mockSession.expects(atLeastOnce()).method("getUsers").will(returnValue(mockUsersRepository.proxy())); 33 34 mockUsersRepository.expects(once()).method("test").with( eq("joachim2"),eq("abc")).will(returnValue(true)); 35 mockUsersRepository.expects(once()).method("getUserByName").with( eq("joachim2")).will(returnValue(mockUser.proxy())); 36 37 mockSession.expects(once()).method("setAuthenticated").with( same(mockUser.proxy())); 38 39 String response = handleRequest("1 LOGIN joachim2 abc\n"); 40 41 assertEquals("1 OK LOGIN completed.\r\n",response); 42 } 43 public void testInvalidUserStateNonAuth() throws ProtocolException { 44 mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.NON_AUTHENTICATED)); 45 mockSession.expects(atLeastOnce()).method("getUsers").will(returnValue(mockUsersRepository.proxy())); 46 47 mockUsersRepository.expects(once()).method("test").with( eq("joachim2"),eq("abc")).will(returnValue(false)); 48 49 String response = handleRequest("1 LOGIN joachim2 abc\n"); 50 51 assertEquals("1 NO LOGIN failed. Invalid login/password\r\n",response); 52 } 53 public void testValidUserStateAuth() throws ProtocolException { 54 mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.AUTHENTICATED)); 55 56 String response = handleRequest("1 LOGIN joachim2 abc\n"); 57 assertEquals("1 NO LOGIN failed. Command not valid in this state\r\n",response); 58 } 59 60 public void testValidUserStateLogout() throws ProtocolException { 61 mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.LOGOUT)); 62 63 String response = handleRequest("1 LOGIN joachim2 abc\n"); 64 assertEquals("1 NO LOGIN failed. Command not valid in this state\r\n",response); 65 } 66 public void testValidUserStateSelected() throws ProtocolException { 67 mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.SELECTED)); 68 69 String response = handleRequest("1 LOGIN joachim2 abc\n"); 70 assertEquals("1 NO LOGIN failed. Command not valid in this state\r\n",response); 71 } 72 } 73 | Popular Tags |