├── .document ├── .gitignore ├── .rvmrc ├── Gemfile ├── Gemfile.lock ├── MIT-LICENSE ├── README.rdoc ├── Rakefile ├── lib ├── mongoid_session_store.rb ├── mongoid_session_store │ └── mongoid_store.rb └── tasks │ └── mongoid_session_store_tasks.rake ├── mongoid_session_store.gemspec ├── script └── rails └── test ├── dummy ├── Rakefile ├── app │ ├── assets │ │ ├── javascripts │ │ │ └── application.js │ │ └── stylesheets │ │ │ └── application.css │ ├── controllers │ │ ├── application_controller.rb │ │ └── sessions_controller.rb │ ├── helpers │ │ └── application_helper.rb │ ├── mailers │ │ └── .gitkeep │ ├── models │ │ └── .gitkeep │ └── views │ │ └── layouts │ │ └── application.html.erb ├── config.ru ├── config │ ├── application.rb │ ├── boot.rb │ ├── database.yml │ ├── environment.rb │ ├── environments │ │ ├── development.rb │ │ ├── production.rb │ │ └── test.rb │ ├── initializers │ │ ├── backtrace_silencers.rb │ │ ├── inflections.rb │ │ ├── mime_types.rb │ │ ├── secret_token.rb │ │ ├── session_store.rb │ │ └── wrap_parameters.rb │ ├── locales │ │ └── en.yml │ ├── mongoid.yml │ └── routes.rb ├── log │ └── .gitkeep ├── public │ ├── 404.html │ ├── 422.html │ ├── 500.html │ └── favicon.ico └── script │ └── rails ├── mongoid_session_store_test.rb └── test_helper.rb /.document: -------------------------------------------------------------------------------- 1 | README.rdoc 2 | lib/**/*.rb 3 | bin/* 4 | features/**/*.feature 5 | LICENSE 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle/ 2 | log/*.log 3 | pkg/ 4 | test/dummy/db/*.sqlite3 5 | test/dummy/log/*.log 6 | test/dummy/tmp/ -------------------------------------------------------------------------------- /.rvmrc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # This is an RVM Project .rvmrc file, used to automatically load the ruby 4 | # development environment upon cd'ing into the directory 5 | 6 | # First we specify our desired [@], the @gemset name is optional. 7 | environment_id="ruby-1.9.2-p180@mongoid_session_store" 8 | 9 | # 10 | # First we attempt to load the desired environment directly from the environment 11 | # file, this is very fast and efficicent compared to running through the entire 12 | # CLI and selector. If you want feedback on which environment was used then 13 | # insert the word 'use' after --create as this triggers verbose mode. 14 | # 15 | if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \ 16 | && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then 17 | \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id" 18 | else 19 | # If the environment file has not yet been created, use the RVM CLI to select. 20 | rvm --create "$environment_id" 21 | fi 22 | 23 | # 24 | # If you use an RVM gemset file to install a list of gems (*.gems), you can have 25 | # it be automatically loaded, uncomment the following and adjust the filename if 26 | # necessary. 27 | # 28 | # filename=".gems" 29 | # if [[ -s "$filename" ]] ; then 30 | # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d' 31 | # fi 32 | 33 | # 34 | # If you use bundler and would like to run bundle each time you enter the 35 | # directory you can uncomment the following code. 36 | # 37 | # Ensure that Bundler is installed, install it if it is not. 38 | if ! command -v bundle ; then 39 | printf "The rubygem 'bundler' is not installed, installing it now.\n" 40 | gem install bundler 41 | fi 42 | # 43 | # # Bundle while redcing excess noise. 44 | # printf "Bundling your gems this may take a few minutes on a fresh clone.\n" 45 | # bundle | grep -v 'Using' | grep -v 'complete' | sed '/^$/d' 46 | # 47 | 48 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | 3 | gem 'rails', '3.1.0' 4 | gem "rake", "~> 0.9.2.2" 5 | # gem 'rails', :git => 'git://github.com/rails/rails.git' 6 | 7 | gem "mongoid", "~> 2.3.3" 8 | gem "bson_ext", "~> 1.4" 9 | 10 | if RUBY_VERSION < '1.9' 11 | gem "ruby-debug", ">= 0.10.3" 12 | end 13 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: http://rubygems.org/ 3 | specs: 4 | actionmailer (3.1.0) 5 | actionpack (= 3.1.0) 6 | mail (~> 2.3.0) 7 | actionpack (3.1.0) 8 | activemodel (= 3.1.0) 9 | activesupport (= 3.1.0) 10 | builder (~> 3.0.0) 11 | erubis (~> 2.7.0) 12 | i18n (~> 0.6) 13 | rack (~> 1.3.2) 14 | rack-cache (~> 1.0.3) 15 | rack-mount (~> 0.8.2) 16 | rack-test (~> 0.6.1) 17 | sprockets (~> 2.0.0) 18 | activemodel (3.1.0) 19 | activesupport (= 3.1.0) 20 | bcrypt-ruby (~> 3.0.0) 21 | builder (~> 3.0.0) 22 | i18n (~> 0.6) 23 | activerecord (3.1.0) 24 | activemodel (= 3.1.0) 25 | activesupport (= 3.1.0) 26 | arel (~> 2.2.1) 27 | tzinfo (~> 0.3.29) 28 | activeresource (3.1.0) 29 | activemodel (= 3.1.0) 30 | activesupport (= 3.1.0) 31 | activesupport (3.1.0) 32 | multi_json (~> 1.0) 33 | arel (2.2.1) 34 | bcrypt-ruby (3.0.0) 35 | bson (1.4.0) 36 | bson_ext (1.4.0) 37 | builder (3.0.0) 38 | erubis (2.7.0) 39 | hike (1.2.1) 40 | i18n (0.6.0) 41 | mail (2.3.0) 42 | i18n (>= 0.4.0) 43 | mime-types (~> 1.16) 44 | treetop (~> 1.4.8) 45 | mime-types (1.16) 46 | mongo (1.4.0) 47 | bson (= 1.4.0) 48 | mongoid (2.3.3) 49 | activemodel (~> 3.1) 50 | mongo (~> 1.3) 51 | tzinfo (~> 0.3.22) 52 | multi_json (1.0.3) 53 | polyglot (0.3.2) 54 | rack (1.3.2) 55 | rack-cache (1.0.3) 56 | rack (>= 0.4) 57 | rack-mount (0.8.3) 58 | rack (>= 1.0.0) 59 | rack-ssl (1.3.2) 60 | rack 61 | rack-test (0.6.1) 62 | rack (>= 1.0) 63 | rails (3.1.0) 64 | actionmailer (= 3.1.0) 65 | actionpack (= 3.1.0) 66 | activerecord (= 3.1.0) 67 | activeresource (= 3.1.0) 68 | activesupport (= 3.1.0) 69 | bundler (~> 1.0) 70 | railties (= 3.1.0) 71 | railties (3.1.0) 72 | actionpack (= 3.1.0) 73 | activesupport (= 3.1.0) 74 | rack-ssl (~> 1.3.2) 75 | rake (>= 0.8.7) 76 | rdoc (~> 3.4) 77 | thor (~> 0.14.6) 78 | rake (0.9.2.2) 79 | rdoc (3.9.4) 80 | sprockets (2.0.0) 81 | hike (~> 1.2) 82 | rack (~> 1.0) 83 | tilt (~> 1.1, != 1.3.0) 84 | thor (0.14.6) 85 | tilt (1.3.3) 86 | treetop (1.4.10) 87 | polyglot 88 | polyglot (>= 0.3.1) 89 | tzinfo (0.3.29) 90 | 91 | PLATFORMS 92 | ruby 93 | 94 | DEPENDENCIES 95 | bson_ext (~> 1.4) 96 | mongoid (~> 2.3.3) 97 | rails (= 3.1.0) 98 | rake (~> 0.9.2.2) 99 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 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. 21 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | = mongoid_session_store 2 | 3 | store rails 3 sessions in mongoDB using mongoid. 4 | 5 | == Installation 6 | This gem supports rails 3, rails 3.1 and mongoid 2.0 7 | 8 | gem install mongoid_session_store 9 | 10 | == Setup 11 | 12 | In your Gemfile: 13 | 14 | gem "mongoid", "~> 2.0" 15 | gem "bson_ext", "~> 1.3" 16 | gem "mongoid_session_store" 17 | 18 | In the session_store initializer (config/initializers/session_store.rb) you can comment out every line as 19 | mongoid session store will be setup for use when added to the gemfile. 20 | 21 | If you want to be more explicit you can comment the currently setup store and add: 22 | 23 | Example::Application.config.session_store :mongoid_store 24 | 25 | == Rake Tasks 26 | Mongoid Session Store comes with a rake task to clear out the sessions it stores in mongoDB 27 | 28 | rake db:mongoid:sessions:clear 29 | 30 | == Note on Patches/Pull Requests 31 | 32 | * Fork the project. 33 | * Make your feature addition or bug fix. 34 | * Add tests for it. This is important so I don't break it in a 35 | future version unintentionally. 36 | * Commit, do not mess with rakefile, version, or history. 37 | (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull) 38 | * Send me a pull request. Bonus points for topic branches. 39 | 40 | == Copyright 41 | 42 | Copyright (c) 2010 Ryan Fitzgerald. See MIT-LICENSE for details. 43 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | begin 3 | require 'bundler/setup' 4 | require 'bundler/gem_tasks' 5 | rescue LoadError 6 | puts 'You must `gem install bundler` and `bundle install` to run rake tasks' 7 | end 8 | begin 9 | require 'rdoc/task' 10 | rescue LoadError 11 | require 'rdoc/rdoc' 12 | require 'rake/rdoctask' 13 | RDoc::Task = Rake::RDocTask 14 | end 15 | 16 | RDoc::Task.new(:rdoc) do |rdoc| 17 | rdoc.rdoc_dir = 'rdoc' 18 | rdoc.title = 'MongoidSessionStore' 19 | rdoc.options << '--line-numbers' << '--inline-source' 20 | rdoc.rdoc_files.include('README.rdoc') 21 | rdoc.rdoc_files.include('lib/**/*.rb') 22 | end 23 | 24 | 25 | require 'rake/testtask' 26 | 27 | Rake::TestTask.new(:test) do |t| 28 | t.libs << 'lib' 29 | t.libs << 'test' 30 | t.pattern = 'test/**/*_test.rb' 31 | t.verbose = false 32 | end 33 | 34 | 35 | task :default => :test 36 | -------------------------------------------------------------------------------- /lib/mongoid_session_store.rb: -------------------------------------------------------------------------------- 1 | require 'rails' 2 | 3 | module MongoidSessionStore 4 | 5 | class Railtie < Rails::Railtie 6 | rake_tasks do 7 | load "tasks/mongoid_session_store_tasks.rake" 8 | end 9 | 10 | initializer "setup mongoid session store" do |app| 11 | require 'mongoid_session_store/mongoid_store' 12 | app.config.session_store :mongoid_store 13 | end 14 | end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /lib/mongoid_session_store/mongoid_store.rb: -------------------------------------------------------------------------------- 1 | module ActionDispatch 2 | module Session 3 | class MongoidStore < AbstractStore 4 | 5 | class Session 6 | include Mongoid::Document 7 | 8 | store_in :sessions 9 | 10 | identity :type => String 11 | 12 | field :data, :type => String, :default => [Marshal.dump({})].pack("m*") 13 | end 14 | 15 | # The class used for session storage. 16 | cattr_accessor :session_class 17 | self.session_class = Session 18 | 19 | SESSION_RECORD_KEY = 'rack.session.record' 20 | ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY if ::Rails.version >= "3.1" 21 | 22 | private 23 | 24 | def get_session(env, sid) 25 | sid ||= generate_sid 26 | session = find_session(sid) 27 | env[SESSION_RECORD_KEY] = session 28 | [sid, unpack(session.data)] 29 | end 30 | 31 | def set_session(env, sid, session_data, options = nil) 32 | record = get_session_model(env, sid) 33 | record.data = pack(session_data) 34 | 35 | # Rack spec dictates that set_session should return true or false 36 | # depending on whether or not the session was saved or not. 37 | # However, ActionPack seems to want a session id instead. 38 | record.save ? sid : false 39 | end 40 | 41 | def find_session(id) 42 | @@session_class.find_or_create_by(:id => id) 43 | end 44 | 45 | # def destroy(env) 46 | # if sid = current_session_id(env) 47 | # find_session(sid).destroy 48 | # end 49 | # end 50 | 51 | def destroy(env) 52 | destroy_session(env, current_session_id(env), {}) 53 | end 54 | 55 | def destroy_session(env, session_id, options) 56 | if sid = current_session_id(env) 57 | get_session_model(env, sid).destroy 58 | env[SESSION_RECORD_KEY] = nil 59 | end 60 | 61 | generate_sid unless options[:drop] 62 | end 63 | 64 | def get_session_model(env, sid) 65 | if env[ENV_SESSION_OPTIONS_KEY][:id].nil? 66 | env[SESSION_RECORD_KEY] = find_session(sid) 67 | else 68 | env[SESSION_RECORD_KEY] ||= find_session(sid) 69 | end 70 | end 71 | 72 | def pack(data) 73 | [Marshal.dump(data)].pack("m*") 74 | end 75 | 76 | def unpack(packed) 77 | return nil unless packed 78 | Marshal.load(packed.unpack("m*").first) 79 | end 80 | 81 | end 82 | end 83 | end -------------------------------------------------------------------------------- /lib/tasks/mongoid_session_store_tasks.rake: -------------------------------------------------------------------------------- 1 | namespace :db do 2 | namespace :mongoid do 3 | namespace :sessions do 4 | desc "Clears sessions stored in mongoDB" 5 | task :clear => :environment do 6 | ActionDispatch::Session::MongoidStore::Session.destroy_all 7 | end 8 | end 9 | end 10 | end -------------------------------------------------------------------------------- /mongoid_session_store.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = "mongoid_session_store" 3 | s.version = "2.1.0" 4 | s.authors = ["Ryan Fitzgerald", "Code Brew Studios"] 5 | s.email = ["ryan@codebrewstudios.com"] 6 | s.homepage = "http://github.com/codebrew/mongoid_session_store" 7 | s.summary = "Store rails 3 sessions in mongoDB." 8 | s.description = "Store rails 3 sessions in mongoDB." 9 | s.files = Dir["lib/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"] 10 | 11 | s.add_dependency('rails', "~> 3.0") 12 | s.add_dependency('mongoid', '~> 2.3') 13 | end 14 | -------------------------------------------------------------------------------- /script/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | #!/usr/bin/env ruby 3 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 4 | 5 | ENGINE_PATH = File.expand_path('../..', __FILE__) 6 | load File.expand_path('../../test/dummy/script/rails', __FILE__) 7 | -------------------------------------------------------------------------------- /test/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | # Add your own tasks in files placed in lib/tasks ending in .rake, 3 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 4 | 5 | require File.expand_path('../config/application', __FILE__) 6 | 7 | Dummy::Application.load_tasks 8 | -------------------------------------------------------------------------------- /test/dummy/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into including all the files listed below. 2 | // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically 3 | // be included in the compiled file accessible from http://example.com/assets/application.js 4 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 5 | // the compiled file. 6 | // 7 | //= require jquery 8 | //= require jquery_ujs 9 | //= require_tree . 10 | -------------------------------------------------------------------------------- /test/dummy/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll automatically include all the stylesheets available in this directory 3 | * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at 4 | * the top of the compiled file, but it's generally better to create a new file per style scope. 5 | *= require_self 6 | *= require_tree . 7 | */ -------------------------------------------------------------------------------- /test/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/sessions_controller.rb: -------------------------------------------------------------------------------- 1 | class SessionsController < ApplicationController 2 | def no_session_access 3 | head :ok 4 | end 5 | 6 | def set_session_value 7 | raise "missing session!" unless session 8 | session[:foo] = params[:foo] || "bar" 9 | head :ok 10 | end 11 | 12 | def get_session_value 13 | render :text => "foo: #{session[:foo].inspect}" 14 | end 15 | 16 | def get_session_id 17 | render :text => "#{request.session_options[:id]}" 18 | end 19 | 20 | def call_reset_session 21 | session[:foo] 22 | reset_session 23 | reset_session if params[:twice] 24 | session[:foo] = "baz" 25 | head :ok 26 | end 27 | 28 | def renew 29 | env["rack.session.options"][:renew] = true 30 | session[:foo] = "baz" 31 | head :ok 32 | end 33 | 34 | def rescue_action(e) raise end 35 | end -------------------------------------------------------------------------------- /test/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /test/dummy/app/mailers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codebrew/mongoid_session_store/1563a150ec15ddc5c77827ed8f47bdca7896428d/test/dummy/app/mailers/.gitkeep -------------------------------------------------------------------------------- /test/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codebrew/mongoid_session_store/1563a150ec15ddc5c77827ed8f47bdca7896428d/test/dummy/app/models/.gitkeep -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | <%= stylesheet_link_tag "application" %> 6 | <%= javascript_include_tag "application" %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/dummy/config.ru: -------------------------------------------------------------------------------- 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 5 | -------------------------------------------------------------------------------- /test/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require "action_controller/railtie" 4 | require "action_mailer/railtie" 5 | require "active_resource/railtie" 6 | require "rails/test_unit/railtie" 7 | 8 | Bundler.require 9 | require "mongoid_session_store" 10 | 11 | module Dummy 12 | class Application < Rails::Application 13 | # Settings in config/environments/* take precedence over those specified here. 14 | # Application configuration should go into files in config/initializers 15 | # -- all .rb files in that directory are automatically loaded. 16 | 17 | # Custom directories with classes and modules you want to be autoloadable. 18 | # config.autoload_paths += %W(#{config.root}/extras) 19 | 20 | # Only load the plugins named here, in the order given (default is alphabetical). 21 | # :all can be used as a placeholder for all plugins not explicitly named. 22 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 23 | 24 | # Activate observers that should always be running. 25 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 26 | 27 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 28 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 29 | # config.time_zone = 'Central Time (US & Canada)' 30 | 31 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 32 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 33 | # config.i18n.default_locale = :de 34 | 35 | # Configure the default encoding used in templates for Ruby 1.9. 36 | config.encoding = "utf-8" 37 | 38 | # Configure sensitive parameters which will be filtered from the log file. 39 | config.filter_parameters += [:password] 40 | 41 | # Enable the asset pipeline 42 | config.assets.enabled = true 43 | end 44 | end 45 | 46 | -------------------------------------------------------------------------------- /test/dummy/config/boot.rb: -------------------------------------------------------------------------------- 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__) -------------------------------------------------------------------------------- /test/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | development: 7 | adapter: sqlite3 8 | database: db/development.sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | # Warning: The database defined as "test" will be erased and 13 | # re-generated from your development database when you run "rake". 14 | # Do not set this db to the same as development or production. 15 | test: 16 | adapter: sqlite3 17 | database: db/test.sqlite3 18 | pool: 5 19 | timeout: 5000 20 | 21 | production: 22 | adapter: sqlite3 23 | database: db/production.sqlite3 24 | pool: 5 25 | timeout: 5000 26 | -------------------------------------------------------------------------------- /test/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the rails application 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the rails application 5 | Dummy::Application.initialize! 6 | -------------------------------------------------------------------------------- /test/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 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 web server 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_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger 20 | config.active_support.deprecation = :log 21 | 22 | # Only use best-standards-support built into browsers 23 | config.action_dispatch.best_standards_support = :builtin 24 | 25 | # Do not compress assets 26 | config.assets.compress = false 27 | end 28 | -------------------------------------------------------------------------------- /test/dummy/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # Code is not reloaded between requests 5 | config.cache_classes = true 6 | 7 | # Full error reports are disabled and caching is turned on 8 | config.consider_all_requests_local = false 9 | config.action_controller.perform_caching = true 10 | 11 | # Disable Rails's static asset server (Apache or nginx will already do this) 12 | config.serve_static_assets = false 13 | 14 | # Compress JavaScripts and CSS 15 | config.assets.compress = true 16 | 17 | # Specify the default JavaScript compressor 18 | config.assets.js_compressor = :uglifier 19 | 20 | # Specifies the header that your server uses for sending files 21 | # (comment out if your front-end server doesn't support this) 22 | config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx 23 | 24 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 25 | # config.force_ssl = true 26 | 27 | # See everything in the log (default is :info) 28 | # config.log_level = :debug 29 | 30 | # Use a different logger for distributed setups 31 | # config.logger = SyslogLogger.new 32 | 33 | # Use a different cache store in production 34 | # config.cache_store = :mem_cache_store 35 | 36 | # Enable serving of images, stylesheets, and JavaScripts from an asset server 37 | # config.action_controller.asset_host = "http://assets.example.com" 38 | 39 | # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 40 | # config.assets.precompile += %w( search.js ) 41 | 42 | # Disable delivery errors, bad email addresses will be ignored 43 | # config.action_mailer.raise_delivery_errors = false 44 | 45 | # Enable threaded mode 46 | # config.threadsafe! 47 | 48 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 49 | # the I18n.default_locale when a translation can not be found) 50 | config.i18n.fallbacks = true 51 | 52 | # Send deprecation notices to registered listeners 53 | config.active_support.deprecation = :notify 54 | end 55 | -------------------------------------------------------------------------------- /test/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 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 | # Configure static asset server for tests with Cache-Control for performance 11 | config.serve_static_assets = true 12 | config.static_cache_control = "public, max-age=3600" 13 | 14 | # Log error messages when you accidentally call methods on nil 15 | config.whiny_nils = true 16 | 17 | # Show full error reports and disable caching 18 | config.consider_all_requests_local = true 19 | config.action_controller.perform_caching = false 20 | 21 | # Raise exceptions instead of rendering exception templates 22 | config.action_dispatch.show_exceptions = false 23 | 24 | # Disable request forgery protection in test environment 25 | config.action_controller.allow_forgery_protection = false 26 | 27 | # Tell Action Mailer not to deliver emails to the real world. 28 | # The :test delivery method accumulates sent emails in the 29 | # ActionMailer::Base.deliveries array. 30 | config.action_mailer.delivery_method = :test 31 | 32 | # Use SQL instead of Active Record's schema dumper when creating the test database. 33 | # This is necessary if your schema can't be completely dumped by the schema dumper, 34 | # like if you have constraints or database-specific column types 35 | # config.active_record.schema_format = :sql 36 | 37 | # Print deprecation notices to the stderr 38 | config.active_support.deprecation = :stderr 39 | end 40 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 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! 8 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 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 6 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 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 = 'c2d455c9d309920b50e6834f0c2f2c2c6d0c380764ca0ed58dcaf4eb62fd8d4c3dddc3a043acfe77bd1b85886aa38401bbd03a6d1841e366ead23a0fd5fce2ef' 8 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActionController::Base.wrap_parameters format: [:json] 8 | 9 | # Disable root element in JSON by default. 10 | if defined?(ActiveRecord) 11 | ActiveRecord::Base.include_root_in_json = false 12 | end 13 | -------------------------------------------------------------------------------- /test/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Sample localization file for English. Add more files in this directory for other locales. 2 | # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. 3 | 4 | en: 5 | hello: "Hello world" 6 | -------------------------------------------------------------------------------- /test/dummy/config/mongoid.yml: -------------------------------------------------------------------------------- 1 | development: 2 | host: localhost 3 | database: dummy_development 4 | 5 | test: 6 | host: localhost 7 | database: dummy_test 8 | 9 | # set these environment variables on your prod server 10 | production: 11 | host: <%= ENV['MONGOID_HOST'] %> 12 | port: <%= ENV['MONGOID_PORT'] %> 13 | username: <%= ENV['MONGOID_USERNAME'] %> 14 | password: <%= ENV['MONGOID_PASSWORD'] %> 15 | database: <%= ENV['MONGOID_DATABASE'] %> 16 | # slaves: 17 | # - host: slave1.local 18 | # port: 27018 19 | # - host: slave2.local 20 | # port: 27019 21 | -------------------------------------------------------------------------------- /test/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.routes.draw do 2 | match ':action', :to => 'sessions' 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy/log/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codebrew/mongoid_session_store/1563a150ec15ddc5c77827ed8f47bdca7896428d/test/dummy/log/.gitkeep -------------------------------------------------------------------------------- /test/dummy/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The page you were looking for doesn't exist.

23 |

You may have mistyped the address or the page may have moved.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /test/dummy/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The change you wanted was rejected.

23 |

Maybe you tried to change something you didn't have access to.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /test/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

We're sorry, but something went wrong.

23 |

We've been notified about this issue and we'll take a look at it shortly.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /test/dummy/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codebrew/mongoid_session_store/1563a150ec15ddc5c77827ed8f47bdca7896428d/test/dummy/public/favicon.ico -------------------------------------------------------------------------------- /test/dummy/script/rails: -------------------------------------------------------------------------------- 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' 7 | -------------------------------------------------------------------------------- /test/mongoid_session_store_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class MongoidSessionStoreTest < ActionDispatch::IntegrationTest 4 | setup do 5 | ActionDispatch::Session::MongoidStore::Session.destroy_all 6 | end 7 | 8 | test "getting nil session value" do 9 | get '/get_session_value' 10 | assert_response :success 11 | assert_equal 'foo: nil', response.body 12 | end 13 | 14 | test "calling reset session twice does not raise errors" do 15 | get '/call_reset_session', :twice => "true" 16 | assert_response :success 17 | 18 | get '/get_session_value' 19 | assert_response :success 20 | assert_equal 'foo: "baz"', response.body 21 | end 22 | 23 | test "setting session value after session reset" do 24 | get '/set_session_value' 25 | assert_response :success 26 | assert cookies['_session_id'] 27 | session_id = cookies['_session_id'] 28 | 29 | get '/call_reset_session' 30 | assert_response :success 31 | assert_not_equal [], headers['Set-Cookie'] 32 | 33 | get '/get_session_value' 34 | assert_response :success 35 | assert_equal 'foo: "baz"', response.body 36 | 37 | get '/get_session_id' 38 | assert_response :success 39 | assert_not_equal session_id, response.body 40 | end 41 | 42 | test "getting session value after session reset" do 43 | get '/set_session_value' 44 | assert_response :success 45 | assert cookies['_session_id'] 46 | session_cookie = cookies.send(:hash_for)['_session_id'] 47 | 48 | get '/call_reset_session' 49 | assert_response :success 50 | assert_not_equal [], headers['Set-Cookie'] 51 | 52 | cookies << session_cookie # replace our new session_id with our old, pre-reset session_id 53 | 54 | get '/get_session_value' 55 | assert_response :success 56 | assert_equal 'foo: nil', response.body, "data for this session should have been obliterated from the database" 57 | end 58 | 59 | test "getting_from_nonexistent_session" do 60 | get '/get_session_value' 61 | assert_response :success 62 | assert_equal 'foo: nil', response.body 63 | assert_nil cookies['_session_id'], "should only create session on write, not read" 64 | end 65 | 66 | test "getting session_id" do 67 | get '/set_session_value' 68 | assert_response :success 69 | assert cookies['_session_id'] 70 | session_id = cookies['_session_id'] 71 | 72 | get '/get_session_id' 73 | assert_response :success 74 | assert_equal session_id, response.body, "should be able to read session id without accessing the session hash" 75 | end 76 | 77 | test "doesnt write session cookie if session_id already exists" do 78 | get '/set_session_value' 79 | assert_response :success 80 | assert cookies['_session_id'] 81 | 82 | get '/get_session_value' 83 | assert_response :success 84 | assert_equal nil, headers['Set-Cookie'], "should not resend the cookie again if session_id cookie already exists" 85 | end 86 | 87 | test "prevents session fixation" do 88 | get '/set_session_value' 89 | assert_response :success 90 | assert cookies['_session_id'] 91 | 92 | get '/get_session_value' 93 | assert_response :success 94 | assert_equal 'foo: "bar"', response.body 95 | session_id = cookies['_session_id'] 96 | assert session_id 97 | 98 | reset! 99 | 100 | get '/get_session_value', :_session_id => session_id 101 | assert_response :success 102 | assert_equal 'foo: nil', response.body 103 | assert_not_equal session_id, cookies['_session_id'] 104 | end 105 | 106 | end -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # Configure Rails Environment 2 | ENV["RAILS_ENV"] = "test" 3 | 4 | require File.expand_path("../dummy/config/environment.rb", __FILE__) 5 | require "rails/test_help" 6 | 7 | Rails.backtrace_cleaner.remove_silencers! 8 | 9 | # Load support files 10 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } 11 | --------------------------------------------------------------------------------