History

Force HTTPS

Thibaut Courouble committed 8 years ago

Commit 7d3c6bd1 parent 24abe4c7 files · +37 −37Browse files

Unified · Split

7 files
  1. Gemfile +1 −0
  2. Gemfile.lock +2 −0
  3. assets/javascripts/lib/page.coffee +1 −1
  4. assets/javascripts/templates/pages/root_tmpl.coffee.erb +0 −11
  5. assets/javascripts/views/content/root_page.coffee +0 −4
  6. lib/app.rb +2 −0
  7. test/app_test.rb +31 −21
Gemfile+1−0
@@ -11,6 +11,7 @@ group :app do · 10 unmodified lines
1111 gem 'rack'
1212 gem 'sinatra'
1313 gem 'sinatra-contrib'
14+ gem 'rack-ssl-enforcer'
1415 gem 'thin'
1516 gem 'sprockets'
1617 gem 'sprockets-helpers'
Gemfile.lock+2−0
@@ -63,6 +63,7 @@ GEM · 62 unmodified lines
6363 rack (2.0.5)
6464 rack-protection (2.0.4)
6565 rack
66+ rack-ssl-enforcer (0.2.9)
6667 rack-test (1.1.0)
6768 rack (>= 1.0, < 3)
6869 rake (12.3.1)
@@ -140,6 +141,7 @@ DEPENDENCIES · 71 unmodified lines
140141 progress_bar
141142 pry (~> 0.11.0)
142143 rack
144+ rack-ssl-enforcer
143145 rack-test
144146 rake
145147 rr
assets/javascripts/lib/page.coffee+1−1
@@ -190,7 +190,7 @@ isSameOrigin = (url) -> · 189 unmodified lines
190190
191191 updateCanonicalLink = ->
192192 @canonicalLink ||= document.head.querySelector('link[rel="canonical"]')
193− @canonicalLink.setAttribute('href', "http://#{location.host}#{location.pathname}")
193+ @canonicalLink.setAttribute('href', "https://#{location.host}#{location.pathname}")
194194
195195 trackers = []
196196
assets/javascripts/templates/pages/root_tmpl.coffee.erb+0−11
@@ -72,14 +72,3 @@ app.templates.androidWarning = """ · 71 unmodified lines
7272 <p>To install DevDocs on your phone, visit <a href="https://devdocs.io" target="_blank" rel="noopener">devdocs.io</a> in Chrome and select "Add to home screen" in the menu.
7373 </div>
7474 """
75−
76−app.templates.httpWarning = """
77− <div class="_intro"><div class="_intro-message">
78− <h2 class="_intro-title">Hi there!</h2>
79− <p>DevDocs is migrating to HTTPS.
80− <p>Please update your bookmarks to point to <a href="https://devdocs.io">https://devdocs.io</a>.
81− <p>When using the HTTPS version, your preferences will carry over automatically, but your offline data will be reset. Simply re-download documentation in the <a href="https://devdocs.io/offline">Offline area</a>, and you'll be all set to use DevDocs securely offline.
82− <p>Sorry for the inconvenience. This migration is needed because browsers are removing support for certain DOM APIs that power DevDocs's offline mode over non-secure origins.
83− <p>Thanks for using DevDocs, and happy coding!
84− </div></div>
85−"""
assets/javascripts/views/content/root_page.coffee+0−4
@@ -19,10 +19,6 @@ class app.views.RootPage extends app.View · 18 unmodified lines
1919 else
2020 'intro'
2121
22− # temporary
23− if location.host is 'devdocs.io' and location.protocol is 'http:'
24− tmpl = 'httpWarning'
25−
2622 @append @tmpl(tmpl)
2723 return
2824
lib/app.rb+2−0
@@ -12,6 +12,8 @@ class App < Sinatra::Application · 11 unmodified lines
1212 Rack::Mime::MIME_TYPES['.webapp'] = 'application/x-web-app-manifest+json'
1313
1414 configure do
15+ use Rack::SslEnforcer, only_environments: ['production', 'test'], hsts: false, force_secure_cookies: false
16+
1517 set :sentry_dsn, ENV['SENTRY_DSN']
1618 set :protection, except: [:frame_options, :xss_header]
1719
test/app_test.rb+31−21
@@ -11,6 +11,16 @@ class AppTest < MiniTest::Spec · 10 unmodified lines
1111 App
1212 end
1313
14+ before do
15+ current_session.env('HTTPS', 'on')
16+ end
17+
18+ it 'redirects to HTTPS' do
19+ get 'http://example.com/test?q=1', {}, 'HTTPS' => 'off'
20+ assert last_response.redirect?
21+ assert_equal 'https://example.com/test?q=1', last_response['Location']
22+ end
23+
1424 describe "/" do
1525 it "works" do
1626 get '/'
@@ -20,13 +30,13 @@ class AppTest < MiniTest::Spec · 3 unmodified lines
2030 it "redirects to /#q= when there is a 'q' query param" do
2131 get '/search', q: 'foo'
2232 assert last_response.redirect?
23− assert_equal 'http://example.org/#q=foo', last_response['Location']
33+ assert_equal 'https://example.org/#q=foo', last_response['Location']
2434 end
2535
2636 it "redirects without the query string" do
2737 get '/', foo: 'bar'
2838 assert last_response.redirect?
29− assert_equal 'http://example.org/', last_response['Location']
39+ assert_equal 'https://example.org/', last_response['Location']
3040 end
3141
3242 it "sets default size" do
@@ -52,7 +62,7 @@ class AppTest < MiniTest::Spec · 19 unmodified lines
5262 %w(offline about news help).each do |page|
5363 get "/#{page}", {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
5464 assert last_response.redirect?
55− assert_equal "http://example.org/#/#{page}", last_response['Location']
65+ assert_equal "https://example.org/#/#{page}", last_response['Location']
5666 end
5767 end
5868
@@ -61,7 +71,7 @@ class AppTest < MiniTest::Spec · 2 unmodified lines
6171 set_cookie('foo=bar')
6272 get "/#{page}", {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
6373 assert last_response.redirect?
64− assert_equal 'http://example.org/', last_response['Location']
74+ assert_equal 'https://example.org/', last_response['Location']
6575 assert last_response['Set-Cookie'].start_with?("initial_path=%2F#{page}; path=/; expires=")
6676 end
6777 end
@@ -71,11 +81,11 @@ class AppTest < MiniTest::Spec · 3 unmodified lines
7181 it "redirects to /#q=" do
7282 get '/search'
7383 assert last_response.redirect?
74− assert_equal 'http://example.org/#q=', last_response['Location']
84+ assert_equal 'https://example.org/#q=', last_response['Location']
7585
7686 get '/search', q: 'foo'
7787 assert last_response.redirect?
78− assert_equal 'http://example.org/#q=foo', last_response['Location']
88+ assert_equal 'https://example.org/#q=foo', last_response['Location']
7989 end
8090 end
8191
@@ -148,7 +158,7 @@ class AppTest < MiniTest::Spec · 66 unmodified lines
148158 set_cookie('docs=html~5')
149159 get '/html~5/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
150160 assert last_response.redirect?
151− assert_equal 'http://example.org/', last_response['Location']
161+ assert_equal 'https://example.org/', last_response['Location']
152162 assert last_response['Set-Cookie'].start_with?("initial_path=%2Fhtml%7E5%2F; path=/; expires=")
153163 end
154164
@@ -161,13 +171,13 @@ class AppTest < MiniTest::Spec · 6 unmodified lines
161171 set_cookie('docs=html~5')
162172 get '/html/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
163173 assert last_response.redirect?
164− assert_equal 'http://example.org/', last_response['Location']
174+ assert_equal 'https://example.org/', last_response['Location']
165175 assert last_response['Set-Cookie'].start_with?("initial_path=%2Fhtml%2F; path=/; expires=")
166176 end
167177
168178 it "renders when the doc exists and is enabled, and the request is from Googlebot" do
169179 set_cookie('docs=html')
170− get '/html/', {}, 'HTTP_USER_AGENT' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
180+ get '/html/', {}, 'HTTP_USER_AGENT' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +https://www.google.com/bot.html)'
171181 assert last_response.ok?
172182 end
173183
@@ -187,17 +197,17 @@ class AppTest < MiniTest::Spec · 13 unmodified lines
187197 it "redirects with trailing slash" do
188198 get '/html'
189199 assert last_response.redirect?
190− assert_equal 'http://example.org/html/', last_response['Location']
200+ assert_equal 'https://example.org/html/', last_response['Location']
191201
192202 get '/html', bar: 'baz'
193203 assert last_response.redirect?
194− assert_equal 'http://example.org/html/?bar=baz', last_response['Location']
204+ assert_equal 'https://example.org/html/?bar=baz', last_response['Location']
195205 end
196206
197207 it "redirects old docs" do
198208 get '/iojs/'
199209 assert last_response.redirect?
200− assert_equal 'http://example.org/node/', last_response['Location']
210+ assert_equal 'https://example.org/node/', last_response['Location']
201211 end
202212 end
203213
@@ -232,17 +242,17 @@ class AppTest < MiniTest::Spec · 28 unmodified lines
232242 it "redirects with trailing slash" do
233243 get '/css-foo'
234244 assert last_response.redirect?
235− assert_equal 'http://example.org/css-foo/', last_response['Location']
245+ assert_equal 'https://example.org/css-foo/', last_response['Location']
236246
237247 get '/css-foo', bar: 'baz'
238248 assert last_response.redirect?
239− assert_equal 'http://example.org/css-foo/?bar=baz', last_response['Location']
249+ assert_equal 'https://example.org/css-foo/?bar=baz', last_response['Location']
240250 end
241251
242252 it "redirects old docs" do
243253 get '/yii1-foo/'
244254 assert last_response.redirect?
245− assert_equal 'http://example.org/yii~1.1-foo/', last_response['Location']
255+ assert_equal 'https://example.org/yii~1.1-foo/', last_response['Location']
246256 end
247257 end
248258
@@ -263,17 +273,17 @@ class AppTest < MiniTest::Spec · 14 unmodified lines
263273 it "redirects without trailing slash" do
264274 get '/css/foo/'
265275 assert last_response.redirect?
266− assert_equal 'http://example.org/css/foo', last_response['Location']
276+ assert_equal 'https://example.org/css/foo', last_response['Location']
267277
268278 get '/css/foo/', bar: 'baz'
269279 assert last_response.redirect?
270− assert_equal 'http://example.org/css/foo?bar=baz', last_response['Location']
280+ assert_equal 'https://example.org/css/foo?bar=baz', last_response['Location']
271281 end
272282
273283 it "redirects old docs" do
274284 get '/python2/foo'
275285 assert last_response.redirect?
276− assert_equal 'http://example.org/python~2.7/foo', last_response['Location']
286+ assert_equal 'https://example.org/python~2.7/foo', last_response['Location']
277287 end
278288 end
279289
@@ -281,7 +291,7 @@ class AppTest < MiniTest::Spec · 1 unmodified line
281291 it "returns to the asset path" do
282292 get '/docs.json'
283293 assert last_response.redirect?
284− assert_equal 'http://example.org/assets/docs.json', last_response['Location']
294+ assert_equal 'https://example.org/assets/docs.json', last_response['Location']
285295 end
286296 end
287297
@@ -289,7 +299,7 @@ class AppTest < MiniTest::Spec · 1 unmodified line
289299 it "returns to the asset path" do
290300 get '/application.js'
291301 assert last_response.redirect?
292− assert_equal 'http://example.org/assets/application.js', last_response['Location']
302+ assert_equal 'https://example.org/assets/application.js', last_response['Location']
293303 end
294304 end
295305
@@ -297,7 +307,7 @@ class AppTest < MiniTest::Spec · 1 unmodified line
297307 it "returns to the asset path" do
298308 get '/application.css'
299309 assert last_response.redirect?
300− assert_equal 'http://example.org/assets/application.css', last_response['Location']
310+ assert_equal 'https://example.org/assets/application.css', last_response['Location']
301311 end
302312 end
303313

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t