use activesupport 4.2.6 + new redirect_to_https property for sites
did
committed May 06, 2016
commit 079f71eb2fa46e7f2d6168ea31919e9d017cfefc
Showing 5
changed files with
92 additions
and 58 deletions
Gemfile.lock
+22
-39
| @@ | @@ -13,7 +13,7 @@ PATH |
| httparty (~> 0.13.6) | |
| kramdown (~> 1.10.0) | |
| locomotivecms-solid (~> 4.0.1) | |
| - | locomotivecms_common (~> 0.1.0) |
| + | locomotivecms_common (~> 0.2.0) |
| mime-types (~> 2.6.1) | |
| mimetype-fu (~> 0.1.2) | |
| moneta (~> 0.8.0) | |
| @@ | @@ -31,7 +31,7 @@ GEM |
| remote: https://rubygems.org/ | |
| specs: | |
| RedCloth (4.2.9) | |
| - | activesupport (4.2.5.2) |
| + | activesupport (4.2.6) |
| i18n (~> 0.7) | |
| json (~> 1.7, >= 1.7.7) | |
| minitest (~> 5.1) | |
| @@ | @@ -41,13 +41,13 @@ GEM |
| attr_extras (4.4.0) | |
| autoprefixer-rails (6.3.3.1) | |
| execjs | |
| - | bson (4.0.2) |
| - | byebug (8.2.1) |
| + | bson (4.1.1) |
| + | byebug (8.2.5) |
| chronic (0.10.2) | |
| chunky_png (1.3.5) | |
| codeclimate-test-reporter (0.4.8) | |
| simplecov (>= 0.7.1, < 1.0.0) | |
| - | coderay (1.1.0) |
| + | coderay (1.1.1) |
| coffee-script (2.4.1) | |
| coffee-script-source | |
| execjs | |
| @@ | @@ -65,10 +65,9 @@ GEM |
| sass (>= 3.3.0, < 3.5) | |
| compass-import-once (1.0.5) | |
| sass (>= 3.2, < 3.5) | |
| - | concurrent-ruby (1.0.1) |
| - | coveralls (0.8.10) |
| + | concurrent-ruby (1.0.2) |
| + | coveralls (0.8.13) |
| json (~> 1.8) | |
| - | rest-client (>= 1.6.8, < 2) |
| simplecov (~> 0.11.0) | |
| term-ansicolor (~> 1.3) | |
| thor (~> 0.19.1) | |
| @@ | @@ -76,24 +75,18 @@ GEM |
| crass (1.0.2) | |
| diff-lcs (1.2.5) | |
| docile (1.1.5) | |
| - | domain_name (0.5.25) |
| - | unf (>= 0.0.5, < 1.0.0) |
| dragonfly (1.0.12) | |
| addressable (~> 2.3) | |
| multi_json (~> 1.0) | |
| rack (>= 1.3.0) | |
| duktape (1.3.0.6) | |
| execjs (2.6.0) | |
| - | fast_stack (0.1.0) |
| - | rake |
| - | rake-compiler |
| + | fast_stack (0.2.0) |
| ffi (1.9.10) | |
| flamegraph (0.1.0) | |
| fast_stack | |
| haml (4.0.7) | |
| tilt | |
| - | http-cookie (1.0.2) |
| - | domain_name (~> 0.5) |
| httparty (0.13.7) | |
| json (~> 1.8) | |
| multi_xml (>= 0.5.2) | |
| @@ | @@ -110,13 +103,13 @@ GEM |
| locomotivecms-liquid (4.0.0) | |
| locomotivecms-solid (4.0.1) | |
| locomotivecms-liquid (~> 4.0.0) | |
| - | locomotivecms_common (0.1.0) |
| - | activesupport (~> 4.2.5.2) |
| + | locomotivecms_common (0.2.0) |
| + | activesupport (~> 4.2.6) |
| attr_extras (~> 4.4.0) | |
| colorize | |
| stringex (~> 2.6.0) | |
| - | mail (2.6.3) |
| - | mime-types (>= 1.16, < 3) |
| + | mail (2.6.4) |
| + | mime-types (>= 1.16, < 4) |
| memory_profiler (0.9.6) | |
| method_source (0.8.2) | |
| mime-types (2.6.2) | |
| @@ | @@ -124,12 +117,11 @@ GEM |
| mini_portile2 (2.0.0) | |
| minitest (5.8.4) | |
| moneta (0.8.0) | |
| - | mongo (2.2.3) |
| + | mongo (2.2.5) |
| bson (~> 4.0) | |
| morphine (0.1.1) | |
| - | multi_json (1.11.2) |
| + | multi_json (1.12.0) |
| multi_xml (0.5.5) | |
| - | netrc (0.11.0) |
| nokogiri (1.6.7.2) | |
| mini_portile2 (~> 2.0.0.rc2) | |
| nokogumbo (1.4.7) | |
| @@ | @@ -144,37 +136,31 @@ GEM |
| pry-byebug (3.3.0) | |
| byebug (~> 8.0) | |
| pry (~> 0.10) | |
| - | puma (2.15.3) |
| + | puma (3.4.0) |
| rack (1.6.4) | |
| rack-cache (1.6.1) | |
| rack (>= 0.4) | |
| - | rack-mini-profiler (0.9.8) |
| - | rack (>= 1.1.3) |
| + | rack-mini-profiler (0.9.9.2) |
| + | rack (>= 1.2.0) |
| rack-rewrite (1.5.1) | |
| rack-test (0.6.3) | |
| rack (>= 1.0) | |
| rack_csrf (2.5.0) | |
| rack (>= 1.1.0) | |
| rake (10.4.2) | |
| - | rake-compiler (0.9.5) |
| - | rake |
| rb-fsevent (0.9.7) | |
| rb-inotify (0.9.7) | |
| ffi (>= 0.5.0) | |
| - | rest-client (1.8.0) |
| - | http-cookie (>= 1.0.2, < 2.0) |
| - | mime-types (>= 1.16, < 3.0) |
| - | netrc (~> 0.7) |
| rspec (3.4.0) | |
| rspec-core (~> 3.4.0) | |
| rspec-expectations (~> 3.4.0) | |
| rspec-mocks (~> 3.4.0) | |
| - | rspec-core (3.4.1) |
| + | rspec-core (3.4.4) |
| rspec-support (~> 3.4.0) | |
| rspec-expectations (3.4.0) | |
| diff-lcs (>= 1.2.0, < 2.0) | |
| rspec-support (~> 3.4.0) | |
| - | rspec-mocks (3.4.0) |
| + | rspec-mocks (3.4.1) |
| diff-lcs (>= 1.2.0, < 2.0) | |
| rspec-support (~> 3.4.0) | |
| rspec-support (3.4.1) | |
| @@ | @@ -183,7 +169,7 @@ GEM |
| nokogiri (>= 1.4.4) | |
| nokogumbo (~> 1.4.1) | |
| sass (3.4.22) | |
| - | simplecov (0.11.1) |
| + | simplecov (0.11.2) |
| docile (~> 1.1.0) | |
| json (~> 1.8) | |
| simplecov-html (~> 0.10.0) | |
| @@ | @@ -192,20 +178,17 @@ GEM |
| sprockets (3.5.2) | |
| concurrent-ruby (~> 1.0) | |
| rack (> 1, < 3) | |
| - | stackprof (0.2.7) |
| + | stackprof (0.2.9) |
| stringex (2.6.0) | |
| term-ansicolor (1.3.2) | |
| tins (~> 1.0) | |
| thor (0.19.1) | |
| thread_safe (0.3.5) | |
| tilt (2.0.2) | |
| - | timecop (0.8.0) |
| + | timecop (0.8.1) |
| tins (1.6.0) | |
| tzinfo (1.2.2) | |
| thread_safe (~> 0.1) | |
| - | unf (0.1.4) |
| - | unf_ext |
| - | unf_ext (0.0.7.1) |
| yui-compressor (0.12.0) | |
| PLATFORMS | |
locomotive/steam/entities/site.rb b/lib/locomotive/steam/entities/site.rb
+1
-0
| @@ | @@ -13,6 +13,7 @@ module Locomotive::Steam |
| template_version: nil, | |
| domains: [], | |
| redirect_to_first_domain: false, | |
| + | redirect_to_https: false, |
| url_redirections: [], | |
| private_access: false, | |
| password: nil, | |
locomotive/steam/middlewares/site.rb b/lib/locomotive/steam/middlewares/site.rb
+12
-5
| @@ | @@ -16,7 +16,8 @@ module Locomotive::Steam |
| # log anyway | |
| log_site(site) | |
| - | redirect_to_first_domain_if_enabled(site) |
| + | # redirect to the first domain and/or HTTPS if defined by the site |
| + | redirect_if_required(site) |
| end | |
| private | |
| @@ | @@ -40,9 +41,11 @@ module Locomotive::Steam |
| end | |
| end | |
| - | def redirect_to_first_domain_if_enabled(site) |
| - | if redirect_to_first_domain?(site) |
| - | klass = request.scheme == 'https' ? URI::HTTPS : URI::HTTP |
| + | def redirect_if_required(site) |
| + | return if env['steam.is_default_host'] |
| + | |
| + | if redirect_to_first_domain?(site) || redirect_to_https?(site) |
| + | klass = request.scheme == 'https' || redirect_to_https?(site) ? URI::HTTPS : URI::HTTP |
| redirect_to klass.build( | |
| host: site.domains.first, | |
| port: [80, 443].include?(request.port) ? nil : request.port, | |
| @@ | @@ -54,11 +57,15 @@ module Locomotive::Steam |
| def redirect_to_first_domain?(site) | |
| # the site parameter can be an instance of Locomotive::Steam::Services::Defer and | |
| # so comparing just site may not be reliable. | |
| - | !env['steam.is_default_host'] && |
| site.try(:redirect_to_first_domain) && | |
| site.domains.first != request.host | |
| end | |
| + | def redirect_to_https?(site) |
| + | site.try(:redirect_to_https) && |
| + | request.scheme != 'https' |
| + | end |
| + | |
| def log_site(site) | |
| if site.nil? | |
| msg = "Unable to find a site, url asked: #{request.url} ".colorize(color: :light_white, background: :red) | |
locomotivecms_steam.gemspec
+1
-1
| @@ | @@ -48,7 +48,7 @@ Gem::Specification.new do |spec| |
| spec.add_dependency 'pony', '~> 1.11' | |
| spec.add_dependency 'locomotivecms-solid', '~> 4.0.1' | |
| - | spec.add_dependency 'locomotivecms_common', '~> 0.1.0' |
| + | spec.add_dependency 'locomotivecms_common', '~> 0.2.0' |
| spec.required_ruby_version = '>= 2.0' | |
| end | |
spec/unit/middlewares/site_spec.rb
+56
-13
| @@ | @@ -42,38 +42,81 @@ describe Locomotive::Steam::Middlewares::Site do |
| end | |
| - | describe 'redirection to the first domain' do |
| + | describe 'redirection' do |
| - | let(:redirect_to_first_domain) { false } |
| + | let(:redirect_to_first_domain) { false } |
| + | let(:redirect_to_https) { false } |
| let(:url) { 'http://acme.com' } | |
| - | let(:site) { instance_double('SiteWithDomains', name: 'Acme', domains: ['www.acme.com', 'acme.com'], redirect_to_first_domain: redirect_to_first_domain) } |
| + | let(:site) { instance_double('SiteWithDomains', name: 'Acme', domains: ['www.acme.com', 'acme.com'], redirect_to_first_domain: redirect_to_first_domain, redirect_to_https: redirect_to_https) } |
| before { expect(services).to receive(:current_site).and_return(site) } | |
| - | it { is_expected.to eq [200, nil] } |
| + | describe 'redirection to https' do |
| - | describe 'option enabled' do |
| + | it { is_expected.to eq [200, nil] } |
| - | let(:redirect_to_first_domain) { true } |
| + | describe 'option enabled' do |
| - | it { is_expected.to eq [301, 'http://www.acme.com/'] } |
| + | let(:redirect_to_https) { true } |
| - | context 'first domain requested' do |
| + | it { is_expected.to eq [301, 'https://www.acme.com/'] } |
| - | let(:url) { 'http://www.acme.com' } |
| - | it { is_expected.to eq [200, nil] } |
| + | context 'https requested' do |
| + | |
| + | let(:url) { 'https://www.acme.com' } |
| + | it { is_expected.to eq [200, nil] } |
| + | |
| + | end |
| + | |
| + | context 'requesting the default host' do |
| + | |
| + | let(:is_default_host) { true } |
| + | it { is_expected.to eq [200, nil] } |
| + | |
| + | end |
| end | |
| - | context 'requesting the default host' do |
| + | end |
| + | |
| + | describe 'redirection to the first domain' do |
| + | |
| + | it { is_expected.to eq [200, nil] } |
| + | |
| + | describe 'option enabled' do |
| + | |
| + | let(:redirect_to_first_domain) { true } |
| + | |
| + | it { is_expected.to eq [301, 'http://www.acme.com/'] } |
| - | let(:is_default_host) { true } |
| - | it { is_expected.to eq [200, nil] } |
| + | context 'first domain requested' do |
| + | |
| + | let(:url) { 'http://www.acme.com' } |
| + | it { is_expected.to eq [200, nil] } |
| + | |
| + | end |
| + | |
| + | context 'requesting the default host' do |
| + | |
| + | let(:is_default_host) { true } |
| + | it { is_expected.to eq [200, nil] } |
| + | |
| + | end |
| end | |
| end | |
| + | describe 'redirection to both https and the first domain' do |
| + | |
| + | let(:redirect_to_https) { true } |
| + | let(:redirect_to_first_domain) { true } |
| + | let(:url) { 'http://acme.com/foo/bar' } |
| + | |
| + | it { is_expected.to eq [301, 'https://www.acme.com/foo/bar'] } |
| + | |
| + | end |
| + | |
| end | |
| end | |