Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.cloud.network.vpc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
Expand Down Expand Up @@ -619,7 +620,8 @@ protected void validateProtocol(NetworkACLItemVO networkACLItemVO) {
throw new InvalidParameterValueException("Invalid protocol number: " + protoNumber);
}
} else {
if (!supportedProtocolsForAclRules.contains(protocol.toLowerCase())) {
// one of the names, not just part of the string: "cp" or "dp,ic" must not pass
if (!Arrays.asList(supportedProtocolsForAclRules.split(",")).contains(protocol.toLowerCase(Locale.ROOT))) {
Comment thread
bhouse-nexthop marked this conversation as resolved.
Resolved
throw new InvalidParameterValueException(String.format("Invalid protocol [%s]. Expected one of: [%s]", protocol, supportedProtocolsForAclRules));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,32 @@ public void validateProtocolTestProtocolIsStringInvalid() {
networkAclServiceImpl.validateProtocol(networkAclItemVoMock);
}

@Test
public void validateProtocolTestProtocolIsPartOfTheSupportedList() {
for (String protocol : new String[] {"cp", "t", "dp,ic", ",", "tcp,udp"}) {
Mockito.when(networkAclItemVoMock.getProtocol()).thenReturn(protocol);
try {
networkAclServiceImpl.validateProtocol(networkAclItemVoMock);
Assert.fail("protocol [" + protocol + "] should have been rejected");
} catch (InvalidParameterValueException e) {
// expected
}
}
}

@Test
public void validateProtocolTestProtocolNameInAnyCase() {
Mockito.doNothing().when(networkAclServiceImpl).validateIcmpTypeAndCode(networkAclItemVoMock);
Mockito.when(networkAclItemVoMock.getIcmpCode()).thenReturn(null);
Mockito.when(networkAclItemVoMock.getIcmpType()).thenReturn(null);
Mockito.when(networkAclItemVoMock.getSourcePortStart()).thenReturn(null);
Mockito.when(networkAclItemVoMock.getSourcePortEnd()).thenReturn(null);
for (String protocol : new String[] {"TCP", "Udp", "ICMP", "All"}) {
Mockito.when(networkAclItemVoMock.getProtocol()).thenReturn(protocol);
networkAclServiceImpl.validateProtocol(networkAclItemVoMock);
}
}

@Test
public void validateProtocolTestProtocolIsStringValid() {
Mockito.doNothing().when(networkAclServiceImpl).validateIcmpTypeAndCode(networkAclItemVoMock);
Expand Down
Loading