secure_routes 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails"
4
+
5
+ group :development, :test do
6
+ gem "sqlite3-ruby", :require => "sqlite3"
7
+
8
+ gem "rspec-rails"
9
+ gem "jeweler"
10
+ gem "mongrel"
11
+ end
@@ -0,0 +1,106 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.4)
6
+ actionpack (= 3.0.4)
7
+ mail (~> 2.2.15)
8
+ actionpack (3.0.4)
9
+ activemodel (= 3.0.4)
10
+ activesupport (= 3.0.4)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.4)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.13)
16
+ rack-test (~> 0.5.7)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.4)
19
+ activesupport (= 3.0.4)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4)
22
+ activerecord (3.0.4)
23
+ activemodel (= 3.0.4)
24
+ activesupport (= 3.0.4)
25
+ arel (~> 2.0.2)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.4)
28
+ activemodel (= 3.0.4)
29
+ activesupport (= 3.0.4)
30
+ activesupport (3.0.4)
31
+ arel (2.0.8)
32
+ builder (2.1.2)
33
+ cgi_multipart_eof_fix (2.5.0)
34
+ daemons (1.1.0)
35
+ diff-lcs (1.1.2)
36
+ erubis (2.6.6)
37
+ abstract (>= 1.0.0)
38
+ fastthread (1.0.7)
39
+ gem_plugin (0.2.3)
40
+ git (1.2.5)
41
+ i18n (0.5.0)
42
+ jeweler (1.5.2)
43
+ bundler (~> 1.0.0)
44
+ git (>= 1.2.5)
45
+ rake
46
+ mail (2.2.15)
47
+ activesupport (>= 2.3.6)
48
+ i18n (>= 0.4.0)
49
+ mime-types (~> 1.16)
50
+ treetop (~> 1.4.8)
51
+ mime-types (1.16)
52
+ mongrel (1.1.5)
53
+ cgi_multipart_eof_fix (>= 2.4)
54
+ daemons (>= 1.0.3)
55
+ fastthread (>= 1.0.1)
56
+ gem_plugin (>= 0.2.3)
57
+ polyglot (0.3.1)
58
+ rack (1.2.1)
59
+ rack-mount (0.6.13)
60
+ rack (>= 1.0.0)
61
+ rack-test (0.5.7)
62
+ rack (>= 1.0)
63
+ rails (3.0.4)
64
+ actionmailer (= 3.0.4)
65
+ actionpack (= 3.0.4)
66
+ activerecord (= 3.0.4)
67
+ activeresource (= 3.0.4)
68
+ activesupport (= 3.0.4)
69
+ bundler (~> 1.0)
70
+ railties (= 3.0.4)
71
+ railties (3.0.4)
72
+ actionpack (= 3.0.4)
73
+ activesupport (= 3.0.4)
74
+ rake (>= 0.8.7)
75
+ thor (~> 0.14.4)
76
+ rake (0.8.7)
77
+ rspec (2.5.0)
78
+ rspec-core (~> 2.5.0)
79
+ rspec-expectations (~> 2.5.0)
80
+ rspec-mocks (~> 2.5.0)
81
+ rspec-core (2.5.1)
82
+ rspec-expectations (2.5.0)
83
+ diff-lcs (~> 1.1.2)
84
+ rspec-mocks (2.5.0)
85
+ rspec-rails (2.5.0)
86
+ actionpack (~> 3.0)
87
+ activesupport (~> 3.0)
88
+ railties (~> 3.0)
89
+ rspec (~> 2.5.0)
90
+ sqlite3 (1.3.3)
91
+ sqlite3-ruby (1.3.3)
92
+ sqlite3 (>= 1.3.3)
93
+ thor (0.14.6)
94
+ treetop (1.4.9)
95
+ polyglot (>= 0.3.1)
96
+ tzinfo (0.3.24)
97
+
98
+ PLATFORMS
99
+ ruby
100
+
101
+ DEPENDENCIES
102
+ jeweler
103
+ mongrel
104
+ rails
105
+ rspec-rails
106
+ sqlite3-ruby
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ = SecureRoutes
2
+
3
+ == Warning! Proof of concept.
4
+
5
+ Secure routes is routing-level support for ssl in your rails 3 application.
6
+
7
+ == Installation
8
+
9
+ To install simply add this to your Gemfile:
10
+ gem 'secure_routes'
11
+
12
+ Then you need to enable secure routing in your environment config:
13
+ config.action_dispatch.secure_routes = true
14
+
15
+ == Usage
16
+
17
+ If you want your action to force https protocol, add this to routes:
18
+ match 'login' => 'sessions#new', :secure => true
19
+
20
+ Or
21
+ scope :secure => true do
22
+ match 'login' => 'sessions#new'
23
+ end
24
+
25
+ And if you'll try to access http://host.com/login then you'll be redirected to https://host.com/login
26
+
27
+ To force http protocol, just set <tt>:secure => false</tt>. Redirection rules works here too.
28
+ If protocol is unnesesary - don't set <tt>:secure</tt> option.
29
+
30
+ You can setup secure actions usage with:
31
+ config.action_dispatch.secure_routes = true
32
+
33
+ in your environment. It is <tt>false</tt> by default. So you can use securing for production only.
34
+
35
+ To spec it just clone repo, then:
36
+ bundle && rake spec
@@ -0,0 +1,37 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/rdoctask'
11
+
12
+ require 'rspec/core'
13
+ require 'rspec/core/rake_task'
14
+
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+ task :default => :spec
18
+
19
+ Rake::RDocTask.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'SecureRoutes'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README.rdoc')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
26
+
27
+ require 'jeweler'
28
+
29
+ Jeweler::Tasks.new do |gem|
30
+ gem.name = "secure_routes"
31
+ gem.summary = %Q{Rails ssl requirements}
32
+ gem.description = %Q{Routing-level ssl support for ruby application actions}
33
+ gem.email = "kinwizard@gmail.com"
34
+ gem.homepage = "http://github.com/pyromaniac/secure_routes"
35
+ gem.authors = ["pyromaniac"]
36
+ end
37
+ Jeweler::GemcutterTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,7 @@
1
+ module SecureRoutes
2
+ end
3
+
4
+ require 'secure_routes/options'
5
+ require 'secure_routes/mapper'
6
+ require 'secure_routes/route_set'
7
+
@@ -0,0 +1,32 @@
1
+ module SecureRoutes
2
+ module Mapper
3
+
4
+ def self.included base
5
+ base.class_eval do
6
+ alias_method_chain :match, :secure
7
+ end
8
+ end
9
+
10
+ def match_with_secure path, options
11
+ if Rails.application.config.action_dispatch.secure_routes
12
+ options_ssl = options[:secure]
13
+ options_without_ssl = options.dup
14
+ options_without_ssl.delete(:as)
15
+
16
+ ssl = @scope[:secure] === true || options_ssl === true
17
+ no_ssl = @scope[:secure] === false || options_ssl === false
18
+ options.deep_merge! :constraints => { :protocol => 'https://' } if ssl
19
+ options.deep_merge! :constraints => { :protocol => 'http://' } if no_ssl
20
+
21
+ match_without_secure path, options
22
+
23
+ match_without_secure path, options_without_ssl.merge(:to => redirect {|p, req| req.url.gsub(/^http/, 'https') }) if ssl
24
+ match_without_secure path, options_without_ssl.merge(:to => redirect {|p, req| req.url.gsub(/^https/, 'http') }) if no_ssl
25
+ else
26
+ match_without_secure path, options
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ ActionDispatch::Routing::Mapper::Base.send :include, SecureRoutes::Mapper
@@ -0,0 +1,13 @@
1
+ module SecureRoutes
2
+ module Options
3
+
4
+ def self.included base
5
+ base.class_eval do
6
+ config.action_dispatch.secure_routes = false
7
+ end
8
+ end
9
+
10
+ end
11
+ end
12
+
13
+ ActionDispatch::Railtie.send :include, SecureRoutes::Options
@@ -0,0 +1,22 @@
1
+ module SecureRoutes
2
+ module RouteSet
3
+
4
+ def self.included base
5
+ base.class_eval do
6
+ alias_method_chain :url_for, :secure
7
+ end
8
+ end
9
+
10
+ def url_for_with_secure options
11
+ if Rails.application.config.action_dispatch.secure_routes
12
+ options[:only_path] = false if (options[:secure] === true && options[:protocol] == 'http://') || (options[:secure] === false && options[:protocol] == 'https://')
13
+ options[:protocol] = 'http://' if options[:secure] === false
14
+ options[:protocol] = 'https://' if options[:secure] === true
15
+ end
16
+ url_for_without_secure options
17
+ end
18
+
19
+ end
20
+ end
21
+
22
+ ActionDispatch::Routing::RouteSet.send :include, SecureRoutes::RouteSet
@@ -0,0 +1,101 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{secure_routes}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["pyromaniac"]
12
+ s.date = %q{2011-02-10}
13
+ s.description = %q{Routing-level ssl support for ruby application actions}
14
+ s.email = %q{kinwizard@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".rspec",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "MIT-LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/secure_routes.rb",
27
+ "lib/secure_routes/mapper.rb",
28
+ "lib/secure_routes/options.rb",
29
+ "lib/secure_routes/route_set.rb",
30
+ "secure_routes.gemspec",
31
+ "spec/dummy/Rakefile",
32
+ "spec/dummy/app/controllers/application_controller.rb",
33
+ "spec/dummy/app/controllers/ssl_controller.rb",
34
+ "spec/dummy/app/views/layouts/application.html.erb",
35
+ "spec/dummy/app/views/ssl/action.html.erb",
36
+ "spec/dummy/config.ru",
37
+ "spec/dummy/config/application.rb",
38
+ "spec/dummy/config/boot.rb",
39
+ "spec/dummy/config/database.yml",
40
+ "spec/dummy/config/environment.rb",
41
+ "spec/dummy/config/environments/development.rb",
42
+ "spec/dummy/config/environments/production.rb",
43
+ "spec/dummy/config/environments/test.rb",
44
+ "spec/dummy/config/initializers/backtrace_silencers.rb",
45
+ "spec/dummy/config/initializers/inflections.rb",
46
+ "spec/dummy/config/initializers/mime_types.rb",
47
+ "spec/dummy/config/initializers/secret_token.rb",
48
+ "spec/dummy/config/initializers/session_store.rb",
49
+ "spec/dummy/config/routes.rb",
50
+ "spec/dummy/script/rails",
51
+ "spec/secure_routes_spec.rb",
52
+ "spec/spec_helper.rb"
53
+ ]
54
+ s.homepage = %q{http://github.com/pyromaniac/secure_routes}
55
+ s.require_paths = ["lib"]
56
+ s.rubygems_version = %q{1.4.2}
57
+ s.summary = %q{Rails ssl requirements}
58
+ s.test_files = [
59
+ "spec/dummy/app/controllers/application_controller.rb",
60
+ "spec/dummy/app/controllers/ssl_controller.rb",
61
+ "spec/dummy/config/application.rb",
62
+ "spec/dummy/config/boot.rb",
63
+ "spec/dummy/config/environment.rb",
64
+ "spec/dummy/config/environments/development.rb",
65
+ "spec/dummy/config/environments/production.rb",
66
+ "spec/dummy/config/environments/test.rb",
67
+ "spec/dummy/config/initializers/backtrace_silencers.rb",
68
+ "spec/dummy/config/initializers/inflections.rb",
69
+ "spec/dummy/config/initializers/mime_types.rb",
70
+ "spec/dummy/config/initializers/secret_token.rb",
71
+ "spec/dummy/config/initializers/session_store.rb",
72
+ "spec/dummy/config/routes.rb",
73
+ "spec/secure_routes_spec.rb",
74
+ "spec/spec_helper.rb"
75
+ ]
76
+
77
+ if s.respond_to? :specification_version then
78
+ s.specification_version = 3
79
+
80
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
81
+ s.add_runtime_dependency(%q<rails>, [">= 0"])
82
+ s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
83
+ s.add_development_dependency(%q<rspec-rails>, [">= 0"])
84
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
85
+ s.add_development_dependency(%q<mongrel>, [">= 0"])
86
+ else
87
+ s.add_dependency(%q<rails>, [">= 0"])
88
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
89
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
90
+ s.add_dependency(%q<jeweler>, [">= 0"])
91
+ s.add_dependency(%q<mongrel>, [">= 0"])
92
+ end
93
+ else
94
+ s.add_dependency(%q<rails>, [">= 0"])
95
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
96
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
97
+ s.add_dependency(%q<jeweler>, [">= 0"])
98
+ s.add_dependency(%q<mongrel>, [">= 0"])
99
+ end
100
+ end
101
+
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,15 @@
1
+ class SslController < ApplicationController
2
+
3
+ def ssl_action
4
+ render 'action'
5
+ end
6
+
7
+ def action
8
+ render 'action'
9
+ end
10
+
11
+ def no_ssl_action
12
+ render 'action'
13
+ end
14
+
15
+ end
@@ -0,0 +1,6 @@
1
+ <%= ssl_action_path %>
2
+ <%= action_path %>
3
+ <%= no_ssl_action_path %>
4
+ <%= ssl_action_url %>
5
+ <%= action_url %>
6
+ <%= no_ssl_action_url %>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "active_model/railtie"
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_view/railtie"
7
+ require "action_mailer/railtie"
8
+
9
+ Bundler.require
10
+ require "secure_routes"
11
+
12
+ module Dummy
13
+ class Application < Rails::Application
14
+ # Settings in config/environments/* take precedence over those specified here.
15
+ # Application configuration should go into files in config/initializers
16
+ # -- all .rb files in that directory are automatically loaded.
17
+
18
+ # Custom directories with classes and modules you want to be autoloadable.
19
+ # config.autoload_paths += %W(#{config.root}/extras)
20
+
21
+ # Only load the plugins named here, in the order given (default is alphabetical).
22
+ # :all can be used as a placeholder for all plugins not explicitly named.
23
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
24
+
25
+ # Activate observers that should always be running.
26
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
27
+
28
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
29
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
30
+ # config.time_zone = 'Central Time (US & Canada)'
31
+
32
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
33
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
34
+ # config.i18n.default_locale = :de
35
+
36
+ # JavaScript files you want as :defaults (application.js is always included).
37
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
38
+
39
+ # Configure the default encoding used in templates for Ruby 1.9.
40
+ config.encoding = "utf-8"
41
+
42
+ # Configure sensitive parameters which will be filtered from the log file.
43
+ config.filter_parameters += [:password]
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,22 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ # Warning: The database defined as "test" will be erased and
10
+ # re-generated from your development database when you run "rake".
11
+ # Do not set this db to the same as development or production.
12
+ test:
13
+ adapter: sqlite3
14
+ database: db/test.sqlite3
15
+ pool: 5
16
+ timeout: 5000
17
+
18
+ production:
19
+ adapter: sqlite3
20
+ database: db/production.sqlite3
21
+ pool: 5
22
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,26 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the webserver when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_view.debug_rjs = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Don't care if the mailer can't send
18
+ config.action_mailer.raise_delivery_errors = false
19
+
20
+ # Print deprecation notices to the Rails logger
21
+ config.active_support.deprecation = :log
22
+
23
+ # Only use best-standards-support built into browsers
24
+ config.action_dispatch.best_standards_support = :builtin
25
+ end
26
+
@@ -0,0 +1,49 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The production environment is meant for finished, "live" apps.
5
+ # Code is not reloaded between requests
6
+ config.cache_classes = true
7
+
8
+ # Full error reports are disabled and caching is turned on
9
+ config.consider_all_requests_local = false
10
+ config.action_controller.perform_caching = true
11
+
12
+ # Specifies the header that your server uses for sending files
13
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
+
15
+ # For nginx:
16
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17
+
18
+ # If you have no front-end server that supports something like X-Sendfile,
19
+ # just comment this out and Rails will serve the files
20
+
21
+ # See everything in the log (default is :info)
22
+ # config.log_level = :debug
23
+
24
+ # Use a different logger for distributed setups
25
+ # config.logger = SyslogLogger.new
26
+
27
+ # Use a different cache store in production
28
+ # config.cache_store = :mem_cache_store
29
+
30
+ # Disable Rails's static asset server
31
+ # In production, Apache or nginx will already do this
32
+ config.serve_static_assets = false
33
+
34
+ # Enable serving of images, stylesheets, and javascripts from an asset server
35
+ # config.action_controller.asset_host = "http://assets.example.com"
36
+
37
+ # Disable delivery errors, bad email addresses will be ignored
38
+ # config.action_mailer.raise_delivery_errors = false
39
+
40
+ # Enable threaded mode
41
+ # config.threadsafe!
42
+
43
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
+ # the I18n.default_locale when a translation can not be found)
45
+ config.i18n.fallbacks = true
46
+
47
+ # Send deprecation notices to registered listeners
48
+ config.active_support.deprecation = :notify
49
+ end
@@ -0,0 +1,36 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Log error messages when you accidentally call methods on nil.
11
+ config.whiny_nils = true
12
+
13
+ # Show full error reports and disable caching
14
+ config.consider_all_requests_local = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Raise exceptions instead of rendering exception templates
18
+ config.action_dispatch.show_exceptions = false
19
+
20
+ config.action_dispatch.secure_routes = true
21
+ # Disable request forgery protection in test environment
22
+ config.action_controller.allow_forgery_protection = false
23
+
24
+ # Tell Action Mailer not to deliver emails to the real world.
25
+ # The :test delivery method accumulates sent emails in the
26
+ # ActionMailer::Base.deliveries array.
27
+ config.action_mailer.delivery_method = :test
28
+
29
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
30
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
31
+ # like if you have constraints or database-specific column types
32
+ # config.active_record.schema_format = :sql
33
+
34
+ # Print deprecation notices to the stderr
35
+ config.active_support.deprecation = :stderr
36
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = '5bf98aacce9285353bad569fbc9e2b7b39be543052b945523538cd77371fe190051e3706e43589d2db8faa9e47c353afc57bb9bb087dcc3a769035b582a695f4'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,5 @@
1
+ Dummy::Application.routes.draw do
2
+ match 'ssl_action' => 'ssl#ssl_action', :secure => true
3
+ match 'action' => 'ssl#action'
4
+ match 'no_ssl_action' => 'ssl#no_ssl_action', :secure => false
5
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe SecureRoutes do
4
+
5
+ include RSpec::Rails::RequestExampleGroup
6
+
7
+ describe 'require ssl route' do
8
+
9
+ it 'should redirect http request' do
10
+ get 'http://localhost/ssl_action'
11
+ response.should be_redirect
12
+ end
13
+
14
+ it 'should handle https request' do
15
+ get 'https://localhost/ssl_action'
16
+ response.should be_success
17
+ response.body.should == <<-BODY
18
+ /ssl_action
19
+ /action
20
+ http://localhost/no_ssl_action
21
+ https://localhost/ssl_action
22
+ https://localhost/action
23
+ http://localhost/no_ssl_action
24
+
25
+ BODY
26
+ end
27
+
28
+ end
29
+
30
+ describe 'allow ssl route' do
31
+
32
+ it 'should handle https request' do
33
+ get 'https://localhost/action'
34
+ response.should be_success
35
+ response.body.should == <<-BODY
36
+ /ssl_action
37
+ /action
38
+ http://localhost/no_ssl_action
39
+ https://localhost/ssl_action
40
+ https://localhost/action
41
+ http://localhost/no_ssl_action
42
+
43
+ BODY
44
+ end
45
+
46
+ it 'should handle http request' do
47
+ get 'http://localhost/action'
48
+ response.should be_success
49
+ response.body.should == <<-BODY
50
+ https://localhost/ssl_action
51
+ /action
52
+ /no_ssl_action
53
+ https://localhost/ssl_action
54
+ http://localhost/action
55
+ http://localhost/no_ssl_action
56
+
57
+ BODY
58
+ end
59
+
60
+ end
61
+
62
+ describe 'require no ssl route' do
63
+
64
+ it 'should handle http request' do
65
+ get 'http://localhost/no_ssl_action'
66
+ response.should be_success
67
+ response.body.should == <<-BODY
68
+ https://localhost/ssl_action
69
+ /action
70
+ /no_ssl_action
71
+ https://localhost/ssl_action
72
+ http://localhost/action
73
+ http://localhost/no_ssl_action
74
+
75
+ BODY
76
+ end
77
+
78
+ it 'should redirect https request' do
79
+ get 'https://localhost/no_ssl_action'
80
+ response.should be_redirect
81
+ end
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,33 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+ require "rspec/rails"
7
+
8
+ ActionMailer::Base.delivery_method = :test
9
+ ActionMailer::Base.perform_deliveries = true
10
+ ActionMailer::Base.default_url_options[:host] = "test.com"
11
+
12
+ Rails.backtrace_cleaner.remove_silencers!
13
+
14
+ # Configure capybara for integration testing
15
+ #require "capybara/rails"
16
+ #Capybara.default_driver = :rack_test
17
+ #Capybara.default_selector = :css
18
+
19
+ # Run any available migration
20
+ #ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
21
+
22
+ # Load support files
23
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
24
+
25
+ RSpec.configure do |config|
26
+ # Remove this line if you don't want RSpec's should and should_not
27
+ # methods or matchers
28
+ require 'rspec/expectations'
29
+ config.include RSpec::Matchers
30
+
31
+ # == Mock Framework
32
+ config.mock_with :rspec
33
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: secure_routes
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - pyromaniac
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-10 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ requirement: *id001
33
+ prerelease: false
34
+ name: rails
35
+ - !ruby/object:Gem::Dependency
36
+ type: :development
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ requirement: *id002
47
+ prerelease: false
48
+ name: sqlite3-ruby
49
+ - !ruby/object:Gem::Dependency
50
+ type: :development
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirement: *id003
61
+ prerelease: false
62
+ name: rspec-rails
63
+ - !ruby/object:Gem::Dependency
64
+ type: :development
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ requirement: *id004
75
+ prerelease: false
76
+ name: jeweler
77
+ - !ruby/object:Gem::Dependency
78
+ type: :development
79
+ version_requirements: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirement: *id005
89
+ prerelease: false
90
+ name: mongrel
91
+ description: Routing-level ssl support for ruby application actions
92
+ email: kinwizard@gmail.com
93
+ executables: []
94
+
95
+ extensions: []
96
+
97
+ extra_rdoc_files:
98
+ - README.rdoc
99
+ files:
100
+ - .rspec
101
+ - Gemfile
102
+ - Gemfile.lock
103
+ - MIT-LICENSE
104
+ - README.rdoc
105
+ - Rakefile
106
+ - VERSION
107
+ - lib/secure_routes.rb
108
+ - lib/secure_routes/mapper.rb
109
+ - lib/secure_routes/options.rb
110
+ - lib/secure_routes/route_set.rb
111
+ - secure_routes.gemspec
112
+ - spec/dummy/Rakefile
113
+ - spec/dummy/app/controllers/application_controller.rb
114
+ - spec/dummy/app/controllers/ssl_controller.rb
115
+ - spec/dummy/app/views/layouts/application.html.erb
116
+ - spec/dummy/app/views/ssl/action.html.erb
117
+ - spec/dummy/config.ru
118
+ - spec/dummy/config/application.rb
119
+ - spec/dummy/config/boot.rb
120
+ - spec/dummy/config/database.yml
121
+ - spec/dummy/config/environment.rb
122
+ - spec/dummy/config/environments/development.rb
123
+ - spec/dummy/config/environments/production.rb
124
+ - spec/dummy/config/environments/test.rb
125
+ - spec/dummy/config/initializers/backtrace_silencers.rb
126
+ - spec/dummy/config/initializers/inflections.rb
127
+ - spec/dummy/config/initializers/mime_types.rb
128
+ - spec/dummy/config/initializers/secret_token.rb
129
+ - spec/dummy/config/initializers/session_store.rb
130
+ - spec/dummy/config/routes.rb
131
+ - spec/dummy/script/rails
132
+ - spec/secure_routes_spec.rb
133
+ - spec/spec_helper.rb
134
+ has_rdoc: true
135
+ homepage: http://github.com/pyromaniac/secure_routes
136
+ licenses: []
137
+
138
+ post_install_message:
139
+ rdoc_options: []
140
+
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 3
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ requirements: []
162
+
163
+ rubyforge_project:
164
+ rubygems_version: 1.4.2
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: Rails ssl requirements
168
+ test_files:
169
+ - spec/dummy/app/controllers/application_controller.rb
170
+ - spec/dummy/app/controllers/ssl_controller.rb
171
+ - spec/dummy/config/application.rb
172
+ - spec/dummy/config/boot.rb
173
+ - spec/dummy/config/environment.rb
174
+ - spec/dummy/config/environments/development.rb
175
+ - spec/dummy/config/environments/production.rb
176
+ - spec/dummy/config/environments/test.rb
177
+ - spec/dummy/config/initializers/backtrace_silencers.rb
178
+ - spec/dummy/config/initializers/inflections.rb
179
+ - spec/dummy/config/initializers/mime_types.rb
180
+ - spec/dummy/config/initializers/secret_token.rb
181
+ - spec/dummy/config/initializers/session_store.rb
182
+ - spec/dummy/config/routes.rb
183
+ - spec/secure_routes_spec.rb
184
+ - spec/spec_helper.rb