awsum 0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +1 -0
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +44 -0
- data/LICENSE +19 -0
- data/README.rdoc +42 -0
- data/Rakefile +75 -0
- data/awsum.gemspec +199 -0
- data/lib/awsum.rb +20 -0
- data/lib/awsum/ec2.rb +741 -0
- data/lib/awsum/ec2/address.rb +67 -0
- data/lib/awsum/ec2/availability_zone.rb +16 -0
- data/lib/awsum/ec2/image.rb +62 -0
- data/lib/awsum/ec2/instance.rb +57 -0
- data/lib/awsum/ec2/keypair.rb +16 -0
- data/lib/awsum/ec2/parsers/address_parser.rb +61 -0
- data/lib/awsum/ec2/parsers/availability_zone_parser.rb +57 -0
- data/lib/awsum/ec2/parsers/image_parser.rb +74 -0
- data/lib/awsum/ec2/parsers/instance_parser.rb +90 -0
- data/lib/awsum/ec2/parsers/keypair_parser.rb +64 -0
- data/lib/awsum/ec2/parsers/purchase_reserved_instances_offering_parser.rb +34 -0
- data/lib/awsum/ec2/parsers/region_parser.rb +56 -0
- data/lib/awsum/ec2/parsers/register_image_parser.rb +34 -0
- data/lib/awsum/ec2/parsers/reserved_instance_parser.rb +64 -0
- data/lib/awsum/ec2/parsers/reserved_instances_offering_parser.rb +63 -0
- data/lib/awsum/ec2/parsers/security_group_parser.rb +106 -0
- data/lib/awsum/ec2/parsers/snapshot_parser.rb +64 -0
- data/lib/awsum/ec2/parsers/volume_parser.rb +77 -0
- data/lib/awsum/ec2/region.rb +54 -0
- data/lib/awsum/ec2/reserved_instance.rb +24 -0
- data/lib/awsum/ec2/reserved_instances_offering.rb +20 -0
- data/lib/awsum/ec2/security_group.rb +74 -0
- data/lib/awsum/ec2/snapshot.rb +23 -0
- data/lib/awsum/ec2/volume.rb +65 -0
- data/lib/awsum/error.rb +53 -0
- data/lib/awsum/net_fix.rb +100 -0
- data/lib/awsum/parser.rb +18 -0
- data/lib/awsum/requestable.rb +216 -0
- data/lib/awsum/s3.rb +220 -0
- data/lib/awsum/s3/bucket.rb +28 -0
- data/lib/awsum/s3/headers.rb +24 -0
- data/lib/awsum/s3/object.rb +138 -0
- data/lib/awsum/s3/parsers/bucket_parser.rb +43 -0
- data/lib/awsum/support.rb +94 -0
- data/spec/fixtures/ec2/addresses.xml +10 -0
- data/spec/fixtures/ec2/allocate_address.xml +5 -0
- data/spec/fixtures/ec2/associate_address.xml +5 -0
- data/spec/fixtures/ec2/attach_volume.xml +9 -0
- data/spec/fixtures/ec2/authorize_ip_access.xml +5 -0
- data/spec/fixtures/ec2/authorize_owner_group_access.xml +5 -0
- data/spec/fixtures/ec2/authorize_owner_group_access_error.xml +2 -0
- data/spec/fixtures/ec2/availability_zones.xml +16 -0
- data/spec/fixtures/ec2/available_volume.xml +14 -0
- data/spec/fixtures/ec2/create_key_pair.xml +29 -0
- data/spec/fixtures/ec2/create_security_group.xml +5 -0
- data/spec/fixtures/ec2/create_snapshot.xml +9 -0
- data/spec/fixtures/ec2/create_volume.xml +10 -0
- data/spec/fixtures/ec2/delete_key_pair.xml +5 -0
- data/spec/fixtures/ec2/delete_security_group.xml +5 -0
- data/spec/fixtures/ec2/delete_snapshot.xml +5 -0
- data/spec/fixtures/ec2/delete_volume.xml +5 -0
- data/spec/fixtures/ec2/deregister_image.xml +5 -0
- data/spec/fixtures/ec2/detach_volume.xml +9 -0
- data/spec/fixtures/ec2/disassociate_address.xml +5 -0
- data/spec/fixtures/ec2/image.xml +15 -0
- data/spec/fixtures/ec2/images.xml +77 -0
- data/spec/fixtures/ec2/instance.xml +36 -0
- data/spec/fixtures/ec2/instances.xml +88 -0
- data/spec/fixtures/ec2/internal_error.xml +2 -0
- data/spec/fixtures/ec2/invalid_amiid_error.xml +2 -0
- data/spec/fixtures/ec2/invalid_request_error.xml +2 -0
- data/spec/fixtures/ec2/key_pairs.xml +10 -0
- data/spec/fixtures/ec2/purchase_reserved_instances_offering.xml +5 -0
- data/spec/fixtures/ec2/purchase_reserved_instances_offerings.xml +6 -0
- data/spec/fixtures/ec2/regions.xml +14 -0
- data/spec/fixtures/ec2/register_image.xml +5 -0
- data/spec/fixtures/ec2/release_address.xml +5 -0
- data/spec/fixtures/ec2/reserved_instances.xml +18 -0
- data/spec/fixtures/ec2/reserved_instances_offering.xml +15 -0
- data/spec/fixtures/ec2/reserved_instances_offerings.xml +276 -0
- data/spec/fixtures/ec2/revoke_ip_access.xml +5 -0
- data/spec/fixtures/ec2/revoke_owner_group_access.xml +5 -0
- data/spec/fixtures/ec2/run_instances.xml +30 -0
- data/spec/fixtures/ec2/security_groups.xml +159 -0
- data/spec/fixtures/ec2/snapshots.xml +13 -0
- data/spec/fixtures/ec2/terminate_instances.xml +17 -0
- data/spec/fixtures/ec2/unassociated_address.xml +10 -0
- data/spec/fixtures/ec2/volumes.xml +23 -0
- data/spec/fixtures/errors/invalid_parameter_value.xml +2 -0
- data/spec/fixtures/s3/buckets.xml +2 -0
- data/spec/fixtures/s3/copy_failure.xml +23 -0
- data/spec/fixtures/s3/invalid_request_signature.xml +5 -0
- data/spec/fixtures/s3/keys.xml +2 -0
- data/spec/lib/awsum/ec2/address_spec.rb +149 -0
- data/spec/lib/awsum/ec2/availability_zones_spec.rb +21 -0
- data/spec/lib/awsum/ec2/image_spec.rb +92 -0
- data/spec/lib/awsum/ec2/instance_spec.rb +125 -0
- data/spec/lib/awsum/ec2/keypair_spec.rb +55 -0
- data/spec/lib/awsum/ec2/parsers/address_parser_spec.rb +51 -0
- data/spec/lib/awsum/ec2/parsers/availability_zone_parser_spec.rb +28 -0
- data/spec/lib/awsum/ec2/parsers/image_parser_spec.rb +66 -0
- data/spec/lib/awsum/ec2/parsers/instance_parser_spec.rb +75 -0
- data/spec/lib/awsum/ec2/parsers/keypair_parser_spec.rb +74 -0
- data/spec/lib/awsum/ec2/parsers/purchase_reserved_instances_offering_parser_spec.rb +14 -0
- data/spec/lib/awsum/ec2/parsers/region_parser_spec.rb +27 -0
- data/spec/lib/awsum/ec2/parsers/register_image_parser_spec.rb +15 -0
- data/spec/lib/awsum/ec2/parsers/reserved_instance_parser_spec.rb +35 -0
- data/spec/lib/awsum/ec2/parsers/reserved_instances_offering_parser_spec.rb +32 -0
- data/spec/lib/awsum/ec2/parsers/security_group_parser_spec.rb +78 -0
- data/spec/lib/awsum/ec2/parsers/snapshot_parser_spec.rb +30 -0
- data/spec/lib/awsum/ec2/parsers/volume_parser_spec.rb +35 -0
- data/spec/lib/awsum/ec2/region_spec.rb +73 -0
- data/spec/lib/awsum/ec2/reserved_instance_spec.rb +61 -0
- data/spec/lib/awsum/ec2/reserved_instances_offering_spec.rb +33 -0
- data/spec/lib/awsum/ec2/security_group_spec.rb +179 -0
- data/spec/lib/awsum/ec2/snapshots_spec.rb +69 -0
- data/spec/lib/awsum/ec2/volume_spec.rb +107 -0
- data/spec/lib/awsum/ec2_spec.rb +6 -0
- data/spec/lib/awsum/error_spec.rb +31 -0
- data/spec/lib/awsum/requestable_spec.rb +126 -0
- data/spec/lib/awsum/s3/bucket_spec.rb +95 -0
- data/spec/lib/awsum/s3/object_spec.rb +128 -0
- data/spec/lib/awsum/s3/parsers/bucket_parser_spec.rb +41 -0
- data/spec/lib/awsum/s3/parsers/object_parser_spec.rb +41 -0
- data/spec/spec_helper.rb +16 -0
- metadata +240 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Awsum
|
|
4
|
+
describe Ec2 do
|
|
5
|
+
|
|
6
|
+
subject { Ec2.new('abc', 'xyz') }
|
|
7
|
+
let(:ec2) { subject }
|
|
8
|
+
|
|
9
|
+
describe "retrieving a list of available reserved instance offerrings" do
|
|
10
|
+
before do
|
|
11
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeReservedInstancesOfferings|, :body => fixture('ec2/reserved_instances_offerings'), :status => 200)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:result) { ec2.reserved_instances_offerings }
|
|
15
|
+
|
|
16
|
+
it "should return an array of reserverd instances offerings" do
|
|
17
|
+
result.first.should be_a(Awsum::Ec2::ReservedInstancesOffering)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "retrieving a single reserved instance offerring" do
|
|
22
|
+
before do
|
|
23
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeReservedInstancesOfferings.*ReservedInstancesOfferingId.1=e5a2ff3b-f6eb-4b4e-83f8-b879d7060257|, :body => fixture('ec2/reserved_instances_offerings'), :status => 200)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
let(:result) { ec2.reserved_instances_offering 'e5a2ff3b-f6eb-4b4e-83f8-b879d7060257' }
|
|
27
|
+
|
|
28
|
+
it "should return a reserverd instances offering" do
|
|
29
|
+
result.should be_a(Awsum::Ec2::ReservedInstancesOffering)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Awsum
|
|
4
|
+
describe Ec2 do
|
|
5
|
+
|
|
6
|
+
subject { Ec2.new('abc', 'xyz') }
|
|
7
|
+
let(:ec2) { subject }
|
|
8
|
+
|
|
9
|
+
describe "retrieving a list of security groups" do
|
|
10
|
+
before do
|
|
11
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeSecurityGroups|, :body => fixture('ec2/security_groups'), :status => 200)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:result) { ec2.security_groups }
|
|
15
|
+
|
|
16
|
+
it "should return an array of security groups" do
|
|
17
|
+
result.first.should be_a(Awsum::Ec2::SecurityGroup)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "retrieving a security group by name" do
|
|
22
|
+
before do
|
|
23
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeSecurityGroups.*GroupName.1=default|, :body => fixture('ec2/security_groups'), :status => 200)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
let(:result) { ec2.security_group 'default' }
|
|
27
|
+
|
|
28
|
+
it "should return a security group" do
|
|
29
|
+
result.should be_a(Awsum::Ec2::SecurityGroup)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "creating a security group" do
|
|
34
|
+
before do
|
|
35
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=CreateSecurityGroup.*GroupDescription=test%20group.*GroupName=test|, :body => fixture('ec2/create_security_group'), :status => 200)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should return true" do
|
|
39
|
+
ec2.create_security_group('test', 'test group').should be_true
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe "deleting a security group" do
|
|
44
|
+
before do
|
|
45
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DeleteSecurityGroup.*GroupName=test|, :body => fixture('ec2/delete_security_group'), :status => 200)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "should return true" do
|
|
49
|
+
ec2.delete_security_group('test').should be_true
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe "authorizing group access" do
|
|
54
|
+
before do
|
|
55
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AuthorizeSecurityGroupIngress.*GroupName=test.*SourceSecurityGroupName=default.*SourceSecurityGroupOwnerId=111111111111|, :body => fixture('ec2/delete_security_group'), :status => 200)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should return true" do
|
|
59
|
+
ec2.authorize_security_group_ingress('test', :source_security_group_name => 'default', :source_security_group_owner_id => '111111111111').should be_true
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe "authorizing ip access" do
|
|
64
|
+
before do
|
|
65
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AuthorizeSecurityGroupIngress.*CidrIp=0.0.0.0%2F0.*FromPort=80.*GroupName=test.*IpProtocol=tcp.*ToPort=80|, :body => fixture('ec2/delete_security_group'), :status => 200)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should return true" do
|
|
69
|
+
ec2.authorize_security_group_ingress('test', :ip_protocol => 'tcp', :from_port => 80, :to_port => 80, :cidr_ip => '0.0.0.0/0').should be_true
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
describe "sending ip authorization options to a user/group authorization request" do
|
|
74
|
+
it "should raise an error" do
|
|
75
|
+
expect { ec2.authorize_security_group_ingress('test', :ip_protocol => 'tcp', :from_port => 80, :to_port => 80, :cidr_ip => '0.0.0.0/0', :source_security_group_name => 'default') }.to raise_error
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe "sending user/group options to a ip authorization request" do
|
|
80
|
+
it "should raise an error" do
|
|
81
|
+
expect { ec2.authorize_security_group_ingress('test', :source_security_group_name => 'default', :source_security_group_owner_id => '111111111111', :from_port => 80, :to_port => 80) }.to raise_error
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe "sending all options to an authorization request" do
|
|
86
|
+
it "should raise an error" do
|
|
87
|
+
expect { ec2.authorize_security_group_ingress('test', :source_security_group_name => 'default', :source_security_group_owner_id => '111111111111', :ip_protocol => 'tcp', :from_port => 80, :to_port => 80, :cidr_ip => '0.0.0.0/0') }.to raise_error
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe "including a wrong protocol in an authorization request" do
|
|
92
|
+
it "should raise an error" do
|
|
93
|
+
expect { ec2.authorize_security_group_ingress('test', :ip_protocol => 'test', :from_port => 80, :to_port => 80, :cidr_ip => '0.0.0.0/0') }.to raise_error
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe "revoking group access" do
|
|
98
|
+
before do
|
|
99
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RevokeSecurityGroupIngress.*GroupName=test.*SourceSecurityGroupName=default.*SourceSecurityGroupOwnerId=111111111111|, :body => fixture('ec2/delete_security_group'), :status => 200)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "should return true" do
|
|
103
|
+
ec2.revoke_security_group_ingress('test', :source_security_group_name => 'default', :source_security_group_owner_id => '111111111111').should be_true
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe "revoking ip access" do
|
|
108
|
+
before do
|
|
109
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RevokeSecurityGroupIngress.*CidrIp=0.0.0.0%2F0.*FromPort=80.*GroupName=test.*IpProtocol=tcp.*ToPort=80|, :body => fixture('ec2/delete_security_group'), :status => 200)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "should return true" do
|
|
113
|
+
ec2.revoke_security_group_ingress('test', :ip_protocol => 'tcp', :from_port => 80, :to_port => 80, :cidr_ip => '0.0.0.0/0').should be_true
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
describe "sending ip revokation options to a user/group authorization request" do
|
|
118
|
+
it "should raise an error" do
|
|
119
|
+
expect { ec2.revoke_security_group_ingress('test', :ip_protocol => 'tcp', :from_port => 80, :to_port => 80, :cidr_ip => '0.0.0.0/0', :source_security_group_name => 'default') }.to raise_error
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
describe "sending user/group options to a ip revokation request" do
|
|
124
|
+
it "should raise an error" do
|
|
125
|
+
expect { ec2.revoke_security_group_ingress('test', :source_security_group_name => 'default', :source_security_group_owner_id => '111111111111', :from_port => 80, :to_port => 80) }.to raise_error
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
describe "sending all options to an revokation request" do
|
|
130
|
+
it "should raise an error" do
|
|
131
|
+
expect { ec2.revoke_security_group_ingress('test', :source_security_group_name => 'default', :source_security_group_owner_id => '111111111111', :ip_protocol => 'tcp', :from_port => 80, :to_port => 80, :cidr_ip => '0.0.0.0/0') }.to raise_error
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
describe "including a wrong protocol in an revokation request" do
|
|
136
|
+
it "should raise an error" do
|
|
137
|
+
expect { ec2.revoke_security_group_ingress('test', :ip_protocol => 'test', :from_port => 80, :to_port => 80, :cidr_ip => '0.0.0.0/0') }.to raise_error
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
describe "a security group" do
|
|
142
|
+
before do
|
|
143
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeSecurityGroups.*GroupName.1=default|, :body => fixture('ec2/security_groups'), :status => 200)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
let(:security_group) { ec2.security_group('default') }
|
|
147
|
+
|
|
148
|
+
it "should be able to authorize a group" do
|
|
149
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AuthorizeSecurityGroupIngress.*GroupName=default.*SourceSecurityGroupName=test.*SourceSecurityGroupOwnerId=111111111111|, :body => fixture('ec2/delete_security_group'), :status => 200)
|
|
150
|
+
|
|
151
|
+
security_group.authorize_group('test', '111111111111').should be_true
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it "should be able to authorize ip access" do
|
|
155
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AuthorizeSecurityGroupIngress.*CidrIp=0.0.0.0%2F0.*FromPort=80.*GroupName=default.*IpProtocol=tcp.*ToPort=80|, :body => fixture('ec2/delete_security_group'), :status => 200)
|
|
156
|
+
|
|
157
|
+
security_group.authorize_ip(80, 80, 'tcp', '0.0.0.0/0').should be_true
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
it "should be able to revoke a group" do
|
|
161
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RevokeSecurityGroupIngress.*GroupName=default.*SourceSecurityGroupName=test.*SourceSecurityGroupOwnerId=111111111111|, :body => fixture('ec2/delete_security_group'), :status => 200)
|
|
162
|
+
|
|
163
|
+
security_group.revoke_group('test', '111111111111').should be_true
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it "should be able to authorize ip access" do
|
|
167
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=RevokeSecurityGroupIngress.*CidrIp=0.0.0.0%2F0.*FromPort=80.*GroupName=default.*IpProtocol=tcp.*ToPort=80|, :body => fixture('ec2/delete_security_group'), :status => 200)
|
|
168
|
+
|
|
169
|
+
security_group.revoke_ip(80, 80, 'tcp', '0.0.0.0/0').should be_true
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
it "should be able to delete itself" do
|
|
173
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DeleteSecurityGroup.*GroupName=default|, :body => fixture('ec2/delete_security_group'), :status => 200)
|
|
174
|
+
|
|
175
|
+
security_group.delete.should be_true
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Awsum
|
|
4
|
+
describe Ec2 do
|
|
5
|
+
|
|
6
|
+
subject { Ec2.new('abc', 'xyz') }
|
|
7
|
+
let(:ec2) { subject }
|
|
8
|
+
|
|
9
|
+
describe "creating a snapshot" do
|
|
10
|
+
before do
|
|
11
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=CreateSnapshot.*VolumeId=vol-44d6322d|, :body => fixture('ec2/create_snapshot'), :status => 200)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:result) { ec2.create_snapshot 'vol-44d6322d' }
|
|
15
|
+
|
|
16
|
+
it "should return a snapshot" do
|
|
17
|
+
result.should be_a(Awsum::Ec2::Snapshot)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "retrieving a snapshot" do
|
|
22
|
+
before do
|
|
23
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeSnapshots.*SnapshotId.1=snap-747c911d|, :body => fixture('ec2/snapshots'), :status => 200)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
let(:result) { ec2.snapshot 'snap-747c911d' }
|
|
27
|
+
|
|
28
|
+
it "should return a snapshot" do
|
|
29
|
+
result.should be_a(Awsum::Ec2::Snapshot)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "retrieving a list of snapshots" do
|
|
34
|
+
before do
|
|
35
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeSnapshots|, :body => fixture('ec2/snapshots'), :status => 200)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
let(:result) { ec2.snapshots }
|
|
39
|
+
|
|
40
|
+
it "should return a snapshot" do
|
|
41
|
+
result.first.should be_a(Awsum::Ec2::Snapshot)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "deleting a snapshot" do
|
|
46
|
+
before do
|
|
47
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DeleteSnapshot.*SnapshotId=snap-747c911d|, :body => fixture('ec2/delete_snapshot'), :status => 200)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should be true" do
|
|
51
|
+
ec2.delete_snapshot('snap-747c911d').should be_true
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe "a snapshot" do
|
|
56
|
+
before do
|
|
57
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeSnapshots.*SnapshotId.1=snap-747c911d|, :body => fixture('ec2/snapshots'), :status => 200)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
let(:snapshot) { ec2.snapshot 'snap-747c911d' }
|
|
61
|
+
|
|
62
|
+
it "should be able to delete itself" do
|
|
63
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DeleteSnapshot.*SnapshotId=snap-747c911d|, :body => fixture('ec2/snapshots'), :status => 200)
|
|
64
|
+
|
|
65
|
+
snapshot.delete.should be_true
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Awsum
|
|
4
|
+
describe Ec2 do
|
|
5
|
+
|
|
6
|
+
subject { Ec2.new('abc', 'xyz') }
|
|
7
|
+
let(:ec2) { subject }
|
|
8
|
+
|
|
9
|
+
describe "creating a volume" do
|
|
10
|
+
before do
|
|
11
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=CreateVolume.*AvailabilityZone=us-east-1b.*Size=10|, :body => fixture('ec2/create_volume'), :status => 200)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:result) { ec2.create_volume 'us-east-1b', :size => 10 }
|
|
15
|
+
|
|
16
|
+
it "should return a volume" do
|
|
17
|
+
result.should be_a(Awsum::Ec2::Volume)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "retrieving a list of volumes" do
|
|
22
|
+
before do
|
|
23
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeVolumes|, :body => fixture('ec2/volumes'), :status => 200)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
let(:result) { ec2.volumes }
|
|
27
|
+
|
|
28
|
+
it "should return an array of volumes" do
|
|
29
|
+
result.first.should be_a(Awsum::Ec2::Volume)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "retrieving a volume by id" do
|
|
34
|
+
before do
|
|
35
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeVolumes.*VolumeId.1=vol-44d6322d|, :body => fixture('ec2/volumes'), :status => 200)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
let(:result) { ec2.volume 'vol-44d6322d' }
|
|
39
|
+
|
|
40
|
+
it "should return a volume" do
|
|
41
|
+
result.should be_a(Awsum::Ec2::Volume)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "attaching a volume" do
|
|
46
|
+
before do
|
|
47
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=AttachVolume.*Device=%2Fdev%2Fsdb.*InstanceId=i-3f1cc856.*VolumeId=vol-44d6322d|, :body => fixture('ec2/attach_volume'), :status => 200)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should return true" do
|
|
51
|
+
ec2.attach_volume('vol-44d6322d', 'i-3f1cc856', '/dev/sdb').should be_true
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe "detaching a volume" do
|
|
56
|
+
before do
|
|
57
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DetachVolume.*VolumeId=vol-44d6322d|, :body => fixture('ec2/detach_volume'), :status => 200)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should return true" do
|
|
61
|
+
ec2.detach_volume('vol-44d6322d').should be_true
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe "deleting a volume" do
|
|
66
|
+
before do
|
|
67
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DeleteVolume.*VolumeId=vol-44d6322d|, :body => fixture('ec2/delete_volume'), :status => 200)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should return true" do
|
|
71
|
+
ec2.delete_volume('vol-44d6322d').should be_true
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe "a volume" do
|
|
76
|
+
before do
|
|
77
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeVolumes.*VolumeId.1=vol-44d6322d|, :body => fixture('ec2/volumes'), :status => 200)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
let(:volume) { ec2.volume 'vol-44d6322d' }
|
|
81
|
+
|
|
82
|
+
it "should be able to detach itself" do
|
|
83
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DetachVolume.*VolumeId=vol-44d6322d|, :body => fixture('ec2/detach_volume'), :status => 200)
|
|
84
|
+
|
|
85
|
+
volume.detach.should be_true
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should be able to delete itself" do
|
|
89
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DeleteVolume.*VolumeId=vol-44d6322d|, :body => fixture('ec2/delete_volume'), :status => 200)
|
|
90
|
+
|
|
91
|
+
volume.delete.should be_true
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "should be able to create a snapshot of itself" do
|
|
95
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=CreateSnapshot.*VolumeId=vol-44d6322d|, :body => fixture('ec2/create_snapshot'), :status => 200)
|
|
96
|
+
|
|
97
|
+
volume.create_snapshot
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "should be able list it's snapshots" do
|
|
101
|
+
FakeWeb.register_uri(:get, %r|https://ec2\.amazonaws\.com/?.*Action=DescribeSnapshots|, :body => fixture('ec2/snapshots'), :status => 200)
|
|
102
|
+
|
|
103
|
+
volume.snapshots.first.should be_a(Awsum::Ec2::Snapshot)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Awsum
|
|
4
|
+
describe Error do
|
|
5
|
+
subject {
|
|
6
|
+
response = mock(:response, :code => 404, :body => fixture('ec2/invalid_request_error'))
|
|
7
|
+
Error.new(response)
|
|
8
|
+
}
|
|
9
|
+
let(:error) { subject }
|
|
10
|
+
|
|
11
|
+
it "should return the correct response code" do
|
|
12
|
+
error.response_code.should == 404
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should return the correct code" do
|
|
16
|
+
error.code.should == 'InvalidRequest'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should return the correct message" do
|
|
20
|
+
error.message.should == 'The request received was invalid.'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should return the correct request id" do
|
|
24
|
+
error.request_id.should == '7cbacf61-c7df-468a-8130-cf5d659f8144'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should return the correct additional info" do
|
|
28
|
+
error.additional.should == {'Unknown' => 'Test message'}
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Awsum
|
|
4
|
+
describe Requestable do
|
|
5
|
+
describe "ec2 requests" do
|
|
6
|
+
subject {
|
|
7
|
+
Class.new {
|
|
8
|
+
include Awsum::Requestable
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
@access_key = 'ABCDEF'
|
|
12
|
+
@secret_key = '123456'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def host
|
|
16
|
+
'test.amazonaws.com'
|
|
17
|
+
end
|
|
18
|
+
}.new
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe "#send_query_request" do
|
|
22
|
+
it "should generate the correct request uri" do
|
|
23
|
+
FakeWeb.register_uri(:get, 'https://test.amazonaws.com/?AWSAccessKeyId=ABCDEF&Action=DescribeImages&ImageId.1=ami-1234567&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-01-23T03%3A34%3A38.000Z&Version=2010-06-15&Signature=ZkjqlJRngvT4sITa50ZODqeYn%2FMBBDNtFhFf6ucz7QI%3D', :body => '', :status => 200)
|
|
24
|
+
|
|
25
|
+
subject.send(:send_query_request, {'Action' => 'DescribeImages', 'ImageId.1' => 'ami-1234567', 'Timestamp' => '2009-01-23T03:34:38.000Z'})
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# These test are taken directly from Amazon's examples at
|
|
31
|
+
# http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAuthentication.html
|
|
32
|
+
describe "an S3" do
|
|
33
|
+
subject {
|
|
34
|
+
Class.new {
|
|
35
|
+
include Awsum::Requestable
|
|
36
|
+
|
|
37
|
+
def initialize
|
|
38
|
+
@access_key = '0PN5J17HBGZHT7JJ3X82'
|
|
39
|
+
@secret_key = 'uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def host
|
|
43
|
+
's3.amazonaws.com'
|
|
44
|
+
end
|
|
45
|
+
}.new
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe "GET request" do
|
|
49
|
+
it "should generate the correct authorization header" do
|
|
50
|
+
subject.should_receive(:process_request).with { |method, uri, headers, data|
|
|
51
|
+
headers['authorization'].should == 'AWS 0PN5J17HBGZHT7JJ3X82:xXjDGYUmKxnwqr5KXNPGldn5LbA='
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
subject.send(:send_s3_request, 'GET', {:bucket => 'johnsmith', :key => '/photos/puppy.jpg', :headers => {'Date' => 'Tue, 27 Mar 2007 19:36:42 +0000'}})
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe "PUT request" do
|
|
59
|
+
it "should generate the correct authorization header" do
|
|
60
|
+
subject.should_receive(:process_request).with { |method, uri, headers, data|
|
|
61
|
+
headers['authorization'].should == 'AWS 0PN5J17HBGZHT7JJ3X82:hcicpDDvL9SsO6AkvxqmIWkmOuQ='
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
subject.send(:send_s3_request, 'PUT', {:bucket => 'johnsmith', :key => '/photos/puppy.jpg', :headers => {'Date' => 'Tue, 27 Mar 2007 21:15:45 +0000', 'Content-Type' => 'image/jpeg', 'Content-Length' => 94328}})
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe "GET request to list bucket contents" do
|
|
69
|
+
it "should generate the correct authorization header" do
|
|
70
|
+
subject.should_receive(:process_request).with { |method, uri, headers, data|
|
|
71
|
+
headers['authorization'].should == 'AWS 0PN5J17HBGZHT7JJ3X82:thdUi9VAkzhkniLj96JIrOPGi0g='
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
subject.send(:send_s3_request, 'GET', {:bucket => 'johnsmith', :key => '', :parameters => {'acl' => nil}, :headers => {'Date' => 'Tue, 27 Mar 2007 19:44:46 +0000'}})
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe "DELETE request" do
|
|
79
|
+
it "should generate the correct authorization header" do
|
|
80
|
+
subject.should_receive(:process_request).with { |method, uri, headers, data|
|
|
81
|
+
headers['authorization'].should == 'AWS 0PN5J17HBGZHT7JJ3X82:k3nL7gH3+PadhTEVn5Ip83xlYzk='
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
subject.send(:send_s3_request, 'DELETE', {:bucket => 'johnsmith', :key => '/photos/puppy.jpg', :headers => {'Date' => 'Tue, 27 Mar 2007 21:20:27 +0000', 'User-Agent' => 'dotnet', 'x-amz-date' => 'Tue, 27 Mar 2007 21:20:26 +0000'}})
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe "PUT request to upload" do
|
|
89
|
+
it "should generate the correct authorization header" do
|
|
90
|
+
subject.should_receive(:process_request).with { |method, uri, headers, data|
|
|
91
|
+
headers['authorization'].should == 'AWS 0PN5J17HBGZHT7JJ3X82:C0FlOtU8Ylb9KDTpZqYkZPX91iI='
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
subject.send(:send_s3_request, 'PUT', {:bucket => 'static.johnsmith.net', :key => '/db-backup.dat.gz', :headers => {'Date' => 'Tue, 27 Mar 2007 21:06:08 +0000', 'User-Agent' => 'curl/7.15.5', 'x-amz-acl' => 'public-read', 'content-type' => 'application/x-download', 'Content-MD5' => '4gJE4saaMU4BqNR0kLY+lw==', 'X-Amz-Meta-ReviewedBy' => ['joe@johnsmith.net', 'jane@johnsmith.net'], 'X-Amz-Meta-FileChecksum' => '0x02661779', 'X-Amz-Meta-ChecksumAlgorithm' => 'crc32', 'Content-Disposition' => 'attachment; filename=database.dat', 'Content-Encoding' => 'gzip', 'Content-Length' => '5913339'}})
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe "GET request to list all buckets" do
|
|
99
|
+
it "should generate the correct authorization header" do
|
|
100
|
+
subject.should_receive(:process_request).with { |method, uri, headers, data|
|
|
101
|
+
headers['authorization'].should == 'AWS 0PN5J17HBGZHT7JJ3X82:Db+gepJSUbZKwpx1FR0DLtEYoZA='
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
subject.send(:send_s3_request, 'GET', {:bucket => '', :key => '', :headers => {'Date' => 'Wed, 28 Mar 2007 01:29:59 +0000'}})
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe "GET request with unicode keys" do
|
|
109
|
+
it "should generate the correct authorization header" do
|
|
110
|
+
subject.should_receive(:process_request).with { |method, uri, headers, data|
|
|
111
|
+
headers['authorization'].should == 'AWS 0PN5J17HBGZHT7JJ3X82:dxhSBHoI6eVSPcXJqEghlUzZMnY='
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
subject.send(:send_s3_request, 'GET', {:bucket => 'dictionary', :key => '/fran%C3%A7ais/pr%c3%a9f%c3%a8re', :headers => {'Date' => 'Wed, 28 Mar 2007 01:49:49 +0000'}})
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe "signed request" do
|
|
119
|
+
it "should generate the correct signed URI" do
|
|
120
|
+
signed_request = subject.send(:generate_s3_signed_request_url, 'GET', 'johnsmith', '/photos/puppy.jpg', 1175139620)
|
|
121
|
+
signed_request.should == 'http://johnsmith.s3.amazonaws.com/photos/puppy.jpg?AWSAccessKeyId=0PN5J17HBGZHT7JJ3X82&Signature=rucSbH0yNEcP9oM2XNlouVI3BH4%3D&Expires=1175139620'
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|