EprtCommandHandlerTest.groovy revision 75520503341f870a8d2a27e0a82cca14f8aa6a4b
1/* 2 * Copyright 2009 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.command 17 18import org.mockftpserver.core.command.Command 19import org.mockftpserver.core.command.CommandHandler 20import org.mockftpserver.core.command.CommandNames 21import org.mockftpserver.core.command.ReplyCodes 22 23/** 24 * Tests for PortCommandHandler 25 * 26 * @version $Revision$ - $Date$ 27 * 28 * @author Chris Mair 29 */ 30class EprtCommandHandlerTest extends AbstractFakeCommandHandlerTest { 31 32 static final PARAMETERS_IPV4 = ["|1|132.235.1.2|6275|"] 33 static final HOST_IPV4 = InetAddress.getByName("132.235.1.2") 34 static final PARAMETERS_IPV6 = ["|2|1080::8:800:200C:417A|6275|"] 35 static final HOST_IPV6 = InetAddress.getByName("1080::8:800:200C:417A") 36 static final PORT = 6275 37 38 boolean testNotLoggedIn = false 39 40 void testHandleCommand_IPv4() { 41 handleCommand(PARAMETERS_IPV4) 42 assertSessionReply(ReplyCodes.EPRT_OK, 'eprt') 43 assert session.clientDataHost == HOST_IPV4 44 assert session.clientDataPort == PORT 45 } 46 47 void testHandleCommand_IPv6() { 48 handleCommand(PARAMETERS_IPV6) 49 assertSessionReply(ReplyCodes.EPRT_OK, 'eprt') 50 assert session.clientDataHost == HOST_IPV6 51 assert session.clientDataPort == PORT 52 } 53 54 void testHandleCommand_IPv6_CustomDelimiter() { 55 handleCommand(["@2@1080::8:800:200C:417A@6275@"]) 56 assertSessionReply(ReplyCodes.EPRT_OK, 'eprt') 57 assert session.clientDataHost == HOST_IPV6 58 assert session.clientDataPort == PORT 59 } 60 61 void testHandleCommand_IllegalParameterFormat() { 62 handleCommand(['abcdef']) 63 assertSessionReply(ReplyCodes.COMMAND_SYNTAX_ERROR) 64 } 65 66 void testHandleCommand_PortMissing() { 67 handleCommand(['|1|132.235.1.2|']) 68 assertSessionReply(ReplyCodes.COMMAND_SYNTAX_ERROR) 69 } 70 71 void testHandleCommand_IllegalHostName() { 72 handleCommand(['|1|132.xxx.rrr|6275|']) 73 assertSessionReply(ReplyCodes.COMMAND_SYNTAX_ERROR) 74 } 75 76 void testHandleCommand_MissingRequiredParameter() { 77 testHandleCommand_MissingRequiredParameter([]) 78 } 79 80 //------------------------------------------------------------------------- 81 // Helper Methods 82 //------------------------------------------------------------------------- 83 84 void setUp() { 85 super.setUp() 86 } 87 88 CommandHandler createCommandHandler() { 89 new EprtCommandHandler() 90 } 91 92 Command createValidCommand() { 93 return new Command(CommandNames.EPRT, PARAMETERS_IPV4) 94 } 95 96}