implement dependency checking for security rule's group
[neutron.git] / integration / test-standalone / src / main / java / org / opendaylight / neutron / e2etest / NeutronSecurityRuleTests.java
1 /*
2  * Copyright (C) 2015 IBM, Inc.
3  *
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
7  */
8 package org.opendaylight.neutron.e2etest;
9
10 public class NeutronSecurityRuleTests {
11
12     private static final String TEST_SECURITY_GROUP_ID = "b60490fe-60a5-40be-af63-1d641381b784";
13
14     private final String base;
15
16     public NeutronSecurityRuleTests(String base) {
17         this.base = base;
18     }
19
20     private void securityRule_collection_get_test() {
21         String url = base + "/security-group-rules";
22         HttpUtils.test_fetch(url, "Security Rule Collection GET failed");
23     }
24
25     private void singleton_sr_without_groupid_create_test(int responseCode) {
26         String url = base + "/security-group-rules";
27         String content = " {\"security_group_rule\": " + "{\"remote_group_id\": null, \"direction\": \"ingress\", "
28                 + "\"remote_ip_prefix\": null, \"protocol\": \"tcp\", " + "\"ethertype\": \"IPv6\", \"tenant_id\": "
29                 + "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " + "\"port_range_min\": 77, "
30                 + "\"id\": \"9b4be7fa-e56e-40fb-9516-1f0fa9185669\"}}"; // no security_group_id
31         HttpUtils.test_create(url, responseCode, content, "Security Rule Singleton Post Failed");
32     }
33
34     private String singleton_sr_create_test(int responseCode) {
35         String url = base + "/security-group-rules";
36         String content = " {\"security_group_rule\": " + "{\"remote_group_id\": null, \"direction\": \"ingress\", "
37                 + "\"remote_ip_prefix\": null, \"protocol\": \"tcp\", " + "\"ethertype\": \"IPv6\", \"tenant_id\": "
38                 + "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " + "\"port_range_min\": 77, "
39                 + "\"id\": \"9b4be7fa-e56e-40fb-9516-1f0fa9185669\", " + "\"security_group_id\": "
40                 + "\"" + TEST_SECURITY_GROUP_ID + "\"}}";
41         HttpUtils.test_create(url, responseCode, content, "Security Rule Singleton Post Failed");
42         return content;
43     }
44
45     private void singleton_sr_get_with_one_query_item_test(String createJsonString) {
46         String url = base + "/security-group-rules";
47         HttpUtils.test_fetch_with_one_query_item(url, createJsonString, "security_group_rules");
48     }
49
50     private void multiple_sr_create_test() {
51         String url = base + "/security-group-rules";
52         String content = " {\"security_group_rules\": [" + "{" + "  \"id\": \"35fb0f34-c8d3-416d-a205-a2c75f7b8e22\","
53                 + "  \"direction\": \"egress\"," + "  \"ethertype\": \"IPv6\"," + "  \"protocol\": \"tcp\","
54                 + "  \"security_group_id\": \"b60490fe-60a5-40be-af63-1d641381b784\","
55                 + "  \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" + "}," + "{"
56                 + "  \"id\": \"63814eed-bc12-4fe4-8b17-2af178224c71\"," + "  \"direction\": \"egress\","
57                 + "  \"ethertype\": \"IPv4\"," + "  \"protocol\": \"6\","
58                 + "  \"security_group_id\": \"b60490fe-60a5-40be-af63-1d641381b784\","
59                 + "  \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" + "}," + "{"
60                 + "  \"id\": \"ccb9823e-559b-4d84-b656-2739f8e56d89\"," + "  \"direction\": \"ingress\","
61                 + "  \"ethertype\": \"IPv6\"," + "  \"protocol\": 6,"
62                 + "  \"remote_group_id\": \"b60490fe-60a5-40be-af63-1d641381b784\","
63                 + "  \"security_group_id\": \"b60490fe-60a5-40be-af63-1d641381b784\","
64                 + "  \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" + "}," + "{"
65                 + "  \"id\": \"fbc3f809-7378-40a4-822f-7a70f6ccba98\"," + "  \"direction\": \"ingress\","
66                 + "  \"ethertype\": \"IPv4\"," + "  \"protocol\": \"udp\","
67                 + "  \"remote_group_id\": \"b60490fe-60a5-40be-af63-1d641381b784\","
68                 + "  \"security_group_id\": \"b60490fe-60a5-40be-af63-1d641381b784\","
69                 + "  \"tenant_id\": \"2640ee2ac2474bf3906e482047204fcb\"" + "}" + "]}";
70         HttpUtils.test_create(url, content, "Security Rule Multiple Post Failed");
71     }
72
73     private void singleton_sr_modify_test() {
74         String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
75         String content = " {\"security_group_rule\": " + "{\"remote_group_id\": null, \"direction\": \"egress\", "
76                 + "\"remote_ip_prefix\": null, \"protocol\": \"tcp\", " + "\"ethertype\": \"IPv6\", \"tenant_id\": "
77                 + "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " + "\"port_range_min\": 77, "
78                 + "\"id\": \"9b4be7fa-e56e-40fb-9516-1f0fa9185669\", " + "\"security_group_id\": "
79                 + "\"" + TEST_SECURITY_GROUP_ID + "\"}}";
80         HttpUtils.test_modify(url, content, "Security Rule Singleton Put Failed");
81     }
82
83     private void sr_element_get_test() {
84         String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
85         HttpUtils.test_fetch(url, true, "Security Rule Element Get Failed");
86     }
87
88     private void sr_element_get_with_query_test() {
89         String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669"
90                 + "?fields=id&fields=direction&fields=protocol&fields=port_range_min"
91                 + "&fields=port_range_max&fields=ethertype&fields=remote_ip_prefix"
92                 + "&fields=remote_group_id&fields=security_group_id&fields=tenant_id"
93                 + "&fields=limit&fields=marker&fields=page_reverse";
94         HttpUtils.test_fetch(url, true, "Security Rule Element Get With Query Failed");
95     }
96
97     private void sr_delete_test() {
98         String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
99         HttpUtils.test_delete(url, "Security Rule Delete Failed");
100     }
101
102     private void sr_element_negative_get_test() {
103         String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
104         HttpUtils.test_fetch(url, false, "Security Rule Element Negative Get Failed");
105     }
106
107     private void bug5478_rule_delete_negative_test() {
108         String url = base + "/security-group-rules/9b4be7fa-e56e-40fb-9516-1f0fa9185669";
109         HttpUtils.test_delete_404(url, "Security Rule Delete 404 Failed");
110     }
111
112     private void bug4043_ipv4_test() {
113         String url = base + "/security-group-rules";
114         String content = " {\"security_group_rule\": " + "{\"remote_group_id\": null, \"direction\": \"ingress\", "
115                 + "\"remote_ip_prefix\": \"10.10.10.10/16\", \"protocol\": \"tcp\", "
116                 + "\"ethertype\": \"IPv4\", \"tenant_id\": "
117                 + "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " + "\"port_range_min\": 77, "
118                 + "\"id\": \"01234567-0123-0123-0123-01234567890a\", " + "\"security_group_id\": "
119                 + "\"" + TEST_SECURITY_GROUP_ID + "\"}}";
120         HttpUtils.test_create(url, content, "Security Rule bug4043 IPv4 Failed");
121
122         url = url + "/01234567-0123-0123-0123-01234567890a";
123         HttpUtils.test_delete(url, "Security Rule Delete Failed");
124     }
125
126     private void bug4043_ipv6_test() {
127         String url = base + "/security-group-rules";
128         String content = " {\"security_group_rule\": " + "{\"remote_group_id\": null, \"direction\": \"ingress\", "
129                 + "\"remote_ip_prefix\": \"fe80::1/10\", \"protocol\": \"tcp\", "
130                 + "\"ethertype\": \"IPv6\", \"tenant_id\": "
131                 + "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " + "\"port_range_min\": 77, "
132                 + "\"id\": \"01234567-0123-0123-0123-01234567890a\", " + "\"security_group_id\": "
133                 + "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
134         HttpUtils.test_create(url, content, "Security Rule Bug4043 IPv6 Failed");
135
136         url = url + "/01234567-0123-0123-0123-01234567890a";
137         HttpUtils.test_delete(url, "Security Rule Delete Failed");
138     }
139
140     private String bug6398_sr_create_test() {
141         String url = base + "/security-group-rules";
142         String content = " {\"security_group_rule\": " + "{\"remote_group_id\": null, \"direction\": \"ingress\", "
143                 + "\"remote_ip_prefix\": null, \"protocol\": \"TCP\", " + "\"ethertype\": \"IPv6\", \"tenant_id\": "
144                 + "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " + "\"port_range_min\": 77, "
145                 + "\"id\": \"9b4be7fa-e56e-40fb-9516-1f0fa9185669\", " + "\"security_group_id\": "
146                 + "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
147         HttpUtils.test_create(url, 400, content, "Security Rule Singleton Post Bug 6398 regressed");
148         return content;
149     }
150
151     public static void runTests(String base) {
152         NeutronSecurityRuleTests securityRuleTester = new NeutronSecurityRuleTests(base);
153         securityRuleTester.singleton_sr_without_groupid_create_test(500);
154         securityRuleTester.singleton_sr_create_test(HttpUtils.HTTP_MISSING_DEPENDENCY);
155         new NeutronSecurityGroupTests(base).singleton_sg_create(TEST_SECURITY_GROUP_ID);
156         String createJsonString = securityRuleTester.singleton_sr_create_test(201);
157         securityRuleTester.singleton_sr_get_with_one_query_item_test(createJsonString);
158         securityRuleTester.multiple_sr_create_test();
159         securityRuleTester.singleton_sr_modify_test();
160         securityRuleTester.sr_element_get_test();
161         securityRuleTester.sr_element_get_with_query_test();
162         securityRuleTester.securityRule_collection_get_test();
163         securityRuleTester.sr_delete_test();
164         securityRuleTester.sr_element_negative_get_test();
165         securityRuleTester.bug5478_rule_delete_negative_test();
166         securityRuleTester.bug4043_ipv4_test();
167         securityRuleTester.bug4043_ipv6_test();
168         securityRuleTester.bug6398_sr_create_test();
169     }
170 }