redis-actionpack-5.0.1/0000755000004100000410000000000013046252124014764 5ustar www-datawww-dataredis-actionpack-5.0.1/Rakefile0000644000004100000410000000014713046252124016433 0ustar www-datawww-datarequire 'bundler/setup' require 'rake' require 'bundler/gem_tasks' require 'redis-store/testing/tasks' redis-actionpack-5.0.1/Gemfile0000644000004100000410000000004613046252124016257 0ustar www-datawww-datasource 'https://rubygems.org' gemspec redis-actionpack-5.0.1/redis-actionpack.gemspec0000644000004100000410000000242313046252124021552 0ustar www-datawww-data# -*- encoding: utf-8 -*- $:.push File.expand_path('../lib', __FILE__) require 'redis/actionpack/version' Gem::Specification.new do |s| s.name = 'redis-actionpack' s.version = Redis::ActionPack::VERSION s.authors = ['Luca Guidi'] s.email = ['me@lucaguidi.com'] s.homepage = 'http://redis-store.org/redis-actionpack' s.summary = %q{Redis session store for ActionPack} s.description = %q{Redis session store for ActionPack} s.license = 'MIT' s.rubyforge_project = 'redis-actionpack' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ['lib'] s.add_runtime_dependency 'redis-store', '>= 1.1.0', '< 1.4.0' s.add_runtime_dependency 'redis-rack', '>= 1', '< 3' s.add_runtime_dependency 'actionpack', '>= 4.0', '< 6' s.add_development_dependency 'rake', '~> 10' s.add_development_dependency 'bundler', '~> 1.3' s.add_development_dependency 'mocha', '~> 0.14.0' s.add_development_dependency 'minitest-rails' s.add_development_dependency 'tzinfo' # s.add_development_dependency 'mini_backtrace' s.add_development_dependency 'redis-store-testing' end redis-actionpack-5.0.1/MIT-LICENSE0000644000004100000410000000204513046252124016421 0ustar www-datawww-dataCopyright (c) 2009 - 2011 Luca Guidi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. redis-actionpack-5.0.1/.travis.yml0000644000004100000410000000127213046252124017077 0ustar www-datawww-datalanguage: ruby before_install: gem install bundler script: 'bundle exec rake' rvm: - 1.9.3 - 2.0 - 2.1 - 2.2.4 - 2.3.1 - ruby-head gemfile: - test/gemfiles/Gemfile.rails-4.0.x - test/gemfiles/Gemfile.rails-4.1.x - test/gemfiles/Gemfile.rails-4.2.x - test/gemfiles/Gemfile.rails-5.0.x matrix: exclude: - rvm: 1.9.3 gemfile: test/gemfiles/Gemfile.rails-5.0.x - rvm: 2.0 gemfile: test/gemfiles/Gemfile.rails-5.0.x - rvm: 2.1 gemfile: test/gemfiles/Gemfile.rails-5.0.x - rvm: ruby-head gemfile: test/gemfiles/Gemfile.rails-4.0.x - rvm: ruby-head gemfile: test/gemfiles/Gemfile.rails-4.1.x allow_failures: - rvm: ruby-head redis-actionpack-5.0.1/lib/0000755000004100000410000000000013046252124015532 5ustar www-datawww-dataredis-actionpack-5.0.1/lib/redis-actionpack.rb0000644000004100000410000000021013046252124021270 0ustar www-datawww-datarequire 'redis-store' require 'action_pack' require 'redis/actionpack/version' require 'action_dispatch/middleware/session/redis_store' redis-actionpack-5.0.1/lib/action_dispatch/0000755000004100000410000000000013046252124020666 5ustar www-datawww-dataredis-actionpack-5.0.1/lib/action_dispatch/middleware/0000755000004100000410000000000013046252124023003 5ustar www-datawww-dataredis-actionpack-5.0.1/lib/action_dispatch/middleware/session/0000755000004100000410000000000013046252124024466 5ustar www-datawww-dataredis-actionpack-5.0.1/lib/action_dispatch/middleware/session/redis_store.rb0000644000004100000410000000127613046252124027343 0ustar www-datawww-datarequire 'redis-store' require 'redis-rack' require 'action_dispatch/middleware/session/abstract_store' module ActionDispatch module Session class RedisStore < Rack::Session::Redis include Compatibility include StaleSessionCheck include SessionObject def initialize(app, options = {}) options = options.dup options[:redis_server] ||= options[:servers] super end private def set_cookie(env, session_id, cookie) if env.is_a? ActionDispatch::Request request = env else request = ActionDispatch::Request.new(env) end request.cookie_jar[key] = cookie end end end end redis-actionpack-5.0.1/lib/redis/0000755000004100000410000000000013046252124016640 5ustar www-datawww-dataredis-actionpack-5.0.1/lib/redis/actionpack/0000755000004100000410000000000013046252124020754 5ustar www-datawww-dataredis-actionpack-5.0.1/lib/redis/actionpack/version.rb0000644000004100000410000000010013046252124022755 0ustar www-datawww-dataclass Redis module ActionPack VERSION = '5.0.1' end end redis-actionpack-5.0.1/test/0000755000004100000410000000000013046252124015743 5ustar www-datawww-dataredis-actionpack-5.0.1/test/gemfiles/0000755000004100000410000000000013046252124017536 5ustar www-datawww-dataredis-actionpack-5.0.1/test/gemfiles/Gemfile.rails-5.0.x0000644000004100000410000000026513046252124022713 0ustar www-datawww-datasource 'https://rubygems.org' gemspec :path => './../..' gem 'redis-store' gem 'redis-rack', github: 'redis-store/redis-rack' gem 'actionpack', '~> 5.0.0' gem 'minitest-rails' redis-actionpack-5.0.1/test/gemfiles/Gemfile.rails-4.1.x0000644000004100000410000000026613046252124022714 0ustar www-datawww-datasource 'https://rubygems.org' gemspec :path => './../..' gem 'redis-store', '~> 1.1.0' gem 'redis-rack', '~> 1.5.0' gem 'actionpack', '~> 4.1.0' gem 'minitest-rails', '~> 2.2.0' redis-actionpack-5.0.1/test/gemfiles/Gemfile.rails-4.2.x0000644000004100000410000000026613046252124022715 0ustar www-datawww-datasource 'https://rubygems.org' gemspec :path => './../..' gem 'redis-store', '~> 1.1.0' gem 'redis-rack', '~> 1.5.0' gem 'actionpack', '~> 4.2.0' gem 'minitest-rails', '~> 2.2.0' redis-actionpack-5.0.1/test/gemfiles/Gemfile.rails-4.0.x0000644000004100000410000000026613046252124022713 0ustar www-datawww-datasource 'https://rubygems.org' gemspec :path => './../..' gem 'redis-store', '~> 1.1.0' gem 'redis-rack', '~> 1.5.0' gem 'actionpack', '~> 4.0.0' gem 'minitest-rails', '~> 1.0.0' redis-actionpack-5.0.1/test/fixtures/0000755000004100000410000000000013046252124017614 5ustar www-datawww-dataredis-actionpack-5.0.1/test/fixtures/session_autoload_test/0000755000004100000410000000000013046252124024226 5ustar www-datawww-dataredis-actionpack-5.0.1/test/fixtures/session_autoload_test/session_autoload_test/0000755000004100000410000000000013046252124030640 5ustar www-datawww-dataredis-actionpack-5.0.1/test/fixtures/session_autoload_test/session_autoload_test/foo.rb0000644000004100000410000000025513046252124031752 0ustar www-datawww-datamodule SessionAutoloadTest class Foo def initialize(bar='baz') @bar = bar end def inspect "#<#{self.class} bar:#{@bar.inspect}>" end end end redis-actionpack-5.0.1/test/test_helper.rb0000644000004100000410000000122013046252124020601 0ustar www-datawww-datarequire 'bundler/setup' require 'minitest/autorun' require 'active_support/core_ext/numeric/time' ENV["RAILS_ENV"] = "test" require File.expand_path("../dummy/config/environment.rb", __FILE__) require "rails/test_help" Rails.backtrace_cleaner.remove_silencers! def with_autoload_path(path) path = File.join(File.dirname(__FILE__), "fixtures", path) if ActiveSupport::Dependencies.autoload_paths.include?(path) yield else begin ActiveSupport::Dependencies.autoload_paths << path yield ensure ActiveSupport::Dependencies.autoload_paths.reject! {|p| p == path} ActiveSupport::Dependencies.clear end end end redis-actionpack-5.0.1/test/dummy/0000755000004100000410000000000013046252124017076 5ustar www-datawww-dataredis-actionpack-5.0.1/test/dummy/Rakefile0000644000004100000410000000041613046252124020544 0ustar www-datawww-data#!/usr/bin/env rake # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) Dummy::Application.load_tasks redis-actionpack-5.0.1/test/dummy/script/0000755000004100000410000000000013046252124020402 5ustar www-datawww-dataredis-actionpack-5.0.1/test/dummy/script/rails0000755000004100000410000000044713046252124021447 0ustar www-datawww-data#!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands' redis-actionpack-5.0.1/test/dummy/.gitignore0000644000004100000410000000000613046252124021062 0ustar www-datawww-datalog/* redis-actionpack-5.0.1/test/dummy/config/0000755000004100000410000000000013046252124020343 5ustar www-datawww-dataredis-actionpack-5.0.1/test/dummy/config/application.rb0000644000004100000410000000146213046252124023176 0ustar www-datawww-datarequire File.expand_path('../boot', __FILE__) require "action_controller/railtie" Bundler.require module Dummy class Application < Rails::Application # Disable class caching for session auto-load test config.cache_classes = false config.eager_load = false # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false # Print deprecation notices to the stderr config.active_support.deprecation = :stderr config.secret_key_base = 'secret' end end redis-actionpack-5.0.1/test/dummy/config/boot.rb0000644000004100000410000000035413046252124021635 0ustar www-datawww-datarequire 'rubygems' gemfile = File.expand_path('../../../../Gemfile', __FILE__) if File.exist?(gemfile) ENV['BUNDLE_GEMFILE'] = gemfile require 'bundler' Bundler.setup end $:.unshift File.expand_path('../../../../lib', __FILE__) redis-actionpack-5.0.1/test/dummy/config/routes.rb0000644000004100000410000000011513046252124022206 0ustar www-datawww-dataDummy::Application.routes.draw do get ':action', :to => TestController end redis-actionpack-5.0.1/test/dummy/config/environment.rb0000644000004100000410000000022513046252124023233 0ustar www-datawww-data# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Dummy::Application.initialize! redis-actionpack-5.0.1/test/dummy/app/0000755000004100000410000000000013046252124017656 5ustar www-datawww-dataredis-actionpack-5.0.1/test/dummy/app/controllers/0000755000004100000410000000000013046252124022224 5ustar www-datawww-dataredis-actionpack-5.0.1/test/dummy/app/controllers/test_controller.rb0000644000004100000410000000134513046252124025776 0ustar www-datawww-dataclass TestController < ActionController::Base def no_session_access head :ok end def set_session_value session[:foo] = "bar" head :ok end def set_session_value_with_expiry request.session_options[:expire_after] = 1.second set_session_value end def set_serialized_session_value session[:foo] = SessionAutoloadTest::Foo.new head :ok end def get_session_value render :text => "foo: #{session[:foo].inspect}" end def get_session_id session_id = request.session_options[:id] || cookies["_session_id"] render :text => session_id end def call_reset_session session[:bar] reset_session session[:bar] = "baz" head :ok end def rescue_action(e) raise end end redis-actionpack-5.0.1/test/dummy/config.ru0000644000004100000410000000023313046252124020711 0ustar www-datawww-data# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Dummy::Application redis-actionpack-5.0.1/test/integration/0000755000004100000410000000000013046252124020266 5ustar www-datawww-dataredis-actionpack-5.0.1/test/integration/redis_store_integration_test.rb0000644000004100000410000001402213046252124026576 0ustar www-datawww-datarequire 'test_helper' class RedisStoreIntegrationTest < ::ActionDispatch::IntegrationTest SessionKey = '_session_id' SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33' test "reads the data" do with_test_route_set do get '/set_session_value' assert_response :success assert cookies['_session_id'].present? get '/get_session_value' assert_response :success assert_equal response.body, 'foo: "bar"' end end test "should get nil session value" do with_test_route_set do get '/get_session_value' assert_response :success assert_equal 'foo: nil', response.body end end test "should delete the data after session reset" do with_test_route_set do get '/set_session_value' assert_response :success assert cookies['_session_id'].present? session_cookie = cookies.send(:hash_for)['_session_id'] get '/call_reset_session' assert_response :success assert !headers['Set-Cookie'].blank? cookies << session_cookie get '/get_session_value' assert_response :success assert_equal 'foo: nil', response.body end end test "should not send cookies on write, not read" do with_test_route_set do get '/get_session_value' assert_response :success assert_equal 'foo: nil', response.body assert cookies['_session_id'].nil? end end test "should set session value after session reset" do with_test_route_set do get '/set_session_value' assert_response :success assert cookies['_session_id'].present? session_id = cookies['_session_id'] get '/call_reset_session' assert_response :success assert !headers['Set-Cookie'].blank? get '/get_session_value' assert_response :success assert_equal 'foo: nil', response.body get '/get_session_id' assert_response :success assert(response.body != session_id) end end test "should be able to read session id without accessing the session hash" do with_test_route_set do get '/set_session_value' assert_response :success assert cookies['_session_id'].present? session_id = cookies['_session_id'] get '/get_session_id' assert_response :success assert_equal response.body, session_id end end test "should auto-load unloaded class" do with_test_route_set do with_autoload_path "session_autoload_test" do get '/set_serialized_session_value' assert_response :success assert cookies['_session_id'].present? end with_autoload_path "session_autoload_test" do get '/get_session_id' assert_response :success end with_autoload_path "session_autoload_test" do get '/get_session_value' assert_response :success assert_equal response.body, 'foo: #' end end end test "should not resend the cookie again if session_id cookie is already exists" do with_test_route_set do get '/set_session_value' assert_response :success assert cookies['_session_id'].present? get '/get_session_value' assert_response :success assert headers['Set-Cookie'].nil? end end test "should prevent session fixation" do with_test_route_set do get '/get_session_value' assert_response :success assert_equal 'foo: nil', response.body session_id = cookies['_session_id'] reset! get '/set_session_value', :_session_id => session_id assert_response :success assert(cookies['_session_id'] != session_id) end end test "should write the data with expiration time" do with_test_route_set do get '/set_session_value_with_expiry' assert_response :success get '/get_session_value' assert_response :success assert_equal response.body, 'foo: "bar"' sleep 1 get '/get_session_value' assert_response :success assert_equal 'foo: nil', response.body end end test "session store with explicit domain" do with_test_route_set(:domain => "example.es") do get '/set_session_value' assert_match(/domain=example\.es/, headers['Set-Cookie']) headers['Set-Cookie'] end end test "session store without domain" do with_test_route_set do get '/set_session_value' assert_no_match(/domain\=/, headers['Set-Cookie']) end end test "session store with nil domain" do with_test_route_set(:domain => nil) do get '/set_session_value' assert_no_match(/domain\=/, headers['Set-Cookie']) end end test "session store with all domains" do with_test_route_set(:domain => :all) do get '/set_session_value' assert_match(/domain=\.example\.com/, headers['Set-Cookie']) end end private # from actionpack/test/abstract_unit.rb class RoutedRackApp attr_reader :routes def initialize(routes, &blk) @routes = routes @stack = ActionDispatch::MiddlewareStack.new(&blk).build(@routes) end def call(env) @stack.call(env) end end # from actionpack/test/abstract_unit.rb def self.build_app(routes = nil) RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware| middleware.use ActionDispatch::DebugExceptions middleware.use ActionDispatch::Callbacks middleware.use ActionDispatch::ParamsParser middleware.use ActionDispatch::Cookies middleware.use ActionDispatch::Flash middleware.use Rack::Head yield(middleware) if block_given? end end # from actionpack/test/dispatch/session/cookie_store_test.rb def with_test_route_set(options = {}) with_routing do |set| set.draw do get ':action', :to => ::TestController end options = { :key => SessionKey }.merge!(options) @app = self.class.build_app(set) do |middleware| middleware.use ActionDispatch::Session::RedisStore, options end yield end end end redis-actionpack-5.0.1/.gitignore0000644000004100000410000000006413046252124016754 0ustar www-datawww-dataGemfile.lock test/gemfiles/*.lock *.gem tmp/ stdout redis-actionpack-5.0.1/README.md0000644000004100000410000000252313046252124016245 0ustar www-datawww-data# Redis stores for ActionPack __`redis-actionpack`__ provides a session store for __ActionPack__, specifically for __ActionDispatch__. See the main [redis-store readme](https://github.com/redis-store/redis-store) for general guidelines. ## Installation ```ruby # Gemfile gem 'redis-actionpack' ``` ## Usage If you are using redis-store with Rails, consider using the [redis-rails gem](https://github.com/redis-store/redis-rails) instead. For standalone usage: ```ruby ActionController::Base.cache_store = ActionDispatch::Session::RedisSessionStore.new ``` ## Running tests ```shell gem install bundler git clone git://github.com/redis-store/redis-actionpack.git cd redis-actionpack bundle install bundle exec rake ``` If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" bundle exec rake` ## Status [![Gem Version](https://badge.fury.io/rb/redis-actionpack.png)](http://badge.fury.io/rb/redis-actionpack) [![Build Status](https://secure.travis-ci.org/redis-store/redis-actionpack.png?branch=master)](http://travis-ci.org/redis-store/redis-actionpack?branch=master) [![Code Climate](https://codeclimate.com/github/redis-store/redis-actionpack.png)](https://codeclimate.com/github/redis-store/redis-actionpack) ## Copyright 2009 - 2013 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license