Skip to content

Commit

Permalink
Enforce SSL in production environment
Browse files Browse the repository at this point in the history
This setting has been on for every thoughtbot Rails app I've touched
in the past year or two (maybe a dozen?).

* Use `configure_environment` helper method more consistently.
* Fixes #781

More about the pervasiveness of SSL in our ecosystem:

https://blog.heroku.com/announcing_heroku_free_ssl_beta_and_flexible_dyno_hours
https://letsencrypt.org/
  • Loading branch information
croaky committed Aug 1, 2017
1 parent c2f02ae commit 141a965
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/suspenders.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'suspenders/version'
require 'suspenders/generators/app_generator'
require "suspenders/generators/enforce_ssl_generator"
require 'suspenders/generators/static_generator'
require 'suspenders/generators/stylesheet_base_generator'
require 'suspenders/actions'
Expand Down
2 changes: 1 addition & 1 deletion lib/suspenders/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def configure_application_file(config)
def configure_environment(rails_env, config)
inject_into_file(
"config/environments/#{rails_env}.rb",
"\n\n #{config}",
"\n #{config}",
before: "\nend"
)
end
Expand Down
6 changes: 1 addition & 5 deletions lib/suspenders/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,7 @@ def enable_rack_canonical_host
config.middleware.use Rack::CanonicalHost, ENV.fetch("APPLICATION_HOST")
RUBY

inject_into_file(
"config/environments/production.rb",
config,
after: "Rails.application.configure do",
)
configure_environment "production", config
end

def enable_rack_deflater
Expand Down
1 change: 1 addition & 0 deletions lib/suspenders/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def remove_routes_comment_lines

def generate_default
run("spring stop")
generate("suspenders:enforce_ssl")
generate("suspenders:static")
generate("suspenders:stylesheet_base")
end
Expand Down
12 changes: 12 additions & 0 deletions lib/suspenders/generators/enforce_ssl_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require "rails/generators"
require_relative "../actions"

module Suspenders
class EnforceSslGenerator < Rails::Generators::Base
include Suspenders::Actions

def enforce_ssl
configure_environment "production", "config.force_ssl = true"
end
end
end
6 changes: 6 additions & 0 deletions spec/features/new_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@
)
end

it "configures production environment to enforce SSL" do
expect(production_config).to match(
/^ +config.force_ssl = true/,
)
end

it "raises on missing translations in development and test" do
[development_config, test_config].each do |environment_file|
expect(environment_file).to match(
Expand Down

0 comments on commit 141a965

Please sign in to comment.