nifty-cloud-sdk 1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/CHANGELOG +112 -0
  2. data/Gemfile +4 -0
  3. data/INSTALL +30 -0
  4. data/LICENSE.txt +58 -0
  5. data/README.rdoc +375 -0
  6. data/Rakefile +61 -0
  7. data/lib/NIFTY.rb +405 -0
  8. data/lib/NIFTY/Cloud.rb +24 -0
  9. data/lib/NIFTY/Cloud/availability_zones.rb +23 -0
  10. data/lib/NIFTY/Cloud/certificates.rb +283 -0
  11. data/lib/NIFTY/Cloud/images.rb +134 -0
  12. data/lib/NIFTY/Cloud/instances.rb +372 -0
  13. data/lib/NIFTY/Cloud/keypairs.rb +76 -0
  14. data/lib/NIFTY/Cloud/load_balancers.rb +433 -0
  15. data/lib/NIFTY/Cloud/security_groups.rb +357 -0
  16. data/lib/NIFTY/Cloud/volumes.rb +140 -0
  17. data/lib/NIFTY/config.rb +41 -0
  18. data/lib/NIFTY/exceptions.rb +32 -0
  19. data/lib/NIFTY/responses.rb +19 -0
  20. data/lib/NIFTY/version.rb +3 -0
  21. data/nifty-cloud-sdk.gemspec +28 -0
  22. data/sample/availability_zones/describe-availability-zones.rb +37 -0
  23. data/sample/certificate/create-ssl-certificate.rb +41 -0
  24. data/sample/certificate/delete-ssl-certificate.rb +28 -0
  25. data/sample/certificate/describe-ssl-certificate-attribute.rb +58 -0
  26. data/sample/certificate/describe-ssl-certificates.rb +49 -0
  27. data/sample/certificate/download-ssl-certificate.rb +31 -0
  28. data/sample/certificate/modify-ssl-certificate-attribute.rb +29 -0
  29. data/sample/certificate/register-corporate-info-for-certificate.rb +57 -0
  30. data/sample/certificate/upload-ssl-certificate.rb +32 -0
  31. data/sample/images/create-image.rb +33 -0
  32. data/sample/images/delete-image.rb +26 -0
  33. data/sample/images/describe-images.rb +70 -0
  34. data/sample/images/modify-image-attribute.rb +33 -0
  35. data/sample/instances/cancel_copy_instances.rb +26 -0
  36. data/sample/instances/copy-instances.rb +41 -0
  37. data/sample/instances/describe-instance-attribute.rb +78 -0
  38. data/sample/instances/describe-instances.rb +100 -0
  39. data/sample/instances/modify-instance-attribute.rb +30 -0
  40. data/sample/instances/reboot-instances.rb +29 -0
  41. data/sample/instances/run-instances.rb +104 -0
  42. data/sample/instances/start-instances.rb +36 -0
  43. data/sample/instances/stop-instances.rb +35 -0
  44. data/sample/instances/terminate-instances.rb +34 -0
  45. data/sample/keypairs/create-key-pair.rb +31 -0
  46. data/sample/keypairs/delete-key-pair.rb +28 -0
  47. data/sample/keypairs/describe-key-pairs.rb +31 -0
  48. data/sample/load_balancers/configure-health-check.rb +41 -0
  49. data/sample/load_balancers/create-load-balancer.rb +35 -0
  50. data/sample/load_balancers/delete-load-balancer.rb +28 -0
  51. data/sample/load_balancers/deregister-instances-from-load-balancer.rb +35 -0
  52. data/sample/load_balancers/describe-instance-health.rb +36 -0
  53. data/sample/load_balancers/describe-load-balancers.rb +89 -0
  54. data/sample/load_balancers/register-instances-with-load-balancer.rb +33 -0
  55. data/sample/load_balancers/register-port-with-load-balancer.rb +37 -0
  56. data/sample/load_balancers/set-filter-for-load-balancer.rb +38 -0
  57. data/sample/load_balancers/update-load-balancer.rb +33 -0
  58. data/sample/security_groups/authorize-security-group-ingress.rb +36 -0
  59. data/sample/security_groups/create-security-group.rb +29 -0
  60. data/sample/security_groups/delete-security-group.rb +28 -0
  61. data/sample/security_groups/deregister-instances-from-security-group.rb +31 -0
  62. data/sample/security_groups/describe-security-activities.rb +33 -0
  63. data/sample/security_groups/describe-security-groups.rb +59 -0
  64. data/sample/security_groups/register-instances-with-security-group.rb +31 -0
  65. data/sample/security_groups/revoke-security-group-ingress.rb +36 -0
  66. data/sample/security_groups/update-security-group.rb +30 -0
  67. data/sample/volumes/attach-volumes.rb +34 -0
  68. data/sample/volumes/create-volume.rb +38 -0
  69. data/sample/volumes/delete-volume.rb +28 -0
  70. data/sample/volumes/describe-volumes.rb +44 -0
  71. data/sample/volumes/detach-volume.rb +35 -0
  72. data/test/test_Cloud.rb +186 -0
  73. data/test/test_Cloud_availability_zones.rb +50 -0
  74. data/test/test_Cloud_certificates.rb +627 -0
  75. data/test/test_Cloud_images.rb +284 -0
  76. data/test/test_Cloud_instances.rb +941 -0
  77. data/test/test_Cloud_keypairs.rb +177 -0
  78. data/test/test_Cloud_load_balancers.rb +1183 -0
  79. data/test/test_Cloud_responses.rb +43 -0
  80. data/test/test_Cloud_security_groups.rb +699 -0
  81. data/test/test_Cloud_volumes.rb +325 -0
  82. data/test/test_helper.rb +23 -0
  83. metadata +275 -0
@@ -0,0 +1,43 @@
1
+ #--
2
+ # ニフティクラウドSDK for Ruby
3
+ #
4
+ # Ruby Gem Name:: nifty-cloud-sdk
5
+ # Author:: NIFTY Corporation
6
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://cloud.nifty.com/api/
9
+ #++
10
+
11
+ require File.dirname(__FILE__) + '/test_helper.rb'
12
+
13
+ context "Response classes" do
14
+
15
+
16
+ before do
17
+ @http_xml = <<-RESPONSE
18
+ <RebootInstancesResponse xmlns="http://cp.cloud.nifty.com/api/1.7/">
19
+ <return>true</return>
20
+ </RebootInstancesResponse>
21
+ RESPONSE
22
+
23
+ @response = NIFTY::Response.parse(:xml => @http_xml)
24
+ end
25
+
26
+
27
+ specify "should show the response as a formatted string when calling #inspect" do
28
+ # sorting the response hash first since ruby 1.8.6 and ruby 1.9.1 sort the hash differently before the inspect
29
+ @response.sort.inspect.should.equal %{[[\"return\", \"true\"], [\"xmlns\", \"http://cp.cloud.nifty.com/api/1.7/\"]]}
30
+ end
31
+
32
+
33
+ specify "should be a Hash" do
34
+ @response.kind_of?(Hash).should.equal true
35
+ end
36
+
37
+
38
+ specify "should return its members" do
39
+ @response.keys.length.should.equal 2
40
+ test_array = ["return", "xmlns"].sort
41
+ @response.keys.sort.should.equal test_array
42
+ end
43
+ end
@@ -0,0 +1,699 @@
1
+ #--
2
+ # ニフティクラウドSDK for Ruby
3
+ #
4
+ # Ruby Gem Name:: nifty-cloud-sdk
5
+ # Author:: NIFTY Corporation
6
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://cloud.nifty.com/api/
9
+ #++
10
+
11
+ require File.dirname(__FILE__) + '/test_helper.rb'
12
+
13
+ context "security_groups" do
14
+
15
+ before do
16
+ @api = NIFTY::Cloud::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret",
17
+ :server => 'cp.cloud.nifty.com', :path => '/api/1.7/', :user_agent => 'NIFTY Cloud API Ruby SDK',
18
+ :signature_version => '2', :signature_method => 'HmacSHA256')
19
+
20
+ @valid_ip_protocol = %w(TCP UDP ICMP SSH HTTP HTTPS SMTP POP3 IMAP)
21
+ @valid_in_out = %w(IN In in Out Out out)
22
+
23
+ @basic_ip_permissions = {:ip_protocol => 'HTTP', :group_name => 'gr2'}
24
+ @basic_auth_security_params = {:group_name => 'gr1', :ip_permissions => @basic_ip_permissions}
25
+
26
+ @create_security_group_response_body = <<-RESPONSE
27
+ <CreateSecurityGroupResponse xmlns="https://cp.cloud.nifty.com/api/">
28
+ <requestId>320fc738-a1c7-4a2f-abcb-20813a4e997c</requestId>
29
+ <return>true</return>
30
+ </CreateSecurityGroupResponse>
31
+ RESPONSE
32
+
33
+ @delete_security_group_response_body = <<-RESPONSE
34
+ <DeleteSecurityGroupResponse xmlns="https://cp.cloud.nifty.com/api/">
35
+ <requestId>320fc738-a1c7-4a2f-abcb-20813a4e997c</requestId>
36
+ <return>true</return>
37
+ </DeleteSecurityGroupResponse>
38
+ RESPONSE
39
+
40
+ @update_security_group_response_body = <<-RESPONSE
41
+ <UpdateSecurityGroupResponse xmlns="https://cp.cloud.nifty.com/api/">
42
+ <requestId>320fc738-a1c7-4a2f-abcb-20813a4e997c</requestId>
43
+ <return>true</return>
44
+ </UpdateSecurityGroupResponse>
45
+ RESPONSE
46
+
47
+ @describe_security_groups_response_body = <<-RESPONSE
48
+ <DescribeSecurityGroupsResponse xmlns="https://cp.cloud.nifty.com/api/">
49
+ <requestId>320fc738-a1c7-4a2f-abcb-20813a4e997c</requestId>
50
+ <securityGroupInfo>
51
+ <item>
52
+ <ownerId />
53
+ <groupName>websvr2</groupName>
54
+ <groupDescription>webサーバー用</groupDescription>
55
+ <ipPermissions>
56
+ <item>
57
+ <ipProtocol>SSH</ipProtocol>
58
+ <fromPort>22</fromPort>
59
+ <toPort />
60
+ <inOut>IN</inOut>
61
+ <groups />
62
+ <ipRanges>
63
+ <item>
64
+ <cidrIp>0.0.0.0/0</cidrIp>
65
+ </item>
66
+ </ipRanges>
67
+ </item>
68
+ <item>
69
+ <ipProtocol>HTTP</ipProtocol>
70
+ <fromPort>80</fromPort>
71
+ <toPort />
72
+ <inOut>OUT</inOut>
73
+ <groups>
74
+ <item>
75
+ <userId />
76
+ <groupName>Web</groupName>
77
+ </item>
78
+ </groups>
79
+ </item>
80
+ </ipPermissions>
81
+ <instances>
82
+ <member>
83
+ <instanceId>server01</instanceId>
84
+ <instanceId>server02</instanceId>
85
+ </member>
86
+ </instances>
87
+ </item>
88
+ </securityGroupInfo>
89
+ </DescribeSecurityGroupsResponse>
90
+ RESPONSE
91
+
92
+ @authorize_security_group_ingress_response_body = <<-RESPONSE
93
+ <AuthorizeSecurityGroupIngressResponse xmlns="https://cp.cloud.nifty.com/api/">
94
+ <requestId>320fc738-a1c7-4a2f-abcb-20813a4e997c</requestId>
95
+ <return>true</return>
96
+ </AuthorizeSecurityGroupIngressResponse>
97
+ RESPONSE
98
+
99
+ @revoke_security_group_ingress_response_body = <<-RESPONSE
100
+ <RevokeSecurityGroupIngressResponse xmlns="https://cp.cloud.nifty.com/api/">
101
+ <requestId>320fc738-a1c7-4a2f-abcb-20813a4e997c</requestId>
102
+ <return>true</return>
103
+ </RevokeSecurityGroupIngressResponse>
104
+ RESPONSE
105
+
106
+ @register_instances_with_security_group_response_body = <<-RESPONSE
107
+ <RegisterInstancesWithSecurityGroupResponse xmlns="https://cp.cloud.nifty.com/api/">
108
+ <requestId>320fc738-a1c7-4a2f-abcb-20813a4e997c</requestId>
109
+ <instancesSet>
110
+ <item>
111
+ <instanceId>server01</instanceId>
112
+ </item>
113
+ <item>
114
+ <instanceId>server02</instanceId>
115
+ </item>
116
+ </instancesSet>
117
+ </RegisterInstancesWithSecurityGroupResponse>
118
+ RESPONSE
119
+
120
+ @deregister_instances_from_security_group_response_body = <<-RESPONSE
121
+ <DeregisterInstancesWithSecurityGroupResponse xmlns="https://cp.cloud.nifty.com/api/">
122
+ <requestId>320fc738-a1c7-4a2f-abcb-20813a4e997c</requestId>
123
+ <instancesSet>
124
+ <item>
125
+ <instanceId>server01</instanceId>
126
+ </item>
127
+ <item>
128
+ <instanceId>server02</instanceId>
129
+ </item>
130
+ </instancesSet>
131
+ </DeregisterInstancesWithSecurityGroupResponse>
132
+ RESPONSE
133
+
134
+ @describe_security_activities_response_body = <<-RESPONSE
135
+ <DescribeSecurityActivitiesResponse xmlns="https://cp.cloud.nifty.com/api/">
136
+ <requestId>320fc738-a1c7-4a2f-abcb-20813a4e997c</requestId>
137
+ <groupName>websrv</groupName>
138
+ <log>2011-01-05T08:53:29+09:00 Altor_VNF time=1294217609140 fw_id=4 src_ip=10.0.6.201 src_port=68 dst_ip=10.0.4.11 dst_port=67 ip_proto=17 action=accept vm_id=16853 rule_id=52 type=fw
139
+ 2011-01-09T11:21:53+09:00 Altor_VNF time=2297218603613 fw_id=4 src_ip=10.0.6.201 src_port=68 dst_ip=10.0.4.11 dst_port=67 ip_proto=17 action=accept vm_id=16853 rule_id=52 type=fw</log>
140
+ </DescribeSecurityActivitiesResponse>
141
+ RESPONSE
142
+ end
143
+
144
+
145
+ # create_security_group
146
+ specify "create_security_group - レスポンスを正しく解析できるか" do
147
+ @api.stubs(:exec_request).returns stub(:body => @create_security_group_response_body, :is_a? => true)
148
+ response = @api.create_security_group(:group_name => 'gr1')
149
+ response.requestId.should.equal '320fc738-a1c7-4a2f-abcb-20813a4e997c'
150
+ response.return.should.equal 'true'
151
+ end
152
+
153
+ specify "create_security_group - パラメータが正しく作られるか" do
154
+ @api.stubs(:make_request).with("Action" => "CreateSecurityGroup",
155
+ "GroupName" => "a",
156
+ "GroupDescription" => "a"
157
+ ).returns stub(:body => @create_security_group_response_body, :is_a? => true)
158
+ @api.stubs(:exec_request).returns stub(:body => @create_security_group_response_body, :is_a? => true)
159
+ response = @api.create_security_group(:group_name => "a", :group_description => "a")
160
+ end
161
+
162
+ specify "create_security_group - :group_name正常" do
163
+ @api.stubs(:exec_request).returns stub(:body => @create_security_group_response_body, :is_a? => true)
164
+ lambda { @api.create_security_group(:group_name => 'Group') }.should.not.raise(NIFTY::ArgumentError)
165
+ end
166
+
167
+ specify "create_security_group - :group_description正常" do
168
+ @api.stubs(:exec_request).returns stub(:body => @create_security_group_response_body, :is_a? => true)
169
+ lambda { @api.create_security_group(:group_name => 'foo', :group_description => 'メモ') }.should.not.raise(NIFTY::ArgumentError)
170
+ end
171
+
172
+ specify "create_security_group - :group_name未指定/不正" do
173
+ lambda { @api.create_security_group }.should.raise(NIFTY::ArgumentError)
174
+ lambda { @api.create_security_group(:group_name => nil) }.should.raise(NIFTY::ArgumentError)
175
+ lambda { @api.create_security_group(:group_name => '') }.should.raise(NIFTY::ArgumentError)
176
+ lambda { @api.create_security_group(:group_name => 'group_name') }.should.raise(NIFTY::ArgumentError)
177
+ lambda { @api.create_security_group(:group_name => 'default(Linux)') }.should.raise(NIFTY::ArgumentError)
178
+ lambda { @api.create_security_group(:group_name => 'default(Windows)') }.should.raise(NIFTY::ArgumentError)
179
+ end
180
+
181
+
182
+ # delete_security_group
183
+ specify "delete_security_group - レスポンスを正しく解析できるか" do
184
+ @api.stubs(:exec_request).returns stub(:body => @delete_security_group_response_body, :is_a? => true)
185
+ response = @api.delete_security_group(:group_name => 'gr1')
186
+ response.requestId.should.equal '320fc738-a1c7-4a2f-abcb-20813a4e997c'
187
+ response.return.should.equal 'true'
188
+ end
189
+
190
+ specify "delete_security_group - パラメータが正しく作られるか" do
191
+ @api.stubs(:make_request).with("Action" => "DeleteSecurityGroup", "GroupName" => "a"
192
+ ).returns stub(:body => @delete_security_group_response_body, :is_a? => true)
193
+ @api.stubs(:exec_request).returns stub(:body => @delete_security_group_response_body, :is_a? => true)
194
+ response = @api.delete_security_group(:group_name => "a")
195
+ end
196
+
197
+ specify "delete_security_group - :group_name正常" do
198
+ @api.stubs(:exec_request).returns stub(:body => @delete_security_group_response_body, :is_a? => true)
199
+ lambda { @api.delete_security_group(:group_name => 'Group') }.should.not.raise(NIFTY::ArgumentError)
200
+ end
201
+
202
+ specify "delete_security_group - :group_name未指定/不正" do
203
+ lambda { @api.delete_security_group }.should.raise(NIFTY::ArgumentError)
204
+ lambda { @api.delete_security_group(:group_name => nil) }.should.raise(NIFTY::ArgumentError)
205
+ lambda { @api.delete_security_group(:group_name => '') }.should.raise(NIFTY::ArgumentError)
206
+ lambda { @api.delete_security_group(:group_name => 'Group_name') }.should.raise(NIFTY::ArgumentError)
207
+ lambda { @api.delete_security_group(:group_name => 'default(Linux)') }.should.raise(NIFTY::ArgumentError)
208
+ lambda { @api.delete_security_group(:group_name => 'default(Windows)') }.should.raise(NIFTY::ArgumentError)
209
+ end
210
+
211
+
212
+ # update_security_group
213
+ specify "update_security_group - レスポンスを正しく解析できるか" do
214
+ @api.stubs(:exec_request).returns stub(:body => @update_security_group_response_body, :is_a? => true)
215
+ response = @api.update_security_group(:group_name => 'gr1')
216
+ response.requestId.should.equal '320fc738-a1c7-4a2f-abcb-20813a4e997c'
217
+ response.return.should.equal 'true'
218
+ end
219
+
220
+ specify "update_security_group - パラメータが正しく作られるか" do
221
+ @api.stubs(:make_request).with("Action" => "UpdateSecurityGroup",
222
+ "GroupName" => "a",
223
+ "GroupNameUpdate" => "a",
224
+ "GroupDescriptionUpdate" => "a"
225
+ ).returns stub(:body => @update_security_group_response_body, :is_a? => true)
226
+ @api.stubs(:exec_request).returns stub(:body => @update_security_group_response_body, :is_a? => true)
227
+ response = @api.update_security_group(:group_name => "a", :group_name_update => "a", :group_description_update => "a")
228
+ end
229
+
230
+ specify "update_security_group - :group_name正常" do
231
+ @api.stubs(:exec_request).returns stub(:body => @update_security_group_response_body, :is_a? => true)
232
+ lambda { @api.update_security_group(:group_name => 'default(Linux)') }.should.not.raise(NIFTY::ArgumentError)
233
+ lambda { @api.update_security_group(:group_name => 'default(Windows)') }.should.not.raise(NIFTY::ArgumentError)
234
+ lambda { @api.update_security_group(:group_name => 'Group') }.should.not.raise(NIFTY::ArgumentError)
235
+ end
236
+
237
+ specify "update_security_group - :group_name_update正常" do
238
+ @api.stubs(:exec_request).returns stub(:body => @update_security_group_response_body, :is_a? => true)
239
+ lambda { @api.update_security_group(:group_name => 'foo', :group_name_update => 'bar') }.should.not.raise(NIFTY::ArgumentError)
240
+ end
241
+
242
+ specify "update_security_group - :group_description_update正常" do
243
+ @api.stubs(:exec_request).returns stub(:body => @update_security_group_response_body, :is_a? => true)
244
+ lambda { @api.update_security_group(:group_name => 'foo', :group_description_update => 'テスト') }.should.not.raise(NIFTY::ArgumentError)
245
+ end
246
+
247
+ specify "update_security_group - :group_name未指定/不正" do
248
+ lambda { @api.update_security_group }.should.raise(NIFTY::ArgumentError)
249
+ lambda { @api.update_security_group(:group_name => nil) }.should.raise(NIFTY::ArgumentError)
250
+ lambda { @api.update_security_group(:group_name => '') }.should.raise(NIFTY::ArgumentError)
251
+ lambda { @api.update_security_group(:group_name => 'Group_name') }.should.raise(NIFTY::ArgumentError)
252
+ end
253
+
254
+
255
+ # describe_security_groups
256
+ specify "describe_security_groups - レスポンスを正しく解析できるか" do
257
+ @api.stubs(:exec_request).returns stub(:body => @describe_security_groups_response_body, :is_a? => true)
258
+ response = @api.describe_security_groups
259
+ response.requestId.should.equal '320fc738-a1c7-4a2f-abcb-20813a4e997c'
260
+ response.securityGroupInfo.item[0].ownerId.should.equal nil
261
+ response.securityGroupInfo.item[0].groupName.should.equal 'websvr2'
262
+ response.securityGroupInfo.item[0].groupDescription.should.equal 'webサーバー用'
263
+ response.securityGroupInfo.item[0].ipPermissions.item[0].ipProtocol.should.equal 'SSH'
264
+ response.securityGroupInfo.item[0].ipPermissions.item[0].fromPort.should.equal '22'
265
+ response.securityGroupInfo.item[0].ipPermissions.item[0].toPort.should.equal nil
266
+ response.securityGroupInfo.item[0].ipPermissions.item[0].inOut.should.equal 'IN'
267
+ response.securityGroupInfo.item[0].ipPermissions.item[0].groups.should.equal nil
268
+ response.securityGroupInfo.item[0].ipPermissions.item[0].ipRanges.item[0].cidrIp.should.equal '0.0.0.0/0'
269
+ response.securityGroupInfo.item[0].ipPermissions.item[1].ipProtocol.should.equal 'HTTP'
270
+ response.securityGroupInfo.item[0].ipPermissions.item[1].fromPort.should.equal '80'
271
+ response.securityGroupInfo.item[0].ipPermissions.item[1].toPort.should.equal nil
272
+ response.securityGroupInfo.item[0].ipPermissions.item[1].inOut.should.equal 'OUT'
273
+ response.securityGroupInfo.item[0].ipPermissions.item[1].groups.item[0].userId.should.equal nil
274
+ response.securityGroupInfo.item[0].ipPermissions.item[1].groups.item[0].groupName.should.equal 'Web'
275
+ response.securityGroupInfo.item[0].instances.member[0].instanceId[0].should.equal 'server01'
276
+ response.securityGroupInfo.item[0].instances.member[0].instanceId[1].should.equal 'server02'
277
+ end
278
+
279
+ specify "describe_security_groups - パラメータが正しく作られるか" do
280
+ @api.stubs(:make_request).with("Action" => "DescribeSecurityGroups",
281
+ "GroupName.1" => "a",
282
+ "GroupName.2" => "a",
283
+ "Filter.1.Name" => "description",
284
+ "Filter.1.Value.1" => "a",
285
+ "Filter.1.Value.2" => "a"
286
+ ).returns stub(:body => @describe_security_groups_response_body, :is_a? => true)
287
+ @api.stubs(:exec_request).returns stub(:body => @describe_security_groups_response_body, :is_a? => true)
288
+ response = @api.describe_security_groups(:group_name => %w(a a), :filter => {:name => "description", :value => %w(a a)})
289
+ end
290
+
291
+ specify "describe_security_groups - :group_name正常" do
292
+ @api.stubs(:exec_request).returns stub(:body => @describe_security_groups_response_body, :is_a? => true)
293
+ lambda { @api.describe_security_groups(:group_name => 'Group') }.should.not.raise(NIFTY::ArgumentError)
294
+ lambda { @api.describe_security_groups(:group_name => 'default(Linux)') }.should.not.raise(NIFTY::ArgumentError)
295
+ lambda { @api.describe_security_groups(:group_name => 'default(Windows)') }.should.not.raise(NIFTY::ArgumentError)
296
+ lambda { @api.describe_security_groups(:group_name => %w(Group1 Group2 group3)) }.should.not.raise(NIFTY::ArgumentError)
297
+ end
298
+
299
+ specify "describe_security_groups - :filter正常" do
300
+ @api.stubs(:exec_request).returns stub(:body => @describe_security_groups_response_body, :is_a? => true)
301
+ filter_params = {
302
+ 'Action' => 'DescribeSecurityGroups',
303
+ 'Filter.1.Name'=>'description',
304
+ 'Filter.1.Value.1'=>'foo'
305
+ }
306
+ @api.stubs(:make_request).with(filter_params).returns stub(nil)
307
+ lambda { @api.describe_security_groups(:filter => {:name => 'description', :value => 'foo'}) }.should.not.raise(NIFTY::ArgumentError)
308
+ @api.stubs(:make_request).with(filter_params.merge('Filter.1.Value.2'=>'bar',
309
+ 'Filter.2.Name'=>'group-name',
310
+ 'Filter.2.Value.1'=>'bar')).returns stub(nil)
311
+ lambda { @api.describe_security_groups(:filter => [{:name => 'description', :value => %w(foo bar)},{:name => 'group-name', :value => 'bar'}]) }.should.not.raise(NIFTY::ArgumentError)
312
+ end
313
+
314
+ specify "describe_security_groups - :filter - :name不正" do
315
+ lambda { @api.describe_security_groups(:filter => {:name => 'foo', :value => 'foo'}) }.should.raise(NIFTY::ArgumentError)
316
+ lambda { @api.describe_security_groups(:filter => [{:name => 'description', :value => %w(foo bar)},{:name => 'bar', :value => 'bar'}]) }.should.raise(NIFTY::ArgumentError)
317
+ end
318
+
319
+
320
+ # authorize_security_group_ingress
321
+ specify "authorize_security_group_ingress - レスポンスを正しく解析できるか" do
322
+ @api.stubs(:make_request).with({'Action'=>'AuthorizeSecurityGroupIngress',
323
+ 'GroupName'=>'gr1',
324
+ 'IpPermissions.1.IpProtocol'=>'HTTP',
325
+ 'IpPermissions.1.Groups.1.GroupName'=>'gr2'}).returns stub(nil)
326
+ @api.stubs(:exec_request).returns stub(:body => @authorize_security_group_ingress_response_body, :is_a? => true)
327
+ response = @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => {:ip_protocol => 'HTTP', :group_name => 'gr2'})
328
+ response.requestId.should.equal '320fc738-a1c7-4a2f-abcb-20813a4e997c'
329
+ response.return.should.equal 'true'
330
+ end
331
+
332
+ specify "authorize_security_group_ingress - パラメータが正しく作られるか" do
333
+ @api.stubs(:make_request).with({'Action'=>'AuthorizeSecurityGroupIngress',
334
+ 'IpPermissions.1.FromPort'=>'80',
335
+ 'IpPermissions.1.Groups.1.GroupName'=>'gr1',
336
+ 'IpPermissions.2.Groups.1.GroupName'=>'default(Linux)',
337
+ 'IpPermissions.2.Groups.2.GroupName'=>'default(Windows)',
338
+ 'IpPermissions.2.Groups.1.UserId'=>'id1',
339
+ 'IpPermissions.2.Groups.2.UserId'=>'id2',
340
+ 'IpPermissions.1.InOut'=>'IN',
341
+ 'IpPermissions.2.IpProtocol'=>'HTTP',
342
+ 'IpPermissions.1.IpProtocol'=>'TCP',
343
+ 'IpPermissions.1.IpRanges.1.CidrIp'=>'111.111.111.111',
344
+ 'IpPermissions.1.IpRanges.2.CidrIp'=>'111.111.111.112',
345
+ 'IpPermissions.1.ToPort'=>'80',
346
+ 'GroupName'=>'gr1',
347
+ }).returns stub(nil)
348
+
349
+ @api.stubs(:exec_request).returns stub(:body => @authorize_security_group_ingress_response_body, :is_a? => true)
350
+ response = @api.authorize_security_group_ingress(:group_name => 'gr1',
351
+ :ip_permissions => [
352
+ {:ip_protocol => 'TCP', :from_port => 80, :to_port => 80, :in_out => 'IN',
353
+ :group_name => 'gr1', :cidr_ip => %w(111.111.111.111 111.111.111.112)},
354
+ {:ip_protocol => 'HTTP', :user_id => %w(id1 id2), :group_name => %w(default(Linux) default(Windows))}])
355
+ response.requestId.should.equal '320fc738-a1c7-4a2f-abcb-20813a4e997c'
356
+ response.return.should.equal 'true'
357
+ end
358
+
359
+ specify "authorize_security_group_ingress - :ip_permissions未指定" do
360
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => "") }.should.raise(NIFTY::ArgumentError)
361
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => nil) }.should.raise(NIFTY::ArgumentError)
362
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => {}) }.should.raise(NIFTY::ArgumentError)
363
+ end
364
+
365
+ specify "authorize_security_group_ingress - :ip_permissions - :ip_protocol正常" do
366
+ @api.stubs(:exec_request).returns stub(:body => @authorize_security_group_ingress_response_body, :is_a? => true)
367
+ @valid_ip_protocol.each do |protocol|
368
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => protocol, :from_port => 8080)) }.should.not.raise(NIFTY::ArgumentError)
369
+ end
370
+ end
371
+
372
+ specify "authorize_security_group_ingress - :ip_permissions - :from_port正常" do
373
+ @api.stubs(:exec_request).returns stub(:body => @authorize_security_group_ingress_response_body, :is_a? => true)
374
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => {:ip_protocol => 'HTTP', :from_port => 80, :group_name => 'gr2'}) }.should.not.raise(NIFTY::ArgumentError)
375
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => {:ip_protocol => 'TCP', :from_port => 443, :group_name => 'gr2'}) }.should.not.raise(NIFTY::ArgumentError)
376
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => {:ip_protocol => 'UDP', :from_port => 22, :group_name => 'gr2'}) }.should.not.raise(NIFTY::ArgumentError)
377
+ end
378
+
379
+ specify "authorize_security_group_ingress - :ip_permissions - :to_port正常" do
380
+ @api.stubs(:exec_request).returns stub(:body => @authorize_security_group_ingress_response_body, :is_a? => true)
381
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:to_port => 80)) }.should.not.raise(NIFTY::ArgumentError)
382
+ end
383
+
384
+ specify "authorize_security_group_ingress - :ip_permissions - :in_ou正常" do
385
+ @api.stubs(:exec_request).returns stub(:body => @authorize_security_group_ingress_response_body, :is_a? => true)
386
+ @valid_in_out.each do |io|
387
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:in_out => io)) }.should.not.raise(NIFTY::ArgumentError)
388
+ end
389
+ end
390
+
391
+ specify "authorize_security_group_ingress - :ip_permissions - :user_id正常" do
392
+ @api.stubs(:exec_request).returns stub(:body => @authorize_security_group_ingress_response_body, :is_a? => true)
393
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:user_id => 'user')) }.should.not.raise(NIFTY::ArgumentError)
394
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:user_id => %w(foo bar hoge))) }.should.not.raise(NIFTY::ArgumentError)
395
+ end
396
+
397
+ specify "authorize_security_group_ingress - :ip_permissions - :group_name正常" do
398
+ @api.stubs(:exec_request).returns stub(:body => @authorize_security_group_ingress_response_body, :is_a? => true)
399
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:group_name => 'foo')) }.should.not.raise(NIFTY::ArgumentError)
400
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:group_name => %w(foo bar hoge))) }.should.not.raise(NIFTY::ArgumentError)
401
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => [@basic_ip_permissions.merge(:group_name => 'foo'), @basic_ip_permissions.merge(:group_name => 'bar')]) }.should.not.raise(NIFTY::ArgumentError)
402
+ end
403
+
404
+ specify "authorize_security_group_ingress - :ip_permissions - :cidr_ip正常" do
405
+ @api.stubs(:exec_request).returns stub(:body => @authorize_security_group_ingress_response_body, :is_a? => true)
406
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:group_name => nil, :cidr_ip => '111.111.111.111')) }.should.not.raise(NIFTY::ArgumentError)
407
+ lambda { @api.authorize_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:group_name => nil, :cidr_ip => ['111.111.111.111', '::ffff:6f6f:6f6f'])) }.should.not.raise(NIFTY::ArgumentError)
408
+ end
409
+
410
+ specify "authorize_security_group_ingress - :group_name未指定" do
411
+ lambda { @api.authorize_security_group_ingress(@basic_auth_security_params.reject{|k, v| k == :group_name}) }.should.raise(NIFTY::ArgumentError)
412
+ lambda { @api.authorize_security_group_ingress(@basic_auth_security_params.merge(:group_name => nil)) }.should.raise(NIFTY::ArgumentError)
413
+ lambda { @api.authorize_security_group_ingress(@basic_auth_security_params.merge(:group_name => '')) }.should.raise(NIFTY::ArgumentError)
414
+ end
415
+
416
+ specify "authorize_security_group_ingress - :ip_permissions - :ip_protocol不正" do
417
+ lambda { @api.authorize_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => 'bar')) }.should.raise(NIFTY::ArgumentError)
418
+ lambda { @api.authorize_security_group_ingress(:group_name => 'foo', :ip_permissions => [@basic_ip_permissions.merge(:ip_protocol => 'HTTP'), @basic_ip_permissions.merge(:ip_protocol => 'bar')]) }.should.raise(NIFTY::ArgumentError)
419
+ end
420
+
421
+ specify "authorize_security_group_ingress - :ip_permissions - :from_port未指定" do
422
+ lambda { @api.authorize_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => 'TCP')) }.should.raise(NIFTY::ArgumentError)
423
+ lambda { @api.authorize_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => 'TCP', :from_port => nil)) }.should.raise(NIFTY::ArgumentError)
424
+ lambda { @api.authorize_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => 'TCP', :from_port => '')) }.should.raise(NIFTY::ArgumentError)
425
+ lambda { @api.authorize_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => 'UDP')) }.should.raise(NIFTY::ArgumentError)
426
+ lambda { @api.authorize_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => 'UDP', :from_port => nil)) }.should.raise(NIFTY::ArgumentError)
427
+ lambda { @api.authorize_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => 'UDP', :from_port => '')) }.should.raise(NIFTY::ArgumentError)
428
+ end
429
+
430
+ specify "authorize_security_group_ingress - :cidr_ip不正" do
431
+ lambda { @api.authorize_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:cidr_ip => 'foo')) }.should.raise(NIFTY::ArgumentError)
432
+ lambda { @api.authorize_security_group_ingress(:group_name => 'foo', :ip_permissions => [@basic_ip_permissions.merge(:cidr_ip => '111.111.111.111'), @basic_ip_permissions.merge(:cidr_ip => 'foo')]) }.should.raise(NIFTY::ArgumentError)
433
+ end
434
+
435
+
436
+ # revoke_security_group_ingress
437
+ specify "revoke_security_group_ingress - レスポンスを正しく解析できるか" do
438
+ @api.stubs(:make_request).with({'Action'=>'RevokeSecurityGroupIngress',
439
+ 'GroupName'=>'gr1',
440
+ 'IpPermissions.1.IpProtocol'=>'HTTP',
441
+ 'IpPermissions.1.Groups.1.GroupName'=>'gr2'}).returns stub(nil)
442
+ @api.stubs(:exec_request).returns stub(:body => @revoke_security_group_ingress_response_body, :is_a? => true)
443
+ response = @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => {:ip_protocol => 'HTTP', :group_name => 'gr2'})
444
+ response.requestId.should.equal '320fc738-a1c7-4a2f-abcb-20813a4e997c'
445
+ response.return.should.equal 'true'
446
+ end
447
+
448
+ specify "revoke_security_group_ingress - パラメータが正しく作られるか" do
449
+ @api.stubs(:make_request).with({'Action'=>'RevokeSecurityGroupIngress',
450
+ 'IpPermissions.1.FromPort'=>'80',
451
+ 'IpPermissions.1.Groups.1.GroupName'=>'gr1',
452
+ 'IpPermissions.2.Groups.1.GroupName'=>'default(Linux)',
453
+ 'IpPermissions.2.Groups.2.GroupName'=>'default(Windows)',
454
+ 'IpPermissions.2.Groups.1.UserId'=>'id1',
455
+ 'IpPermissions.2.Groups.2.UserId'=>'id2',
456
+ 'IpPermissions.2.Groups.3.UserId'=>'id3',
457
+ 'IpPermissions.1.InOut'=>'IN',
458
+ 'IpPermissions.2.IpProtocol'=>'HTTP',
459
+ 'IpPermissions.1.IpProtocol'=>'TCP',
460
+ 'IpPermissions.1.IpRanges.1.CidrIp'=>'111.111.111.111',
461
+ 'IpPermissions.1.IpRanges.2.CidrIp'=>'111.111.111.112',
462
+ 'IpPermissions.1.ToPort'=>'80',
463
+ 'GroupName'=>'gr1',
464
+ }).returns stub(nil)
465
+
466
+ @api.stubs(:exec_request).returns stub(:body => @revoke_security_group_ingress_response_body, :is_a? => true)
467
+ response = @api.revoke_security_group_ingress(:group_name => 'gr1',
468
+ :ip_permissions => [
469
+ {:ip_protocol => 'TCP', :from_port => 80, :to_port => 80, :in_out => 'IN',
470
+ :group_name => 'gr1', :cidr_ip => %w(111.111.111.111 111.111.111.112)},
471
+ {:ip_protocol => 'HTTP', :user_id => %w(id1 id2)<<''<<'id3', :group_name => %w(default(Linux) default(Windows))}])
472
+ response.requestId.should.equal '320fc738-a1c7-4a2f-abcb-20813a4e997c'
473
+ response.return.should.equal 'true'
474
+ end
475
+
476
+
477
+ specify "revoke_security_group_ingress - :ip_permissions未指定" do
478
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => "") }.should.raise(NIFTY::ArgumentError)
479
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => nil) }.should.raise(NIFTY::ArgumentError)
480
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => {}) }.should.raise(NIFTY::ArgumentError)
481
+ end
482
+
483
+ specify "revoke_security_group_ingress - :ip_permissions - :ip_protocol正常" do
484
+ @api.stubs(:exec_request).returns stub(:body => @revoke_security_group_ingress_response_body, :is_a? => true)
485
+ @valid_ip_protocol.each do |protocol|
486
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => protocol, :from_port => 8080)) }.should.not.raise(NIFTY::ArgumentError)
487
+ end
488
+ end
489
+
490
+ specify "revoke_security_group_ingress - :ip_permissions - :from_port正常" do
491
+ @api.stubs(:exec_request).returns stub(:body => @revoke_security_group_ingress_response_body, :is_a? => true)
492
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => {:ip_protocol => 'HTTP', :from_port => 80, :group_name => 'gr2'}) }.should.not.raise(NIFTY::ArgumentError)
493
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => {:ip_protocol => 'TCP', :from_port => 443, :group_name => 'gr2'}) }.should.not.raise(NIFTY::ArgumentError)
494
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => {:ip_protocol => 'UDP', :from_port => 22, :group_name => 'gr2'}) }.should.not.raise(NIFTY::ArgumentError)
495
+ end
496
+
497
+ specify "revoke_security_group_ingress - :ip_permissions - :to_port正常" do
498
+ @api.stubs(:exec_request).returns stub(:body => @revoke_security_group_ingress_response_body, :is_a? => true)
499
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:to_port => 80)) }.should.not.raise(NIFTY::ArgumentError)
500
+ end
501
+
502
+ specify "revoke_security_group_ingress - :ip_permissions - :in_ou正常" do
503
+ @api.stubs(:exec_request).returns stub(:body => @revoke_security_group_ingress_response_body, :is_a? => true)
504
+ @valid_in_out.each do |io|
505
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:in_out => io)) }.should.not.raise(NIFTY::ArgumentError)
506
+ end
507
+ end
508
+
509
+ specify "revoke_security_group_ingress - :ip_permissions - :user_id正常" do
510
+ @api.stubs(:exec_request).returns stub(:body => @revoke_security_group_ingress_response_body, :is_a? => true)
511
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:user_id => 'user')) }.should.not.raise(NIFTY::ArgumentError)
512
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:user_id => %w(foo bar hoge))) }.should.not.raise(NIFTY::ArgumentError)
513
+ end
514
+
515
+ specify "revoke_security_group_ingress - :ip_permissions - :group_name正常" do
516
+ @api.stubs(:exec_request).returns stub(:body => @revoke_security_group_ingress_response_body, :is_a? => true)
517
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:group_name => 'foo')) }.should.not.raise(NIFTY::ArgumentError)
518
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:group_name => %w(foo bar hoge))) }.should.not.raise(NIFTY::ArgumentError)
519
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => [@basic_ip_permissions.merge(:group_name => 'foo'), @basic_ip_permissions.merge(:group_name => 'bar')]) }.should.not.raise(NIFTY::ArgumentError)
520
+ end
521
+
522
+ specify "revoke_security_group_ingress - :ip_permissions - :cidr_ip正常" do
523
+ @api.stubs(:exec_request).returns stub(:body => @revoke_security_group_ingress_response_body, :is_a? => true)
524
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:group_name => nil, :cidr_ip => '111.111.111.111')) }.should.not.raise(NIFTY::ArgumentError)
525
+ lambda { @api.revoke_security_group_ingress(:group_name => 'gr1', :ip_permissions => @basic_ip_permissions.merge(:group_name => nil, :cidr_ip => ['111.111.111.111', '::ffff:6f6f:6f6f'])) }.should.not.raise(NIFTY::ArgumentError)
526
+ end
527
+
528
+ specify "revoke_security_group_ingress - :group_name未指定" do
529
+ lambda { @api.revoke_security_group_ingress(@basic_auth_security_params.reject{|k, v| k == :group_name}) }.should.raise(NIFTY::ArgumentError)
530
+ lambda { @api.revoke_security_group_ingress(@basic_auth_security_params.merge(:group_name => nil)) }.should.raise(NIFTY::ArgumentError)
531
+ lambda { @api.revoke_security_group_ingress(@basic_auth_security_params.merge(:group_name => '')) }.should.raise(NIFTY::ArgumentError)
532
+ end
533
+
534
+ specify "revoke_security_group_ingress - :ip_permissions - :ip_protocol不正" do
535
+ lambda { @api.revoke_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => 'bar')) }.should.raise(NIFTY::ArgumentError)
536
+ lambda { @api.revoke_security_group_ingress(:group_name => 'foo', :ip_permissions => [@basic_ip_permissions.merge(:ip_protocol => 'HTTP'), @basic_ip_permissions.merge(:ip_protocol => 'bar')]) }.should.raise(NIFTY::ArgumentError)
537
+ end
538
+
539
+ specify "revoke_security_group_ingress - :ip_permissions - :from_port未指定" do
540
+ lambda { @api.revoke_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => 'TCP')) }.should.raise(NIFTY::ArgumentError)
541
+ lambda { @api.revoke_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => 'TCP', :from_port => nil)) }.should.raise(NIFTY::ArgumentError)
542
+ lambda { @api.revoke_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => 'TCP', :from_port => '')) }.should.raise(NIFTY::ArgumentError)
543
+ lambda { @api.revoke_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => 'UDP')) }.should.raise(NIFTY::ArgumentError)
544
+ lambda { @api.revoke_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => 'UDP', :from_port => nil)) }.should.raise(NIFTY::ArgumentError)
545
+ lambda { @api.revoke_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:ip_protocol => 'UDP', :from_port => '')) }.should.raise(NIFTY::ArgumentError)
546
+ end
547
+
548
+ specify "revoke_security_group_ingress - :cidr_ip不正" do
549
+ lambda { @api.revoke_security_group_ingress(:group_name => 'foo', :ip_permissions => @basic_ip_permissions.merge(:cidr_ip => 'foo')) }.should.raise(NIFTY::ArgumentError)
550
+ lambda { @api.revoke_security_group_ingress(:group_name => 'foo', :ip_permissions => [@basic_ip_permissions.merge(:cidr_ip => '111.111.111.111'), @basic_ip_permissions.merge(:cidr_ip => 'foo')]) }.should.raise(NIFTY::ArgumentError)
551
+ end
552
+
553
+
554
+ # register_instances_with_security_group
555
+ specify "register_instances_with_security_group - レスポンスを正しく解析できるか" do
556
+ @api.stubs(:exec_request).returns stub(:body => @register_instances_with_security_group_response_body, :is_a? => true)
557
+ response = @api.register_instances_with_security_group(:group_name => 'gr1', :instance_id => 'server01')
558
+ response.requestId.should.equal '320fc738-a1c7-4a2f-abcb-20813a4e997c'
559
+ response.instancesSet.item[0].instanceId.should.equal 'server01'
560
+ response.instancesSet.item[1].instanceId.should.equal 'server02'
561
+ end
562
+
563
+ specify "register_instances_with_security_group - パラメータが正しく作られるか" do
564
+ @api.stubs(:make_request).with("Action" => "RegisterInstancesWithSecurityGroup",
565
+ "GroupName" => "a",
566
+ "InstanceId.1" => "a",
567
+ "InstanceId.2" => "a"
568
+ ).returns stub(:body => @register_instances_with_security_group_response_body, :is_a? => true)
569
+ @api.stubs(:exec_request).returns stub(:body => @register_instances_with_security_group_response_body, :is_a? => true)
570
+ response = @api.register_instances_with_security_group(:group_name => "a", :instance_id => %w(a a))
571
+ end
572
+
573
+ specify "register_instances_with_security_group - :group_name, :instance_id正常" do
574
+ @api.stubs(:exec_request).returns stub(:body => @register_instances_with_security_group_response_body, :is_a? => true)
575
+ lambda { @api.register_instances_with_security_group(:group_name => 'foo', :instance_id => 'bar') }.should.not.raise(NIFTY::ArgumentError)
576
+ lambda { @api.register_instances_with_security_group(:group_name => 'default(Linux)', :instance_id => 'bar') }.should.not.raise(NIFTY::ArgumentError)
577
+ lambda { @api.register_instances_with_security_group(:group_name => 'default(Windows)', :instance_id => 'bar') }.should.not.raise(NIFTY::ArgumentError)
578
+ lambda { @api.register_instances_with_security_group(:group_name => 'foo', :instance_id => %w(bar hoge)) }.should.not.raise(NIFTY::ArgumentError)
579
+ end
580
+
581
+ specify "register_instances_with_security_group - :group_name未指定" do
582
+ lambda { @api.register_instances_with_security_group }.should.raise(NIFTY::ArgumentError)
583
+ lambda { @api.register_instances_with_security_group(:group_name => nil) }.should.raise(NIFTY::ArgumentError)
584
+ lambda { @api.register_instances_with_security_group(:group_name => '') }.should.raise(NIFTY::ArgumentError)
585
+ end
586
+
587
+ specify "register_instances_with_security_group - :instance_id未指定" do
588
+ lambda { @api.register_instances_with_security_group(:group_name => 'foo') }.should.raise(NIFTY::ArgumentError)
589
+ lambda { @api.register_instances_with_security_group(:group_name => 'foo', :instance_id => nil) }.should.raise(NIFTY::ArgumentError)
590
+ lambda { @api.register_instances_with_security_group(:group_name => 'foo', :instance_id => '') }.should.raise(NIFTY::ArgumentError)
591
+ end
592
+
593
+
594
+ # deregister_instances_from_security_group
595
+ specify "deregister_instances_from_security_group - レスポンスを正しく解析できるか" do
596
+ @api.stubs(:exec_request).returns stub(:body => @deregister_instances_from_security_group_response_body, :is_a? => true)
597
+ response = @api.deregister_instances_from_security_group(:group_name => 'gr1', :instance_id => 'server01')
598
+ response.requestId.should.equal '320fc738-a1c7-4a2f-abcb-20813a4e997c'
599
+ response.instancesSet.item[0].instanceId.should.equal 'server01'
600
+ response.instancesSet.item[1].instanceId.should.equal 'server02'
601
+ end
602
+
603
+ specify "deregister_instances_from_security_group - パラメータが正しく作られるか" do
604
+ @api.stubs(:make_request).with("Action" => "DeregisterInstancesFromSecurityGroup",
605
+ "GroupName" => "a",
606
+ "InstanceId.1" => "a",
607
+ "InstanceId.2" => "a"
608
+ ).returns stub(:body => @deregister_instances_from_security_group_response_body, :is_a? => true)
609
+ @api.stubs(:exec_request).returns stub(:body => @deregister_instances_from_security_group_response_body, :is_a? => true)
610
+ response = @api.deregister_instances_from_security_group(:group_name => "a", :instance_id => %w(a a))
611
+ end
612
+
613
+ specify "deregister_instances_from_security_group - :group_name, :instance_id正常" do
614
+ @api.stubs(:exec_request).returns stub(:body => @deregister_instances_from_security_group_response_body, :is_a? => true)
615
+ lambda { @api.deregister_instances_from_security_group(:group_name => 'foo', :instance_id => 'bar') }.should.not.raise(NIFTY::ArgumentError)
616
+ lambda { @api.deregister_instances_from_security_group(:group_name => 'default(Linux)', :instance_id => 'bar') }.should.not.raise(NIFTY::ArgumentError)
617
+ lambda { @api.deregister_instances_from_security_group(:group_name => 'default(Windows)', :instance_id => 'bar') }.should.not.raise(NIFTY::ArgumentError)
618
+ lambda { @api.deregister_instances_from_security_group(:group_name => 'foo', :instance_id => %w(bar hoge)) }.should.not.raise(NIFTY::ArgumentError)
619
+ end
620
+
621
+ specify "deregister_instances_from_security_group - :group_name未指定" do
622
+ lambda { @api.deregister_instances_from_security_group }.should.raise(NIFTY::ArgumentError)
623
+ lambda { @api.deregister_instances_from_security_group(:group_name => nil) }.should.raise(NIFTY::ArgumentError)
624
+ lambda { @api.deregister_instances_from_security_group(:group_name => '') }.should.raise(NIFTY::ArgumentError)
625
+ end
626
+
627
+ specify "deregister_instances_from_security_group - :instance_id未指定" do
628
+ lambda { @api.deregister_instances_from_security_group(:group_name => 'foo') }.should.raise(NIFTY::ArgumentError)
629
+ lambda { @api.deregister_instances_from_security_group(:group_name => 'foo', :instance_id => nil) }.should.raise(NIFTY::ArgumentError)
630
+ lambda { @api.deregister_instances_from_security_group(:group_name => 'foo', :instance_id => '') }.should.raise(NIFTY::ArgumentError)
631
+ end
632
+
633
+
634
+ # describe_security_activities
635
+ specify "describe_security_activities - レスポンスを正しく解析できるか" do
636
+ @api.stubs(:exec_request).returns stub(:body => @describe_security_activities_response_body, :is_a? => true)
637
+ response = @api.describe_security_activities(:group_name => 'default(Linux)')
638
+ response.requestId.should.equal '320fc738-a1c7-4a2f-abcb-20813a4e997c'
639
+ response.groupName.should.equal 'websrv'
640
+ response.log.should.equal "2011-01-05T08:53:29+09:00 Altor_VNF time=1294217609140 fw_id=4 src_ip=10.0.6.201 src_port=68 dst_ip=10.0.4.11 dst_port=67 ip_proto=17 action=accept vm_id=16853 rule_id=52 type=fw\n2011-01-09T11:21:53+09:00 Altor_VNF time=2297218603613 fw_id=4 src_ip=10.0.6.201 src_port=68 dst_ip=10.0.4.11 dst_port=67 ip_proto=17 action=accept vm_id=16853 rule_id=52 type=fw"
641
+ end
642
+
643
+ specify "describe_security_activities - パラメータが正しく作られるか" do
644
+ @api.stubs(:make_request).with("Action" => "DescribeSecurityActivities",
645
+ "GroupName" => "default(Windows)",
646
+ "ActivityDate" => "20110617",
647
+ "Range.All" => "true",
648
+ "Range.StartNumber" => "1",
649
+ "Range.EndNumber" => "2"
650
+ ).returns stub(:body => @describe_security_activities_response_body, :is_a? => true)
651
+ @api.stubs(:exec_request).returns stub(:body => @describe_security_activities_response_body, :is_a? => true)
652
+ response = @api.describe_security_activities(:group_name => "default(Windows)", :activity_date => "20110617", :range_all => true, :range_start_number => 1, :range_end_number => 2)
653
+ end
654
+
655
+ specify "describe_security_activities - :activity_date正常" do
656
+ @api.stubs(:exec_request).returns stub(:body => @describe_security_activities_response_body, :is_a? => true)
657
+ lambda { @api.describe_security_activities(:group_name => 'foo', :activity_date => '20110530') }.should.not.raise(NIFTY::ArgumentError)
658
+ lambda { @api.describe_security_activities(:group_name => 'foo', :activity_date => '2011-05-30') }.should.not.raise(NIFTY::ArgumentError)
659
+ lambda { @api.describe_security_activities(:group_name => 'foo', :activity_date => '2011/05/30') }.should.not.raise(NIFTY::ArgumentError)
660
+ end
661
+
662
+ specify "describe_security_activities - :all正常" do
663
+ @api.stubs(:exec_request).returns stub(:body => @describe_security_activities_response_body, :is_a? => true)
664
+ lambda { @api.describe_security_activities(:group_name => 'foo', :all => true) }.should.not.raise(NIFTY::ArgumentError)
665
+ lambda { @api.describe_security_activities(:group_name => 'foo', :all => false) }.should.not.raise(NIFTY::ArgumentError)
666
+ lambda { @api.describe_security_activities(:group_name => 'foo', :all => 'true') }.should.not.raise(NIFTY::ArgumentError)
667
+ lambda { @api.describe_security_activities(:group_name => 'foo', :all => 'false') }.should.not.raise(NIFTY::ArgumentError)
668
+ end
669
+
670
+ specify "describe_security_activities - :start_number, :end_number正常" do
671
+ @api.stubs(:exec_request).returns stub(:body => @describe_security_activities_response_body, :is_a? => true)
672
+ lambda { @api.describe_security_activities(:group_name => 'foo', :start_number => 1) }.should.not.raise(NIFTY::ArgumentError)
673
+ lambda { @api.describe_security_activities(:group_name => 'foo', :start_number => 5) }.should.not.raise(NIFTY::ArgumentError)
674
+ lambda { @api.describe_security_activities(:group_name => 'foo', :start_number => 1, :end_number => 100) }.should.not.raise(NIFTY::ArgumentError)
675
+ lambda { @api.describe_security_activities(:group_name => 'foo', :start_number => 100, :end_number => 100) }.should.not.raise(NIFTY::ArgumentError)
676
+ end
677
+
678
+ specify "describe_security_activities - :group_name未指定" do
679
+ lambda { @api.describe_security_activities }.should.raise(NIFTY::ArgumentError)
680
+ lambda { @api.describe_security_activities(:group_name => nil) }.should.raise(NIFTY::ArgumentError)
681
+ lambda { @api.describe_security_activities(:group_name => '') }.should.raise(NIFTY::ArgumentError)
682
+ end
683
+
684
+ specify "describe_security_activities - :group_name不正" do
685
+ lambda { @api.describe_security_activities(:group_name => 'foo', :activity_date => '2011-5-30') }.should.raise(NIFTY::ArgumentError)
686
+ end
687
+
688
+ specify "describe_security_activities - :range_all不正" do
689
+ lambda { @api.describe_security_activities(:group_name => 'foo', :range_all => 'foo') }.should.raise(NIFTY::ArgumentError)
690
+ end
691
+
692
+ specify "describe_security_activities - :range_start_number, :range_end_number不正" do
693
+ lambda { @api.describe_security_activities(:group_name => 'foo', :range_start_number => 'foo') }.should.raise(NIFTY::ArgumentError)
694
+ lambda { @api.describe_security_activities(:group_name => 'foo', :range_start_number => 0) }.should.raise(NIFTY::ArgumentError)
695
+ lambda { @api.describe_security_activities(:group_name => 'foo', :range_end_number => 'foo') }.should.raise(NIFTY::ArgumentError)
696
+ lambda { @api.describe_security_activities(:group_name => 'foo', :range_end_number => 0) }.should.raise(NIFTY::ArgumentError)
697
+ lambda { @api.describe_security_activities(:group_name => 'foo', :range_start_number => 5, :range_end_number => 1) }.should.raise(NIFTY::ArgumentError)
698
+ end
699
+ end