1/* 2 * Copyright 2008 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package org.mockftpserver.fake.user 17 18import org.mockftpserver.test.* 19 20/** 21 * Tests for UserAccount 22 * 23 * @version $Revision: $ - $Date: $ 24 * 25 * @author Chris Mair 26 */ 27class UserAccountTest extends AbstractGroovyTest { 28 29 private static final USERNAME = "user123" 30 private static final PASSWORD = "password123" 31 private static final HOME_DIR = "/usr/user123" 32 33 private UserAccount userAccount 34 35 void testIsValidPassword() { 36 userAccount.username = USERNAME 37 userAccount.password = PASSWORD 38 assert userAccount.isValidPassword(PASSWORD) 39 40 assert userAccount.isValidPassword("") == false 41 assert userAccount.isValidPassword("wrong") == false 42 assert userAccount.isValidPassword(null) == false 43 } 44 45 void testIsValidPassword_UsernameNullOrEmpty() { 46 userAccount.password = PASSWORD 47 shouldFail(AssertionError) { userAccount.isValidPassword(PASSWORD) } 48 49 userAccount.username = '' 50 shouldFail(AssertionError) { userAccount.isValidPassword(PASSWORD) } 51 } 52 53 void testIsValidPassword_OverrideComparePassword() { 54 def customUserAccount = new CustomUserAccount() 55 customUserAccount.username = USERNAME 56 customUserAccount.password = PASSWORD 57 println customUserAccount 58 assert customUserAccount.isValidPassword(PASSWORD) == false 59 assert customUserAccount.isValidPassword(PASSWORD + "123") 60 } 61 62 void testIsValidPassword_PasswordNotCheckedDuringValidation() { 63 userAccount.username = USERNAME 64 userAccount.password = PASSWORD 65 userAccount.passwordCheckedDuringValidation = false 66 assert userAccount.isValidPassword("wrong") 67 } 68 69 void setUp() { 70 userAccount = new UserAccount() 71 } 72}