1fba2635c088b01af59300e8a02611bb788ee3bffchrismair/* 2fba2635c088b01af59300e8a02611bb788ee3bffchrismair * Copyright 2009 the original author or authors. 3fba2635c088b01af59300e8a02611bb788ee3bffchrismair * 4fba2635c088b01af59300e8a02611bb788ee3bffchrismair * Licensed under the Apache License, Version 2.0 (the "License"); 5fba2635c088b01af59300e8a02611bb788ee3bffchrismair * you may not use this file except in compliance with the License. 6fba2635c088b01af59300e8a02611bb788ee3bffchrismair * You may obtain a copy of the License at 7fba2635c088b01af59300e8a02611bb788ee3bffchrismair * 8fba2635c088b01af59300e8a02611bb788ee3bffchrismair * http://www.apache.org/licenses/LICENSE-2.0 9fba2635c088b01af59300e8a02611bb788ee3bffchrismair * 10fba2635c088b01af59300e8a02611bb788ee3bffchrismair * Unless required by applicable law or agreed to in writing, software 11fba2635c088b01af59300e8a02611bb788ee3bffchrismair * distributed under the License is distributed on an "AS IS" BASIS, 12fba2635c088b01af59300e8a02611bb788ee3bffchrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fba2635c088b01af59300e8a02611bb788ee3bffchrismair * See the License for the specific language governing permissions and 14fba2635c088b01af59300e8a02611bb788ee3bffchrismair * limitations under the License. 15fba2635c088b01af59300e8a02611bb788ee3bffchrismair */ 16fba2635c088b01af59300e8a02611bb788ee3bffchrismairpackage org.mockftpserver.fake.command 17fba2635c088b01af59300e8a02611bb788ee3bffchrismair 18fba2635c088b01af59300e8a02611bb788ee3bffchrismairimport org.mockftpserver.core.command.Command 19fba2635c088b01af59300e8a02611bb788ee3bffchrismairimport org.mockftpserver.core.command.CommandHandler 20fba2635c088b01af59300e8a02611bb788ee3bffchrismairimport org.mockftpserver.core.command.CommandNames 21fba2635c088b01af59300e8a02611bb788ee3bffchrismairimport org.mockftpserver.core.command.ReplyCodes 22fba2635c088b01af59300e8a02611bb788ee3bffchrismair 23fba2635c088b01af59300e8a02611bb788ee3bffchrismair/** 24fba2635c088b01af59300e8a02611bb788ee3bffchrismair * Tests for PortCommandHandler 25fba2635c088b01af59300e8a02611bb788ee3bffchrismair * 26fba2635c088b01af59300e8a02611bb788ee3bffchrismair * @version $Revision$ - $Date$ 27fba2635c088b01af59300e8a02611bb788ee3bffchrismair * 28fba2635c088b01af59300e8a02611bb788ee3bffchrismair * @author Chris Mair 29fba2635c088b01af59300e8a02611bb788ee3bffchrismair */ 30fba2635c088b01af59300e8a02611bb788ee3bffchrismairclass EprtCommandHandlerTest extends AbstractFakeCommandHandlerTestCase { 31fba2635c088b01af59300e8a02611bb788ee3bffchrismair 32fba2635c088b01af59300e8a02611bb788ee3bffchrismair static final PARAMETERS_IPV4 = ["|1|132.235.1.2|6275|"] 33fba2635c088b01af59300e8a02611bb788ee3bffchrismair static final HOST_IPV4 = InetAddress.getByName("132.235.1.2") 34fba2635c088b01af59300e8a02611bb788ee3bffchrismair static final PARAMETERS_IPV6 = ["|2|1080::8:800:200C:417A|6275|"] 35fba2635c088b01af59300e8a02611bb788ee3bffchrismair static final HOST_IPV6 = InetAddress.getByName("1080::8:800:200C:417A") 36fba2635c088b01af59300e8a02611bb788ee3bffchrismair static final PORT = 6275 37fba2635c088b01af59300e8a02611bb788ee3bffchrismair 38fba2635c088b01af59300e8a02611bb788ee3bffchrismair boolean testNotLoggedIn = false 39fba2635c088b01af59300e8a02611bb788ee3bffchrismair 40fba2635c088b01af59300e8a02611bb788ee3bffchrismair void testHandleCommand_IPv4() { 41fba2635c088b01af59300e8a02611bb788ee3bffchrismair handleCommand(PARAMETERS_IPV4) 42fba2635c088b01af59300e8a02611bb788ee3bffchrismair assertSessionReply(ReplyCodes.EPRT_OK, 'eprt') 43fba2635c088b01af59300e8a02611bb788ee3bffchrismair assert session.clientDataHost == HOST_IPV4 44fba2635c088b01af59300e8a02611bb788ee3bffchrismair assert session.clientDataPort == PORT 45fba2635c088b01af59300e8a02611bb788ee3bffchrismair } 46fba2635c088b01af59300e8a02611bb788ee3bffchrismair 47fba2635c088b01af59300e8a02611bb788ee3bffchrismair void testHandleCommand_IPv6() { 48fba2635c088b01af59300e8a02611bb788ee3bffchrismair handleCommand(PARAMETERS_IPV6) 49fba2635c088b01af59300e8a02611bb788ee3bffchrismair assertSessionReply(ReplyCodes.EPRT_OK, 'eprt') 50fba2635c088b01af59300e8a02611bb788ee3bffchrismair assert session.clientDataHost == HOST_IPV6 51fba2635c088b01af59300e8a02611bb788ee3bffchrismair assert session.clientDataPort == PORT 52fba2635c088b01af59300e8a02611bb788ee3bffchrismair } 53fba2635c088b01af59300e8a02611bb788ee3bffchrismair 54fba2635c088b01af59300e8a02611bb788ee3bffchrismair void testHandleCommand_IPv6_CustomDelimiter() { 55fba2635c088b01af59300e8a02611bb788ee3bffchrismair handleCommand(["@2@1080::8:800:200C:417A@6275@"]) 56fba2635c088b01af59300e8a02611bb788ee3bffchrismair assertSessionReply(ReplyCodes.EPRT_OK, 'eprt') 57fba2635c088b01af59300e8a02611bb788ee3bffchrismair assert session.clientDataHost == HOST_IPV6 58fba2635c088b01af59300e8a02611bb788ee3bffchrismair assert session.clientDataPort == PORT 59fba2635c088b01af59300e8a02611bb788ee3bffchrismair } 60fba2635c088b01af59300e8a02611bb788ee3bffchrismair 61fba2635c088b01af59300e8a02611bb788ee3bffchrismair void testHandleCommand_IllegalParameterFormat() { 62fba2635c088b01af59300e8a02611bb788ee3bffchrismair handleCommand(['abcdef']) 63fba2635c088b01af59300e8a02611bb788ee3bffchrismair assertSessionReply(ReplyCodes.COMMAND_SYNTAX_ERROR) 64fba2635c088b01af59300e8a02611bb788ee3bffchrismair } 65fba2635c088b01af59300e8a02611bb788ee3bffchrismair 66fba2635c088b01af59300e8a02611bb788ee3bffchrismair void testHandleCommand_PortMissing() { 67fba2635c088b01af59300e8a02611bb788ee3bffchrismair handleCommand(['|1|132.235.1.2|']) 68fba2635c088b01af59300e8a02611bb788ee3bffchrismair assertSessionReply(ReplyCodes.COMMAND_SYNTAX_ERROR) 69fba2635c088b01af59300e8a02611bb788ee3bffchrismair } 70fba2635c088b01af59300e8a02611bb788ee3bffchrismair 71fba2635c088b01af59300e8a02611bb788ee3bffchrismair void testHandleCommand_IllegalHostName() { 72fba2635c088b01af59300e8a02611bb788ee3bffchrismair handleCommand(['|1|132.@|6275|']) 73fba2635c088b01af59300e8a02611bb788ee3bffchrismair assertSessionReply(ReplyCodes.COMMAND_SYNTAX_ERROR) 74fba2635c088b01af59300e8a02611bb788ee3bffchrismair } 75fba2635c088b01af59300e8a02611bb788ee3bffchrismair 76fba2635c088b01af59300e8a02611bb788ee3bffchrismair void testHandleCommand_MissingRequiredParameter() { 77fba2635c088b01af59300e8a02611bb788ee3bffchrismair testHandleCommand_MissingRequiredParameter([]) 78fba2635c088b01af59300e8a02611bb788ee3bffchrismair } 79fba2635c088b01af59300e8a02611bb788ee3bffchrismair 80fba2635c088b01af59300e8a02611bb788ee3bffchrismair //------------------------------------------------------------------------- 81fba2635c088b01af59300e8a02611bb788ee3bffchrismair // Helper Methods 82fba2635c088b01af59300e8a02611bb788ee3bffchrismair //------------------------------------------------------------------------- 83fba2635c088b01af59300e8a02611bb788ee3bffchrismair 84fba2635c088b01af59300e8a02611bb788ee3bffchrismair void setUp() { 85fba2635c088b01af59300e8a02611bb788ee3bffchrismair super.setUp() 86fba2635c088b01af59300e8a02611bb788ee3bffchrismair } 87fba2635c088b01af59300e8a02611bb788ee3bffchrismair 88fba2635c088b01af59300e8a02611bb788ee3bffchrismair CommandHandler createCommandHandler() { 89fba2635c088b01af59300e8a02611bb788ee3bffchrismair new EprtCommandHandler() 90fba2635c088b01af59300e8a02611bb788ee3bffchrismair } 91fba2635c088b01af59300e8a02611bb788ee3bffchrismair 92fba2635c088b01af59300e8a02611bb788ee3bffchrismair Command createValidCommand() { 93fba2635c088b01af59300e8a02611bb788ee3bffchrismair return new Command(CommandNames.EPRT, PARAMETERS_IPV4) 94fba2635c088b01af59300e8a02611bb788ee3bffchrismair } 95fba2635c088b01af59300e8a02611bb788ee3bffchrismair 96fba2635c088b01af59300e8a02611bb788ee3bffchrismair}