summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-05-12 14:30:23 +0200
committerAzul <azul@riseup.net>2016-05-12 14:30:23 +0200
commitaeb0f39362b2195d4aec418349538b5f8443f693 (patch)
tree66f599cac18e14e8fdc278ac080a48e35ffd68d2
parent90e2145e33913ff59b99b81a660cb730e3c7efd8 (diff)
minor: no need to vendor couchrest_session_store
-rw-r--r--vendor/gems/couchrest_session_store/.travis.yml6
-rw-r--r--vendor/gems/couchrest_session_store/Gemfile7
-rw-r--r--vendor/gems/couchrest_session_store/README.md133
-rw-r--r--vendor/gems/couchrest_session_store/Rakefile9
-rw-r--r--vendor/gems/couchrest_session_store/couchrest_session_store.gemspec25
-rw-r--r--vendor/gems/couchrest_session_store/design/Session.json8
-rw-r--r--vendor/gems/couchrest_session_store/lib/couchrest/model/database_method.rb131
-rw-r--r--vendor/gems/couchrest_session_store/lib/couchrest/model/rotation.rb263
-rw-r--r--vendor/gems/couchrest_session_store/lib/couchrest/session.rb105
-rw-r--r--vendor/gems/couchrest_session_store/lib/couchrest/session/document.rb34
-rw-r--r--vendor/gems/couchrest_session_store/lib/couchrest/session/store.rb94
-rw-r--r--vendor/gems/couchrest_session_store/lib/couchrest/session/utility.rb12
-rw-r--r--vendor/gems/couchrest_session_store/lib/couchrest_session_store.rb11
-rw-r--r--vendor/gems/couchrest_session_store/test/couch_tester.rb27
-rw-r--r--vendor/gems/couchrest_session_store/test/database_method_test.rb116
-rw-r--r--vendor/gems/couchrest_session_store/test/database_rotation_test.rb88
-rw-r--r--vendor/gems/couchrest_session_store/test/session_document_test.rb27
-rw-r--r--vendor/gems/couchrest_session_store/test/session_store_test.rb168
-rwxr-xr-xvendor/gems/couchrest_session_store/test/setup_couch.sh7
-rw-r--r--vendor/gems/couchrest_session_store/test/stress_test.rb51
-rw-r--r--vendor/gems/couchrest_session_store/test/test_clock.rb12
-rw-r--r--vendor/gems/couchrest_session_store/test/test_helper.rb9
22 files changed, 0 insertions, 1343 deletions
diff --git a/vendor/gems/couchrest_session_store/.travis.yml b/vendor/gems/couchrest_session_store/.travis.yml
deleted file mode 100644
index 073d421..0000000
--- a/vendor/gems/couchrest_session_store/.travis.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-services:
- - couchdb
-notifications:
- email: false
-before_script:
- - "test/setup_couch.sh"
diff --git a/vendor/gems/couchrest_session_store/Gemfile b/vendor/gems/couchrest_session_store/Gemfile
deleted file mode 100644
index 88b81a0..0000000
--- a/vendor/gems/couchrest_session_store/Gemfile
+++ /dev/null
@@ -1,7 +0,0 @@
-source 'https://rubygems.org'
-
-# Specify your gem's dependencies in couchrest-session-store.gemspec
-gemspec
-
-gem 'debugger'
-
diff --git a/vendor/gems/couchrest_session_store/README.md b/vendor/gems/couchrest_session_store/README.md
deleted file mode 100644
index 60e692e..0000000
--- a/vendor/gems/couchrest_session_store/README.md
+++ /dev/null
@@ -1,133 +0,0 @@
-# CouchRest::Session::Store #
-
-A simple session store based on CouchRest Model.
-
-## Setup ##
-
-`CouchRest::Session::Store` will automatically pick up the config/couch.yml
-file used by CouchRest Model.
-
-Cleaning up sessions requires a design document in the sessions database that
-enables querying by expiry. See `design/Session.json` for an example. This
-design document is loaded for tests, but you will need to load it on your own
-in a production environment. For example:
-
- curl -X PUT username:password@localhost:5984/couchrest_sessions/_design/Session --data @design/Session.json
-
-## Options ##
-
-* marshal_data: (_defaults true_) - if set to false session data will be stored
- directly in the couch document. Otherwise it's marshalled and base64 encoded
- to enable restoring ruby data structures.
-* database: database to use combined with config prefix and suffix
-* expire_after: lifetime of a session in seconds.
-
-## Dynamic Databases ##
-
-This gem also includes the module `CouchRest::Model::DatabaseMethod`, which
-allow a Model to dynamically choose what database to use.
-
-An example of specifying database dynamically:
-
- class Token < CouchRest::Model::Base
- include CouchRest::Model::DatabaseMethod
-
- use_database_method :database_name
-
- def self.database_name
- time = Time.now.utc
- "tokens_#{time.year}_#{time.month}"
- end
- end
-
-A couple notes:
-
-Once you include `CouchRest::Model::DatabaseMethod`, the database is no longer
-automatically created. In this example, you would need to run
-`Token.database.create!` or `Token.database!` in order to create the database.
-
-The symbol passed to `database_method` must match the name of a class method,
-but if there is also an instance method with the same name then this instance
-method will be called when appropriate. To state the obvious, tread lightly:
-there be dragons when generating database names that depend on properties of
-the instance.
-
-## Database Rotation ##
-
-The module `CouchRest::Model::Rotation` can be included in a Model in
-order to use dynamic databases to perform database rotation.
-
-CouchDB is not good for ephemeral data because old documents are never really
-deleted: when you deleted a document, it just appends a new revision. The bulk
-of the old data is not stored, but it does store a record for each doc id and
-revision id for the document. In the case of ephemeral data, like tokens,
-sessions, or statistics, this will quickly bloat the database with a ton of
-useless deleted documents. The proper solution is to rotate the databases:
-create a new one regularly and delete the old one entirely. This will allow
-you to recover the storage space.
-
-A better solution might be to just use a different database for all
-ephemeral data, like MariaDB or Redis. But, if you really want to use CouchDB, this
-is how you can do it.
-
-An example of specifying database rotation:
-
- class Token < CouchRest::Model::Base
- include CouchRest::Model::Rotation
-
- rotate_database 'tokens', :every => 30.days
- end
-
-Then, in a task triggered by a cron job:
-
- CouchRest::Model::Base.configure do |conf|
- conf.environment = Rails.env
- conf.connection_config_file = File.join(Rails.root, 'config', 'couchdb.admin.yml')
- end
- Token.rotate_database_now(:window => 1.day)
-
-Or perhaps:
-
- Rails.application.eager_load!
- CouchRest::Model::Rotation.descendants.each do |model|
- model.rotate_database_now
- end
-
-The `:window` argument to `rotate_database_now` specifies how far in advance we
-should create the new database (default 1.day). For ideal behavior, this value
-should be GREATER than or equal to the frequency with which the cron job is
-run. For example, if the cron job is run every hour, the argument can be
-`1.hour`, `2.hours`, `1.day`, but not `20.minutes`.
-
-The method `rotate_database_now` will do nothing if the database has already
-been rotated. Otherwise, as needed, it will create the new database, create
-the design documents, set up replication between the old and new databases,
-and delete the old database (once it is not used anymore).
-
-These actions will require admin access, so if your application normally runs
-without admin rights you will need specify a different configuration for
-CouchRest::Model before `rotate_database_now` is called.
-
-Known issues:
-
-* If you change the rotation period, there will be a break in the rotation
- (old documents will not get replicated to the new rotated db) and the old db
- will not get automatically deleted.
-
-* Calling `Model.database.delete!` will not necessarily remove all the
- relevant databases because of the way prior and future databases are kept
- for the 'window' period.
-
-## Changes ##
-
-0.3.0
-
-* Added support for dynamic and rotating databases.
-
-0.2.4
-
-* Do not crash if can't connect to CouchDB
-
-0.2.3
-
-* Better retry and conflict catching.d \ No newline at end of file
diff --git a/vendor/gems/couchrest_session_store/Rakefile b/vendor/gems/couchrest_session_store/Rakefile
deleted file mode 100644
index 8e1dc9c..0000000
--- a/vendor/gems/couchrest_session_store/Rakefile
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/usr/bin/env rake
-require "bundler/gem_tasks"
-require 'rake/testtask'
-
-task default: [:test]
-
-Rake::TestTask.new do |t|
- t.pattern = "test/*_test.rb"
-end
diff --git a/vendor/gems/couchrest_session_store/couchrest_session_store.gemspec b/vendor/gems/couchrest_session_store/couchrest_session_store.gemspec
deleted file mode 100644
index bf3b2b2..0000000
--- a/vendor/gems/couchrest_session_store/couchrest_session_store.gemspec
+++ /dev/null
@@ -1,25 +0,0 @@
-# _*_ encoding: utf-8 -*-
-
-Gem::Specification.new do |gem|
-
- gem.authors = ["Azul"]
- gem.email = ["azul@leap.se"]
- gem.summary = "A Rails Session Store based on CouchRest Model"
- gem.description = gem.summary
- gem.homepage = "http://github.com/azul/couchrest_session_store"
-
- gem.has_rdoc = true
-# gem.extra_rdoc_files = ["LICENSE"]
-
- gem.files = `git ls-files`.split("\n")
- gem.name = "couchrest_session_store"
- gem.require_paths = ["lib"]
- gem.version = '0.4.0'
-
- gem.add_dependency "couchrest"
- gem.add_dependency "couchrest_model"
- gem.add_dependency "actionpack", '~> 4.0'
-
- gem.add_development_dependency "minitest"
- gem.add_development_dependency "rake"
-end
diff --git a/vendor/gems/couchrest_session_store/design/Session.json b/vendor/gems/couchrest_session_store/design/Session.json
deleted file mode 100644
index 7020278..0000000
--- a/vendor/gems/couchrest_session_store/design/Session.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "views": {
- "by_expires": {
- "reduce": "_sum",
- "map": "function(doc) {\n if(typeof doc.expires !== \"undefined\") {\n emit(doc.expires, 1);\n }\n}\n"
- }
- }
-}
diff --git a/vendor/gems/couchrest_session_store/lib/couchrest/model/database_method.rb b/vendor/gems/couchrest_session_store/lib/couchrest/model/database_method.rb
deleted file mode 100644
index 6ecc8f3..0000000
--- a/vendor/gems/couchrest_session_store/lib/couchrest/model/database_method.rb
+++ /dev/null
@@ -1,131 +0,0 @@
-#
-# Allow setting the database to happen dynamically.
-#
-# Unlike normal CouchRest::Model, the database is not automatically created
-# unless you call database!()
-#
-# The method specified by `database_method` must exist as a class method but
-# may optionally also exist as an instance method.
-#
-
-module CouchRest
- module Model
- module DatabaseMethod
- extend ActiveSupport::Concern
-
- def database
- if self.class.database_method
- self.class.server.database(call_database_method)
- else
- self.class.database
- end
- end
-
- def database!
- if self.class.database_method
- self.class.server.database!(call_database_method)
- else
- self.class.database!
- end
- end
-
- def database_exists?(db_name)
- self.class.database_exists?(db_name)
- end
-
- #
- # The normal CouchRest::Model::Base comparison checks if the model's
- # database objects are the same. That is not good for use here, since
- # the objects will always be different. Instead, we compare the string
- # that each database evaluates to.
- #
- def ==(other)
- return false unless other.is_a?(Base)
- if id.nil? && other.id.nil?
- to_hash == other.to_hash
- else
- id == other.id && database.to_s == other.database.to_s
- end
- end
- alias :eql? :==
-
- protected
-
- def call_database_method
- if self.respond_to?(self.class.database_method)
- name = self.send(self.class.database_method)
- self.class.db_name_with_prefix(name)
- else
- self.class.send(:call_database_method)
- end
- end
-
- module ClassMethods
-
- def database_method(method = nil)
- if method
- @database_method = method
- end
- @database_method
- end
- alias :use_database_method :database_method
-
- def database
- if database_method
- if !self.respond_to?(database_method)
- raise ArgumentError.new("Incorrect argument to database_method(): no such method '#{method}' found in class #{self}.")
- end
- self.server.database(call_database_method)
- else
- @database ||= prepare_database(super)
- end
- end
-
- def database!
- if database_method
- self.server.database!(call_database_method)
- else
- @database ||= prepare_database(super)
- end
- end
-
- #
- # same as database(), but allows for an argument that gets passed through to
- # database method.
- #
- def choose_database(*args)
- self.server.database(call_database_method(*args))
- end
-
- def db_name_with_prefix(name)
- conf = self.send(:connection_configuration)
- [conf[:prefix], name, conf[:suffix]].reject{|i|i.to_s.empty?}.join(conf[:join])
- end
-
- def database_exists?(name)
- name = db_name_with_prefix(name)
- begin
- CouchRest.head "#{self.server.uri}/#{name}"
- return true
- rescue CouchRest::NotFound
- return false
- end
- end
-
- protected
-
- def call_database_method(*args)
- name = nil
- method = self.method(database_method)
- if method.arity == 0
- name = method.call
- else
- name = method.call(*args)
- end
- db_name_with_prefix(name)
- end
-
- end
- end
- end
-end
diff --git a/vendor/gems/couchrest_session_store/lib/couchrest/model/rotation.rb b/vendor/gems/couchrest_session_store/lib/couchrest/model/rotation.rb
deleted file mode 100644
index 9e1a5c3..0000000
--- a/vendor/gems/couchrest_session_store/lib/couchrest/model/rotation.rb
+++ /dev/null
@@ -1,263 +0,0 @@
-module CouchRest
- module Model
- module Rotation
- extend ActiveSupport::Concern
- include CouchRest::Model::DatabaseMethod
-
- included do
- use_database_method :rotated_database_name
- end
-
- def create(*args)
- super(*args)
- rescue CouchRest::NotFound => exc
- raise storage_missing(exc)
- end
-
- def update(*args)
- super(*args)
- rescue CouchRest::NotFound => exc
- raise storage_missing(exc)
- end
-
- def destroy(*args)
- super(*args)
- rescue CouchRest::NotFound => exc
- raise storage_missing(exc)
- end
-
- private
-
- # returns a special 'storage missing' exception when the db has
- # not been created. very useful, since this happens a lot and a
- # generic 404 is not that helpful.
- def storage_missing(exc)
- if exc.http_body =~ /no_db_file/
- CouchRest::StorageMissing.new(exc.response, database)
- else
- exc
- end
- end
-
- public
-
- module ClassMethods
- #
- # Set up database rotation.
- #
- # base_name -- the name of the db before the rotation number is
- # appended.
- #
- # options -- one of:
- #
- # * :every -- frequency of rotation
- # * :expiration_field - what field to use to determine if a
- # document is expired.
- # * :timestamp_field - alternately, what field to use for the
- # document timestamp.
- # * :timeout -- used to expire documents with only a timestamp
- # field (in minutes)
- #
- def rotate_database(base_name, options={})
- @rotation_base_name = base_name
- @rotation_every = (options.delete(:every) || 30.days).to_i
- @expiration_field = options.delete(:expiration_field)
- @timestamp_field = options.delete(:timestamp_field)
- @timeout = options.delete(:timeout)
- if options.any?
- raise ArgumentError.new('Could not understand options %s' % options.keys)
- end
- end
-
- #
- # Check to see if dbs should be rotated. The :window
- # argument specifies how far in advance we should
- # create the new database (default 1.day).
- #
- # This method relies on the assumption that it is called
- # at least once within each @rotation_every period.
- #
- def rotate_database_now(options={})
- window = options[:window] || 1.day
-
- now = Time.now.utc
- current_name = rotated_database_name(now)
- current_count = now.to_i/@rotation_every
-
- next_time = window.from_now.utc
- next_name = rotated_database_name(next_time)
- next_count = current_count+1
-
- prev_name = current_name.sub(/(\d+)$/) {|i| i.to_i-1}
- replication_started = false
- old_name = prev_name.sub(/(\d+)$/) {|i| i.to_i-1} # even older than prev_name
- trailing_edge_time = window.ago.utc
-
- if !database_exists?(current_name)
- # we should have created the current db earlier, but if somehow
- # it is missing we must make sure it exists.
- create_new_rotated_database(:from => prev_name, :to => current_name)
- replication_started = true
- end
-
- if next_time.to_i/@rotation_every >= next_count && !database_exists?(next_name)
- # time to create the next db in advance of actually needing it.
- create_new_rotated_database(:from => current_name, :to => next_name)
- end
-
- if trailing_edge_time.to_i/@rotation_every == current_count
- # delete old dbs, but only after window time has past since the last rotation
- if !replication_started && database_exists?(prev_name)
- # delete previous, but only if we didn't just start replicating from it
- self.server.database(db_name_with_prefix(prev_name)).delete!
- end
- if database_exists?(old_name)
- # there are some edge cases, when rotate_database_now is run
- # infrequently, that an older db might be left around.
- self.server.database(db_name_with_prefix(old_name)).delete!
- end
- end
- end
-
- def rotated_database_name(time=nil)
- unless @rotation_base_name && @rotation_every
- raise ArgumentError.new('missing @rotation_base_name or @rotation_every')
- end
- time ||= Time.now.utc
- units = time.to_i / @rotation_every.to_i
- "#{@rotation_base_name}_#{units}"
- end
-
- #
- # create a new empty database.
- #
- def create_database!(name=nil)
- db = if name
- self.server.database!(db_name_with_prefix(name))
- else
- self.database!
- end
- create_rotation_filter(db)
- if self.respond_to?(:design_doc)
- design_doc.sync!(db)
- # or maybe this?:
- #self.design_docs.each do |design|
- # design.migrate(to_db)
- #end
- end
- return db
- end
-
- protected
-
- #
- # Creates database named by options[:to]. Optionally, set up
- # continuous replication from the options[:from] db, if it exists. The
- # assumption is that the from db will be destroyed later, cleaning up
- # the replication once it is no longer needed.
- #
- # This method will also copy design documents if present in the from
- # db, in the CouchRest::Model, or in a database named after
- # @rotation_base_name.
- #
- def create_new_rotated_database(options={})
- from = options[:from]
- to = options[:to]
- to_db = self.create_database!(to)
- if database_exists?(@rotation_base_name)
- base_db = self.server.database(db_name_with_prefix(@rotation_base_name))
- copy_design_docs(base_db, to_db)
- end
- if from && from != to && database_exists?(from)
- from_db = self.server.database(db_name_with_prefix(from))
- replicate_old_to_new(from_db, to_db)
- end
- end
-
- def copy_design_docs(from, to)
- params = {:startkey => '_design/', :endkey => '_design0', :include_docs => true}
- from.documents(params) do |doc_hash|
- design = doc_hash['doc']
- begin
- to.get(design['_id'])
- rescue CouchRest::NotFound
- design.delete('_rev')
- to.save_doc(design)
- end
- end
- end
-
- def create_rotation_filter(db)
- name = 'rotation_filter'
- filter_string = if @expiration_field
- NOT_EXPIRED_FILTER % {:expires => @expiration_field}
- elsif @timestamp_field && @timeout
- NOT_TIMED_OUT_FILTER % {:timestamp => @timestamp_field, :timeout => (60 * @timeout)}
- else
- NOT_DELETED_FILTER
- end
- filters = {"not_expired" => filter_string}
- db.save_doc("_id" => "_design/#{name}", "filters" => filters)
- rescue CouchRest::Conflict
- end
-
- #
- # Replicates documents from_db to to_db, skipping documents that have
- # expired or been deleted.
- #
- # NOTE: It would be better if we could do this:
- #
- # from_db.replicate_to(to_db, true, false,
- # :filter => 'rotation_filter/not_expired')
- #
- # But replicate_to() does not support a filter argument, so we call
- # the private method replication() directly.
- #
- def replicate_old_to_new(from_db, to_db)
- create_rotation_filter(from_db)
- from_db.send(:replicate, to_db, true, :source => from_db.name, :filter => 'rotation_filter/not_expired')
- end
-
- #
- # Three different filters, depending on how the model is set up.
- #
- # NOT_EXPIRED_FILTER is used when there is a single field that
- # contains an absolute time for when the document has expired. The
- #
- # NOT_TIMED_OUT_FILTER is used when there is a field that records the
- # timestamp of the last time the document was used. The expiration in
- # this case is calculated from the timestamp plus @timeout.
- #
- # NOT_DELETED_FILTER is used when the other two cannot be.
- #
- NOT_EXPIRED_FILTER = "" +
-%[function(doc, req) {
- if (doc._deleted) {
- return false;
- } else if (typeof(doc.%{expires}) != "undefined") {
- return Date.now() < (new Date(doc.%{expires})).getTime();
- } else {
- return true;
- }
-}]
-
- NOT_TIMED_OUT_FILTER = "" +
-%[function(doc, req) {
- if (doc._deleted) {
- return false;
- } else if (typeof(doc.%{timestamp}) != "undefined") {
- return Date.now() < (new Date(doc.%{timestamp})).getTime() + %{timeout};
- } else {
- return true;
- }
-}]
-
- NOT_DELETED_FILTER = "" +
-%[function(doc, req) {
- return !doc._deleted;
-}]
-
- end
- end
- end
-end
diff --git a/vendor/gems/couchrest_session_store/lib/couchrest/session.rb b/vendor/gems/couchrest_session_store/lib/couchrest/session.rb
deleted file mode 100644
index 416a88d..0000000
--- a/vendor/gems/couchrest_session_store/lib/couchrest/session.rb
+++ /dev/null
@@ -1,105 +0,0 @@
-class CouchRest::Session
-end
-
-require 'couchrest/session/utility'
-require 'couchrest/session/document'
-
-module CouchRest
-
- class StorageMissing < Exception
- attr_reader :db
- def initialize(request, db)
- super(request)
- @db = db.name
- @message = "The database '#{db}' does not exist."
- end
- end
-
- class Session
- include CouchRest::Session::Utility
-
- def self.fetch(sid)
- self.allocate.tap do |session_doc|
- session_doc.fetch(sid) || raise(CouchRest::NotFound)
- end
- end
-
- def self.build(sid, session, options = {})
- session_doc = CouchRest::Session::Document.new "_id" => sid
- self.new(session_doc).
- update session, options
- end
-
- def self.build_or_update(sid, session, options = {})
- options[:marshal_data] = true if options[:marshal_data].nil?
- self.fetch(sid).
- update session, options
- rescue CouchRest::NotFound
- self.build sid, session, options
- end
-
- def initialize(doc)
- @doc = doc
- end
-
- def fetch(sid = nil)
- @doc = CouchRest::Session::Document.fetch(sid || doc['_id'])
- end
-
- def to_session
- if doc["marshalled"]
- session = unmarshal(doc["data"])
- else
- session = doc["data"]
- end
- return session
- end
-
- def delete
- doc.destroy
- end
-
- def update(session, options)
- # clean up old data but leave id and revision intact
- doc.reject! { |k,_v| k[0] != '_' }
- doc.merge! data_for_doc(session, options)
- self
- end
-
- def save
- doc.save
- rescue CouchRest::Conflict
- fetch
- retry
- rescue CouchRest::NotFound => exc
- if exc.http_body =~ /no_db_file/
- exc = CouchRest::StorageMissing.new(exc.response, doc.database)
- end
- raise exc
- end
-
- def expired?
- expires && expires < Time.now
- end
-
- protected
-
- attr_reader :doc
-
- def data_for_doc(session, options)
- { "data" => options[:marshal_data] ? marshal(session) : session,
- "marshalled" => options[:marshal_data],
- "expires" => expiry_from_options(options) }
- end
-
- def expiry_from_options(options)
- expire_after = options[:expire_after]
- expire_after && (Time.now + expire_after).utc
- end
-
- def expires
- doc["expires"] && Time.iso8601(doc["expires"])
- end
-
- end
-end
diff --git a/vendor/gems/couchrest_session_store/lib/couchrest/session/document.rb b/vendor/gems/couchrest_session_store/lib/couchrest/session/document.rb
deleted file mode 100644
index dc938cf..0000000
--- a/vendor/gems/couchrest_session_store/lib/couchrest/session/document.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-require 'time'
-
-class CouchRest::Session::Document < CouchRest::Document
- include CouchRest::Model::Configuration
- include CouchRest::Model::Connection
- include CouchRest::Model::Rotation
-
- rotate_database 'sessions',
- :every => 1.month, :expiration_field => :expires
-
- def self.fetch(id)
- database.get(id)
- end
-
- def self.find_by_expires(options = {})
- options[:reduce] ||= false
- design = database.get '_design/Session'
- response = design.view :by_expires, options
- response['rows']
- end
-
- def self.create_database!(name=nil)
- db = super(name)
- begin
- db.get('_design/Session')
- rescue CouchRest::NotFound
- design = File.read(File.expand_path('../../../../design/Session.json', __FILE__))
- design = JSON.parse(design)
- db.save_doc(design.merge({"_id" => "_design/Session"}))
- end
- db
- end
-
-end
diff --git a/vendor/gems/couchrest_session_store/lib/couchrest/session/store.rb b/vendor/gems/couchrest_session_store/lib/couchrest/session/store.rb
deleted file mode 100644
index 516d5dd..0000000
--- a/vendor/gems/couchrest_session_store/lib/couchrest/session/store.rb
+++ /dev/null
@@ -1,94 +0,0 @@
-class CouchRest::Session::Store < ActionDispatch::Session::AbstractStore
-
- # delegate configure to document
- def self.configure(*args, &block)
- CouchRest::Session::Document.configure *args, &block
- end
-
- def self.set_options(options)
- @options = options
- if @options[:database]
- CouchRest::Session::Document.use_database @options[:database]
- end
- end
-
- def initialize(app, options = {})
- super
- self.class.set_options(options)
- end
-
- def cleanup(rows)
- rows.each do |row|
- doc = CouchRest::Session::Document.fetch(row['id'])
- doc.delete
- end
- end
-
- def expired
- CouchRest::Session::Document.find_by_expires startkey: 1,
- endkey: Time.now.utc.iso8601
- end
-
- def never_expiring
- CouchRest::Session::Document.find_by_expires endkey: 1
- end
-
- private
-
- def get_session(env, sid)
- if session = fetch_session(sid)
- [sid, session]
- else
- [generate_sid, {}]
- end
- rescue CouchRest::NotFound
- # session data does not exist anymore
- return [sid, {}]
- rescue CouchRest::Unauthorized,
- Errno::EHOSTUNREACH,
- Errno::ECONNREFUSED => e
- # can't connect to couch. We add some status to the session
- # so the app can react. (Display error for example)
- return [sid, {"_status" => {"couch" => "unreachable"}}]
- end
-
- def set_session(env, sid, session, options)
- raise CouchRest::NotFound if /^_design\/(.*)/ =~ sid
- couchrest_session = build_or_update_doc(sid, session, options)
- couchrest_session.save
- return sid
- # if we can't store the session we just return false.
- rescue CouchRest::Unauthorized,
- Errno::EHOSTUNREACH,
- Errno::ECONNREFUSED => e
- return false
- end
-
- def destroy_session(env, sid, options)
- doc = secure_get(sid)
- doc.delete
- generate_sid unless options[:drop]
- rescue CouchRest::NotFound
- # already destroyed - we're done.
- generate_sid unless options[:drop]
- end
-
- def fetch_session(sid)
- return nil unless sid
- couchrest_session = secure_get(sid)
- couchrest_session.to_session unless couchrest_session.expired?
- end
-
- def build_or_update_doc(sid, session, options)
- CouchRest::Session.build_or_update(sid, session, options)
- end
-
- # prevent access to design docs
- # this should be prevented on a couch permission level as well.
- # but better be save than sorry.
- def secure_get(sid)
- raise CouchRest::NotFound if /^_design\/(.*)/ =~ sid
- CouchRest::Session.fetch(sid)
- end
-
-end
diff --git a/vendor/gems/couchrest_session_store/lib/couchrest/session/utility.rb b/vendor/gems/couchrest_session_store/lib/couchrest/session/utility.rb
deleted file mode 100644
index 3982c28..0000000
--- a/vendor/gems/couchrest_session_store/lib/couchrest/session/utility.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-module CouchRest::Session::Utility
- module_function
-
- def marshal(data)
- ::Base64.encode64(Marshal.dump(data)) if data
- end
-
- def unmarshal(data)
- Marshal.load(::Base64.decode64(data)) if data
- end
-
-end
diff --git a/vendor/gems/couchrest_session_store/lib/couchrest_session_store.rb b/vendor/gems/couchrest_session_store/lib/couchrest_session_store.rb
deleted file mode 100644
index 78c6a25..0000000
--- a/vendor/gems/couchrest_session_store/lib/couchrest_session_store.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require 'couchrest'
-require 'couchrest_model'
-# ensure compatibility with couchrest_model
-gem 'actionpack', '~> 4.0'
-require 'action_dispatch'
-
-require 'couchrest/model/database_method'
-require 'couchrest/model/rotation'
-require 'couchrest/session'
-require 'couchrest/session/store'
-require 'couchrest/session/document'
diff --git a/vendor/gems/couchrest_session_store/test/couch_tester.rb b/vendor/gems/couchrest_session_store/test/couch_tester.rb
deleted file mode 100644
index b623044..0000000
--- a/vendor/gems/couchrest_session_store/test/couch_tester.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# Access the couch directly so we can test its state without relying
-# on the SessionStore
-#
-
-class CouchTester < CouchRest::Document
- include CouchRest::Model::Configuration
- include CouchRest::Model::Connection
- include CouchRest::Model::Rotation
-
- rotate_database 'sessions',
- :every => 1.month, :expiration_field => :expires
-
- def initialize(options = {})
- end
-
- def get(sid)
- database.get(sid)
- end
-
- def update(sid, diff)
- doc = database.get(sid)
- doc.merge! diff
- database.save_doc(doc)
- end
-
-end
diff --git a/vendor/gems/couchrest_session_store/test/database_method_test.rb b/vendor/gems/couchrest_session_store/test/database_method_test.rb
deleted file mode 100644
index 18985c3..0000000
--- a/vendor/gems/couchrest_session_store/test/database_method_test.rb
+++ /dev/null
@@ -1,116 +0,0 @@
-require_relative 'test_helper'
-
-class DatabaseMethodTest < MiniTest::Test
-
- class TestModel < CouchRest::Model::Base
- include CouchRest::Model::DatabaseMethod
-
- use_database_method :db_name
- property :dbname, String
- property :confirm, String
-
- def db_name
- "test_db_#{self[:dbname]}"
- end
- end
-
- def test_instance_method
- doc1 = TestModel.new({:dbname => 'one'})
- doc1.database.create!
- assert doc1.database.root.ends_with?('test_db_one')
- assert doc1.save
- doc1.update_attributes(:confirm => 'yep')
-
- doc2 = TestModel.new({:dbname => 'two'})
- doc2.database.create!
- assert doc2.database.root.ends_with?('test_db_two')
- assert doc2.save
- doc2.confirm = 'sure'
- doc2.save!
-
- doc1_copy = CouchRest.get([doc1.database.root, doc1.id].join('/'))
- assert_equal "yep", doc1_copy["confirm"]
-
- doc2_copy = CouchRest.get([doc2.database.root, doc2.id].join('/'))
- assert_equal "sure", doc2_copy["confirm"]
-
- doc1.database.delete!
- doc2.database.delete!
- end
-
- def test_switch_db
- doc_red = TestModel.new({:dbname => 'red', :confirm => 'rose'})
- doc_red.database.create!
- root = doc_red.database.root
-
- doc_blue = doc_red.clone
- doc_blue.dbname = 'blue'
- doc_blue.database!
- doc_blue.save!
-
- doc_blue_copy = CouchRest.get([root.sub('red','blue'), doc_blue.id].join('/'))
- assert_equal "rose", doc_blue_copy["confirm"]
-
- doc_red.database.delete!
- doc_blue.database.delete!
- end
-
- #
- # A test scenario for database_method in which some user accounts
- # are stored in a seperate temporary database (so that the test
- # accounts don't bloat the normal database).
- #
-
- class User < CouchRest::Model::Base
- include CouchRest::Model::DatabaseMethod
-
- use_database_method :db_name
- property :login, String
- before_save :create_db
-
- class << self
- def get(id, db = database)
- result = super(id, db)
- if result.nil?
- return super(id, choose_database('test-user'))
- else
- return result
- end
- end
- alias :find :get
- end
-
- protected
-
- def self.db_name(login = nil)
- if !login.nil? && login =~ /test-user/
- 'tmp_users'
- else
- 'users'
- end
- end
-
- def db_name
- self.class.db_name(self.login)
- end
-
- def create_db
- unless database_exists?(db_name)
- self.database!
- end
- end
-
- end
-
- def test_tmp_user_db
- user1 = User.new({:login => 'test-user-1'})
- assert user1.save
- assert User.find(user1.id), 'should find user in tmp_users'
- assert_equal user1.login, User.find(user1.id).login
- assert_equal 'test-user-1', User.server.database('couchrest_tmp_users').get(user1.id)['login']
- assert_raises CouchRest::NotFound do
- User.server.database('couchrest_users').get(user1.id)
- end
- end
-
-end
diff --git a/vendor/gems/couchrest_session_store/test/database_rotation_test.rb b/vendor/gems/couchrest_session_store/test/database_rotation_test.rb
deleted file mode 100644
index 856db11..0000000
--- a/vendor/gems/couchrest_session_store/test/database_rotation_test.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-require_relative 'test_helper'
-
-class RotationTest < MiniTest::Test
-
- class Token < CouchRest::Model::Base
- include CouchRest::Model::Rotation
- property :token, String
- rotate_database 'test_rotate', :every => 1.day
- end
-
- TEST_DB_RE = /test_rotate_\d+/
-
- def test_rotate
- delete_all_dbs
- doc = nil
- original_name = nil
- next_db_name = nil
-
- Time.stub :now, Time.gm(2015,3,7,0) do
- Token.create_database!
- doc = Token.create!(:token => 'aaaa')
- original_name = Token.rotated_database_name
- assert database_exists?(original_name)
- assert_equal 1, count_dbs
- end
-
- # do nothing yet
- Time.stub :now, Time.gm(2015,3,7,22) do
- Token.rotate_database_now(:window => 1.hour)
- assert_equal original_name, Token.rotated_database_name
- assert_equal 1, count_dbs
- end
-
- # create next db, but don't switch yet.
- Time.stub :now, Time.gm(2015,3,7,23) do
- Token.rotate_database_now(:window => 1.hour)
- assert_equal 2, count_dbs
- next_db_name = Token.rotated_database_name(Time.gm(2015,3,8))
- assert original_name != next_db_name
- assert database_exists?(next_db_name)
- sleep 0.2 # allow time for documents to replicate
- assert_equal(
- Token.get(doc.id).token,
- Token.get(doc.id, database(next_db_name)).token
- )
- end
-
- # use next db
- Time.stub :now, Time.gm(2015,3,8) do
- Token.rotate_database_now(:window => 1.hour)
- assert_equal 2, count_dbs
- assert_equal next_db_name, Token.rotated_database_name
- token = Token.get(doc.id)
- token.update_attributes(:token => 'bbbb')
- assert_equal 'bbbb', Token.get(doc.id).token
- assert_equal 'aaaa', Token.get(doc.id, database(original_name)).token
- end
-
- # delete prior db
- Time.stub :now, Time.gm(2015,3,8,1) do
- Token.rotate_database_now(:window => 1.hour)
- assert_equal 1, count_dbs
- end
- end
-
- private
-
- def database(db_name)
- Token.server.database(Token.db_name_with_prefix(db_name))
- end
-
- def database_exists?(dbname)
- Token.database_exists?(dbname)
- end
-
- def delete_all_dbs(regexp=TEST_DB_RE)
- Token.server.databases.each do |db|
- if regexp.match(db)
- Token.server.database(db).delete!
- end
- end
- end
-
- def count_dbs(regexp=TEST_DB_RE)
- Token.server.databases.grep(regexp).count
- end
-
-end
diff --git a/vendor/gems/couchrest_session_store/test/session_document_test.rb b/vendor/gems/couchrest_session_store/test/session_document_test.rb
deleted file mode 100644
index 43fbbca..0000000
--- a/vendor/gems/couchrest_session_store/test/session_document_test.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-require_relative 'test_helper'
-
-class SessionDocumentTest < MiniTest::Test
-
- def test_storing_session
- sid = '1234'
- session = {'a' => 'b'}
- options = {}
- couchrest_session = CouchRest::Session.build_or_update(sid, session, options)
- couchrest_session.save
- couchrest_session.fetch(sid)
- assert_equal session, couchrest_session.to_session
- end
-
- def test_storing_session_with_conflict
- sid = '1234'
- session = {'a' => 'b'}
- options = {}
- cr_session = CouchRest::Session.build_or_update(sid, session, options)
- cr_session2 = CouchRest::Session.build_or_update(sid, session, options)
- cr_session.save
- cr_session2.save
- cr_session2.fetch(sid)
- assert_equal session, cr_session2.to_session
- end
-
-end
diff --git a/vendor/gems/couchrest_session_store/test/session_store_test.rb b/vendor/gems/couchrest_session_store/test/session_store_test.rb
deleted file mode 100644
index 5949ae6..0000000
--- a/vendor/gems/couchrest_session_store/test/session_store_test.rb
+++ /dev/null
@@ -1,168 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/test_helper')
-
-class SessionStoreTest < MiniTest::Test
-
- def test_session_initialization
- sid, session = store.send :get_session, env, nil
- assert sid
- assert_equal Hash.new, session
- end
-
- def test_normal_session_flow
- sid, session = never_expiring_session
- assert_equal [sid, session], store.send(:get_session, env, sid)
- store.send :destroy_session, env, sid, {}
- end
-
- def test_updating_session
- sid, session = never_expiring_session
- session[:bla] = "blub"
- store.send :set_session, env, sid, session, {}
- assert_equal [sid, session], store.send(:get_session, env, sid)
- store.send :destroy_session, env, sid, {}
- end
-
- def test_prevent_access_to_design_docs
- sid = '_design/bla'
- session = {views: 'my hacked view'}
- assert_raises CouchRest::NotFound do
- store_session(sid, session)
- end
- end
-
- def test_unmarshalled_session_flow
- sid, session = init_session
- store_session sid, session, :marshal_data => false
- new_sid, new_session = store.send(:get_session, env, sid)
- assert_equal sid, new_sid
- assert_equal session[:key], new_session["key"]
- store.send :destroy_session, env, sid, {}
- end
-
- def test_unmarshalled_data
- sid, session = init_session
- store_session sid, session, :marshal_data => false
- couch = CouchTester.new
- data = couch.get(sid)["data"]
- assert_equal session[:key], data["key"]
- end
-
- def test_logout_in_between
- sid, session = never_expiring_session
- store.send :destroy_session, env, sid, {}
- other_sid, other_session = store.send(:get_session, env, sid)
- assert_equal Hash.new, other_session
- end
-
- def test_can_logout_twice
- sid, session = never_expiring_session
- store.send :destroy_session, env, sid, {}
- store.send :destroy_session, env, sid, {}
- other_sid, other_session = store.send(:get_session, env, sid)
- assert_equal Hash.new, other_session
- end
-
- def test_stored_and_not_expired_yet
- sid, session = expiring_session
- couchrest_session = CouchRest::Session.fetch(sid)
- expires = couchrest_session.send :expires
- assert expires
- assert !couchrest_session.expired?
- assert (expires - Time.now) > 0, "Exiry should be in the future"
- assert (expires - Time.now) <= 300, "Should expire after 300 seconds - not more"
- assert_equal [sid, session], store.send(:get_session, env, sid)
- end
-
- def test_stored_but_expired
- sid, session = expired_session
- other_sid, other_session = store.send(:get_session, env, sid)
- assert_equal Hash.new, other_session, "session should have expired"
- assert other_sid != sid
- end
-
- def test_find_expired_sessions
- expired, expiring, never_expiring = seed_sessions
- expired_session_ids = store.expired.map {|row| row['id']}
- assert expired_session_ids.include?(expired)
- assert !expired_session_ids.include?(expiring)
- assert !expired_session_ids.include?(never_expiring)
- end
-
- def test_find_never_expiring_sessions
- expired, expiring, never_expiring = seed_sessions
- never_expiring_session_ids = store.never_expiring.map {|row| row['id']}
- assert never_expiring_session_ids.include?(never_expiring)
- assert !never_expiring_session_ids.include?(expiring)
- assert !never_expiring_session_ids.include?(expired)
- end
-
- def test_cleanup_expired_sessions
- sid, session = expired_session
- store.cleanup(store.expired)
- assert_raises CouchRest::NotFound do
- CouchTester.new.get(sid)
- end
- end
-
- def test_keep_fresh_during_cleanup
- sid, session = expiring_session
- store.cleanup(store.expired)
- assert_equal [sid, session], store.send(:get_session, env, sid)
- end
-
- def test_store_without_expiry
- sid, session = never_expiring_session
- couch = CouchTester.new
- assert_nil couch.get(sid)["expires"]
- assert_equal [sid, session], store.send(:get_session, env, sid)
- end
-
- def app
- nil
- end
-
- def store(options = {})
- @store ||= CouchRest::Session::Store.new(app, options)
- end
-
- def env(settings = {})
- env ||= settings
- end
-
- # returns the session ids of an expired, and expiring and a never
- # expiring session
- def seed_sessions
- [expired_session, expiring_session, never_expiring_session].map(&:first)
- end
-
- def never_expiring_session
- store_session *init_session
- end
-
- def expiring_session
- sid, session = init_session
- store_session(sid, session, expire_after: 300)
- end
-
- def expired_session
- expire_session *expiring_session
- end
-
- def init_session
- sid, session = store.send :get_session, env, nil
- session[:key] = "stub"
- return sid, session
- end
-
- def store_session(sid, session, options = {})
- store.send :set_session, env, sid, session, options
- return sid, session
- end
-
- def expire_session(sid, session)
- CouchTester.new.update sid,
- "expires" => (Time.now - 10.minutes).utc.iso8601
- return sid, session
- end
-
-end
diff --git a/vendor/gems/couchrest_session_store/test/setup_couch.sh b/vendor/gems/couchrest_session_store/test/setup_couch.sh
deleted file mode 100755
index 731534b..0000000
--- a/vendor/gems/couchrest_session_store/test/setup_couch.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-HOST="http://localhost:5984"
-echo "couch version :"
-curl -X GET $HOST
-
-curl -X PUT $HOST/couchrest_sessions
-curl -X PUT $HOST/couchrest_sessions/_design/Session --data @design/Session.json
-
diff --git a/vendor/gems/couchrest_session_store/test/stress_test.rb b/vendor/gems/couchrest_session_store/test/stress_test.rb
deleted file mode 100644
index b74b132..0000000
--- a/vendor/gems/couchrest_session_store/test/stress_test.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-require_relative 'test_helper'
-
-#
-# This doesn't really test much, but is useful if you want to see what happens
-# when you have a lot of documents.
-#
-
-class StressTest < MiniTest::Test
-
- COUNT = 200 # change to 200,000 if you dare
-
- class Stress < CouchRest::Model::Base
- include CouchRest::Model::Rotation
- property :token, String
- property :expires_at, Time
- rotate_database 'stress_test', :every => 1.day, :expiration_field => :expires_at
- end
-
- def test_stress
- delete_all_dbs /^couchrest_stress_test_\d+$/
-
- Stress.database!
- COUNT.times do |i|
- doc = Stress.create!(:token => SecureRandom.hex(32), :expires_at => expires(i))
- end
-
- Time.stub :now, 1.day.from_now do
- Stress.rotate_database_now(:window => 1.hour)
- sleep 0.5
- assert_equal (COUNT/100)+1, Stress.database.info["doc_count"]
- end
- end
-
- private
-
- def delete_all_dbs(regexp=TEST_DB_RE)
- Stress.server.databases.each do |db|
- if regexp.match(db)
- Stress.server.database(db).delete!
- end
- end
- end
-
- def expires(i)
- if i % 100 == 0
- 1.hour.from_now.utc
- else
- 1.hour.ago.utc
- end
- end
-end
diff --git a/vendor/gems/couchrest_session_store/test/test_clock.rb b/vendor/gems/couchrest_session_store/test/test_clock.rb
deleted file mode 100644
index 4170763..0000000
--- a/vendor/gems/couchrest_session_store/test/test_clock.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-class TestClock
- attr_accessor :now
-
- def initialize(tick = 60)
- @tick = tick
- @now = Time.now
- end
-
- def tick(seconds = nil)
- @now += seconds || @tick
- end
-end
diff --git a/vendor/gems/couchrest_session_store/test/test_helper.rb b/vendor/gems/couchrest_session_store/test/test_helper.rb
deleted file mode 100644
index 32f147d..0000000
--- a/vendor/gems/couchrest_session_store/test/test_helper.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require "rubygems"
-gem 'minitest'
-require 'minitest/autorun'
-require File.expand_path(File.dirname(__FILE__) + '/../lib/couchrest_session_store.rb')
-require File.expand_path(File.dirname(__FILE__) + '/couch_tester.rb')
-require File.expand_path(File.dirname(__FILE__) + '/test_clock.rb')
-
-# Create the session db if it does not already exist.
-CouchRest::Session::Document.create_database!