2 * Copyright (C) 2015 IBM, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.neutron.e2etest;
11 import java.io.OutputStreamWriter;
13 import java.lang.Thread;
15 import java.net.HttpURLConnection;
18 import org.junit.Assert;
20 import com.google.gson.Gson;
21 import com.google.gson.JsonArray;
22 import com.google.gson.JsonObject;
24 public class NeutronSecurityRuleTests {
27 public NeutronSecurityRuleTests(String base) {
31 public void securityRule_collection_get_test() {
32 String url = base + "/security-group-rules";
33 ITNeutronE2E.test_fetch(url, "Security Rule Collection GET failed");
36 public String singleton_sr_create_test() {
37 String url = base + "/security-group-rules";
38 String content = " {\"security_group_rule\": " +
39 "{\"remote_group_id\": null, \"direction\": \"ingress\", " +
40 "\"remote_ip_prefix\": null, \"protocol\": \"tcp\", " +
41 "\"ethertype\": \"IPv6\", \"tenant_id\": " +
42 "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " +
43 "\"port_range_min\": 77, " +
44 "\"id\": \"9b4be7fa-e56e-40fb-9516-1f0fa9185669\", " +
45 "\"security_group_id\": " +
46 "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
47 ITNeutronE2E.test_create(url, content, "Security Rule Singleton Post Failed");
51 public void singleton_sr_get_with_one_query_item_test(String createJsonString) {
52 String url = base + "/security-group-rules";
53 ITNeutronE2E.test_fetch_with_one_query_item(url, createJsonString, "security_group_rules");
56 public void multiple_sr_create_test() {
57 String url = base + "/security-group-rules";
58 String content = " {\"security_group_rules\": [" +
60 " \"id\": \"35fb0f34-c8d3-416d-a205-a2c75f7b8e22\"," +
61 " \"direction\": \"egress\"," +
62 " \"ethertype\": \"IPv6\"," +
63 " \"security_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
64 " \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" +
67 " \"id\": \"63814eed-bc12-4fe4-8b17-2af178224c71\"," +
68 " \"direction\": \"egress\"," +
69 " \"ethertype\": \"IPv4\"," +
70 " \"security_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
71 " \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" +
74 " \"id\": \"ccb9823e-559b-4d84-b656-2739f8e56d89\"," +
75 " \"direction\": \"ingress\"," +
76 " \"ethertype\": \"IPv6\"," +
77 " \"remote_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
78 " \"security_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
79 " \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" +
82 " \"id\": \"fbc3f809-7378-40a4-822f-7a70f6ccba98\"," +
83 " \"direction\": \"ingress\"," +
84 " \"ethertype\": \"IPv4\"," +
85 " \"remote_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
86 " \"security_group_id\": \"70f1b157-e79b-44dc-85a8-7de0fc9f2aab\"," +
87 " \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" +
90 ITNeutronE2E.test_create(url, content, "Security Rule Multiple Post Failed");
93 public void singleton_sr_modify_test() {
94 String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
95 String content = " {\"security_group_rule\": " +
96 "{\"remote_group_id\": null, \"direction\": \"egress\", " +
97 "\"remote_ip_prefix\": null, \"protocol\": \"tcp\", " +
98 "\"ethertype\": \"IPv6\", \"tenant_id\": " +
99 "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " +
100 "\"port_range_min\": 77, " +
101 "\"id\": \"9b4be7fa-e56e-40fb-9516-1f0fa9185669\", " +
102 "\"security_group_id\": " +
103 "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
104 ITNeutronE2E.test_modify(url, content, "Security Rule Singleton Put Failed");
107 public void sr_element_get_test() {
108 String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
109 ITNeutronE2E.test_fetch(url, true, "Security Rule Element Get Failed");
112 public void sr_element_get_with_query_test() {
113 String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669" +
114 "?fields=id&fields=direction&fields=protocol&fields=port_range_min" +
115 "&fields=port_range_max&fields=ethertype&fields=remote_ip_prefix" +
116 "&fields=remote_group_id&fields=security_group_id&fields=tenant_id" +
117 "&fields=limit&fields=marker&fields=page_reverse";
118 ITNeutronE2E.test_fetch(url, true, "Security Rule Element Get With Query Failed");
121 public void sr_delete_test() {
122 String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
123 ITNeutronE2E.test_delete(url, "Security Rule Delete Failed");
126 public void sr_element_negative_get_test() {
127 String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
128 ITNeutronE2E.test_fetch(url, false, "Security Rule Element Negative Get Failed");
131 public void bug4043_ipv4_test() {
132 String url = base + "/security-group-rules";
133 String content = " {\"security_group_rule\": " +
134 "{\"remote_group_id\": null, \"direction\": \"ingress\", " +
135 "\"remote_ip_prefix\": \"10.10.10.10/16\", \"protocol\": \"tcp\", " +
136 "\"ethertype\": \"IPv4\", \"tenant_id\": " +
137 "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " +
138 "\"port_range_min\": 77, " +
139 "\"id\": \"01234567-0123-0123-0123-01234567890a\", " +
140 "\"security_group_id\": " +
141 "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
142 ITNeutronE2E.test_create(url, content, "Security Rule bug4043 IPv4 Failed");
144 url = url + "/01234567-0123-0123-0123-01234567890a";
145 ITNeutronE2E.test_delete(url, "Security Rule Delete Failed");
148 public void bug4043_ipv6_test() {
149 String url = base + "/security-group-rules";
150 String content = " {\"security_group_rule\": " +
151 "{\"remote_group_id\": null, \"direction\": \"ingress\", " +
152 "\"remote_ip_prefix\": \"fe80::1/10\", \"protocol\": \"tcp\", " +
153 "\"ethertype\": \"IPv6\", \"tenant_id\": " +
154 "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " +
155 "\"port_range_min\": 77, " +
156 "\"id\": \"01234567-0123-0123-0123-01234567890a\", " +
157 "\"security_group_id\": " +
158 "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
159 ITNeutronE2E.test_create(url, content, "Security Rule Bug4043 IPv6 Failed");
161 url = url + "/01234567-0123-0123-0123-01234567890a";
162 ITNeutronE2E.test_delete(url, "Security Rule Delete Failed");
165 public void bug4550_sg_sr_test() {
166 String sg_uuid = "d55c7ec4-6189-4cbf-b136-3059dc2afd37";
167 String sg_url = base + "/security-groups";
168 String sg_content = "{\"security_group\": {\"tenant_id\": " +
169 "\"4693014ff2dd4485b32d778c4942b18f\", \"description\": \"\", " +
170 "\"id\": \"" + sg_uuid + "\", " +
171 "\"security_group_rules\": [], " +
172 "\"name\": \"tempest-secgroup-bug4550-sg-sr-test\"}}";
173 ITNeutronE2E.test_create(sg_url, sg_content, "Security Group Singleton Post Failed");
175 String rule_uuid = "19a72e11-783c-4baf-bf49-ed8053956d5e";
176 String rule_url = base + "/security-group-rules";
177 String rule_content = " {\"security_group_rules\": [" +
179 " \"id\": \"" + rule_uuid + "\"," +
180 " \"direction\": \"egress\"," +
181 " \"ethertype\": \"IPv4\"," +
182 " \"security_group_id\": \"" + sg_uuid + "\"," +
183 " \"tenant_id\": \"4693014ff2dd4485b32d778c4942b18f\"" +
186 ITNeutronE2E.test_create(rule_url, rule_content, "Security Rule bug4550 Failed");
188 String sg_one_url = sg_url + "/" + sg_uuid;
189 JsonObject jsonObject = ITNeutronE2E.test_fetch_gson(sg_one_url, "Security group bug4550 fetch");
190 JsonObject sg = jsonObject.getAsJsonObject("security_group");
191 JsonArray sgRules = sg.getAsJsonArray("security_group_rules");
192 Assert.assertEquals("security rule bug4550 array size", 1, sgRules.size());
193 Assert.assertEquals("security rule bug4550 uuid",
194 rule_uuid, sgRules.get(0).getAsJsonObject().get("id").getAsString());
197 public static void runTests(String base) {
198 NeutronSecurityRuleTests securityRule_tester = new NeutronSecurityRuleTests(base);
199 String createJsonString = securityRule_tester.singleton_sr_create_test();
200 securityRule_tester.singleton_sr_get_with_one_query_item_test(createJsonString);
201 securityRule_tester.multiple_sr_create_test();
202 securityRule_tester.singleton_sr_modify_test();
203 securityRule_tester.sr_element_get_test();
204 securityRule_tester.sr_element_get_with_query_test();
205 securityRule_tester.securityRule_collection_get_test();
206 securityRule_tester.sr_delete_test();
207 securityRule_tester.sr_element_negative_get_test();
208 securityRule_tester.bug4043_ipv4_test();
209 securityRule_tester.bug4043_ipv6_test();
210 securityRule_tester.bug4550_sg_sr_test();