This repository was archived by the owner on Aug 1, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +127
-0
lines changed
openstack/compute/v2/extensions Expand file tree Collapse file tree 4 files changed +127
-0
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,41 @@ func mockCreateRuleResponse(t *testing.T) {
72
72
})
73
73
}
74
74
75
+ func mockCreateRuleResponseICMPZero (t * testing.T ) {
76
+ th .Mux .HandleFunc (rootPath , func (w http.ResponseWriter , r * http.Request ) {
77
+ th .TestMethod (t , r , "POST" )
78
+ th .TestHeader (t , r , "X-Auth-Token" , fake .TokenID )
79
+
80
+ th .TestJSONRequest (t , r , `
81
+ {
82
+ "security_group_default_rule": {
83
+ "ip_protocol": "ICMP",
84
+ "from_port": 0,
85
+ "to_port": 0,
86
+ "cidr": "10.10.12.0/24"
87
+ }
88
+ }
89
+ ` )
90
+
91
+ w .Header ().Add ("Content-Type" , "application/json" )
92
+ w .WriteHeader (http .StatusOK )
93
+
94
+ fmt .Fprintf (w , `
95
+ {
96
+ "security_group_default_rule": {
97
+ "from_port": 0,
98
+ "id": "{ruleID}",
99
+ "ip_protocol": "ICMP",
100
+ "ip_range": {
101
+ "cidr": "10.10.12.0/24"
102
+ },
103
+ "to_port": 0
104
+ }
105
+ }
106
+ ` )
107
+ })
108
+ }
109
+
75
110
func mockGetRuleResponse (t * testing.T , ruleID string ) {
76
111
url := rootPath + "/" + ruleID
77
112
th .Mux .HandleFunc (url , func (w http.ResponseWriter , r * http.Request ) {
Original file line number Diff line number Diff line change @@ -69,6 +69,32 @@ func TestCreate(t *testing.T) {
69
69
th .AssertDeepEquals (t , expected , group )
70
70
}
71
71
72
+ func TestCreateICMPZero (t * testing.T ) {
73
+ th .SetupHTTP ()
74
+ defer th .TeardownHTTP ()
75
+
76
+ mockCreateRuleResponseICMPZero (t )
77
+
78
+ opts := CreateOpts {
79
+ IPProtocol : "ICMP" ,
80
+ FromPort : 0 ,
81
+ ToPort : 0 ,
82
+ CIDR : "10.10.12.0/24" ,
83
+ }
84
+
85
+ group , err := Create (client .ServiceClient (), opts ).Extract ()
86
+ th .AssertNoErr (t , err )
87
+
88
+ expected := & DefaultRule {
89
+ ID : ruleID ,
90
+ FromPort : 0 ,
91
+ ToPort : 0 ,
92
+ IPProtocol : "ICMP" ,
93
+ IPRange : secgroups.IPRange {CIDR : "10.10.12.0/24" },
94
+ }
95
+ th .AssertDeepEquals (t , expected , group )
96
+ }
97
+
72
98
func TestGet (t * testing.T ) {
73
99
th .SetupHTTP ()
74
100
defer th .TeardownHTTP ()
Original file line number Diff line number Diff line change @@ -216,6 +216,42 @@ func mockAddRuleResponse(t *testing.T) {
216
216
})
217
217
}
218
218
219
+ func mockAddRuleResponseICMPZero (t * testing.T ) {
220
+ th .Mux .HandleFunc ("/os-security-group-rules" , func (w http.ResponseWriter , r * http.Request ) {
221
+ th .TestMethod (t , r , "POST" )
222
+ th .TestHeader (t , r , "X-Auth-Token" , fake .TokenID )
223
+
224
+ th .TestJSONRequest (t , r , `
225
+ {
226
+ "security_group_rule": {
227
+ "from_port": 0,
228
+ "ip_protocol": "ICMP",
229
+ "to_port": 0,
230
+ "parent_group_id": "{groupID}",
231
+ "cidr": "0.0.0.0/0"
232
+ }
233
+ } ` )
234
+
235
+ w .Header ().Add ("Content-Type" , "application/json" )
236
+ w .WriteHeader (http .StatusOK )
237
+
238
+ fmt .Fprintf (w , `
239
+ {
240
+ "security_group_rule": {
241
+ "from_port": 0,
242
+ "group": {},
243
+ "ip_protocol": "ICMP",
244
+ "to_port": 0,
245
+ "parent_group_id": "{groupID}",
246
+ "ip_range": {
247
+ "cidr": "0.0.0.0/0"
248
+ },
249
+ "id": "{ruleID}"
250
+ }
251
+ }` )
252
+ })
253
+ }
254
+
219
255
func mockDeleteRuleResponse (t * testing.T , ruleID string ) {
220
256
url := fmt .Sprintf ("/os-security-group-rules/%s" , ruleID )
221
257
th .Mux .HandleFunc (url , func (w http.ResponseWriter , r * http.Request ) {
Original file line number Diff line number Diff line change @@ -217,6 +217,36 @@ func TestAddRule(t *testing.T) {
217
217
th .AssertDeepEquals (t , expected , rule )
218
218
}
219
219
220
+ func TestAddRuleICMPZero (t * testing.T ) {
221
+ th .SetupHTTP ()
222
+ defer th .TeardownHTTP ()
223
+
224
+ mockAddRuleResponseICMPZero (t )
225
+
226
+ opts := CreateRuleOpts {
227
+ ParentGroupID : groupID ,
228
+ FromPort : 0 ,
229
+ ToPort : 0 ,
230
+ IPProtocol : "ICMP" ,
231
+ CIDR : "0.0.0.0/0" ,
232
+ }
233
+
234
+ rule , err := CreateRule (client .ServiceClient (), opts ).Extract ()
235
+ th .AssertNoErr (t , err )
236
+
237
+ expected := & Rule {
238
+ FromPort : 0 ,
239
+ ToPort : 0 ,
240
+ Group : Group {},
241
+ IPProtocol : "ICMP" ,
242
+ ParentGroupID : groupID ,
243
+ IPRange : IPRange {CIDR : "0.0.0.0/0" },
244
+ ID : ruleID ,
245
+ }
246
+
247
+ th .AssertDeepEquals (t , expected , rule )
248
+ }
249
+
220
250
func TestDeleteRule (t * testing.T ) {
221
251
th .SetupHTTP ()
222
252
defer th .TeardownHTTP ()
You can’t perform that action at this time.
0 commit comments