hackerdude-aws 2.3.25

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.
@@ -0,0 +1,148 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require File.dirname(__FILE__) + '/../test_credentials.rb'
3
+
4
+ class TestAcf < Test::Unit::TestCase
5
+
6
+ RIGHT_OBJECT_TEXT = 'Right test message'
7
+
8
+ STDOUT.sync = true
9
+
10
+ def setup
11
+ TestCredentials.get_credentials
12
+ @acf= Aws::AcfInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
13
+ @s3 = Aws::S3.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
14
+ @bucket_name = "right-acf-awesome-test-bucket-0001"
15
+ @bucket_domain = "#{@bucket_name}.s3.amazonaws.com"
16
+ end
17
+
18
+ def test_01_list_distributions_part1
19
+ distributions = nil
20
+ assert_nothing_raised(Aws::AwsError) do
21
+ distributions = @acf.list_distributions
22
+ end
23
+ assert distributions.is_a?(Array)
24
+ end
25
+
26
+ def test_02_try_to_create_for_bad_bucket
27
+ # a bucket does not exist
28
+ assert_raise(Aws::AwsError) do
29
+ @acf.create_distribution("right-cloudfront-awesome-test-bucket-not-exist", "Mustn't to be born", true)
30
+ end
31
+ # a bucket is not a domain naming complied guy
32
+ bucket_name = 'right_cloudfront_awesome_test_bucket_BAD'
33
+ @s3.bucket(bucket_name, :create)
34
+ assert_raise(Aws::AwsError) do
35
+ @acf.create_distribution(bucket_name, "Mustn't to be born", true)
36
+ end
37
+ end
38
+
39
+ def test_03_create
40
+ comment = 'WooHoo!!!'
41
+ # create a test bucket
42
+ @s3.bucket(@bucket_name, :create)
43
+ # create a distribution
44
+ distribution = @acf.create_distribution(@bucket_domain, comment, true)
45
+ assert_equal comment, distribution[:comment]
46
+ assert distribution[:cnames].size == 0
47
+ assert distribution[:enabled]
48
+ end
49
+
50
+ def test_04_list_distributions_part2
51
+ distributions = @acf.list_distributions
52
+ assert distributions.size > 0
53
+ end
54
+
55
+ def get_test_distribution
56
+ @acf.list_distributions.select{ |d| d[:origin] == @bucket_domain }.first
57
+ end
58
+
59
+ def test_05_get_distribution
60
+ old = get_test_distribution
61
+ assert_nothing_raised do
62
+ @acf.get_distribution(old[:aws_id])
63
+ end
64
+ end
65
+
66
+ def test_06_get_and_set_config
67
+ config = nil
68
+ old = get_test_distribution
69
+ assert_nothing_raised do
70
+ config = @acf.get_distribution_config(old[:aws_id])
71
+ end
72
+ # change a config
73
+ config[:enabled] = false
74
+ config[:cnames] << 'x1.myawesomesite.com'
75
+ config[:cnames] << 'x2.myawesomesite.com'
76
+ # set config
77
+ set_config_result = nil
78
+ assert_nothing_raised do
79
+ set_config_result = @acf.set_distribution_config(old[:aws_id], config)
80
+ end
81
+ assert set_config_result
82
+ # reget the config and check
83
+ new_config = nil
84
+ assert_nothing_raised do
85
+ new_config = @acf.get_distribution_config(old[:aws_id])
86
+ end
87
+ assert !new_config[:enabled]
88
+ assert_equal new_config[:cnames].sort, ['x1.myawesomesite.com', 'x2.myawesomesite.com']
89
+ assert_not_equal config[:e_tag], new_config[:e_tag]
90
+
91
+ # try to update the old config again (must fail because ETAG has changed)
92
+ assert_raise(Aws::AwsError) do
93
+ @acf.set_distribution_config(old[:aws_id], config)
94
+ end
95
+ end
96
+
97
+ def test_07_caching
98
+ # enable caching
99
+ @acf.params[:cache] = true
100
+ # list distributions
101
+ @acf.list_distributions
102
+ # list the distributions again - cache should hit
103
+ assert_raise(Aws::AwsNoChange) do
104
+ @acf.list_distributions
105
+ end
106
+ # disable caching
107
+ @acf.params[:cache] = true
108
+ end
109
+
110
+ def test_08_delete_distribution
111
+ # we need ETAG so use get_distribution
112
+ distribution = @acf.get_distribution(get_test_distribution[:aws_id])
113
+ # try to delete a distribution
114
+ # should fail because
115
+ if distribution[:status] == 'InProgress'
116
+ # should fail because the distribution is not deployed yet
117
+ assert_raise(Aws::AwsError) do
118
+ @acf.delete_distribution(distribution[:aws_id], distribution[:e_tag])
119
+ end
120
+ # wait for a deployed state
121
+ print "waiting up to 5 min while the distribution is being deployed: "
122
+ 100.times do
123
+ print '.'
124
+ distribution = @acf.get_distribution(distribution[:aws_id])
125
+ if distribution[:status] == 'Deployed'
126
+ print ' done'
127
+ break
128
+ end
129
+ sleep 3
130
+ end
131
+ puts
132
+ end
133
+
134
+ # only disabled and deployed distribution can be deleted
135
+ assert_equal 'Deployed', distribution[:status]
136
+ assert !distribution[:enabled]
137
+
138
+ # delete the distribution
139
+ assert_nothing_raised do
140
+ @acf.delete_distribution(distribution[:aws_id], distribution[:e_tag])
141
+ end
142
+ end
143
+
144
+ def test_09_drop_bucket
145
+ assert @s3.bucket(@bucket_name).delete
146
+ end
147
+
148
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../../lib/right_aws'
@@ -0,0 +1,53 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'pp'
3
+ require File.dirname(__FILE__) + '/../test_credentials.rb'
4
+
5
+ require 'ruby-debug'
6
+ Debugger.start
7
+
8
+ # Tests the Alexa AWS implementation
9
+ # Note this is very preliminary code. The code just spits back hashes
10
+ # and it has no concept of types just yet. The parser can
11
+ # be overriden on the calls if you need stronger types and must
12
+ # have something right away.
13
+ class TestAlexa < Test::Unit::TestCase
14
+
15
+ def setup
16
+ TestCredentials.get_credentials
17
+ @alexa = Aws::Alexa.new(TestCredentials.aws_access_key_id,
18
+ TestCredentials.aws_secret_access_key)
19
+ end
20
+
21
+ # Quick rank request
22
+ def test_rank
23
+ return
24
+ TestCredentials.get_credentials
25
+ rank = @alexa.alexa_rank("http://www.youtube.com")
26
+ assert ! rank.empty?
27
+ assert ! rank[:rank][:text].blank?
28
+ assert rank[:rank][:text].to_i > 0
29
+ assert ! rank[:data_url][:text].blank?
30
+ end
31
+
32
+ def test_alexa_urlinfo
33
+ TestCredentials.get_credentials
34
+ result = @alexa.alexa_url_info("http://www.yahoo.com")
35
+ assert result[:url_info_response][:response][:url_info_result][:alexa][:contact_info][:company_stock_ticker][:text] == "YHOO"
36
+ end
37
+
38
+ def test_alexa_category_browse
39
+ TestCredentials.get_credentials
40
+ category_browse = @alexa.alexa_category_browse("Top/Computers/Software/Operating_Systems")
41
+ assert ! category_browse.empty?
42
+ assert ! category_browse[:category_browse_response][:response][:category_browse_result][:alexa][:category_browse][:categories][:category].first[:path][:text].blank?
43
+
44
+ end
45
+
46
+ def test_alexa_category_listings
47
+ TestCredentials.get_credentials
48
+ category_browse = @alexa.alexa_category_listings("Top/Computers/Software/Operating_Systems")
49
+ assert ! category_browse.empty?
50
+ assert category_browse[:category_listings_response][:response][:category_listings_result][:alexa][:category_listings][:listings][:listing].length > 0
51
+ end
52
+
53
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../../lib/aws'
@@ -0,0 +1,205 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'pp'
3
+ require File.dirname(__FILE__) + '/../test_credentials.rb'
4
+
5
+ class TestEc2 < Test::Unit::TestCase
6
+
7
+ # Some of RightEc2 instance methods concerning instance launching and image registration
8
+ # are not tested here due to their potentially risk.
9
+
10
+ def setup
11
+ TestCredentials.get_credentials
12
+ @ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id,
13
+ TestCredentials.aws_secret_access_key)
14
+ @key = 'right_ec2_awesome_test_key'
15
+ @group = 'right_ec2_awesome_test_security_group'
16
+ end
17
+
18
+ def test_001_describe_availability_zones
19
+ TestCredentials.get_credentials
20
+ @ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id,
21
+ TestCredentials.aws_secret_access_key)
22
+ zones = @ec2.describe_availability_zones
23
+ puts zones.inspect
24
+ assert zones.is_a? Array
25
+ assert zones.size > 3
26
+ zones.each do |z|
27
+ puts z[:zone_name]
28
+ end
29
+ assert zones[0][:zone_name] == "us-east-1a"
30
+ end
31
+
32
+ def test_01_create_describe_key_pairs
33
+ new_key = @ec2.create_key_pair(@key)
34
+ assert new_key[:aws_material][/BEGIN RSA PRIVATE KEY/], "New key material is absent"
35
+ keys = @ec2.describe_key_pairs
36
+ assert keys.map { |key| key[:aws_key_name] }.include?(@key), "#{@key} must exist"
37
+ end
38
+
39
+ def test_02_create_security_group
40
+ assert @ec2.create_security_group(@group, 'My awesone test group'), 'Create_security_group fail'
41
+ group = @ec2.describe_security_groups([@group])[0]
42
+ assert_equal @group, group[:aws_group_name], 'Group must be created but does not exist'
43
+ end
44
+
45
+ def test_03_perms_add
46
+ assert @ec2.authorize_security_group_named_ingress(@group, TestCredentials.account_number, 'default')
47
+ assert @ec2.authorize_security_group_IP_ingress(@group, 80, 80, 'udp', '192.168.1.0/8')
48
+ end
49
+
50
+ def test_04_check_new_perms_exist
51
+ assert_equal 2, @ec2.describe_security_groups([@group])[0][:aws_perms].size
52
+ end
53
+
54
+ def test_05_perms_remove
55
+ assert @ec2.revoke_security_group_IP_ingress(@group, 80, 80, 'udp', '192.168.1.0/8')
56
+ assert @ec2.revoke_security_group_named_ingress(@group,
57
+ TestCredentials.account_number, 'default')
58
+ end
59
+
60
+ def test_06_describe_images
61
+ images = describe_images
62
+ # unknown image
63
+ assert_raise(Aws::AwsError) { @ec2.describe_images(['ami-ABCDEFGH']) }
64
+ end
65
+
66
+ def test_07_describe_instanses
67
+ assert @ec2.describe_instances
68
+ # unknown image
69
+ assert_raise(Aws::AwsError) { @ec2.describe_instances(['i-ABCDEFGH']) }
70
+ end
71
+
72
+ def test_08_delete_security_group
73
+ assert @ec2.delete_security_group(@group), 'Delete_security_group fail'
74
+ end
75
+
76
+ def test_09_delete_key_pair
77
+ assert @ec2.delete_key_pair(@key), 'Delete_key_pair fail'
78
+ ## Hmmm... Amazon does not through the exception any more. It now just returns a 'true' if the key does not exist any more...
79
+ ## # key must be deleted already
80
+ ## assert_raise(Aws::AwsError) { @ec2.delete_key_pair(@key) }
81
+ end
82
+
83
+ def test_10_signature_version_0
84
+ ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :signature_version => '0')
85
+ images = ec2.describe_images
86
+ assert images.size>0, 'Amazon must have at least some public images'
87
+ # check that the request has correct signature version
88
+ assert ec2.last_request.path.include?('SignatureVersion=0')
89
+ end
90
+
91
+ def test_11_regions
92
+ regions = nil
93
+ assert_nothing_raised do
94
+ regions = @ec2.describe_regions
95
+ end
96
+ # check we got more that 0 regions
97
+ assert regions.size > 0
98
+ # check an access to regions
99
+ regions.each do |region|
100
+ regional_ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :region => region)
101
+ # do we have a correct endpoint server?
102
+ assert_equal "#{region}.ec2.amazonaws.com", regional_ec2.params[:server]
103
+ # get a list of images from every region
104
+ images = nil
105
+ assert_nothing_raised do
106
+ images = regional_ec2.describe_regions
107
+ end
108
+ # every region must have images
109
+ assert images.size > 0
110
+ end
111
+ end
112
+
113
+ def test_12_endpoint_url
114
+ ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :endpoint_url => 'a://b.c:0/d/', :region => 'z')
115
+ # :endpoint_url has a priority hence :region should be ommitted
116
+ assert_equal 'a', ec2.params[:protocol]
117
+ assert_equal 'b.c', ec2.params[:server]
118
+ assert_equal '/d/', ec2.params[:service]
119
+ assert_equal 0, ec2.params[:port]
120
+ assert_nil ec2.params[:region]
121
+ end
122
+
123
+ def test_13a_create_describe_delete_tag
124
+ images = describe_images
125
+ resource_id = images.first[:aws_id]
126
+
127
+ assert @ec2.create_tag(resource_id, 'testkey', 'testvalue').inspect, "Could not add a tag to #{resource_id}"
128
+ assert_equal(
129
+ [{:aws_resource_id=>resource_id, :aws_resource_type=>"image", :aws_key=>"testkey", :aws_value=>"testvalue"}],
130
+ @ec2.describe_tags('Filter.1.Name' => 'resource-id', 'Filter.1.Value.1' => resource_id)
131
+ )
132
+ assert_equal(
133
+ [],
134
+ @ec2.describe_tags('Filter.1.Name' => 'resource-id', 'Filter.1.Value.1' => '__blah__')
135
+ )
136
+
137
+ assert @ec2.delete_tag(resource_id, 'testkey').inspect, "Could not delete tag 'testkey' from #{resource_id}"
138
+ sleep 1 # :(
139
+ assert_equal(
140
+ [],
141
+ @ec2.describe_tags('Filter.1.Name' => 'resource-id', 'Filter.1.Value.1' => resource_id)
142
+ )
143
+ end
144
+
145
+ def test_13b_create_describe_delete_tag_by_value
146
+ images = describe_images
147
+ resource_id = images.first[:aws_id]
148
+
149
+ assert @ec2.create_tag(resource_id, 'testkey', 'testvalue').inspect, "Could not add a tag to #{resource_id}"
150
+ assert_equal(
151
+ [{:aws_resource_id=>resource_id, :aws_resource_type=>"image", :aws_key=>"testkey", :aws_value=>"testvalue"}],
152
+ @ec2.describe_tags('Filter.1.Name' => 'resource-id', 'Filter.1.Value.1' => resource_id, 'Filter.2.Name' => 'key', 'Filter.2.Value.1' => 'testkey')
153
+ )
154
+ assert_equal(
155
+ [],
156
+ @ec2.describe_tags('Filter.1.Name' => 'resource-id', 'Filter.1.Value.1' => resource_id, 'Filter.2.Name' => 'key', 'Filter.2.Value.1' => '__blah__')
157
+ )
158
+
159
+ assert @ec2.delete_tag(resource_id, 'testkey', 'testvalue').inspect, "Could not delete tag 'testkey' from #{resource_id}"
160
+ sleep 1 # :(
161
+ assert_equal(
162
+ [],
163
+ @ec2.describe_tags('Filter.1.Name' => 'resource-id', 'Filter.1.Value.1' => resource_id, 'Filter.2.Name' => 'key', 'Filter.2.Value.1' => 'testkey')
164
+ )
165
+ end
166
+
167
+ def test_13c_delete_tag_with_empty_or_nil_value
168
+ images = describe_images
169
+ resource_id = images.first[:aws_id]
170
+
171
+ assert @ec2.create_tag(resource_id, 'testkey', 'testvalue').inspect, "Could not add a tag to #{resource_id}"
172
+ assert_equal(
173
+ [{:aws_resource_id=>resource_id, :aws_resource_type=>"image", :aws_key=>"testkey", :aws_value=>"testvalue"}],
174
+ @ec2.describe_tags('Filter.1.Name' => 'resource-id', 'Filter.1.Value.1' => resource_id)
175
+ )
176
+
177
+ # Delete a tag with an empty string value...
178
+ assert @ec2.delete_tag(resource_id, 'testkey', '').inspect, "Could not delete tag 'testkey' from #{resource_id}"
179
+ sleep 1 # :(
180
+ # ... does nothing
181
+ assert_equal(
182
+ [{:aws_resource_id=>resource_id, :aws_resource_type=>"image", :aws_key=>"testkey", :aws_value=>"testvalue"}],
183
+ @ec2.describe_tags('Filter.1.Name' => 'resource-id', 'Filter.1.Value.1' => resource_id)
184
+ )
185
+
186
+ # Delete a tag with value = nil...
187
+ assert @ec2.delete_tag(resource_id, 'testkey', nil).inspect, "Could not delete tag 'testkey' from #{resource_id}"
188
+ sleep 1 # :(
189
+ # ... deletes all tags with the given key
190
+ assert_equal(
191
+ [],
192
+ @ec2.describe_tags('Filter.1.Name' => 'resource-id', 'Filter.1.Value.1' => resource_id)
193
+ )
194
+ end
195
+
196
+ private
197
+
198
+ # Memoize the images to speed up the tests
199
+ def describe_images
200
+ @@images ||= @ec2.describe_images
201
+ assert @@images.size>0, 'Amazon must have at least some public images'
202
+ @@images
203
+ end
204
+
205
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../../lib/aws'
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require File.dirname(__FILE__) + '/../test_credentials.rb'
3
+ require 'pp'
4
+
5
+ class TestEc2 < Test::Unit::TestCase
6
+
7
+ # Some of RightEc2 instance methods concerning instance launching and image registration
8
+ # are not tested here due to their potentially risk.
9
+
10
+ def setup
11
+ TestCredentials.get_credentials
12
+ @ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id,
13
+ TestCredentials.aws_secret_access_key)
14
+ @key = 'right_ec2_awesome_test_key'
15
+ @group = 'right_ec2_awesome_test_security_group'
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../../lib/aws'
3
+ require 'pp'
4
+ require File.dirname(__FILE__) + '/../test_credentials.rb'
5
+
6
+ class TestElb < Test::Unit::TestCase
7
+
8
+ # Some of RightEc2 instance methods concerning instance launching and image registration
9
+ # are not tested here due to their potentially risk.
10
+
11
+ def setup
12
+ TestCredentials.get_credentials
13
+
14
+ @ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id,
15
+ TestCredentials.aws_secret_access_key)
16
+
17
+ @elb = Aws::Elb.new(TestCredentials.aws_access_key_id,
18
+ TestCredentials.aws_secret_access_key)
19
+ @key = 'right_ec2_awesome_test_key'
20
+ @group = 'right_ec2_awesome_test_security_group'
21
+ end
22
+
23
+ def test_01_create_elb
24
+
25
+ end
26
+
27
+ def test_02_register_instances
28
+
29
+ end
30
+
31
+ def test_03_deregister_instances
32
+
33
+ end
34
+
35
+
36
+ def test_04_describe_elb
37
+ desc = @elb.describe_load_balancers
38
+ puts desc.inspect
39
+ end
40
+
41
+ def test_06_describe_instance_health
42
+
43
+ end
44
+
45
+
46
+ def test_15_delete_elb
47
+
48
+ end
49
+
50
+
51
+ end