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
11 gem 'rack'11 gem 'rack'
12 gem 'sinatra'12 gem 'sinatra'
13 gem 'sinatra-contrib'13 gem 'sinatra-contrib'
14 gem 'rack-ssl-enforcer'
14 gem 'thin'15 gem 'thin'
15 gem 'sprockets'16 gem 'sprockets'
16 gem 'sprockets-helpers'17 gem 'sprockets-helpers'
Gemfile.lock+2−0
@@ -63,6 +63,7 @@ GEM · 62 unmodified lines
63 rack (2.0.5)63 rack (2.0.5)
64 rack-protection (2.0.4)64 rack-protection (2.0.4)
65 rack65 rack
66 rack-ssl-enforcer (0.2.9)
66 rack-test (1.1.0)67 rack-test (1.1.0)
67 rack (>= 1.0, < 3)68 rack (>= 1.0, < 3)
68 rake (12.3.1)69 rake (12.3.1)
@@ -140,6 +141,7 @@ DEPENDENCIES · 71 unmodified lines
140 progress_bar141 progress_bar
141 pry (~> 0.11.0)142 pry (~> 0.11.0)
142 rack143 rack
144 rack-ssl-enforcer
143 rack-test145 rack-test
144 rake146 rake
145 rr147 rr
assets/javascripts/lib/page.coffee+1−1
@@ -190,7 +190,7 @@ isSameOrigin = (url) -> · 189 unmodified lines
190 190
191updateCanonicalLink = ->191updateCanonicalLink = ->
192 @canonicalLink ||= document.head.querySelector('link[rel="canonical"]')192 @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}")
194 194
195trackers = []195trackers = []
196 196
assets/javascripts/templates/pages/root_tmpl.coffee.erb+0−11
@@ -72,14 +72,3 @@ app.templates.androidWarning = """ · 71 unmodified lines
72 <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.72 <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.
73 </div>73 </div>
74"""74"""
75
76app.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
19 else19 else
20 'intro'20 'intro'
21 21
22 # temporary
23 if location.host is 'devdocs.io' and location.protocol is 'http:'
24 tmpl = 'httpWarning'
25
26 @append @tmpl(tmpl)22 @append @tmpl(tmpl)
27 return23 return
28 24
lib/app.rb+2−0
@@ -12,6 +12,8 @@ class App < Sinatra::Application · 11 unmodified lines
12 Rack::Mime::MIME_TYPES['.webapp'] = 'application/x-web-app-manifest+json'12 Rack::Mime::MIME_TYPES['.webapp'] = 'application/x-web-app-manifest+json'
13 13
14 configure do14 configure do
15 use Rack::SslEnforcer, only_environments: ['production', 'test'], hsts: false, force_secure_cookies: false
16
15 set :sentry_dsn, ENV['SENTRY_DSN']17 set :sentry_dsn, ENV['SENTRY_DSN']
16 set :protection, except: [:frame_options, :xss_header]18 set :protection, except: [:frame_options, :xss_header]
17 19
test/app_test.rb+31−21
@@ -11,6 +11,16 @@ class AppTest < MiniTest::Spec · 10 unmodified lines
11 App11 App
12 end12 end
13 13
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
14 describe "/" do24 describe "/" do
15 it "works" do25 it "works" do
16 get '/'26 get '/'
@@ -20,13 +30,13 @@ class AppTest < MiniTest::Spec · 3 unmodified lines
20 it "redirects to /#q= when there is a 'q' query param" do30 it "redirects to /#q= when there is a 'q' query param" do
21 get '/search', q: 'foo'31 get '/search', q: 'foo'
22 assert last_response.redirect?32 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']
24 end34 end
25 35
26 it "redirects without the query string" do36 it "redirects without the query string" do
27 get '/', foo: 'bar'37 get '/', foo: 'bar'
28 assert last_response.redirect?38 assert last_response.redirect?
29 assert_equal 'http://example.org/', last_response['Location']39 assert_equal 'https://example.org/', last_response['Location']
30 end40 end
31 41
32 it "sets default size" do42 it "sets default size" do
@@ -52,7 +62,7 @@ class AppTest < MiniTest::Spec · 19 unmodified lines
52 %w(offline about news help).each do |page|62 %w(offline about news help).each do |page|
53 get "/#{page}", {}, 'HTTP_USER_AGENT' => MODERN_BROWSER63 get "/#{page}", {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
54 assert last_response.redirect?64 assert last_response.redirect?
55 assert_equal "http://example.org/#/#{page}", last_response['Location']65 assert_equal "https://example.org/#/#{page}", last_response['Location']
56 end66 end
57 end67 end
58 68
@@ -61,7 +71,7 @@ class AppTest < MiniTest::Spec · 2 unmodified lines
61 set_cookie('foo=bar')71 set_cookie('foo=bar')
62 get "/#{page}", {}, 'HTTP_USER_AGENT' => MODERN_BROWSER72 get "/#{page}", {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
63 assert last_response.redirect?73 assert last_response.redirect?
64 assert_equal 'http://example.org/', last_response['Location']74 assert_equal 'https://example.org/', last_response['Location']
65 assert last_response['Set-Cookie'].start_with?("initial_path=%2F#{page}; path=/; expires=")75 assert last_response['Set-Cookie'].start_with?("initial_path=%2F#{page}; path=/; expires=")
66 end76 end
67 end77 end
@@ -71,11 +81,11 @@ class AppTest < MiniTest::Spec · 3 unmodified lines
71 it "redirects to /#q=" do81 it "redirects to /#q=" do
72 get '/search'82 get '/search'
73 assert last_response.redirect?83 assert last_response.redirect?
74 assert_equal 'http://example.org/#q=', last_response['Location']84 assert_equal 'https://example.org/#q=', last_response['Location']
75 85
76 get '/search', q: 'foo'86 get '/search', q: 'foo'
77 assert last_response.redirect?87 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']
79 end89 end
80 end90 end
81 91
@@ -148,7 +158,7 @@ class AppTest < MiniTest::Spec · 66 unmodified lines
148 set_cookie('docs=html~5')158 set_cookie('docs=html~5')
149 get '/html~5/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER159 get '/html~5/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
150 assert last_response.redirect?160 assert last_response.redirect?
151 assert_equal 'http://example.org/', last_response['Location']161 assert_equal 'https://example.org/', last_response['Location']
152 assert last_response['Set-Cookie'].start_with?("initial_path=%2Fhtml%7E5%2F; path=/; expires=")162 assert last_response['Set-Cookie'].start_with?("initial_path=%2Fhtml%7E5%2F; path=/; expires=")
153 end163 end
154 164
@@ -161,13 +171,13 @@ class AppTest < MiniTest::Spec · 6 unmodified lines
161 set_cookie('docs=html~5')171 set_cookie('docs=html~5')
162 get '/html/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER172 get '/html/', {}, 'HTTP_USER_AGENT' => MODERN_BROWSER
163 assert last_response.redirect?173 assert last_response.redirect?
164 assert_equal 'http://example.org/', last_response['Location']174 assert_equal 'https://example.org/', last_response['Location']
165 assert last_response['Set-Cookie'].start_with?("initial_path=%2Fhtml%2F; path=/; expires=")175 assert last_response['Set-Cookie'].start_with?("initial_path=%2Fhtml%2F; path=/; expires=")
166 end176 end
167 177
168 it "renders when the doc exists and is enabled, and the request is from Googlebot" do178 it "renders when the doc exists and is enabled, and the request is from Googlebot" do
169 set_cookie('docs=html')179 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)'
171 assert last_response.ok?181 assert last_response.ok?
172 end182 end
173 183
@@ -187,17 +197,17 @@ class AppTest < MiniTest::Spec · 13 unmodified lines
187 it "redirects with trailing slash" do197 it "redirects with trailing slash" do
188 get '/html'198 get '/html'
189 assert last_response.redirect?199 assert last_response.redirect?
190 assert_equal 'http://example.org/html/', last_response['Location']200 assert_equal 'https://example.org/html/', last_response['Location']
191 201
192 get '/html', bar: 'baz'202 get '/html', bar: 'baz'
193 assert last_response.redirect?203 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']
195 end205 end
196 206
197 it "redirects old docs" do207 it "redirects old docs" do
198 get '/iojs/'208 get '/iojs/'
199 assert last_response.redirect?209 assert last_response.redirect?
200 assert_equal 'http://example.org/node/', last_response['Location']210 assert_equal 'https://example.org/node/', last_response['Location']
201 end211 end
202 end212 end
203 213
@@ -232,17 +242,17 @@ class AppTest < MiniTest::Spec · 28 unmodified lines
232 it "redirects with trailing slash" do242 it "redirects with trailing slash" do
233 get '/css-foo'243 get '/css-foo'
234 assert last_response.redirect?244 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']
236 246
237 get '/css-foo', bar: 'baz'247 get '/css-foo', bar: 'baz'
238 assert last_response.redirect?248 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']
240 end250 end
241 251
242 it "redirects old docs" do252 it "redirects old docs" do
243 get '/yii1-foo/'253 get '/yii1-foo/'
244 assert last_response.redirect?254 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']
246 end256 end
247 end257 end
248 258
@@ -263,17 +273,17 @@ class AppTest < MiniTest::Spec · 14 unmodified lines
263 it "redirects without trailing slash" do273 it "redirects without trailing slash" do
264 get '/css/foo/'274 get '/css/foo/'
265 assert last_response.redirect?275 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']
267 277
268 get '/css/foo/', bar: 'baz'278 get '/css/foo/', bar: 'baz'
269 assert last_response.redirect?279 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']
271 end281 end
272 282
273 it "redirects old docs" do283 it "redirects old docs" do
274 get '/python2/foo'284 get '/python2/foo'
275 assert last_response.redirect?285 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']
277 end287 end
278 end288 end
279 289
@@ -281,7 +291,7 @@ class AppTest < MiniTest::Spec · 1 unmodified line
281 it "returns to the asset path" do291 it "returns to the asset path" do
282 get '/docs.json'292 get '/docs.json'
283 assert last_response.redirect?293 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']
285 end295 end
286 end296 end
287 297
@@ -289,7 +299,7 @@ class AppTest < MiniTest::Spec · 1 unmodified line
289 it "returns to the asset path" do299 it "returns to the asset path" do
290 get '/application.js'300 get '/application.js'
291 assert last_response.redirect?301 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']
293 end303 end
294 end304 end
295 305
@@ -297,7 +307,7 @@ class AppTest < MiniTest::Spec · 1 unmodified line
297 it "returns to the asset path" do307 it "returns to the asset path" do
298 get '/application.css'308 get '/application.css'
299 assert last_response.redirect?309 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']
301 end311 end
302 end312 end
303 313

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