You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ko...@apache.org on 2016/04/11 18:55:00 UTC
[2/6] git commit: updated refs/heads/master to d1def0a
security rules test
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1ead444c
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1ead444c
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1ead444c
Branch: refs/heads/master
Commit: 1ead444cca7c11181899627698b7a0779812c76c
Parents: ffce2d6
Author: Daan Hoogland <da...@onecht.net>
Authored: Fri Dec 25 13:51:50 2015 +0100
Committer: Daan Hoogland <da...@onecht.net>
Committed: Sat Dec 26 09:02:28 2015 +0100
----------------------------------------------------------------------
.../cloud/agent/api/SecurityGroupRulesCmd.java | 2 +
.../agent/api/SecurityGroupRulesCmdTest.java | 101 +++++++++++++++++++
2 files changed, 103 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1ead444c/core/src/com/cloud/agent/api/SecurityGroupRulesCmd.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/SecurityGroupRulesCmd.java b/core/src/com/cloud/agent/api/SecurityGroupRulesCmd.java
index b9bdef5..098d82c 100644
--- a/core/src/com/cloud/agent/api/SecurityGroupRulesCmd.java
+++ b/core/src/com/cloud/agent/api/SecurityGroupRulesCmd.java
@@ -32,6 +32,8 @@ import com.cloud.agent.api.LogLevel.Log4jLevel;
import com.cloud.utils.net.NetUtils;
public class SecurityGroupRulesCmd extends Command {
+ static final String EGRESS_RULE = "E:";
+ static final String INGRESS_RULE = "I:";
private static Logger s_logger = Logger.getLogger(SecurityGroupRulesCmd.class);
public static class IpPortAndProto {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1ead444c/core/test/com/cloud/agent/api/SecurityGroupRulesCmdTest.java
----------------------------------------------------------------------
diff --git a/core/test/com/cloud/agent/api/SecurityGroupRulesCmdTest.java b/core/test/com/cloud/agent/api/SecurityGroupRulesCmdTest.java
new file mode 100644
index 0000000..2b094c5
--- /dev/null
+++ b/core/test/com/cloud/agent/api/SecurityGroupRulesCmdTest.java
@@ -0,0 +1,101 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.agent.api;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.Vector;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.cloud.agent.api.SecurityGroupRulesCmd.IpPortAndProto;
+
+/**
+ * @author daan
+ *
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class SecurityGroupRulesCmdTest {
+ private SecurityGroupRulesCmd securityGroupRulesCmd;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ String guestIp = "10.10.10.10";
+ String guestMac = "aa:aa:aa:aa:aa:aa";
+ String vmName = "vm";
+ Long vmId = 1L;
+ String signature = "sig";
+ Long seqNum = 0L;
+ String proto = "abc";
+ int startPort = 1;
+ int endPort = 2;
+ String[] allowedCidrs = new String[] {"1.2.3.4/5","6.7.8.9/0"};
+ IpPortAndProto[] ingressRuleSet = new IpPortAndProto[]{new IpPortAndProto(proto, startPort, endPort, allowedCidrs)};
+ IpPortAndProto[] egressRuleSet = new IpPortAndProto[]{new IpPortAndProto(proto, startPort, endPort, allowedCidrs)};
+ List<String> secIps = new Vector<String>();
+ securityGroupRulesCmd = new SecurityGroupRulesCmd(guestIp, guestMac, vmName, vmId, signature, seqNum, ingressRuleSet, egressRuleSet, secIps);
+ }
+
+ /**
+ * Test method for {@link com.cloud.agent.api.SecurityGroupRulesCmd#stringifyRules()}.
+ */
+ @Test
+ public void testStringifyRules() throws Exception {
+ String a = securityGroupRulesCmd.stringifyRules();
+// do verification on a
+ assertTrue(a.contains(SecurityGroupRulesCmd.EGRESS_RULE));
+ }
+
+ /**
+ * Test method for {@link com.cloud.agent.api.SecurityGroupRulesCmd#stringifyCompressedRules()}.
+ */
+ @Test
+ public void testStringifyCompressedRules() throws Exception {
+ String a = securityGroupRulesCmd.stringifyCompressedRules();
+// do verification on a
+ assertTrue(a.contains(SecurityGroupRulesCmd.EGRESS_RULE));
+ }
+
+ /**
+ * Test method for {@link com.cloud.agent.api.SecurityGroupRulesCmd#compressStringifiedRules()}.
+ */
+ @Test
+ public void testCompressStringifiedRules() throws Exception {
+ String compressed = "eJzztEpMSrYytDKyMtQz0jPWM9E31THTM9ez0LPUN9Dxc40IUXAlrAQAPdoP3Q==";
+ String a = securityGroupRulesCmd.compressStringifiedRules();
+ assertTrue(compressed.equals(a));
+ }
+
+}