configure-s3-website 1.7.3 → 1.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/Rakefile +0 -5
  4. data/changelog.md +4 -0
  5. data/configure-s3-website.gemspec +4 -8
  6. data/lib/configure-s3-website.rb +1 -0
  7. data/lib/configure-s3-website/cloudfront_client.rb +1 -1
  8. data/lib/configure-s3-website/config_source/file_config_source.rb +6 -1
  9. data/lib/configure-s3-website/endpoint_helper.rb +26 -0
  10. data/lib/configure-s3-website/http_helper.rb +0 -23
  11. data/lib/configure-s3-website/s3_client.rb +71 -137
  12. data/lib/configure-s3-website/version.rb +1 -1
  13. data/spec/cloudfront_client_spec.rb +44 -27
  14. data/spec/config_source/file_config_source_spec.rb +6 -6
  15. data/spec/s3_client_spec.rb +116 -91
  16. data/spec/sample_files/_config_file_EU.yml +4 -0
  17. data/spec/xml_helper_spec.rb +5 -5
  18. metadata +15 -122
  19. data/features/cassettes/cucumber_tags/apply-configs-on-cf-dist.yml +0 -172
  20. data/features/cassettes/cucumber_tags/bucket-does-not-exist-in-tokyo.yml +0 -159
  21. data/features/cassettes/cucumber_tags/bucket-does-not-exist.yml +0 -159
  22. data/features/cassettes/cucumber_tags/bucket-exists.yml +0 -78
  23. data/features/cassettes/cucumber_tags/create-cf-dist.yml +0 -137
  24. data/features/cassettes/cucumber_tags/redirects.yml +0 -203
  25. data/features/config_file.feature +0 -57
  26. data/features/configure_bucket.feature +0 -64
  27. data/features/create_cloudfront_dist.feature +0 -232
  28. data/features/modify_cloudfront_dist.feature +0 -19
  29. data/features/step_definitions/steps.rb +0 -80
  30. data/features/support/env.rb +0 -22
  31. data/features/support/sample_config_files/apply_configs_on_cf_dist.yml +0 -8
  32. data/features/support/sample_config_files/config_with_cloudfront_distribution_id.yml +0 -4
  33. data/features/support/sample_config_files/create_cf_dist.yml +0 -3
  34. data/features/support/sample_config_files/create_cf_dist_with_custom_configs.yml +0 -7
  35. data/features/support/sample_config_files/endpoint_tokyo.yml +0 -4
  36. data/features/support/sample_config_files/redirects.yml +0 -10
  37. data/features/support/sample_config_files/s3_config_with_existing_bucket.yml +0 -3
  38. data/features/support/sample_config_files/s3_config_with_non-existing_bucket.yml +0 -3
  39. data/features/support/vcr.rb +0 -15
  40. data/spec/endpoint_spec.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f6972f08379371509616f8749054228cd210ae9
4
- data.tar.gz: 0af5ebe8a97271862fa888332bb97a3213ca7e3a
3
+ metadata.gz: 1520dfada65dc18e62434f4374df69305fc87b01
4
+ data.tar.gz: 65ca8ec93209289f9039628f3db2ae40f9306267
5
5
  SHA512:
6
- metadata.gz: c598441c45d35f9137da165ecbc67889f3f5e0c9be906d9eb2bfca82db810dc8d5fa62b619870d72b0598efe6800fdc0a3483a44b2cab8d2d419f7be84cb888a
7
- data.tar.gz: d6aea64ea95f47f46781663078e398ff053b7ab988bd0fb05dd91feb291d24e1bfd501675f66d730174be0d1130b3e3f1f5ba3086062fade14d13761a4c3e60d
6
+ metadata.gz: c86f7290d8c4f61887eb05d8b0d1a623b8031ef279879d503277231beae3983ac64a9b763ecd740cb8bbd4395a6317921021b51341ab82577827794e60509f46
7
+ data.tar.gz: 5b0d6d7a2bcf29909210afbd006facb81519a770ebae665bad370528a8bde4886e5565a838401c7c0dafb2b0c912f18fc615f91d06fb5fc3bb82b0f9ea04f665
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
3
  - 2.1.0
4
+ - 2.2.0
5
+ - 2.3.0
data/Rakefile CHANGED
@@ -7,10 +7,5 @@ task :default => 'test'
7
7
  desc "Run tests"
8
8
  task :test do
9
9
  sh "bundle exec rspec"
10
- sh "bundle exec cucumber"
11
10
  end
12
11
 
13
- desc 'Run features tagged with @wip'
14
- task 'cucumber:wip' do
15
- sh "bundle exec cucumber --tags @wip"
16
- end
@@ -2,6 +2,10 @@
2
2
 
3
3
  This project uses [Semantic Versioning](http://semver.org).
4
4
 
5
+ ## 1.7.4
6
+
7
+ * Support all AWS regions
8
+
5
9
  ## 1.7.3
6
10
 
7
11
  * see <https://github.com/laurilehmijoki/configure-s3-website/pull/13>
@@ -10,18 +10,14 @@ spec = Gem::Specification.new do |s|
10
10
  s.bindir = 'bin'
11
11
 
12
12
  s.add_dependency 'deep_merge', '~> 1.0.0'
13
+ s.add_dependency 'aws-sdk', '~> 2'
13
14
 
14
- s.add_development_dependency 'rspec', '~> 2.10.0'
15
- s.add_development_dependency 'rspec-expectations', '~> 2.10.0'
16
- s.add_development_dependency 'cucumber', '~> 1.2.0'
17
- s.add_development_dependency 'aruba', '~> 0.4.0'
15
+ s.add_development_dependency 'rspec', '~> 3'
16
+ s.add_development_dependency 'rspec-expectations', '~> 3'
18
17
  s.add_development_dependency 'rake', '~> 0.9.0'
19
- s.add_development_dependency 'vcr', '~> 2.3.0'
20
- s.add_development_dependency 'webmock', '~> 1.8.0'
21
- s.add_development_dependency 'json', '~> 1.7.7'
22
18
 
23
19
  s.files = `git ls-files`.split("\n")
24
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
25
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
22
  s.require_paths = ["lib"]
27
23
  end
@@ -3,6 +3,7 @@ require 'configure-s3-website/s3_client'
3
3
  require 'configure-s3-website/cloudfront_client'
4
4
  require 'configure-s3-website/xml_helper'
5
5
  require 'configure-s3-website/http_helper'
6
+ require 'configure-s3-website/endpoint_helper'
6
7
  require 'configure-s3-website/runner'
7
8
  require 'configure-s3-website/cli'
8
9
  require 'configure-s3-website/config_source/config_source'
@@ -113,7 +113,7 @@ module ConfigureS3Website
113
113
  end
114
114
 
115
115
  def self.distribution_config_xml(config_source, custom_cf_settings)
116
- domain_name = "#{config_source.s3_bucket_name}.#{Endpoint.by_config_source(config_source).website_hostname}"
116
+ domain_name = "#{config_source.s3_bucket_name}.#{EndpointHelper.s3_website_hostname(config_source.s3_endpoint)}"
117
117
  %|
118
118
  <DistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2012-07-01/">
119
119
  <Origins>
@@ -25,7 +25,12 @@ module ConfigureS3Website
25
25
  end
26
26
 
27
27
  def s3_endpoint
28
- @config['s3_endpoint']
28
+ endpoint = @config['s3_endpoint'] || 'us-east-1'
29
+ if endpoint == 'EU'
30
+ 'eu-west-1'
31
+ else
32
+ endpoint
33
+ end
29
34
  end
30
35
 
31
36
  def routing_rules
@@ -0,0 +1,26 @@
1
+ module ConfigureS3Website
2
+ class EndpointHelper
3
+ def self.s3_website_hostname(region)
4
+ if old_regions.include?(region)
5
+ "s3-website-#{region}.amazonaws.com"
6
+ else
7
+ "s3-website.#{region}.amazonaws.com"
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def self.old_regions
14
+ [
15
+ 'us-east-1',
16
+ 'us-west-1',
17
+ 'us-west-2',
18
+ 'ap-southeast-1',
19
+ 'ap-southeast-2',
20
+ 'ap-northeast-1',
21
+ 'eu-west-1',
22
+ 'sa-east-1'
23
+ ]
24
+ end
25
+ end
26
+ end
@@ -1,20 +1,5 @@
1
1
  module ConfigureS3Website
2
2
  class HttpHelper
3
- def self.call_s3_api(path, method, body, config_source)
4
- endpoint = Endpoint.by_config_source(config_source)
5
- date = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S %Z")
6
- digest = create_s3_digest(path, method, config_source, date)
7
- self.call_api(
8
- path,
9
- method,
10
- body,
11
- config_source,
12
- endpoint.hostname,
13
- digest,
14
- date
15
- )
16
- end
17
-
18
3
  def self.call_cloudfront_api(path, method, body, config_source, headers = {})
19
4
  date = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S %Z")
20
5
  digest = create_cloudfront_digest(config_source, date)
@@ -55,14 +40,6 @@ module ConfigureS3Website
55
40
  end
56
41
  end
57
42
 
58
- def self.create_s3_digest(path, method, config_source, date)
59
- digest = OpenSSL::Digest.new('sha1')
60
- method_string = method.to_s.match(/Net::HTTP::(\w+)/)[1].upcase
61
- can_string = "#{method_string}\n\n\n#{date}\n#{path}"
62
- hmac = OpenSSL::HMAC.digest(digest, config_source.s3_secret_access_key, can_string)
63
- signature = Base64.encode64(hmac).strip
64
- end
65
-
66
43
  def self.create_cloudfront_digest(config_source, date)
67
44
  digest = Base64.encode64(
68
45
  OpenSSL::HMAC.digest(
@@ -3,6 +3,7 @@ require 'openssl'
3
3
  require 'digest/sha1'
4
4
  require 'digest/md5'
5
5
  require 'net/https'
6
+ require 'aws-sdk'
6
7
 
7
8
  module ConfigureS3Website
8
9
  class S3Client
@@ -11,8 +12,7 @@ module ConfigureS3Website
11
12
  begin
12
13
  enable_website_configuration(config_source)
13
14
  make_bucket_readable_to_everyone(config_source)
14
- configure_bucket_redirects(config_source)
15
- rescue NoSuchBucketError
15
+ rescue Aws::S3::Errors::NoSuchBucket
16
16
  create_bucket(config_source)
17
17
  retry
18
18
  end
@@ -20,157 +20,91 @@ module ConfigureS3Website
20
20
 
21
21
  private
22
22
 
23
- def self.enable_website_configuration(config_source)
24
- body = %|
25
- <WebsiteConfiguration xmlns='http://s3.amazonaws.com/doc/2006-03-01/'>
26
- <IndexDocument>
27
- <Suffix>#{config_source.index_document || "index.html"}</Suffix>
28
- </IndexDocument>
29
- <ErrorDocument>
30
- <Key>#{config_source.error_document || "error.html"}</Key>
31
- </ErrorDocument>
32
- </WebsiteConfiguration>
33
- |
34
- HttpHelper.call_s3_api(
35
- path = "/#{config_source.s3_bucket_name}/?website",
36
- method = Net::HTTP::Put,
37
- body = body,
38
- config_source = config_source
39
- )
40
- puts "Bucket #{config_source.s3_bucket_name} now functions as a website"
41
- end
42
-
43
- def self.make_bucket_readable_to_everyone(config_source)
44
- policy_json = %|{
45
- "Version":"2008-10-17",
46
- "Statement":[{
47
- "Sid":"PublicReadForGetBucketObjects",
48
- "Effect":"Allow",
49
- "Principal": { "AWS": "*" },
50
- "Action":["s3:GetObject"],
51
- "Resource":["arn:aws:s3:::#{config_source.s3_bucket_name}/*"]
52
- }]
53
- }|
54
- HttpHelper.call_s3_api(
55
- path = "/#{config_source.s3_bucket_name}/?policy",
56
- method = Net::HTTP::Put,
57
- body = policy_json,
58
- config_source = config_source
23
+ def self.s3(config_source)
24
+ s3 = Aws::S3::Client.new(
25
+ region: config_source.s3_endpoint,
26
+ access_key_id: config_source.s3_access_key_id,
27
+ secret_access_key: config_source.s3_secret_access_key
59
28
  )
60
- puts "Bucket #{config_source.s3_bucket_name} is now readable to the whole world"
61
29
  end
62
30
 
63
- def self.configure_bucket_redirects(config_source)
64
- routing_rules = config_source.routing_rules
65
- if routing_rules.is_a?(Array) && routing_rules.any?
66
- body = %|
67
- <WebsiteConfiguration xmlns='http://s3.amazonaws.com/doc/2006-03-01/'>
68
- <IndexDocument>
69
- <Suffix>#{config_source.index_document || "index.html"}</Suffix>
70
- </IndexDocument>
71
- <ErrorDocument>
72
- <Key>#{config_source.error_document || "error.html"}</Key>
73
- </ErrorDocument>
74
- <RoutingRules>
75
- |
76
- routing_rules.each do |routing_rule|
77
- body << %|
78
- <RoutingRule>
79
- |
80
- body << XmlHelper.hash_to_api_xml(routing_rule, 7)
81
- body << %|
82
- </RoutingRule>
83
- |
31
+ def self.enable_website_configuration(config_source)
32
+ routing_rules =
33
+ if config_source.routing_rules && config_source.routing_rules.is_a?(Array)
34
+ config_source.routing_rules.map { |rule|
35
+ Hash[
36
+ rule.map { |rule_key, rule_value|
37
+ [
38
+ rule_key.to_sym,
39
+ Hash[ # Assume that each rule value is a Hash
40
+ rule_value.map { |redirect_rule_key, redirect_rule_value|
41
+ [
42
+ redirect_rule_key.to_sym,
43
+ redirect_rule_key == "http_redirect_code" ?
44
+ redirect_rule_value.to_s
45
+ #redirect_rule_value.to_s # Permit numeric redirect values in the YAML config file. (The S3 API does not allow numeric redirect values, hence this block of code.)
46
+ :
47
+ redirect_rule_value
48
+ ]
49
+ }
50
+ ]
51
+ ]
52
+ }
53
+ ]
54
+ }
55
+ else
56
+ nil
84
57
  end
85
- body << %|
86
- </RoutingRules>
87
- </WebsiteConfiguration>
88
- |
89
-
90
- HttpHelper.call_s3_api(
91
- path = "/#{config_source.s3_bucket_name}/?website",
92
- method = Net::HTTP::Put,
93
- body = body,
94
- config_source = config_source
95
- )
58
+ s3(config_source).put_bucket_website({
59
+ bucket: config_source.s3_bucket_name,
60
+ website_configuration: {
61
+ index_document: {
62
+ suffix: config_source.index_document || "index.html"
63
+ },
64
+ error_document: {
65
+ key: config_source.error_document || "error.html"
66
+ },
67
+ routing_rules: routing_rules
68
+ }
69
+ })
70
+ puts "Bucket #{config_source.s3_bucket_name} now functions as a website"
71
+ if routing_rules && routing_rules.any?
96
72
  puts "#{routing_rules.size} redirects configured for #{config_source.s3_bucket_name} bucket"
97
73
  else
98
74
  puts "No redirects to configure for #{config_source.s3_bucket_name} bucket"
99
75
  end
100
76
  end
101
77
 
102
- def self.create_bucket(config_source)
103
- endpoint = Endpoint.new(config_source.s3_endpoint || '')
104
- body = if endpoint.region == 'US Standard'
105
- '' # The standard endpoint does not need a location constraint
106
- else
107
- %|
108
- <CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
109
- <LocationConstraint>#{endpoint.location_constraint}</LocationConstraint>
110
- </CreateBucketConfiguration >
111
- |
112
- end
78
+ def self.make_bucket_readable_to_everyone(config_source)
79
+ s3(config_source).put_bucket_policy({
80
+ bucket: config_source.s3_bucket_name,
81
+ policy: %|{
82
+ "Version":"2008-10-17",
83
+ "Statement":[{
84
+ "Sid":"PublicReadForGetBucketObjects",
85
+ "Effect":"Allow",
86
+ "Principal": { "AWS": "*" },
87
+ "Action":["s3:GetObject"],
88
+ "Resource":["arn:aws:s3:::#{config_source.s3_bucket_name}/*"]
89
+ }]
90
+ }|
91
+ })
92
+ puts "Bucket #{config_source.s3_bucket_name} is now readable to the whole world"
93
+ end
113
94
 
114
- HttpHelper.call_s3_api(
115
- path = "/#{config_source.s3_bucket_name}",
116
- method = Net::HTTP::Put,
117
- body = body,
118
- config_source = config_source
119
- )
95
+ def self.create_bucket(config_source)
96
+ s3(config_source).create_bucket({
97
+ bucket: config_source.s3_bucket_name,
98
+ create_bucket_configuration: {
99
+ location_constraint: config_source.s3_endpoint
100
+ }
101
+ })
120
102
  puts "Created bucket %s in the %s Region" %
121
103
  [
122
104
  config_source.s3_bucket_name,
123
- endpoint.region
105
+ config_source.s3_endpoint
124
106
  ]
125
107
  end
126
108
  end
127
109
  end
128
110
 
129
- private
130
-
131
- module ConfigureS3Website
132
- class Endpoint
133
- attr_reader :region, :location_constraint, :hostname, :website_hostname
134
-
135
- def initialize(location_constraint)
136
- raise InvalidS3LocationConstraintError unless
137
- location_constraints.has_key?location_constraint
138
- @region = location_constraints.fetch(location_constraint)[:region]
139
- @hostname = location_constraints.fetch(location_constraint)[:endpoint]
140
- @website_hostname = location_constraints.fetch(location_constraint)[:website_endpoint]
141
- @location_constraint = location_constraint
142
- end
143
-
144
- # http://docs.amazonwebservices.com/general/latest/gr/rande.html#s3_region
145
- def location_constraints
146
- eu_west_1_region = {
147
- :region => 'EU (Ireland)',
148
- :website_endpoint => 's3-website-eu-west-1.amazonaws.com',
149
- :endpoint => 's3-eu-west-1.amazonaws.com'
150
- }
151
-
152
- {
153
- '' => { :region => 'US Standard', :endpoint => 's3.amazonaws.com', :website_endpoint => 's3-website-us-east-1.amazonaws.com' },
154
- 'us-west-2' => { :region => 'US West (Oregon)', :endpoint => 's3-us-west-2.amazonaws.com', :website_endpoint => 's3-website-us-west-2.amazonaws.com' },
155
- 'us-west-1' => { :region => 'US West (Northern California)', :endpoint => 's3-us-west-1.amazonaws.com', :website_endpoint => 's3-website-us-west-1.amazonaws.com' },
156
- 'EU' => eu_west_1_region,
157
- 'eu-west-1' => eu_west_1_region,
158
- 'eu-central-1' => { :region => 'EU (Frankfurt)', :endpoint => 's3.eu-central-1.amazonaws.com', :website_endpoint => 's3-website.eu-central-1.amazonaws.com' },
159
- 'ap-southeast-1' => { :region => 'Asia Pacific (Singapore)', :endpoint => 's3-ap-southeast-1.amazonaws.com', :website_endpoint => 's3-website-ap-southeast-1.amazonaws.com' },
160
- 'ap-southeast-2' => { :region => 'Asia Pacific (Sydney)', :endpoint => 's3-ap-southeast-2.amazonaws.com', :website_endpoint => 's3-website-ap-southeast-2.amazonaws.com' },
161
- 'ap-northeast-1' => { :region => 'Asia Pacific (Tokyo)', :endpoint => 's3-ap-northeast-1.amazonaws.com', :website_endpoint => 's3-website-ap-northeast-1.amazonaws.com' },
162
- 'sa-east-1' => { :region => 'South America (Sao Paulo)', :endpoint => 's3-sa-east-1.amazonaws.com', :website_endpoint => 's3-website-sa-east-1.amazonaws.com' }
163
- }
164
- end
165
-
166
- def self.by_config_source(config_source)
167
- endpoint = Endpoint.new(config_source.s3_endpoint || '')
168
- end
169
- end
170
- end
171
-
172
- class InvalidS3LocationConstraintError < StandardError
173
- end
174
-
175
- class NoSuchBucketError < StandardError
176
- end
@@ -1,3 +1,3 @@
1
1
  module ConfigureS3Website
2
- VERSION = '1.7.3'
2
+ VERSION = '1.7.4'
3
3
  end
@@ -8,8 +8,8 @@ describe ConfigureS3Website::CloudFrontClient do
8
8
  describe 'letting the user to override the default values' do
9
9
  let(:config_source) {
10
10
  mock = double('config_source')
11
- mock.stub(:s3_bucket_name).and_return('test-bucket')
12
- mock.stub(:s3_endpoint).and_return(nil)
11
+ allow(mock).to receive(:s3_bucket_name).and_return('test-bucket')
12
+ allow(mock).to receive(:s3_endpoint).and_return(nil)
13
13
  mock
14
14
  }
15
15
 
@@ -28,44 +28,61 @@ describe ConfigureS3Website::CloudFrontClient do
28
28
  }
29
29
 
30
30
  it 'allows the user to override default CloudFront settings' do
31
- REXML::XPath.first(
31
+ expect(REXML::XPath.first(
32
32
  distribution_config_xml,
33
33
  '/DistributionConfig/DefaultCacheBehavior/MinTTL'
34
- ).get_text.to_s.should eq('987')
34
+ ).get_text.to_s).to eq('987')
35
35
  end
36
36
 
37
37
  it 'retains the default values that are not overriden' do
38
- REXML::XPath.first(
38
+ expect(REXML::XPath.first(
39
39
  distribution_config_xml,
40
40
  '/DistributionConfig/DefaultCacheBehavior/ViewerProtocolPolicy'
41
- ).get_text.to_s.should eq('allow-all')
41
+ ).get_text.to_s).to eq('allow-all')
42
42
  end
43
43
  end
44
44
 
45
- describe 'inferring //Origins/Items/Origin/DomainName' do
46
- let(:config_source) {
47
- mock = double('config_source')
48
- mock.stub(:s3_bucket_name).and_return('test-bucket')
49
- mock.stub(:s3_endpoint).and_return('us-west-1')
50
- mock
51
- }
45
+ [
46
+ { :region => 'us-east-1', :website_endpoint => 's3-website-us-east-1.amazonaws.com' },
47
+ { :region => 'us-west-1', :website_endpoint => 's3-website-us-west-1.amazonaws.com' },
48
+ { :region => 'us-west-2', :website_endpoint => 's3-website-us-west-2.amazonaws.com' },
49
+ { :region => 'ap-south-1', :website_endpoint => 's3-website.ap-south-1.amazonaws.com' },
50
+ { :region => 'ap-northeast-2', :website_endpoint => 's3-website.ap-northeast-2.amazonaws.com' },
51
+ { :region => 'ap-southeast-1', :website_endpoint => 's3-website-ap-southeast-1.amazonaws.com' },
52
+ { :region => 'ap-southeast-2', :website_endpoint => 's3-website-ap-southeast-2.amazonaws.com' },
53
+ { :region => 'ap-northeast-1', :website_endpoint => 's3-website-ap-northeast-1.amazonaws.com' },
54
+ { :region => 'eu-central-1', :website_endpoint => 's3-website.eu-central-1.amazonaws.com' },
55
+ { :region => 'eu-west-1', :website_endpoint => 's3-website-eu-west-1.amazonaws.com' },
56
+ { :region => 'sa-east-1', :website_endpoint => 's3-website-sa-east-1.amazonaws.com' },
57
+ ].each { |conf|
58
+ region = conf[:region]
59
+ website_endpoint = conf[:website_endpoint]
60
+ describe "inferring //Origins/Items/Origin/DomainName (#{region})" do
61
+ let(:config_source) {
62
+ mock = double('config_source')
63
+ allow(mock).to receive(:s3_bucket_name).and_return('test-bucket')
64
+ allow(mock).to receive(:s3_endpoint).and_return(region)
65
+ mock
66
+ }
52
67
 
53
- let(:distribution_config_xml) {
54
- REXML::Document.new(
55
- ConfigureS3Website::CloudFrontClient.send(
56
- :distribution_config_xml,
57
- config_source,
58
- custom_distribution_config = {}
68
+ let(:distribution_config_xml) {
69
+ REXML::Document.new(
70
+ ConfigureS3Website::CloudFrontClient.send(
71
+ :distribution_config_xml,
72
+ config_source,
73
+ custom_distribution_config = {}
74
+ )
59
75
  )
60
- )
61
- }
76
+ }
62
77
 
63
- it 'honors the endpoint of the S3 website' do
64
- REXML::XPath.first(
65
- distribution_config_xml,
66
- '/DistributionConfig/Origins/Items/Origin/DomainName'
67
- ).get_text.to_s.should eq('test-bucket.s3-website-us-west-1.amazonaws.com')
78
+ it "honors the endpoint of the S3 website (#{region})" do
79
+ expect(REXML::XPath.first(
80
+ distribution_config_xml,
81
+ '/DistributionConfig/Origins/Items/Origin/DomainName'
82
+ ).get_text.to_s).to eq("test-bucket.#{website_endpoint}")
83
+ end
68
84
  end
69
- end
85
+ }
86
+
70
87
  end
71
88
  end