├── .gitignore ├── README ├── Rakefile ├── config.ru ├── db ├── config.yml └── migrate │ ├── 20081103171327_create_users.rb │ ├── 20081106072031_create_sessions.rb │ ├── 20090914022630_activation_and_password_reset.rb │ └── 20090920024430_allow_null_password_and_salt.rb ├── public └── style │ └── style.css ├── signup and login.rb ├── sin-auth-template.rb ├── user.rb ├── vendor ├── authlogic-2.1.3 │ ├── .gitignore │ ├── CHANGELOG.rdoc │ ├── LICENSE │ ├── README.rdoc │ ├── Rakefile │ ├── VERSION.yml │ ├── authlogic.gemspec │ ├── generators │ │ └── session │ │ │ ├── session_generator.rb │ │ │ └── templates │ │ │ └── session.rb │ ├── init.rb │ ├── lib │ │ ├── authlogic.rb │ │ └── authlogic │ │ │ ├── acts_as_authentic │ │ │ ├── base.rb │ │ │ ├── email.rb │ │ │ ├── logged_in_status.rb │ │ │ ├── login.rb │ │ │ ├── magic_columns.rb │ │ │ ├── password.rb │ │ │ ├── perishable_token.rb │ │ │ ├── persistence_token.rb │ │ │ ├── restful_authentication.rb │ │ │ ├── session_maintenance.rb │ │ │ ├── single_access_token.rb │ │ │ └── validations_scope.rb │ │ │ ├── authenticates_many │ │ │ ├── association.rb │ │ │ └── base.rb │ │ │ ├── controller_adapters │ │ │ ├── abstract_adapter.rb │ │ │ ├── merb_adapter.rb │ │ │ ├── rails_adapter.rb │ │ │ └── sinatra_adapter.rb │ │ │ ├── crypto_providers │ │ │ ├── aes256.rb │ │ │ ├── bcrypt.rb │ │ │ ├── md5.rb │ │ │ ├── sha1.rb │ │ │ ├── sha256.rb │ │ │ ├── sha512.rb │ │ │ └── wordpress.rb │ │ │ ├── i18n.rb │ │ │ ├── i18n │ │ │ └── translator.rb │ │ │ ├── random.rb │ │ │ ├── regex.rb │ │ │ ├── session │ │ │ ├── activation.rb │ │ │ ├── active_record_trickery.rb │ │ │ ├── base.rb │ │ │ ├── brute_force_protection.rb │ │ │ ├── callbacks.rb │ │ │ ├── cookies.rb │ │ │ ├── existence.rb │ │ │ ├── foundation.rb │ │ │ ├── http_auth.rb │ │ │ ├── id.rb │ │ │ ├── klass.rb │ │ │ ├── magic_columns.rb │ │ │ ├── magic_states.rb │ │ │ ├── params.rb │ │ │ ├── password.rb │ │ │ ├── perishable_token.rb │ │ │ ├── persistence.rb │ │ │ ├── priority_record.rb │ │ │ ├── scopes.rb │ │ │ ├── session.rb │ │ │ ├── timeout.rb │ │ │ ├── unauthorized_record.rb │ │ │ └── validation.rb │ │ │ ├── test_case.rb │ │ │ └── test_case │ │ │ ├── mock_controller.rb │ │ │ ├── mock_cookie_jar.rb │ │ │ ├── mock_logger.rb │ │ │ ├── mock_request.rb │ │ │ └── rails_request_adapter.rb │ ├── rails │ │ └── init.rb │ ├── shoulda_macros │ │ └── authlogic.rb │ └── test │ │ ├── acts_as_authentic_test │ │ ├── base_test.rb │ │ ├── email_test.rb │ │ ├── logged_in_status_test.rb │ │ ├── login_test.rb │ │ ├── magic_columns_test.rb │ │ ├── password_test.rb │ │ ├── perishable_token_test.rb │ │ ├── persistence_token_test.rb │ │ ├── restful_authentication_test.rb │ │ ├── session_maintenance_test.rb │ │ └── single_access_test.rb │ │ ├── authenticates_many_test.rb │ │ ├── crypto_provider_test │ │ ├── aes256_test.rb │ │ ├── bcrypt_test.rb │ │ ├── sha1_test.rb │ │ ├── sha256_test.rb │ │ └── sha512_test.rb │ │ ├── fixtures │ │ ├── companies.yml │ │ ├── employees.yml │ │ ├── projects.yml │ │ └── users.yml │ │ ├── i18n_test.rb │ │ ├── libs │ │ ├── affiliate.rb │ │ ├── company.rb │ │ ├── employee.rb │ │ ├── employee_session.rb │ │ ├── ldaper.rb │ │ ├── ordered_hash.rb │ │ ├── project.rb │ │ ├── user.rb │ │ └── user_session.rb │ │ ├── random_test.rb │ │ ├── session_test │ │ ├── activation_test.rb │ │ ├── active_record_trickery_test.rb │ │ ├── brute_force_protection_test.rb │ │ ├── callbacks_test.rb │ │ ├── cookies_test.rb │ │ ├── credentials_test.rb │ │ ├── existence_test.rb │ │ ├── http_auth_test.rb │ │ ├── id_test.rb │ │ ├── klass_test.rb │ │ ├── magic_columns_test.rb │ │ ├── magic_states_test.rb │ │ ├── params_test.rb │ │ ├── password_test.rb │ │ ├── perishability_test.rb │ │ ├── persistence_test.rb │ │ ├── scopes_test.rb │ │ ├── session_test.rb │ │ ├── timeout_test.rb │ │ ├── unauthorized_record_test.rb │ │ └── validation_test.rb │ │ └── test_helper.rb ├── rack-1.0.0 │ ├── COPYING │ ├── KNOWN-ISSUES │ ├── RDOX │ ├── README │ ├── Rakefile │ ├── SPEC │ ├── bin │ │ └── rackup │ ├── contrib │ │ └── rack_logo.svg │ ├── example │ │ ├── lobster.ru │ │ ├── protectedlobster.rb │ │ └── protectedlobster.ru │ ├── lib │ │ ├── rack.rb │ │ └── rack │ │ │ ├── adapter │ │ │ └── camping.rb │ │ │ ├── auth │ │ │ ├── abstract │ │ │ │ ├── handler.rb │ │ │ │ └── request.rb │ │ │ ├── basic.rb │ │ │ ├── digest │ │ │ │ ├── md5.rb │ │ │ │ ├── nonce.rb │ │ │ │ ├── params.rb │ │ │ │ └── request.rb │ │ │ └── openid.rb │ │ │ ├── builder.rb │ │ │ ├── cascade.rb │ │ │ ├── chunked.rb │ │ │ ├── commonlogger.rb │ │ │ ├── conditionalget.rb │ │ │ ├── content_length.rb │ │ │ ├── content_type.rb │ │ │ ├── deflater.rb │ │ │ ├── directory.rb │ │ │ ├── file.rb │ │ │ ├── handler.rb │ │ │ ├── handler │ │ │ ├── cgi.rb │ │ │ ├── evented_mongrel.rb │ │ │ ├── fastcgi.rb │ │ │ ├── lsws.rb │ │ │ ├── mongrel.rb │ │ │ ├── scgi.rb │ │ │ ├── swiftiplied_mongrel.rb │ │ │ ├── thin.rb │ │ │ └── webrick.rb │ │ │ ├── head.rb │ │ │ ├── lint.rb │ │ │ ├── lobster.rb │ │ │ ├── lock.rb │ │ │ ├── methodoverride.rb │ │ │ ├── mime.rb │ │ │ ├── mock.rb │ │ │ ├── recursive.rb │ │ │ ├── reloader.rb │ │ │ ├── request.rb │ │ │ ├── response.rb │ │ │ ├── rewindable_input.rb │ │ │ ├── session │ │ │ ├── abstract │ │ │ │ └── id.rb │ │ │ ├── cookie.rb │ │ │ ├── memcache.rb │ │ │ └── pool.rb │ │ │ ├── showexceptions.rb │ │ │ ├── showstatus.rb │ │ │ ├── static.rb │ │ │ ├── urlmap.rb │ │ │ └── utils.rb │ ├── rack.gemspec │ └── test │ │ ├── cgi │ │ ├── lighttpd.conf │ │ ├── test │ │ ├── test.fcgi │ │ └── test.ru │ │ ├── multipart │ │ ├── binary │ │ ├── empty │ │ ├── ie │ │ ├── nested │ │ ├── none │ │ └── text │ │ ├── spec_rack_auth_basic.rb │ │ ├── spec_rack_auth_digest.rb │ │ ├── spec_rack_auth_openid.rb │ │ ├── spec_rack_builder.rb │ │ ├── spec_rack_camping.rb │ │ ├── spec_rack_cascade.rb │ │ ├── spec_rack_cgi.rb │ │ ├── spec_rack_chunked.rb │ │ ├── spec_rack_commonlogger.rb │ │ ├── spec_rack_conditionalget.rb │ │ ├── spec_rack_content_length.rb │ │ ├── spec_rack_content_type.rb │ │ ├── spec_rack_deflater.rb │ │ ├── spec_rack_directory.rb │ │ ├── spec_rack_fastcgi.rb │ │ ├── spec_rack_file.rb │ │ ├── spec_rack_handler.rb │ │ ├── spec_rack_head.rb │ │ ├── spec_rack_lint.rb │ │ ├── spec_rack_lobster.rb │ │ ├── spec_rack_lock.rb │ │ ├── spec_rack_methodoverride.rb │ │ ├── spec_rack_mock.rb │ │ ├── spec_rack_mongrel.rb │ │ ├── spec_rack_recursive.rb │ │ ├── spec_rack_request.rb │ │ ├── spec_rack_response.rb │ │ ├── spec_rack_rewindable_input.rb │ │ ├── spec_rack_session_cookie.rb │ │ ├── spec_rack_session_memcache.rb │ │ ├── spec_rack_session_pool.rb │ │ ├── spec_rack_showexceptions.rb │ │ ├── spec_rack_showstatus.rb │ │ ├── spec_rack_static.rb │ │ ├── spec_rack_thin.rb │ │ ├── spec_rack_urlmap.rb │ │ ├── spec_rack_utils.rb │ │ ├── spec_rack_webrick.rb │ │ ├── testrequest.rb │ │ └── unregistered_handler │ │ └── rack │ │ └── handler │ │ ├── unregistered.rb │ │ └── unregistered_long_one.rb └── sinatra-0.9.4 │ ├── AUTHORS │ ├── CHANGES │ ├── LICENSE │ ├── README.rdoc │ ├── Rakefile │ ├── compat │ ├── app_test.rb │ ├── application_test.rb │ ├── builder_test.rb │ ├── compat_test.rb │ ├── custom_error_test.rb │ ├── erb_test.rb │ ├── events_test.rb │ ├── filter_test.rb │ ├── haml_test.rb │ ├── helper.rb │ ├── mapped_error_test.rb │ ├── pipeline_test.rb │ ├── public │ │ └── foo.xml │ ├── sass_test.rb │ ├── sessions_test.rb │ ├── streaming_test.rb │ ├── sym_params_test.rb │ ├── template_test.rb │ ├── use_in_file_templates_test.rb │ └── views │ │ ├── foo.builder │ │ ├── foo.erb │ │ ├── foo.haml │ │ ├── foo.sass │ │ ├── foo_layout.erb │ │ ├── foo_layout.haml │ │ ├── layout_test │ │ ├── foo.builder │ │ ├── foo.erb │ │ ├── foo.haml │ │ ├── foo.sass │ │ ├── layout.builder │ │ ├── layout.erb │ │ ├── layout.haml │ │ └── layout.sass │ │ └── no_layout │ │ ├── no_layout.builder │ │ └── no_layout.haml │ ├── lib │ ├── sinatra.rb │ └── sinatra │ │ ├── base.rb │ │ ├── compat.rb │ │ ├── images │ │ ├── 404.png │ │ └── 500.png │ │ ├── main.rb │ │ ├── showexceptions.rb │ │ ├── test.rb │ │ └── test │ │ ├── bacon.rb │ │ ├── rspec.rb │ │ ├── spec.rb │ │ └── unit.rb │ ├── sinatra.gemspec │ └── test │ ├── base_test.rb │ ├── builder_test.rb │ ├── contest.rb │ ├── data │ └── reload_app_file.rb │ ├── erb_test.rb │ ├── extensions_test.rb │ ├── filter_test.rb │ ├── haml_test.rb │ ├── helper.rb │ ├── helpers_test.rb │ ├── mapped_error_test.rb │ ├── middleware_test.rb │ ├── options_test.rb │ ├── render_backtrace_test.rb │ ├── request_test.rb │ ├── response_test.rb │ ├── result_test.rb │ ├── route_added_hook_test.rb │ ├── routing_test.rb │ ├── sass_test.rb │ ├── server_test.rb │ ├── sinatra_test.rb │ ├── static_test.rb │ ├── templates_test.rb │ ├── test_test.rb │ └── views │ ├── error.builder │ ├── error.erb │ ├── error.haml │ ├── error.sass │ ├── foo │ └── hello.test │ ├── hello.builder │ ├── hello.erb │ ├── hello.haml │ ├── hello.sass │ ├── hello.test │ ├── layout2.builder │ ├── layout2.erb │ ├── layout2.haml │ └── layout2.test └── views ├── activate.haml ├── forgot_password.haml ├── index.haml ├── layout.haml ├── login.haml ├── resend_activation.haml ├── reset_password.haml ├── show.haml └── signup.haml /.gitignore: -------------------------------------------------------------------------------- 1 | db/sin-auth-template.sqlite3 2 | console.rb 3 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Warning: Not really tested in production yet. 2 | 3 | This is a template for a Sinatra app that gets Authlogic (version 2.1.3+) working for authentication. 4 | To use it, make sure that you have the required dependencies (Sinatra and Authlogic are vendored): 5 | 6 | gem install haml activerecord activesupport sqlite3-ruby pony 7 | 8 | 9 | Then clone this repository: 10 | 11 | git clone git://github.com/ehsanul/Sinatra-Authlogic-Template.git 12 | 13 | 14 | Edit the db/config.yml file and specify adapter settings. It defaults to sqlite3. 15 | You have to then run rake to create the database and run migrations. The command is simply: 16 | 17 | rake 18 | 19 | For subsequent migrations, run: 20 | 21 | rake migrate 22 | 23 | 24 | If you have sqlite3 installed and sendmail, or smtp on localhost for the email activation, the app should work out of the box. Run it with: 25 | 26 | ruby sin-auth-template.rb 27 | 28 | Or run it in production using passenger, or just: 29 | 30 | rackup 31 | 32 | 33 | Pony can be configured to use other SMTP settings. Just take a look at the User instance methods and adjust as required. Should probably switch to the Mail library. This is just something to get you started, so it doesn't matter all that much anyways. 34 | 35 | 36 | Contributions: 37 | 38 | Alf Mikulah - Authlogic 2.1.3 compatibility 39 | 40 | 41 | Todo: 42 | 43 | Tests 44 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift *Dir.entries('vendor').map{|gem| File.join 'vendor', gem, 'lib'} 2 | require 'rubygems' 3 | require 'rack' 4 | require 'sinatra' 5 | 6 | set :run, false 7 | set :environment, :production 8 | set :views, File.join(File.dirname(__FILE__), 'views') 9 | 10 | require 'sin-auth-template.rb' 11 | run Sinatra::Application 12 | -------------------------------------------------------------------------------- /db/config.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: sqlite3 3 | database: db/sin-auth-template.sqlite3 4 | timeout: 5000 5 | production: 6 | adapter: sqlite3 7 | database: db/sin-auth-template.sqlite3 8 | timeout: 5000 9 | -------------------------------------------------------------------------------- /db/migrate/20081103171327_create_users.rb: -------------------------------------------------------------------------------- 1 | class CreateUsers < ActiveRecord::Migration 2 | def self.up 3 | create_table :users do |t| 4 | t.timestamps 5 | t.string :email, :null => false 6 | t.string :crypted_password, :null => false 7 | t.string :password_salt, :null => false 8 | t.string :persistence_token, :null => false 9 | t.integer :login_count, :default => 0, :null => false 10 | t.datetime :last_request_at 11 | t.datetime :last_login_at 12 | t.datetime :current_login_at 13 | t.string :last_login_ip 14 | t.string :current_login_ip 15 | end 16 | 17 | add_index :users, :email 18 | add_index :users, :persistence_token 19 | add_index :users, :last_request_at 20 | end 21 | 22 | def self.down 23 | drop_table :users 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /db/migrate/20081106072031_create_sessions.rb: -------------------------------------------------------------------------------- 1 | class CreateSessions < ActiveRecord::Migration 2 | def self.up 3 | create_table :sessions do |t| 4 | t.string :session_id, :null => false 5 | t.text :data 6 | t.timestamps 7 | end 8 | 9 | add_index :sessions, :session_id 10 | add_index :sessions, :updated_at 11 | end 12 | 13 | def self.down 14 | drop_table :sessions 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /db/migrate/20090914022630_activation_and_password_reset.rb: -------------------------------------------------------------------------------- 1 | class ActivationAndPasswordReset < ActiveRecord::Migration 2 | def self.up 3 | add_column :users, :perishable_token, :string, :default => "", :null => false 4 | add_column :users, :active, :boolean, :default => false, :null => false 5 | add_index :users, :perishable_token 6 | end 7 | 8 | def self.down 9 | remove_column :users, :perishable_token 10 | remove_column :users, :active 11 | end 12 | end -------------------------------------------------------------------------------- /db/migrate/20090920024430_allow_null_password_and_salt.rb: -------------------------------------------------------------------------------- 1 | class AllowNullPasswordAndSalt < ActiveRecord::Migration 2 | def self.up 3 | change_column :users, :crypted_password, :string, :null => true 4 | change_column :users, :password_salt, :string, :null => true 5 | end 6 | def self.down 7 | change_column :users, :crypted_password, :string, :null => false 8 | change_column :users, :password_salt, :string, :null => false 9 | end 10 | end -------------------------------------------------------------------------------- /public/style/style.css: -------------------------------------------------------------------------------- 1 | body { overflow: hidden; } 2 | #container { padding: 5px; } 3 | -------------------------------------------------------------------------------- /sin-auth-template.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift *Dir.entries('vendor').map{|gem| File.join 'vendor', gem, 'lib'} 2 | $LOAD_PATH.uniq! 3 | ['rubygems', 'yaml', 'sinatra', 'haml', 'authlogic', 'pony', 'user'].each {|lib| require lib} 4 | 5 | configure do 6 | enable :sessions 7 | dbconfig = YAML::load(File.open 'db/config.yml')[ Sinatra::Application.environment.to_s ] 8 | ActiveRecord::Base.establish_connection(dbconfig) 9 | end 10 | 11 | # Work around a bug in authlogic. See: 12 | # http://github.com/binarylogic/authlogic/issuesearch?state=open&q=remote_ip#issue/80 13 | class Sinatra::Request 14 | alias remote_ip ip 15 | end 16 | 17 | # Rails style nested params 18 | before do 19 | new_params = {} 20 | params.each_pair do |full_key, value| 21 | this_param = new_params 22 | split_keys = full_key.split(/\]\[|\]|\[/) 23 | split_keys.each_index do |index| 24 | break if split_keys.length == index + 1 25 | this_param[split_keys[index]] ||= {} 26 | this_param = this_param[split_keys[index]] 27 | end 28 | this_param[split_keys.last] = value 29 | end 30 | request.params.replace new_params 31 | end 32 | 33 | Notice = Struct.new(:msg).new 34 | 35 | helpers do 36 | def current_user_session 37 | return @current_user_session if defined?(@current_user_session) 38 | @current_user_session = UserSession.find 39 | end 40 | def current_user 41 | return @current_user if defined?(@current_user) 42 | @current_user = current_user_session && current_user_session.record 43 | end 44 | def restrict 45 | ( notify 'You must be logged in to view that page'; redirect '/login' ) unless current_user 46 | end 47 | def notify( msg ) 48 | if Notice.msg.nil? then Notice.msg = msg 49 | else Notice.msg += '
' + msg 50 | end 51 | end 52 | def notice 53 | msg = Notice.msg 54 | Notice.msg = nil; msg 55 | end 56 | def link name, url 57 | "#{name}" 58 | end 59 | end 60 | 61 | 62 | ['signup and login.rb', 'user.rb'].each {|routes_or_classes| load routes_or_classes} 63 | 64 | get '/' do 65 | haml :index 66 | end 67 | 68 | get '/restricted' do 69 | restrict 70 | haml "You're logged in, so you got into a restricted page" 71 | end 72 | 73 | get '/show' do 74 | restrict 75 | @user = current_user 76 | haml :show 77 | end 78 | 79 | -------------------------------------------------------------------------------- /user.rb: -------------------------------------------------------------------------------- 1 | class UserSession < Authlogic::Session::Base 2 | end 3 | 4 | class User < ActiveRecord::Base 5 | acts_as_authentic do |c| 6 | # Bcrypt is recommended 7 | #crypto_provider = Authlogic::CryptoProviders::BCrypt 8 | c.perishable_token_valid_for( 24*60*60 ) 9 | c.validates_length_of_password_field_options = 10 | {:on => :update, :minimum => 6, :if => :has_no_credentials?} 11 | c.validates_length_of_password_confirmation_field_options = 12 | {:on => :update, :minimum => 6, :if => :has_no_credentials?} 13 | end 14 | 15 | def active? 16 | active 17 | end 18 | 19 | def has_no_credentials? 20 | crypted_password.blank? #&& self.openid_identifier.blank? 21 | end 22 | 23 | def send_activation_email 24 | Pony.mail( 25 | :to => self.email, 26 | :from => "no-reply@domain.tld", 27 | :subject => "Activate your account", 28 | :body => "You can activate your account at this link: " + 29 | "http://domain.tld/activate/#{self.perishable_token}" 30 | ) 31 | end 32 | 33 | def send_password_reset_email 34 | Pony.mail( 35 | :to => self.email, 36 | :from => "no-reply@domain.tld", 37 | :subject => "Reset your password", 38 | :body => "We have recieved a request to reset your password. " + 39 | "If you did not send this request, then please ignore this email.\n\n" + 40 | "If you did send the request, you may reset your password using the following link: " + 41 | "http://domain.tld/reset-password/#{self.perishable_token}" 42 | ) 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .swp 3 | *.log 4 | *.sqlite3 5 | pkg/* 6 | coverage/* 7 | doc/* 8 | benchmarks/* 9 | .specification 10 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 Ben Johnson of Binary Logic 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 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/Rakefile: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'rake' 3 | 4 | begin 5 | require 'jeweler' 6 | Jeweler::Tasks.new do |gem| 7 | gem.name = "authlogic" 8 | gem.summary = "A clean, simple, and unobtrusive ruby authentication solution." 9 | gem.email = "bjohnson@binarylogic.com" 10 | gem.homepage = "http://github.com/binarylogic/authlogic" 11 | gem.authors = ["Ben Johnson of Binary Logic"] 12 | gem.rubyforge_project = "authlogic" 13 | gem.add_dependency "activesupport" 14 | end 15 | Jeweler::RubyforgeTasks.new 16 | rescue LoadError 17 | puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler" 18 | end 19 | 20 | require 'rake/testtask' 21 | Rake::TestTask.new(:test) do |test| 22 | test.libs << 'test' 23 | test.pattern = 'test/**/*_test.rb' 24 | test.verbose = true 25 | end 26 | 27 | begin 28 | require 'rcov/rcovtask' 29 | Rcov::RcovTask.new do |test| 30 | test.libs << 'test' 31 | test.pattern = 'test/**/*_test.rb' 32 | test.verbose = true 33 | end 34 | rescue LoadError 35 | task :rcov do 36 | abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov" 37 | end 38 | end 39 | 40 | task :test => :check_dependencies 41 | 42 | task :default => :test 43 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/VERSION.yml: -------------------------------------------------------------------------------- 1 | --- 2 | :minor: 1 3 | :patch: 3 4 | :build: 5 | :major: 2 6 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/generators/session/session_generator.rb: -------------------------------------------------------------------------------- 1 | class SessionGenerator < Rails::Generator::NamedBase 2 | def manifest 3 | record do |m| 4 | m.class_collisions class_name 5 | m.directory File.join('app/models', class_path) 6 | m.template 'session.rb', File.join('app/models', class_path, "#{file_name}.rb") 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/generators/session/templates/session.rb: -------------------------------------------------------------------------------- 1 | class <%= class_name %> < Authlogic::Session::Base 2 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/init.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + "/rails/init.rb" -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/acts_as_authentic/magic_columns.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module ActsAsAuthentic 3 | # Magic columns are like ActiveRecord's created_at and updated_at columns. They are "magically" maintained for 4 | # you. Authlogic has the same thing, but these are maintained on the session side. Please see Authlogic::Session::MagicColumns 5 | # for more details. This module merely adds validations for the magic columns if they exist. 6 | module MagicColumns 7 | def self.included(klass) 8 | klass.class_eval do 9 | add_acts_as_authentic_module(Methods) 10 | end 11 | end 12 | 13 | # Methods relating to the magic columns 14 | module Methods 15 | def self.included(klass) 16 | klass.class_eval do 17 | validates_numericality_of :login_count, :only_integer => :true, :greater_than_or_equal_to => 0, :allow_nil => true if column_names.include?("login_count") 18 | validates_numericality_of :failed_login_count, :only_integer => :true, :greater_than_or_equal_to => 0, :allow_nil => true if column_names.include?("failed_login_count") 19 | end 20 | end 21 | end 22 | end 23 | end 24 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/acts_as_authentic/validations_scope.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module ActsAsAuthentic 3 | # Allows you to scope everything to specific fields. 4 | # See the Config submodule for more info. 5 | # For information on how to scope off of a parent object see Authlogic::AuthenticatesMany 6 | module ValidationsScope 7 | def self.included(klass) 8 | klass.class_eval do 9 | extend Config 10 | end 11 | end 12 | 13 | # All configuration for the scope feature. 14 | module Config 15 | # Allows you to scope everything to specific field(s). Works just like validates_uniqueness_of. 16 | # For example, let's say a user belongs to a company, and you want to scope everything to the 17 | # company: 18 | # 19 | # acts_as_authentic do |c| 20 | # c.validations_scope = :company_id 21 | # end 22 | # 23 | # * Default: nil 24 | # * Accepts: Symbol or Array of symbols 25 | def validations_scope(value = nil) 26 | rw_config(:validations_scope, value) 27 | end 28 | alias_method :validations_scope=, :validations_scope 29 | end 30 | end 31 | end 32 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/authenticates_many/association.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module AuthenticatesMany 3 | # An object of this class is used as a proxy for the authenticates_many relationship. It basically allows you to "save" scope details 4 | # and call them on an object, which allows you to do the following: 5 | # 6 | # @account.user_sessions.new 7 | # @account.user_sessions.find 8 | # # ... etc 9 | # 10 | # You can call all of the class level methods off of an object with a saved scope, so that calling the above methods scopes the user 11 | # sessions down to that specific account. To implement this via ActiveRecord do something like: 12 | # 13 | # class User < ActiveRecord::Base 14 | # authenticates_many :user_sessions 15 | # end 16 | class Association 17 | attr_accessor :klass, :find_options, :id 18 | 19 | def initialize(klass, find_options, id) 20 | self.klass = klass 21 | self.find_options = find_options 22 | self.id = id 23 | end 24 | 25 | [:create, :create!, :find, :new].each do |method| 26 | class_eval <<-"end_eval", __FILE__, __LINE__ 27 | def #{method}(*args) 28 | klass.with_scope(scope_options) do 29 | klass.#{method}(*args) 30 | end 31 | end 32 | end_eval 33 | end 34 | alias_method :build, :new 35 | 36 | private 37 | def scope_options 38 | {:find_options => find_options, :id => id} 39 | end 40 | end 41 | end 42 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/controller_adapters/abstract_adapter.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module ControllerAdapters # :nodoc: 3 | # Allows you to use Authlogic in any framework you want, not just rails. See the RailsAdapter or MerbAdapter 4 | # for an example of how to adapt Authlogic to work with your framework. 5 | class AbstractAdapter 6 | attr_accessor :controller 7 | 8 | def initialize(controller) 9 | self.controller = controller 10 | end 11 | 12 | def authenticate_with_http_basic(&block) 13 | @auth = Rack::Auth::Basic::Request.new(controller.request.env) 14 | if @auth.provided? and @auth.basic? 15 | block.call(*@auth.credentials) 16 | else 17 | false 18 | end 19 | end 20 | 21 | def cookies 22 | controller.cookies 23 | end 24 | 25 | def cookie_domain 26 | raise NotImplementedError.new("The cookie_domain method has not been implemented by the controller adapter") 27 | end 28 | 29 | def params 30 | controller.params 31 | end 32 | 33 | def request 34 | controller.request 35 | end 36 | 37 | def request_content_type 38 | request.content_type 39 | end 40 | 41 | def session 42 | controller.session 43 | end 44 | 45 | def responds_to_single_access_allowed? 46 | controller.respond_to?(:single_access_allowed?, true) 47 | end 48 | 49 | def single_access_allowed? 50 | controller.send(:single_access_allowed?) 51 | end 52 | 53 | def responds_to_last_request_update_allowed? 54 | controller.respond_to?(:last_request_update_allowed?, true) 55 | end 56 | 57 | def last_request_update_allowed? 58 | controller.send(:last_request_update_allowed?) 59 | end 60 | 61 | private 62 | def method_missing(id, *args, &block) 63 | controller.send(id, *args, &block) 64 | end 65 | end 66 | end 67 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/controller_adapters/merb_adapter.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module ControllerAdapters 3 | # Adapts authlogic to work with merb. The point is to close the gap between what authlogic expects and what the merb controller object 4 | # provides. Similar to how ActiveRecord has an adapter for MySQL, PostgreSQL, SQLite, etc. 5 | class MerbAdapter < AbstractAdapter 6 | # Lets Authlogic know about the controller object via a before filter, AKA "activates" authlogic. 7 | module MerbImplementation 8 | def self.included(klass) # :nodoc: 9 | klass.before :activate_authlogic 10 | end 11 | 12 | def cookie_domain 13 | Merb::Config[:session_cookie_domain] 14 | end 15 | 16 | private 17 | def activate_authlogic 18 | Authlogic::Session::Base.controller = MerbAdapter.new(self) 19 | end 20 | end 21 | end 22 | end 23 | end 24 | 25 | # make sure we're running inside Merb 26 | if defined?(Merb::Plugins) 27 | Merb::BootLoader.before_app_loads do 28 | Merb::Controller.send(:include, Authlogic::ControllerAdapters::MerbAdapter::MerbImplementation) 29 | end 30 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/controller_adapters/rails_adapter.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module ControllerAdapters 3 | # Adapts authlogic to work with rails. The point is to close the gap between what authlogic expects and what the rails controller object 4 | # provides. Similar to how ActiveRecord has an adapter for MySQL, PostgreSQL, SQLite, etc. 5 | class RailsAdapter < AbstractAdapter 6 | class AuthlogicLoadedTooLateError < StandardError; end 7 | 8 | def authenticate_with_http_basic(&block) 9 | controller.authenticate_with_http_basic(&block) 10 | end 11 | 12 | def cookies 13 | controller.send(:cookies) 14 | end 15 | 16 | def cookie_domain 17 | @cookie_domain_key ||= Rails::VERSION::STRING >= '2.3' ? :domain : :session_domain 18 | ActionController::Base.session_options[@cookie_domain_key] 19 | end 20 | 21 | def request_content_type 22 | request.format.to_s 23 | end 24 | 25 | # Lets Authlogic know about the controller object via a before filter, AKA "activates" authlogic. 26 | module RailsImplementation 27 | def self.included(klass) # :nodoc: 28 | if defined?(::ApplicationController) 29 | raise AuthlogicLoadedTooLateError.new("Authlogic is trying to prepend a before_filter in ActionController::Base to active itself" + 30 | ", the problem is that ApplicationController has already been loaded meaning the before_filter won't get copied into your" + 31 | " application. Generally this is due to another gem or plugin requiring your ApplicationController prematurely, such as" + 32 | " the resource_controller plugin. The solution is to require Authlogic before these other gems / plugins. Please require" + 33 | " authlogic first to get rid of this error.") 34 | end 35 | 36 | klass.prepend_before_filter :activate_authlogic 37 | end 38 | 39 | private 40 | def activate_authlogic 41 | Authlogic::Session::Base.controller = RailsAdapter.new(self) 42 | end 43 | end 44 | end 45 | end 46 | end 47 | 48 | ActionController::Base.send(:include, Authlogic::ControllerAdapters::RailsAdapter::RailsImplementation) 49 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/controller_adapters/sinatra_adapter.rb: -------------------------------------------------------------------------------- 1 | # Authlogic bridge for Sinatra 2 | module Authlogic 3 | module ControllerAdapters 4 | module SinatraAdapter 5 | class Cookies 6 | attr_reader :request, :response 7 | 8 | def initialize(request, response) 9 | @request = request 10 | @response = response 11 | end 12 | 13 | def delete(key, options = {}) 14 | @request.cookies.delete(key) 15 | end 16 | 17 | def []=(key, options) 18 | @response.set_cookie(key, options) 19 | end 20 | 21 | def method_missing(meth, *args, &block) 22 | @request.cookies.send(meth, *args, &block) 23 | end 24 | end 25 | 26 | class Controller 27 | attr_reader :request, :response, :cookies 28 | 29 | def initialize(request, response) 30 | @request = request 31 | @cookies = Cookies.new(request, response) 32 | end 33 | 34 | def session 35 | env['rack.session'] 36 | end 37 | 38 | def method_missing(meth, *args, &block) 39 | @request.send meth, *args, &block 40 | end 41 | end 42 | 43 | class Adapter < AbstractAdapter 44 | def cookie_domain 45 | env['SERVER_NAME'] 46 | end 47 | 48 | module Implementation 49 | def self.included(klass) 50 | klass.send :before do 51 | controller = Controller.new(request, response) 52 | Authlogic::Session::Base.controller = Adapter.new(controller) 53 | end 54 | end 55 | end 56 | end 57 | end 58 | end 59 | end 60 | 61 | Sinatra::Request.send(:include, Authlogic::ControllerAdapters::SinatraAdapter::Adapter::Implementation) -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/crypto_providers/aes256.rb: -------------------------------------------------------------------------------- 1 | require "openssl" 2 | 3 | module Authlogic 4 | module CryptoProviders 5 | # This encryption method is reversible if you have the supplied key. So in order to use this encryption method you must supply it with a key first. 6 | # In an initializer, or before your application initializes, you should do the following: 7 | # 8 | # Authlogic::CryptoProviders::AES256.key = "my really long and unique key, preferrably a bunch of random characters" 9 | # 10 | # My final comment is that this is a strong encryption method, but its main weakness is that its reversible. If you do not need to reverse the hash 11 | # then you should consider Sha512 or BCrypt instead. 12 | # 13 | # Keep your key in a safe place, some even say the key should be stored on a separate server. 14 | # This won't hurt performance because the only time it will try and access the key on the separate server is during initialization, which only 15 | # happens once. The reasoning behind this is if someone does compromise your server they won't have the key also. Basically, you don't want to 16 | # store the key with the lock. 17 | class AES256 18 | class << self 19 | attr_writer :key 20 | 21 | def encrypt(*tokens) 22 | aes.encrypt 23 | aes.key = @key 24 | [aes.update(tokens.join) + aes.final].pack("m").chomp 25 | end 26 | 27 | def matches?(crypted, *tokens) 28 | aes.decrypt 29 | aes.key = @key 30 | (aes.update(crypted.unpack("m").first) + aes.final) == tokens.join 31 | rescue OpenSSL::CipherError 32 | false 33 | end 34 | 35 | private 36 | def aes 37 | raise ArgumentError.new("You must provide a key like #{name}.key = my_key before using the #{name}") if @key.blank? 38 | @aes ||= OpenSSL::Cipher::Cipher.new("AES-256-ECB") 39 | end 40 | end 41 | end 42 | end 43 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/crypto_providers/md5.rb: -------------------------------------------------------------------------------- 1 | require "digest/md5" 2 | 3 | module Authlogic 4 | module CryptoProviders 5 | # This class was made for the users transitioning from md5 based systems. 6 | # I highly discourage using this crypto provider as it superbly inferior 7 | # to your other options. 8 | # 9 | # Please use any other provider offered by Authlogic. 10 | class MD5 11 | class << self 12 | attr_accessor :join_token 13 | 14 | # The number of times to loop through the encryption. 15 | def stretches 16 | @stretches ||= 1 17 | end 18 | attr_writer :stretches 19 | 20 | # Turns your raw password into a MD5 hash. 21 | def encrypt(*tokens) 22 | digest = tokens.flatten.join(join_token) 23 | stretches.times { digest = Digest::MD5.hexdigest(digest) } 24 | digest 25 | end 26 | 27 | # Does the crypted password match the tokens? Uses the same tokens that were used to encrypt. 28 | def matches?(crypted, *tokens) 29 | encrypt(*tokens) == crypted 30 | end 31 | end 32 | end 33 | end 34 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/crypto_providers/sha1.rb: -------------------------------------------------------------------------------- 1 | require "digest/sha1" 2 | 3 | module Authlogic 4 | module CryptoProviders 5 | # This class was made for the users transitioning from restful_authentication. I highly discourage using this 6 | # crypto provider as it inferior to your other options. Please use any other provider offered by Authlogic. 7 | class Sha1 8 | class << self 9 | def join_token 10 | @join_token ||= "--" 11 | end 12 | attr_writer :join_token 13 | 14 | # The number of times to loop through the encryption. This is ten because that is what restful_authentication defaults to. 15 | def stretches 16 | @stretches ||= 10 17 | end 18 | attr_writer :stretches 19 | 20 | # Turns your raw password into a Sha1 hash. 21 | def encrypt(*tokens) 22 | tokens = tokens.flatten 23 | digest = tokens.shift 24 | stretches.times { digest = Digest::SHA1.hexdigest([digest, *tokens].join(join_token)) } 25 | digest 26 | end 27 | 28 | # Does the crypted password match the tokens? Uses the same tokens that were used to encrypt. 29 | def matches?(crypted, *tokens) 30 | encrypt(*tokens) == crypted 31 | end 32 | end 33 | end 34 | end 35 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/crypto_providers/sha256.rb: -------------------------------------------------------------------------------- 1 | require "digest/sha2" 2 | 3 | module Authlogic 4 | # The acts_as_authentic method has a crypto_provider option. This allows you to use any type of encryption you like. 5 | # Just create a class with a class level encrypt and matches? method. See example below. 6 | # 7 | # === Example 8 | # 9 | # class MyAwesomeEncryptionMethod 10 | # def self.encrypt(*tokens) 11 | # # the tokens passed will be an array of objects, what type of object is irrelevant, 12 | # # just do what you need to do with them and return a single encrypted string. 13 | # # for example, you will most likely join all of the objects into a single string and then encrypt that string 14 | # end 15 | # 16 | # def self.matches?(crypted, *tokens) 17 | # # return true if the crypted string matches the tokens. 18 | # # depending on your algorithm you might decrypt the string then compare it to the token, or you might 19 | # # encrypt the tokens and make sure it matches the crypted string, its up to you 20 | # end 21 | # end 22 | module CryptoProviders 23 | # = Sha256 24 | # 25 | # Uses the Sha256 hash algorithm to encrypt passwords. 26 | class Sha256 27 | class << self 28 | attr_accessor :join_token 29 | 30 | # The number of times to loop through the encryption. This is ten because that is what restful_authentication defaults to. 31 | def stretches 32 | @stretches ||= 20 33 | end 34 | attr_writer :stretches 35 | 36 | # Turns your raw password into a Sha256 hash. 37 | def encrypt(*tokens) 38 | digest = tokens.flatten.join(join_token) 39 | stretches.times { digest = Digest::SHA256.hexdigest(digest) } 40 | digest 41 | end 42 | 43 | # Does the crypted password match the tokens? Uses the same tokens that were used to encrypt. 44 | def matches?(crypted, *tokens) 45 | encrypt(*tokens) == crypted 46 | end 47 | end 48 | end 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/crypto_providers/sha512.rb: -------------------------------------------------------------------------------- 1 | require "digest/sha2" 2 | 3 | module Authlogic 4 | # The acts_as_authentic method has a crypto_provider option. This allows you to use any type of encryption you like. 5 | # Just create a class with a class level encrypt and matches? method. See example below. 6 | # 7 | # === Example 8 | # 9 | # class MyAwesomeEncryptionMethod 10 | # def self.encrypt(*tokens) 11 | # # the tokens passed will be an array of objects, what type of object is irrelevant, 12 | # # just do what you need to do with them and return a single encrypted string. 13 | # # for example, you will most likely join all of the objects into a single string and then encrypt that string 14 | # end 15 | # 16 | # def self.matches?(crypted, *tokens) 17 | # # return true if the crypted string matches the tokens. 18 | # # depending on your algorithm you might decrypt the string then compare it to the token, or you might 19 | # # encrypt the tokens and make sure it matches the crypted string, its up to you 20 | # end 21 | # end 22 | module CryptoProviders 23 | # = Sha512 24 | # 25 | # Uses the Sha512 hash algorithm to encrypt passwords. 26 | class Sha512 27 | class << self 28 | attr_accessor :join_token 29 | 30 | # The number of times to loop through the encryption. This is ten because that is what restful_authentication defaults to. 31 | def stretches 32 | @stretches ||= 20 33 | end 34 | attr_writer :stretches 35 | 36 | # Turns your raw password into a Sha512 hash. 37 | def encrypt(*tokens) 38 | digest = tokens.flatten.join(join_token) 39 | stretches.times { digest = Digest::SHA512.hexdigest(digest) } 40 | digest 41 | end 42 | 43 | # Does the crypted password match the tokens? Uses the same tokens that were used to encrypt. 44 | def matches?(crypted, *tokens) 45 | encrypt(*tokens) == crypted 46 | end 47 | end 48 | end 49 | end 50 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/crypto_providers/wordpress.rb: -------------------------------------------------------------------------------- 1 | require 'digest/md5' 2 | module Authlogic 3 | module CryptoProviders 4 | class Wordpress 5 | class << self 6 | ITOA64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; 7 | 8 | def matches?(crypted, *tokens) 9 | stretches = 1 << ITOA64.index(crypted[3,1]) 10 | plain, salt = *tokens 11 | hashed = Digest::MD5.digest(salt+plain) 12 | stretches.times do |i| 13 | hashed = Digest::MD5.digest(hashed+plain) 14 | end 15 | crypted[0,12]+encode_64(hashed, 16) == crypted 16 | end 17 | 18 | def encode_64(input, length) 19 | output = "" 20 | i = 0 21 | while i < length 22 | value = input[i] 23 | i+=1 24 | break if value.nil? 25 | output += ITOA64[value & 0x3f, 1] 26 | value |= input[i] << 8 if i < length 27 | output += ITOA64[(value >> 6) & 0x3f, 1] 28 | 29 | i+=1 30 | break if i >= length 31 | value |= input[i] << 16 if i < length 32 | output += ITOA64[(value >> 12) & 0x3f,1] 33 | 34 | i+=1 35 | break if i >= length 36 | output += ITOA64[(value >> 18) & 0x3f,1] 37 | end 38 | output 39 | end 40 | end 41 | end 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/i18n/translator.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module I18n 3 | class Translator 4 | # If the I18n gem is present, calls +I18n.translate+ passing all 5 | # arguments, else returns +options[:default]+. 6 | def translate(key, options = {}) 7 | if defined?(::I18n) 8 | ::I18n.translate key, options 9 | else 10 | options[:default] 11 | end 12 | end 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/random.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | # Handles generating random strings. If SecureRandom is installed it will default to this and use it instead. SecureRandom comes with ActiveSupport. 3 | # So if you are using this in a rails app you should have this library. 4 | module Random 5 | extend self 6 | 7 | SecureRandom = (defined?(::SecureRandom) && ::SecureRandom) || (defined?(::ActiveSupport::SecureRandom) && ::ActiveSupport::SecureRandom) 8 | 9 | if SecureRandom 10 | def hex_token 11 | SecureRandom.hex(64) 12 | end 13 | 14 | def friendly_token 15 | # use base64url as defined by RFC4648 16 | SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n") 17 | end 18 | else 19 | def hex_token 20 | Authlogic::CryptoProviders::Sha512.encrypt(Time.now.to_s + (1..10).collect{ rand.to_s }.join) 21 | end 22 | 23 | FRIENDLY_CHARS = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a 24 | 25 | def friendly_token 26 | newpass = "" 27 | 1.upto(20) { |i| newpass << FRIENDLY_CHARS[rand(FRIENDLY_CHARS.size-1)] } 28 | newpass 29 | end 30 | end 31 | 32 | end 33 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/regex.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | # This is a module the contains regular expressions used throughout Authlogic. The point of extracting 3 | # them out into their own module is to make them easily available to you for other uses. Ex: 4 | # 5 | # validates_format_of :my_email_field, :with => Authlogic::Regex.email 6 | module Regex 7 | # A general email regular expression. It allows top level domains (TLD) to be from 2 - 4 in length, any 8 | # TLD longer than that must be manually specified. The decisions behind this regular expression were made 9 | # by reading this website: http://www.regular-expressions.info/email.html, which is an excellent resource 10 | # for regular expressions. 11 | def self.email 12 | return @email_regex if @email_regex 13 | email_name_regex = '[A-Z0-9_\.%\+\-]+' 14 | domain_head_regex = '(?:[A-Z0-9\-]+\.)+' 15 | domain_tld_regex = '(?:[A-Z]{2,4}|museum|travel)' 16 | @email_regex = /^#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}$/i 17 | end 18 | 19 | # A simple regular expression that only allows for letters, numbers, spaces, and .-_@. Just a standard login / username 20 | # regular expression. 21 | def self.login 22 | /\A\w[\w\.+\-_@ ]+$/ 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/session/active_record_trickery.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module Session 3 | # Authlogic looks like ActiveRecord, sounds like ActiveRecord, but its not ActiveRecord. That's the goal here. 4 | # This is useful for the various rails helper methods such as form_for, error_messages_for, or any method that 5 | # expects an ActiveRecord object. The point is to disguise the object as an ActiveRecord object so we can take 6 | # advantage of the many ActiveRecord tools. 7 | module ActiveRecordTrickery 8 | def self.included(klass) 9 | klass.extend ClassMethods 10 | klass.send(:include, InstanceMethods) 11 | end 12 | 13 | module ClassMethods 14 | # How to name the attributes of Authlogic, works JUST LIKE ActiveRecord, but instead it uses the following 15 | # namespace: 16 | # 17 | # authlogic.attributes.user_session.login 18 | def human_attribute_name(attribute_key_name, options = {}) 19 | options[:count] ||= 1 20 | options[:default] ||= attribute_key_name.to_s.humanize 21 | I18n.t("attributes.#{name.underscore}.#{attribute_key_name}", options) 22 | end 23 | 24 | # How to name the class, works JUST LIKE ActiveRecord, except it uses the following namespace: 25 | # 26 | # authlogic.models.user_session 27 | def human_name(*args) 28 | I18n.t("models.#{name.underscore}", {:count => 1, :default => name.humanize}) 29 | end 30 | 31 | # For rails < 2.3, mispelled 32 | def self_and_descendents_from_active_record 33 | [self] 34 | end 35 | 36 | # For rails >= 2.3, mispelling fixed 37 | def self_and_descendants_from_active_record 38 | [self] 39 | end 40 | 41 | # For rails >= 3.0 42 | def model_name 43 | clazz = defined?(::ActiveModel) ? ::ActiveModel::Name : ::ActiveSupport::ModelName 44 | clazz.new(self.to_s) 45 | end 46 | end 47 | 48 | module InstanceMethods 49 | # Don't use this yourself, this is to just trick some of the helpers since this is the method it calls. 50 | def new_record? 51 | new_session? 52 | end 53 | 54 | # For rails >= 3.0 55 | def to_model 56 | self 57 | end 58 | end 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/session/base.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module Session # :nodoc: 3 | # This is the base class Authlogic, where all modules are included. For information on functiionality see the various 4 | # sub modules. 5 | class Base 6 | include Foundation 7 | include Callbacks 8 | 9 | # Included first so that the session resets itself to nil 10 | include Timeout 11 | 12 | # Included in a specific order so they are tried in this order when persisting 13 | include Params 14 | include Cookies 15 | include Session 16 | include HttpAuth 17 | 18 | # Included in a specific order so magic states gets ran after a record is found 19 | include Password 20 | include UnauthorizedRecord 21 | include MagicStates 22 | 23 | include Activation 24 | include ActiveRecordTrickery 25 | include BruteForceProtection 26 | include Existence 27 | include Klass 28 | include MagicColumns 29 | include PerishableToken 30 | include Persistence 31 | include Scopes 32 | include Id 33 | include Validation 34 | include PriorityRecord 35 | end 36 | end 37 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/session/http_auth.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module Session 3 | # Handles all authentication that deals with basic HTTP auth. Which is authentication built into the HTTP protocol: 4 | # 5 | # http://username:password@whatever.com 6 | # 7 | # Also, if you are not comfortable letting users pass their raw username and password you can always use the single 8 | # access token. See Authlogic::Session::Params for more info. 9 | module HttpAuth 10 | def self.included(klass) 11 | klass.class_eval do 12 | extend Config 13 | include InstanceMethods 14 | persist :persist_by_http_auth, :if => :persist_by_http_auth? 15 | end 16 | end 17 | 18 | # Configuration for the HTTP basic auth feature of Authlogic. 19 | module Config 20 | # Do you want to allow your users to log in via HTTP basic auth? 21 | # 22 | # I recommend keeping this enabled. The only time I feel this should be disabled is if you are not comfortable 23 | # having your users provide their raw username and password. Whatever the reason, you can disable it here. 24 | # 25 | # * Default: true 26 | # * Accepts: Boolean 27 | def allow_http_basic_auth(value = nil) 28 | rw_config(:allow_http_basic_auth, value, true) 29 | end 30 | alias_method :allow_http_basic_auth=, :allow_http_basic_auth 31 | end 32 | 33 | # Instance methods for the HTTP basic auth feature of authlogic. 34 | module InstanceMethods 35 | private 36 | def persist_by_http_auth? 37 | allow_http_basic_auth? && login_field && password_field 38 | end 39 | 40 | def persist_by_http_auth 41 | controller.authenticate_with_http_basic do |login, password| 42 | if !login.blank? && !password.blank? 43 | send("#{login_field}=", login) 44 | send("#{password_field}=", password) 45 | return valid? 46 | end 47 | end 48 | 49 | false 50 | end 51 | 52 | def allow_http_basic_auth? 53 | self.class.allow_http_basic_auth == true 54 | end 55 | end 56 | end 57 | end 58 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/session/id.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module Session 3 | # Allows you to separate sessions with an id, ultimately letting you create multiple sessions for the same user. 4 | module Id 5 | def self.included(klass) 6 | klass.class_eval do 7 | attr_writer :id 8 | end 9 | end 10 | 11 | # Setting the id if it is passed in the credentials. 12 | def credentials=(value) 13 | super 14 | values = value.is_a?(Array) ? value : [value] 15 | self.id = values.last if values.last.is_a?(Symbol) 16 | end 17 | 18 | # Allows you to set a unique identifier for your session, so that you can have more than 1 session at a time. 19 | # A good example when this might be needed is when you want to have a normal user session and a "secure" user session. 20 | # The secure user session would be created only when they want to modify their billing information, or other sensitive 21 | # information. Similar to me.com. This requires 2 user sessions. Just use an id for the "secure" session and you should be good. 22 | # 23 | # You can set the id during initialization (see initialize for more information), or as an attribute: 24 | # 25 | # session.id = :my_id 26 | # 27 | # Just be sure and set your id before you save your session. 28 | # 29 | # Lastly, to retrieve your session with the id check out the find class method. 30 | def id 31 | @id 32 | end 33 | 34 | private 35 | # Used for things like cookie_key, session_key, etc. 36 | def build_key(last_part) 37 | [id, super].compact.join("_") 38 | end 39 | end 40 | end 41 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/session/perishable_token.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module Session 3 | # Maintains the perishable token, which is helpful for confirming records or authorizing records to reset their password. All that this 4 | # module does is reset it after a session have been saved, just keep it changing. The more it changes, the tighter the security. 5 | # 6 | # See Authlogic::ActsAsAuthentic::PerishableToken for more information. 7 | module PerishableToken 8 | def self.included(klass) 9 | klass.after_save :reset_perishable_token! 10 | end 11 | 12 | private 13 | def reset_perishable_token! 14 | record.reset_perishable_token if record.respond_to?(:reset_perishable_token) && !record.disable_perishable_token_maintenance? 15 | end 16 | end 17 | end 18 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/session/priority_record.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module Session 3 | # The point of this module is to avoid the StaleObjectError raised when lock_version is implemented in ActiveRecord. 4 | # We accomplish this by using a "priority record". Meaning this record is used if possible, it gets priority. 5 | # This way we don't save a record behind the scenes thus making an object being used stale. 6 | module PriorityRecord 7 | def self.included(klass) 8 | klass.class_eval do 9 | attr_accessor :priority_record 10 | end 11 | end 12 | 13 | # Setting priority record if it is passed. The only way it can be passed is through an array: 14 | # 15 | # session.credentials = [real_user_object, priority_user_object] 16 | def credentials=(value) 17 | super 18 | values = value.is_a?(Array) ? value : [value] 19 | self.priority_record = values[1] if values[1].class < ::ActiveRecord::Base 20 | end 21 | 22 | private 23 | def attempted_record=(value) 24 | value = priority_record if value == priority_record 25 | super 26 | end 27 | 28 | def save_record(alternate_record = nil) 29 | r = alternate_record || record 30 | super if r != priority_record 31 | end 32 | end 33 | end 34 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/session/unauthorized_record.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module Session 3 | # Allows you to create session with an object. Ex: 4 | # 5 | # UserSession.create(my_user_object) 6 | # 7 | # Be careful with this, because Authlogic is assuming that you have already confirmed that the 8 | # user is who he says he is. 9 | # 10 | # For example, this is the method used to persist the session internally. Authlogic finds the user with 11 | # the persistence token. At this point we know the user is who he says he is, so Authlogic just creates a 12 | # session with the record. This is particularly useful for 3rd party authentication methods, such as 13 | # OpenID. Let that method verify the identity, once it's verified, pass the object and create a session. 14 | module UnauthorizedRecord 15 | def self.included(klass) 16 | klass.class_eval do 17 | attr_accessor :unauthorized_record 18 | validate :validate_by_unauthorized_record, :if => :authenticating_with_unauthorized_record? 19 | end 20 | end 21 | 22 | # Returning meaningful credentials 23 | def credentials 24 | if authenticating_with_unauthorized_record? 25 | details = {} 26 | details[:unauthorized_record] = "" 27 | details 28 | else 29 | super 30 | end 31 | end 32 | 33 | # Setting the unauthorized record if it exists in the credentials passed. 34 | def credentials=(value) 35 | super 36 | values = value.is_a?(Array) ? value : [value] 37 | self.unauthorized_record = values.first if values.first.class < ::ActiveRecord::Base 38 | end 39 | 40 | private 41 | def authenticating_with_unauthorized_record? 42 | !unauthorized_record.nil? 43 | end 44 | 45 | def validate_by_unauthorized_record 46 | self.attempted_record = unauthorized_record 47 | end 48 | end 49 | end 50 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/test_case/mock_controller.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module TestCase 3 | # Basically acts like a controller but doesn't do anything. Authlogic can interact with this, do it's thing and then you 4 | # can look at the controller object to see if anything changed. 5 | class MockController < ControllerAdapters::AbstractAdapter 6 | attr_accessor :http_user, :http_password 7 | attr_writer :request_content_type 8 | 9 | def initialize 10 | end 11 | 12 | def authenticate_with_http_basic(&block) 13 | yield http_user, http_password 14 | end 15 | 16 | def cookies 17 | @cookies ||= MockCookieJar.new 18 | end 19 | 20 | def cookie_domain 21 | nil 22 | end 23 | 24 | def logger 25 | @logger ||= MockLogger.new 26 | end 27 | 28 | def params 29 | @params ||= {} 30 | end 31 | 32 | def request 33 | @request ||= MockRequest.new(controller) 34 | end 35 | 36 | def request_content_type 37 | @request_content_type ||= "text/html" 38 | end 39 | 40 | def session 41 | @session ||= {} 42 | end 43 | end 44 | end 45 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/test_case/mock_cookie_jar.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module TestCase 3 | class MockCookieJar < Hash # :nodoc: 4 | def [](key) 5 | hash = super 6 | hash && hash[:value] 7 | end 8 | 9 | def delete(key, options = {}) 10 | super(key) 11 | end 12 | end 13 | end 14 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/test_case/mock_logger.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module TestCase 3 | # Simple class to replace real loggers, so that we can raise any errors being logged. 4 | class MockLogger 5 | def error(message) 6 | raise message 7 | end 8 | end 9 | end 10 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/test_case/mock_request.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module TestCase 3 | class MockRequest # :nodoc: 4 | attr_accessor :controller 5 | 6 | def initialize(controller) 7 | self.controller = controller 8 | end 9 | 10 | def remote_ip 11 | (controller && controller.respond_to?(:env) && controller.env.is_a?(Hash) && controller.env['REMOTE_ADDR']) || "1.1.1.1" 12 | end 13 | 14 | private 15 | def method_missing(*args, &block) 16 | end 17 | end 18 | end 19 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/lib/authlogic/test_case/rails_request_adapter.rb: -------------------------------------------------------------------------------- 1 | module Authlogic 2 | module TestCase 3 | # Adapts authlogic to work with the @request object when testing. This way Authlogic can set cookies and what not before 4 | # a request is made, ultimately letting you log in users in functional tests. 5 | class RailsRequestAdapter < ControllerAdapters::AbstractAdapter 6 | def authenticate_with_http_basic(&block) 7 | end 8 | 9 | def cookies 10 | new_cookies = MockCookieJar.new 11 | super.each do |key, value| 12 | new_cookies[key] = value[:value] 13 | end 14 | new_cookies 15 | end 16 | 17 | def cookie_domain 18 | nil 19 | end 20 | 21 | def request 22 | @request ||= MockRequest.new(controller) 23 | end 24 | 25 | def request_content_type 26 | request.format.to_s 27 | end 28 | end 29 | end 30 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/rails/init.rb: -------------------------------------------------------------------------------- 1 | require "authlogic" -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/shoulda_macros/authlogic.rb: -------------------------------------------------------------------------------- 1 | # Test::Unit 2 | # Place this file into your test/shoulda_macros directory 3 | # 4 | # Example: 5 | # 6 | # class UserTest 7 | # should_have_authlogic 8 | # end 9 | # 10 | # Rspec 11 | # Place this file into your spec/support/shoulda directory 12 | # 13 | # Example: 14 | # 15 | # describe User do 16 | # it { should have_authlogic } 17 | # end 18 | 19 | module Authlogic 20 | module Shoulda 21 | 22 | module Matchers 23 | def have_authlogic 24 | HaveAuthlogic.new 25 | end 26 | alias_method :be_authentic, :have_authlogic 27 | 28 | class HaveAuthlogic 29 | 30 | def matches?(subject) 31 | subject.respond_to?(:password=) && subject.respond_to?(:valid_password?) 32 | end 33 | 34 | def failure_message 35 | "Add the line 'acts_as_authentic' to your model" 36 | end 37 | 38 | def description 39 | "have Authlogic" 40 | end 41 | end 42 | 43 | end 44 | 45 | module Macros 46 | include Matchers 47 | 48 | def should_have_authlogic 49 | klass = described_type rescue model_class 50 | matcher = HaveAuthlogic.new 51 | 52 | should matcher.description do 53 | assert matcher.matches?(klass.new), matcher.failure_message 54 | end 55 | end 56 | alias_method :should_be_authentic, :should_have_authlogic 57 | 58 | end 59 | 60 | end 61 | end 62 | 63 | if defined? Spec 64 | Spec::Runner.configure do |config| 65 | config.include(Authlogic::Shoulda::Matchers) 66 | end 67 | else 68 | Test::Unit::TestCase.class_eval { extend Authlogic::Shoulda::Macros } 69 | end 70 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/acts_as_authentic_test/base_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module ActsAsAuthenticTest 4 | class BaseTest < ActiveSupport::TestCase 5 | def test_acts_as_authentic 6 | assert_nothing_raised do 7 | User.acts_as_authentic do 8 | end 9 | end 10 | end 11 | 12 | def test_acts_as_authentic_with_old_config 13 | assert_raise(ArgumentError) do 14 | User.acts_as_authentic({}) 15 | end 16 | end 17 | end 18 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/acts_as_authentic_test/logged_in_status_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module ActsAsAuthenticTest 4 | class LoggedInStatusTest < ActiveSupport::TestCase 5 | def test_logged_in_timeout_config 6 | assert_equal 10.minutes.to_i, User.logged_in_timeout 7 | assert_equal 10.minutes.to_i, Employee.logged_in_timeout 8 | 9 | User.logged_in_timeout = 1.hour 10 | assert_equal 1.hour.to_i, User.logged_in_timeout 11 | User.logged_in_timeout 10.minutes 12 | assert_equal 10.minutes.to_i, User.logged_in_timeout 13 | end 14 | 15 | def test_named_scope_logged_in 16 | assert_equal 0, User.logged_in.count 17 | User.first.update_attribute(:last_request_at, Time.now) 18 | assert_equal 1, User.logged_in.count 19 | end 20 | 21 | def test_named_scope_logged_out 22 | assert_equal 2, User.logged_out.count 23 | User.first.update_attribute(:last_request_at, Time.now) 24 | assert_equal 1, User.logged_out.count 25 | end 26 | 27 | def test_logged_in_logged_out 28 | u = User.first 29 | assert !u.logged_in? 30 | assert u.logged_out? 31 | u.last_request_at = Time.now 32 | assert u.logged_in? 33 | assert !u.logged_out? 34 | end 35 | end 36 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/acts_as_authentic_test/magic_columns_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module ActsAsAuthenticTest 4 | class MagicColumnsTest < ActiveSupport::TestCase 5 | def test_validates_numericality_of_login_count 6 | u = User.new 7 | u.login_count = -1 8 | assert !u.valid? 9 | assert u.errors[:login_count].size > 0 10 | 11 | u.login_count = 0 12 | assert !u.valid? 13 | assert u.errors[:login_count].size == 0 14 | end 15 | 16 | def test_validates_numericality_of_failed_login_count 17 | u = User.new 18 | u.failed_login_count = -1 19 | assert !u.valid? 20 | assert u.errors[:failed_login_count].size > 0 21 | 22 | u.failed_login_count = 0 23 | assert !u.valid? 24 | assert u.errors[:failed_login_count].size == 0 25 | end 26 | end 27 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/acts_as_authentic_test/persistence_token_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module ActsAsAuthenticTest 4 | class PersistenceTokenTest < ActiveSupport::TestCase 5 | def test_after_password_set_reset_persistence_token 6 | ben = users(:ben) 7 | old_persistence_token = ben.persistence_token 8 | ben.password = "newpass" 9 | assert_not_equal old_persistence_token, ben.persistence_token 10 | end 11 | 12 | def test_after_password_verification_reset_persistence_token 13 | ben = users(:ben) 14 | old_persistence_token = ben.persistence_token 15 | assert ben.valid_password?(password_for(ben)) 16 | assert_equal old_persistence_token, ben.persistence_token 17 | 18 | # only update it if it is nil 19 | assert ben.update_attribute(:persistence_token, nil) 20 | assert ben.valid_password?(password_for(ben)) 21 | assert_not_equal old_persistence_token, ben.persistence_token 22 | end 23 | 24 | def test_before_validate_reset_persistence_token 25 | u = User.new 26 | assert !u.valid? 27 | assert_not_nil u.persistence_token 28 | end 29 | 30 | def test_forget_all 31 | http_basic_auth_for(users(:ben)) { UserSession.find } 32 | http_basic_auth_for(users(:zack)) { UserSession.find(:ziggity_zack) } 33 | assert UserSession.find 34 | assert UserSession.find(:ziggity_zack) 35 | User.forget_all 36 | assert !UserSession.find 37 | assert !UserSession.find(:ziggity_zack) 38 | end 39 | 40 | def test_forget 41 | ben = users(:ben) 42 | zack = users(:zack) 43 | http_basic_auth_for(ben) { UserSession.find } 44 | http_basic_auth_for(zack) { UserSession.find(:ziggity_zack) } 45 | 46 | assert ben.reload.logged_in? 47 | assert zack.reload.logged_in? 48 | 49 | ben.forget! 50 | 51 | assert !UserSession.find 52 | assert UserSession.find(:ziggity_zack) 53 | end 54 | end 55 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/acts_as_authentic_test/restful_authentication_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module ActsAsAuthenticTest 4 | class RestfulAuthenticationTest < ActiveSupport::TestCase 5 | def test_act_like_restful_authentication_config 6 | assert !User.act_like_restful_authentication 7 | assert !Employee.act_like_restful_authentication 8 | 9 | User.act_like_restful_authentication = true 10 | assert User.act_like_restful_authentication 11 | assert_equal Authlogic::CryptoProviders::Sha1, User.crypto_provider 12 | assert defined?(::REST_AUTH_SITE_KEY) 13 | assert_equal '', ::REST_AUTH_SITE_KEY 14 | assert_equal 1, Authlogic::CryptoProviders::Sha1.stretches 15 | 16 | User.act_like_restful_authentication false 17 | assert !User.act_like_restful_authentication 18 | 19 | User.crypto_provider = Authlogic::CryptoProviders::Sha512 20 | User.transition_from_crypto_providers = [] 21 | end 22 | 23 | def test_transition_from_restful_authentication_config 24 | assert !User.transition_from_restful_authentication 25 | assert !Employee.transition_from_restful_authentication 26 | 27 | User.transition_from_restful_authentication = true 28 | assert User.transition_from_restful_authentication 29 | assert defined?(::REST_AUTH_SITE_KEY) 30 | assert_equal '', ::REST_AUTH_SITE_KEY 31 | assert_equal 1, Authlogic::CryptoProviders::Sha1.stretches 32 | 33 | User.transition_from_restful_authentication false 34 | assert !User.transition_from_restful_authentication 35 | 36 | User.crypto_provider = Authlogic::CryptoProviders::Sha512 37 | User.transition_from_crypto_providers = [] 38 | end 39 | end 40 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/acts_as_authentic_test/single_access_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module ActsAsAuthenticTest 4 | class SingleAccessTest < ActiveSupport::TestCase 5 | def test_change_single_access_token_with_password_config 6 | assert !User.change_single_access_token_with_password 7 | assert !Employee.change_single_access_token_with_password 8 | 9 | User.change_single_access_token_with_password = true 10 | assert User.change_single_access_token_with_password 11 | User.change_single_access_token_with_password false 12 | assert !User.change_single_access_token_with_password 13 | end 14 | 15 | def test_validates_uniqueness_of_single_access_token 16 | u = User.new 17 | u.single_access_token = users(:ben).single_access_token 18 | assert !u.valid? 19 | assert u.errors[:single_access_token].size > 0 20 | end 21 | 22 | def test_before_validation_reset_single_access_token 23 | u = User.new 24 | assert !u.valid? 25 | assert_not_nil u.single_access_token 26 | end 27 | 28 | def test_after_password_set_reset_single_access_token 29 | User.change_single_access_token_with_password = true 30 | 31 | ben = users(:ben) 32 | old_single_access_token = ben.single_access_token 33 | ben.password = "new_pass" 34 | assert_not_equal old_single_access_token, ben.single_access_token 35 | 36 | User.change_single_access_token_with_password = false 37 | end 38 | 39 | def test_after_password_set_is_not_called 40 | ldaper = Ldaper.new 41 | assert ldaper.save 42 | end 43 | end 44 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/authenticates_many_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/test_helper.rb' 2 | 3 | class AuthenticatesManyTest < ActiveSupport::TestCase 4 | def test_scoping 5 | zack = users(:zack) 6 | ben = users(:ben) 7 | binary_logic = companies(:binary_logic) 8 | set_session_for(zack) 9 | 10 | assert !binary_logic.user_sessions.find 11 | 12 | set_session_for(ben) 13 | 14 | assert binary_logic.user_sessions.find 15 | end 16 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/crypto_provider_test/aes256_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module CryptoProviderTest 4 | class AES256Test < ActiveSupport::TestCase 5 | def test_encrypt 6 | assert Authlogic::CryptoProviders::AES256.encrypt("mypass") 7 | end 8 | 9 | def test_matches 10 | hash = Authlogic::CryptoProviders::AES256.encrypt("mypass") 11 | assert Authlogic::CryptoProviders::AES256.matches?(hash, "mypass") 12 | end 13 | end 14 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/crypto_provider_test/bcrypt_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module CryptoProviderTest 4 | class BCrpytTest < ActiveSupport::TestCase 5 | def test_encrypt 6 | assert Authlogic::CryptoProviders::BCrypt.encrypt("mypass") 7 | end 8 | 9 | def test_matches 10 | hash = Authlogic::CryptoProviders::BCrypt.encrypt("mypass") 11 | assert Authlogic::CryptoProviders::BCrypt.matches?(hash, "mypass") 12 | end 13 | end 14 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/crypto_provider_test/sha1_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module CryptoProviderTest 4 | class Sha1Test < ActiveSupport::TestCase 5 | def test_encrypt 6 | assert Authlogic::CryptoProviders::Sha1.encrypt("mypass") 7 | end 8 | 9 | def test_matches 10 | hash = Authlogic::CryptoProviders::Sha1.encrypt("mypass") 11 | assert Authlogic::CryptoProviders::Sha1.matches?(hash, "mypass") 12 | end 13 | 14 | def test_old_restful_authentication_passwords 15 | password = "test" 16 | salt = "7e3041ebc2fc05a40c60028e2c4901a81035d3cd" 17 | digest = "00742970dc9e6319f8019fd54864d3ea740f04b1" 18 | Authlogic::CryptoProviders::Sha1.stretches = 1 19 | assert Authlogic::CryptoProviders::Sha1.matches?(digest, nil, salt, password, nil) 20 | Authlogic::CryptoProviders::Sha1.stretches = 10 21 | end 22 | end 23 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/crypto_provider_test/sha256_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module CryptoProviderTest 4 | class Sha256Test < ActiveSupport::TestCase 5 | def test_encrypt 6 | assert Authlogic::CryptoProviders::Sha256.encrypt("mypass") 7 | end 8 | 9 | def test_matches 10 | hash = Authlogic::CryptoProviders::Sha256.encrypt("mypass") 11 | assert Authlogic::CryptoProviders::Sha256.matches?(hash, "mypass") 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/crypto_provider_test/sha512_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module CryptoProviderTest 4 | class Sha512Test < ActiveSupport::TestCase 5 | def test_encrypt 6 | assert Authlogic::CryptoProviders::Sha512.encrypt("mypass") 7 | end 8 | 9 | def test_matches 10 | hash = Authlogic::CryptoProviders::Sha512.encrypt("mypass") 11 | assert Authlogic::CryptoProviders::Sha512.matches?(hash, "mypass") 12 | end 13 | end 14 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/fixtures/companies.yml: -------------------------------------------------------------------------------- 1 | binary_logic: 2 | name: Binary Logic 3 | 4 | logic_over_data: 5 | name: Logic Over Data -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/fixtures/employees.yml: -------------------------------------------------------------------------------- 1 | drew: 2 | company: binary_logic 3 | email: dgainor@binarylogic.com 4 | password_salt: <%= salt = Authlogic::Random.hex_token %> 5 | crypted_password: '<%= Employee.crypto_provider.encrypt("drewrocks" + salt) %>' 6 | persistence_token: 5273d85ed156e9dbd6a7c1438d319ef8c8d41dd24368db6c222de11346c7b11e53ee08d45ecf619b1c1dc91233d22b372482b751b066d0a6f6f9bac42eacaabf 7 | first_name: Drew 8 | last_name: Gainor 9 | 10 | jennifer: 11 | company: logic_over_data 12 | email: jjohnson@logicoverdata.com 13 | password_salt: <%= salt = Authlogic::Random.hex_token %> 14 | crypted_password: '<%= Employee.crypto_provider.encrypt("jenniferocks" + salt) %>' 15 | persistence_token: 2be52a8f741ad00056e6f94eb6844d5316527206da7a3a5e3d0e14d19499ef9fe4c47c89b87febb59a2b41a69edfb4733b6b79302040f3de83f297c6991c75a2 16 | first_name: Jennifer 17 | last_name: Johnson 18 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/fixtures/projects.yml: -------------------------------------------------------------------------------- 1 | web_services: 2 | name: web services 3 | users: ben, zack -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/fixtures/users.yml: -------------------------------------------------------------------------------- 1 | ben: 2 | company: binary_logic 3 | projects: web_services 4 | login: bjohnson 5 | password_salt: <%= salt = Authlogic::Random.hex_token %> 6 | crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("benrocks" + salt) %> 7 | persistence_token: 6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317 8 | single_access_token: <%= Authlogic::Random.friendly_token %> 9 | perishable_token: <%= Authlogic::Random.friendly_token %> 10 | email: bjohnson@binarylogic.com 11 | first_name: Ben 12 | last_name: Johnson 13 | 14 | zack: 15 | company: logic_over_data 16 | projects: web_services 17 | login: zackham 18 | password_salt: <%= salt = Authlogic::Random.hex_token %> 19 | crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("zackrocks" + salt) %> 20 | persistence_token: fd3c2d5ce09ab98e7547d21f1b3dcf9158a9a19b5d3022c0402f32ae197019fce3fdbc6614d7ee57d719bae53bb089e30edc9e5d6153e5bc3afca0ac1d320342 21 | single_access_token: <%= Authlogic::Random.friendly_token %> 22 | email: zham@ziggityzack.com 23 | first_name: Zack 24 | last_name: Ham -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/i18n_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/test_helper.rb' 2 | 3 | class I18nTest < ActiveSupport::TestCase 4 | def test_uses_authlogic_as_scope_by_default 5 | assert_equal :authlogic, Authlogic::I18n.scope 6 | end 7 | 8 | def test_can_set_scope 9 | assert_nothing_raised { Authlogic::I18n.scope = [:a, :b] } 10 | assert_equal [:a, :b], Authlogic::I18n.scope 11 | Authlogic::I18n.scope = :authlogic 12 | end 13 | 14 | def test_uses_built_in_translator_by_default 15 | assert_equal Authlogic::I18n::Translator, Authlogic::I18n.translator.class 16 | end 17 | 18 | def test_can_set_custom_translator 19 | old_translator = Authlogic::I18n.translator 20 | 21 | assert_nothing_raised do 22 | Authlogic::I18n.translator = Class.new do 23 | def translate(key, options = {}) 24 | "Translated: #{key}" 25 | end 26 | end.new 27 | end 28 | 29 | assert_equal "Translated: x", Authlogic::I18n.translate(:x) 30 | 31 | Authlogic::I18n.translator = old_translator 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/libs/affiliate.rb: -------------------------------------------------------------------------------- 1 | class Affiliate < ActiveRecord::Base 2 | acts_as_authentic do |c| 3 | c.crypted_password_field = :pw_hash 4 | end 5 | 6 | belongs_to :company 7 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/libs/company.rb: -------------------------------------------------------------------------------- 1 | class Company < ActiveRecord::Base 2 | authenticates_many :employee_sessions 3 | authenticates_many :user_sessions 4 | has_many :employees, :dependent => :destroy 5 | has_many :users, :dependent => :destroy 6 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/libs/employee.rb: -------------------------------------------------------------------------------- 1 | class Employee < ActiveRecord::Base 2 | acts_as_authentic do |c| 3 | c.crypto_provider Authlogic::CryptoProviders::AES256 4 | end 5 | 6 | belongs_to :company 7 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/libs/employee_session.rb: -------------------------------------------------------------------------------- 1 | class EmployeeSession < Authlogic::Session::Base 2 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/libs/ldaper.rb: -------------------------------------------------------------------------------- 1 | class Ldaper < ActiveRecord::Base 2 | acts_as_authentic 3 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/libs/ordered_hash.rb: -------------------------------------------------------------------------------- 1 | class Hash 2 | def each(&block) 3 | sorted_keys = keys.sort { |a, b| a.to_s <=> b.to_s } 4 | sorted_keys.each do |key| 5 | yield key, self[key] 6 | end 7 | self 8 | end 9 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/libs/project.rb: -------------------------------------------------------------------------------- 1 | class Project < ActiveRecord::Base 2 | has_and_belongs_to_many :users 3 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/libs/user.rb: -------------------------------------------------------------------------------- 1 | class User < ActiveRecord::Base 2 | acts_as_authentic 3 | belongs_to :company 4 | has_and_belongs_to_many :projects 5 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/libs/user_session.rb: -------------------------------------------------------------------------------- 1 | class UserSession < Authlogic::Session::Base 2 | end 3 | 4 | class BackOfficeUserSession < Authlogic::Session::Base 5 | authenticate_with User 6 | end 7 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/random_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/test_helper.rb' 2 | 3 | class RandomTest < ActiveSupport::TestCase 4 | def test_random_tokens_have_consisten_length 5 | with_any_random do 6 | assert_equal 128, Authlogic::Random.hex_token.length 7 | assert_equal 20, Authlogic::Random.friendly_token.length 8 | end 9 | end 10 | 11 | def test_random_tokens_are_indeed_random 12 | # this might fail if you are *really* unlucky :) 13 | with_any_random do 14 | assert_not_equal Authlogic::Random.hex_token, Authlogic::Random.hex_token 15 | assert_not_equal Authlogic::Random.friendly_token, Authlogic::Random.friendly_token 16 | end 17 | end 18 | 19 | private 20 | def with_any_random(&block) 21 | [true, false].each {|val| with_secure_random_enabled(val, &block)} 22 | end 23 | 24 | def with_secure_random_enabled(enabled = true) 25 | # can't really test SecureRandom if we don't have an implementation 26 | return if enabled && !Authlogic::Random::SecureRandom 27 | 28 | current_sec_rand = Authlogic::Random::SecureRandom 29 | reload_authlogic_with_sec_random!(current_sec_rand, enabled) 30 | 31 | yield 32 | ensure 33 | reload_authlogic_with_sec_random!(current_sec_rand) 34 | end 35 | 36 | def reload_authlogic_with_sec_random!(secure_random, enabled = true) 37 | silence_warnings do 38 | secure_random.parent.const_set(secure_random.name.sub("#{secure_random.parent}::", ''), enabled ? secure_random : nil) 39 | load(File.dirname(__FILE__) + '/../lib/authlogic/random.rb') 40 | end 41 | end 42 | 43 | def silence_warnings 44 | old_verbose, $VERBOSE = $VERBOSE, nil 45 | yield 46 | ensure 47 | $VERBOSE = old_verbose 48 | end 49 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/activation_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | module ActivationTest 5 | class ClassMethodsTest < ActiveSupport::TestCase 6 | def test_activated 7 | assert UserSession.activated? 8 | Authlogic::Session::Base.controller = nil 9 | assert !UserSession.activated? 10 | end 11 | 12 | def test_controller 13 | Authlogic::Session::Base.controller = nil 14 | assert_nil Authlogic::Session::Base.controller 15 | thread1 = Thread.new do 16 | controller = MockController.new 17 | Authlogic::Session::Base.controller = controller 18 | assert_equal controller, Authlogic::Session::Base.controller 19 | end 20 | thread1.join 21 | 22 | assert_nil Authlogic::Session::Base.controller 23 | 24 | thread2 = Thread.new do 25 | controller = MockController.new 26 | Authlogic::Session::Base.controller = controller 27 | assert_equal controller, Authlogic::Session::Base.controller 28 | end 29 | thread2.join 30 | 31 | assert_nil Authlogic::Session::Base.controller 32 | end 33 | end 34 | 35 | class InstanceMethodsTest < ActiveSupport::TestCase 36 | def test_init 37 | UserSession.controller = nil 38 | assert_raise(Authlogic::Session::Activation::NotActivatedError) { UserSession.new } 39 | UserSession.controller = controller 40 | end 41 | end 42 | end 43 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/active_record_trickery_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | module ActiveRecordTrickeryTest 5 | class ClassMethodsTest < ActiveSupport::TestCase 6 | def test_human_attribute_name 7 | assert_equal "Some attribute", UserSession.human_attribute_name("some_attribute") 8 | assert_equal "Some attribute", UserSession.human_attribute_name(:some_attribute) 9 | end 10 | 11 | def test_human_name 12 | assert_equal "Usersession", UserSession.human_name 13 | end 14 | 15 | def test_self_and_descendents_from_active_record 16 | assert_equal [UserSession], UserSession.self_and_descendents_from_active_record 17 | end 18 | 19 | def test_self_and_descendants_from_active_record 20 | assert_equal [UserSession], UserSession.self_and_descendants_from_active_record 21 | end 22 | end 23 | 24 | class InstanceMethodsTest < ActiveSupport::TestCase 25 | def test_new_record 26 | session = UserSession.new 27 | assert session.new_record? 28 | end 29 | 30 | def test_to_model 31 | session = UserSession.new 32 | assert session, session.to_model 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/callbacks_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | class CallbacksTest < ActiveSupport::TestCase 5 | end 6 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/credentials_test.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehsanul/Sinatra-Authlogic-Template/3c43548960d34f39d35d7102ba422f26e282586f/vendor/authlogic-2.1.3/test/session_test/credentials_test.rb -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/existence_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | module ExistenceTest 5 | class ClassMethodsTest < ActiveSupport::TestCase 6 | def test_create 7 | ben = users(:ben) 8 | assert UserSession.create(:login => "somelogin", :password => "badpw2").new_session? 9 | assert !UserSession.create(:login => ben.login, :password => "benrocks").new_session? 10 | assert_raise(Authlogic::Session::Existence::SessionInvalidError) { UserSession.create!(:login => ben.login, :password => "badpw") } 11 | assert !UserSession.create!(:login => ben.login, :password => "benrocks").new_session? 12 | end 13 | end 14 | 15 | class IsntaceMethodsTest < ActiveSupport::TestCase 16 | def test_new_session 17 | session = UserSession.new 18 | assert session.new_session? 19 | 20 | set_session_for(users(:ben)) 21 | session = UserSession.find 22 | assert !session.new_session? 23 | end 24 | 25 | def test_save_with_nothing 26 | session = UserSession.new 27 | assert !session.save 28 | assert session.new_session? 29 | end 30 | 31 | def test_save_with_block 32 | ben = users(:ben) 33 | session = UserSession.new 34 | block_result = session.save do |result| 35 | assert !result 36 | end 37 | assert !block_result 38 | assert session.new_session? 39 | end 40 | 41 | def test_save_with_bang 42 | session = UserSession.new 43 | assert_raise(Authlogic::Session::Existence::SessionInvalidError) { session.save! } 44 | 45 | session.unauthorized_record = users(:ben) 46 | assert_nothing_raised { session.save! } 47 | end 48 | 49 | def test_destroy 50 | ben = users(:ben) 51 | session = UserSession.new 52 | assert !session.valid? 53 | assert !session.errors.empty? 54 | assert session.destroy 55 | assert session.errors.empty? 56 | session.unauthorized_record = ben 57 | assert session.save 58 | assert session.record 59 | assert session.destroy 60 | assert !session.record 61 | end 62 | end 63 | end 64 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/http_auth_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | class HttpAuthTest < ActiveSupport::TestCase 5 | class ConfiTest < ActiveSupport::TestCase 6 | def test_allow_http_basic_auth 7 | UserSession.allow_http_basic_auth = false 8 | assert_equal false, UserSession.allow_http_basic_auth 9 | 10 | UserSession.allow_http_basic_auth true 11 | assert_equal true, UserSession.allow_http_basic_auth 12 | end 13 | end 14 | 15 | class InstanceMethodsTest < ActiveSupport::TestCase 16 | def test_persist_persist_by_http_auth 17 | ben = users(:ben) 18 | http_basic_auth_for { assert !UserSession.find } 19 | http_basic_auth_for(ben) do 20 | assert session = UserSession.find 21 | assert_equal ben, session.record 22 | assert_equal ben.login, session.login 23 | assert_equal "benrocks", session.send(:protected_password) 24 | end 25 | end 26 | end 27 | end 28 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/id_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | class IdTest < ActiveSupport::TestCase 5 | def test_credentials 6 | session = UserSession.new 7 | session.credentials = [:my_id] 8 | assert_equal :my_id, session.id 9 | end 10 | 11 | def test_id 12 | session = UserSession.new 13 | session.id = :my_id 14 | assert_equal :my_id, session.id 15 | end 16 | end 17 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/klass_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | module KlassTest 5 | class ConfigTest < ActiveSupport::TestCase 6 | def test_authenticate_with 7 | UserSession.authenticate_with = Employee 8 | assert_equal "Employee", UserSession.klass_name 9 | assert_equal Employee, UserSession.klass 10 | 11 | UserSession.authenticate_with User 12 | assert_equal "User", UserSession.klass_name 13 | assert_equal User, UserSession.klass 14 | end 15 | 16 | def test_klass 17 | assert_equal User, UserSession.klass 18 | end 19 | 20 | def test_klass_name 21 | assert_equal "User", UserSession.klass_name 22 | end 23 | 24 | def test_guessed_klass_name 25 | assert_equal "User", UserSession.guessed_klass_name 26 | assert_equal "BackOfficeUser", BackOfficeUserSession.guessed_klass_name 27 | end 28 | end 29 | 30 | class InstanceMethodsTest < ActiveSupport::TestCase 31 | def test_record_method 32 | ben = users(:ben) 33 | set_session_for(ben) 34 | session = UserSession.find 35 | assert_equal ben, session.record 36 | assert_equal ben, session.user 37 | end 38 | end 39 | end 40 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/magic_states_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | module SessionTest 5 | class ConfigTest < ActiveSupport::TestCase 6 | def test_disable_magic_states_config 7 | UserSession.disable_magic_states = true 8 | assert_equal true, UserSession.disable_magic_states 9 | 10 | UserSession.disable_magic_states false 11 | assert_equal false, UserSession.disable_magic_states 12 | end 13 | end 14 | 15 | class InstanceMethodsTest < ActiveSupport::TestCase 16 | def test_disabling_magic_states 17 | UserSession.disable_magic_states = true 18 | 19 | ben = users(:ben) 20 | ben.update_attribute(:active, false) 21 | assert UserSession.create(ben) 22 | 23 | UserSession.disable_magic_states = false 24 | end 25 | 26 | def test_validate_validate_magic_states_active 27 | session = UserSession.new 28 | ben = users(:ben) 29 | session.unauthorized_record = ben 30 | assert session.valid? 31 | 32 | ben.update_attribute(:active, false) 33 | assert !session.valid? 34 | assert session.errors[:base].size > 0 35 | end 36 | 37 | def test_validate_validate_magic_states_approved 38 | session = UserSession.new 39 | ben = users(:ben) 40 | session.unauthorized_record = ben 41 | assert session.valid? 42 | 43 | ben.update_attribute(:approved, false) 44 | assert !session.valid? 45 | assert session.errors[:base].size > 0 46 | end 47 | 48 | def test_validate_validate_magic_states_confirmed 49 | session = UserSession.new 50 | ben = users(:ben) 51 | session.unauthorized_record = ben 52 | assert session.valid? 53 | 54 | ben.update_attribute(:confirmed, false) 55 | assert !session.valid? 56 | assert session.errors[:base].size > 0 57 | end 58 | end 59 | end 60 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/params_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | module ParamsTest 5 | class ConfigTest < ActiveSupport::TestCase 6 | def test_params_key 7 | UserSession.params_key = "my_params_key" 8 | assert_equal "my_params_key", UserSession.params_key 9 | 10 | UserSession.params_key "user_credentials" 11 | assert_equal "user_credentials", UserSession.params_key 12 | end 13 | 14 | def test_single_access_allowed_request_types 15 | UserSession.single_access_allowed_request_types = ["my request type"] 16 | assert_equal ["my request type"], UserSession.single_access_allowed_request_types 17 | 18 | UserSession.single_access_allowed_request_types ["application/rss+xml", "application/atom+xml"] 19 | assert_equal ["application/rss+xml", "application/atom+xml"], UserSession.single_access_allowed_request_types 20 | end 21 | end 22 | 23 | class InstanceMethodsTest < ActiveSupport::TestCase 24 | def test_persist_persist_by_params 25 | ben = users(:ben) 26 | session = UserSession.new 27 | 28 | assert !session.persisting? 29 | set_params_for(ben) 30 | 31 | assert !session.persisting? 32 | assert !session.unauthorized_record 33 | assert !session.record 34 | assert_nil controller.session["user_credentials"] 35 | 36 | set_request_content_type("text/plain") 37 | assert !session.persisting? 38 | assert !session.unauthorized_record 39 | assert_nil controller.session["user_credentials"] 40 | 41 | set_request_content_type("application/atom+xml") 42 | assert session.persisting? 43 | assert_equal ben, session.record 44 | assert_nil controller.session["user_credentials"] # should not persist since this is single access 45 | 46 | set_request_content_type("application/rss+xml") 47 | assert session.persisting? 48 | assert_equal ben, session.unauthorized_record 49 | assert_nil controller.session["user_credentials"] 50 | end 51 | end 52 | end 53 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/perishability_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | class PerishabilityTest < ActiveSupport::TestCase 5 | def test_after_save 6 | ben = users(:ben) 7 | old_perishable_token = ben.perishable_token 8 | session = UserSession.create(ben) 9 | assert_not_equal old_perishable_token, ben.perishable_token 10 | 11 | drew = employees(:drew) 12 | assert UserSession.create(drew) 13 | end 14 | end 15 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/persistence_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | class PersistenceTest < ActiveSupport::TestCase 5 | def test_find 6 | ben = users(:ben) 7 | assert !UserSession.find 8 | http_basic_auth_for(ben) { assert UserSession.find } 9 | set_cookie_for(ben) 10 | assert UserSession.find 11 | unset_cookie 12 | set_session_for(ben) 13 | session = UserSession.find 14 | assert session 15 | end 16 | 17 | def test_persisting 18 | # tested thoroughly in test_find 19 | end 20 | end 21 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/scopes_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | class ScopesTest < ActiveSupport::TestCase 5 | def test_scope_method 6 | assert_nil Authlogic::Session::Base.scope 7 | 8 | thread1 = Thread.new do 9 | scope = {:id => :scope1} 10 | Authlogic::Session::Base.send(:scope=, scope) 11 | assert_equal scope, Authlogic::Session::Base.scope 12 | end 13 | thread1.join 14 | 15 | assert_nil Authlogic::Session::Base.scope 16 | 17 | thread2 = Thread.new do 18 | scope = {:id => :scope2} 19 | Authlogic::Session::Base.send(:scope=, scope) 20 | assert_equal scope, Authlogic::Session::Base.scope 21 | end 22 | thread2.join 23 | 24 | assert_nil Authlogic::Session::Base.scope 25 | end 26 | 27 | def test_with_scope_method 28 | assert_raise(ArgumentError) { UserSession.with_scope } 29 | 30 | UserSession.with_scope(:find_options => {:conditions => "awesome = 1"}, :id => "some_id") do 31 | assert_equal({:find_options => {:conditions => "awesome = 1"}, :id => "some_id"}, UserSession.scope) 32 | end 33 | 34 | assert_nil UserSession.scope 35 | end 36 | 37 | def test_initialize 38 | UserSession.with_scope(:find_options => {:conditions => "awesome = 1"}, :id => "some_id") do 39 | session = UserSession.new 40 | assert_equal({:find_options => {:conditions => "awesome = 1"}, :id => "some_id"}, session.scope) 41 | session.id = :another_id 42 | assert_equal "another_id_some_id_test", session.send(:build_key, "test") 43 | end 44 | end 45 | 46 | def test_search_for_record_with_scopes 47 | binary_logic = companies(:binary_logic) 48 | ben = users(:ben) 49 | zack = users(:zack) 50 | 51 | session = UserSession.new 52 | assert_equal zack, session.send(:search_for_record, "find_by_login", zack.login) 53 | 54 | session.scope = {:find_options => {:conditions => ["company_id = ?", binary_logic.id]}} 55 | assert_nil session.send(:search_for_record, "find_by_login", zack.login) 56 | 57 | assert_equal ben, session.send(:search_for_record, "find_by_login", ben.login) 58 | end 59 | end 60 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/session_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | module SessionTest 5 | class ConfigTest < ActiveSupport::TestCase 6 | def test_session_key 7 | UserSession.session_key = "my_session_key" 8 | assert_equal "my_session_key", UserSession.session_key 9 | 10 | UserSession.session_key "user_credentials" 11 | assert_equal "user_credentials", UserSession.session_key 12 | end 13 | end 14 | 15 | class InstanceMethodsTest < ActiveSupport::TestCase 16 | def test_persist_persist_by_session 17 | ben = users(:ben) 18 | set_session_for(ben) 19 | assert session = UserSession.find 20 | assert_equal ben, session.record 21 | assert_equal ben.persistence_token, controller.session["user_credentials"] 22 | end 23 | 24 | def test_persist_persist_by_session_with_token_only 25 | ben = users(:ben) 26 | set_session_for(ben) 27 | controller.session["user_credentials_id"] = nil 28 | assert session = UserSession.find 29 | assert_equal ben, session.record 30 | assert_equal ben.persistence_token, controller.session["user_credentials"] 31 | end 32 | 33 | def test_after_save_update_session 34 | ben = users(:ben) 35 | session = UserSession.new(ben) 36 | assert controller.session["user_credentials"].blank? 37 | assert session.save 38 | assert_equal ben.persistence_token, controller.session["user_credentials"] 39 | end 40 | 41 | def test_after_destroy_update_session 42 | ben = users(:ben) 43 | set_session_for(ben) 44 | assert_equal ben.persistence_token, controller.session["user_credentials"] 45 | assert session = UserSession.find 46 | assert session.destroy 47 | assert controller.session["user_credentials"].blank? 48 | end 49 | 50 | def test_after_persisting_update_session 51 | ben = users(:ben) 52 | set_cookie_for(ben) 53 | assert controller.session["user_credentials"].blank? 54 | assert UserSession.find 55 | assert_equal ben.persistence_token, controller.session["user_credentials"] 56 | end 57 | end 58 | end 59 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/timeout_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | module TimeoutTest 5 | class ConfigTest < ActiveSupport::TestCase 6 | def test_logout_on_timeout 7 | UserSession.logout_on_timeout = true 8 | assert UserSession.logout_on_timeout 9 | 10 | UserSession.logout_on_timeout false 11 | assert !UserSession.logout_on_timeout 12 | end 13 | end 14 | 15 | class InstanceMethods < ActiveSupport::TestCase 16 | def test_stale_state 17 | UserSession.logout_on_timeout = true 18 | ben = users(:ben) 19 | ben.last_request_at = 3.years.ago 20 | ben.save 21 | set_session_for(ben) 22 | 23 | session = UserSession.new 24 | assert session.persisting? 25 | assert session.stale? 26 | assert_equal ben, session.stale_record 27 | assert_nil session.record 28 | assert_nil controller.session["user_credentials_id"] 29 | 30 | set_session_for(ben) 31 | 32 | ben.last_request_at = Time.now 33 | ben.save 34 | 35 | assert session.persisting? 36 | assert !session.stale? 37 | assert_nil session.stale_record 38 | 39 | UserSession.logout_on_timeout = false 40 | end 41 | 42 | def test_successful_login 43 | UserSession.logout_on_timeout = true 44 | ben = users(:ben) 45 | assert UserSession.create(:login => ben.login, :password => "benrocks") 46 | assert session = UserSession.find 47 | assert_equal ben, session.record 48 | UserSession.logout_on_timeout = false 49 | end 50 | end 51 | end 52 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/unauthorized_record_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | class UnauthorizedRecordTest < ActiveSupport::TestCase 5 | def test_credentials 6 | ben = users(:ben) 7 | session = UserSession.new 8 | session.credentials = [ben] 9 | assert_equal ben, session.unauthorized_record 10 | assert_equal({:unauthorized_record => ""}, session.credentials) 11 | end 12 | end 13 | end -------------------------------------------------------------------------------- /vendor/authlogic-2.1.3/test/session_test/validation_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/../test_helper.rb' 2 | 3 | module SessionTest 4 | class ValidationTest < ActiveSupport::TestCase 5 | def test_errors 6 | session = UserSession.new 7 | assert session.errors.is_a?(Authlogic::Session::Validation::Errors) 8 | end 9 | 10 | def test_valid 11 | session = UserSession.new 12 | assert !session.valid? 13 | assert_nil session.record 14 | assert session.errors.count > 0 15 | 16 | ben = users(:ben) 17 | session.unauthorized_record = ben 18 | assert session.valid? 19 | assert_equal ben, session.attempted_record 20 | assert session.errors.empty? 21 | end 22 | end 23 | end -------------------------------------------------------------------------------- /vendor/rack-1.0.0/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007, 2008, 2009 Christian Neukirchen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to 5 | deal in the Software without restriction, including without limitation the 6 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/KNOWN-ISSUES: -------------------------------------------------------------------------------- 1 | = Known issues with Rack and Web servers 2 | 3 | * Lighttpd sets wrong SCRIPT_NAME and PATH_INFO if you mount your 4 | FastCGI app at "/". This can be fixed by using this middleware: 5 | 6 | class LighttpdScriptNameFix 7 | def initialize(app) 8 | @app = app 9 | end 10 | 11 | def call(env) 12 | env["PATH_INFO"] = env["SCRIPT_NAME"].to_s + env["PATH_INFO"].to_s 13 | env["SCRIPT_NAME"] = "" 14 | @app.call(env) 15 | end 16 | end 17 | 18 | Of course, use this only when your app runs at "/". 19 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/example/lobster.ru: -------------------------------------------------------------------------------- 1 | require 'rack/lobster' 2 | 3 | use Rack::ShowExceptions 4 | run Rack::Lobster.new 5 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/example/protectedlobster.rb: -------------------------------------------------------------------------------- 1 | require 'rack' 2 | require 'rack/lobster' 3 | 4 | lobster = Rack::Lobster.new 5 | 6 | protected_lobster = Rack::Auth::Basic.new(lobster) do |username, password| 7 | 'secret' == password 8 | end 9 | 10 | protected_lobster.realm = 'Lobster 2.0' 11 | 12 | pretty_protected_lobster = Rack::ShowStatus.new(Rack::ShowExceptions.new(protected_lobster)) 13 | 14 | Rack::Handler::WEBrick.run pretty_protected_lobster, :Port => 9292 15 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/example/protectedlobster.ru: -------------------------------------------------------------------------------- 1 | require 'rack/lobster' 2 | 3 | use Rack::ShowExceptions 4 | use Rack::Auth::Basic, "Lobster 2.0" do |username, password| 5 | 'secret' == password 6 | end 7 | 8 | run Rack::Lobster.new 9 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/adapter/camping.rb: -------------------------------------------------------------------------------- 1 | module Rack 2 | module Adapter 3 | class Camping 4 | def initialize(app) 5 | @app = app 6 | end 7 | 8 | def call(env) 9 | env["PATH_INFO"] ||= "" 10 | env["SCRIPT_NAME"] ||= "" 11 | controller = @app.run(env['rack.input'], env) 12 | h = controller.headers 13 | h.each_pair do |k,v| 14 | if v.kind_of? URI 15 | h[k] = v.to_s 16 | end 17 | end 18 | [controller.status, controller.headers, [controller.body.to_s]] 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/auth/abstract/handler.rb: -------------------------------------------------------------------------------- 1 | module Rack 2 | module Auth 3 | # Rack::Auth::AbstractHandler implements common authentication functionality. 4 | # 5 | # +realm+ should be set for all handlers. 6 | 7 | class AbstractHandler 8 | 9 | attr_accessor :realm 10 | 11 | def initialize(app, realm=nil, &authenticator) 12 | @app, @realm, @authenticator = app, realm, authenticator 13 | end 14 | 15 | 16 | private 17 | 18 | def unauthorized(www_authenticate = challenge) 19 | return [ 401, 20 | { 'Content-Type' => 'text/plain', 21 | 'Content-Length' => '0', 22 | 'WWW-Authenticate' => www_authenticate.to_s }, 23 | [] 24 | ] 25 | end 26 | 27 | def bad_request 28 | return [ 400, 29 | { 'Content-Type' => 'text/plain', 30 | 'Content-Length' => '0' }, 31 | [] 32 | ] 33 | end 34 | 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/auth/abstract/request.rb: -------------------------------------------------------------------------------- 1 | module Rack 2 | module Auth 3 | class AbstractRequest 4 | 5 | def initialize(env) 6 | @env = env 7 | end 8 | 9 | def provided? 10 | !authorization_key.nil? 11 | end 12 | 13 | def parts 14 | @parts ||= @env[authorization_key].split(' ', 2) 15 | end 16 | 17 | def scheme 18 | @scheme ||= parts.first.downcase.to_sym 19 | end 20 | 21 | def params 22 | @params ||= parts.last 23 | end 24 | 25 | 26 | private 27 | 28 | AUTHORIZATION_KEYS = ['HTTP_AUTHORIZATION', 'X-HTTP_AUTHORIZATION', 'X_HTTP_AUTHORIZATION'] 29 | 30 | def authorization_key 31 | @authorization_key ||= AUTHORIZATION_KEYS.detect { |key| @env.has_key?(key) } 32 | end 33 | 34 | end 35 | 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/auth/basic.rb: -------------------------------------------------------------------------------- 1 | require 'rack/auth/abstract/handler' 2 | require 'rack/auth/abstract/request' 3 | 4 | module Rack 5 | module Auth 6 | # Rack::Auth::Basic implements HTTP Basic Authentication, as per RFC 2617. 7 | # 8 | # Initialize with the Rack application that you want protecting, 9 | # and a block that checks if a username and password pair are valid. 10 | # 11 | # See also: example/protectedlobster.rb 12 | 13 | class Basic < AbstractHandler 14 | 15 | def call(env) 16 | auth = Basic::Request.new(env) 17 | 18 | return unauthorized unless auth.provided? 19 | 20 | return bad_request unless auth.basic? 21 | 22 | if valid?(auth) 23 | env['REMOTE_USER'] = auth.username 24 | 25 | return @app.call(env) 26 | end 27 | 28 | unauthorized 29 | end 30 | 31 | 32 | private 33 | 34 | def challenge 35 | 'Basic realm="%s"' % realm 36 | end 37 | 38 | def valid?(auth) 39 | @authenticator.call(*auth.credentials) 40 | end 41 | 42 | class Request < Auth::AbstractRequest 43 | def basic? 44 | :basic == scheme 45 | end 46 | 47 | def credentials 48 | @credentials ||= params.unpack("m*").first.split(/:/, 2) 49 | end 50 | 51 | def username 52 | credentials.first 53 | end 54 | end 55 | 56 | end 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/auth/digest/nonce.rb: -------------------------------------------------------------------------------- 1 | require 'digest/md5' 2 | 3 | module Rack 4 | module Auth 5 | module Digest 6 | # Rack::Auth::Digest::Nonce is the default nonce generator for the 7 | # Rack::Auth::Digest::MD5 authentication handler. 8 | # 9 | # +private_key+ needs to set to a constant string. 10 | # 11 | # +time_limit+ can be optionally set to an integer (number of seconds), 12 | # to limit the validity of the generated nonces. 13 | 14 | class Nonce 15 | 16 | class << self 17 | attr_accessor :private_key, :time_limit 18 | end 19 | 20 | def self.parse(string) 21 | new(*string.unpack("m*").first.split(' ', 2)) 22 | end 23 | 24 | def initialize(timestamp = Time.now, given_digest = nil) 25 | @timestamp, @given_digest = timestamp.to_i, given_digest 26 | end 27 | 28 | def to_s 29 | [([ @timestamp, digest ] * ' ')].pack("m*").strip 30 | end 31 | 32 | def digest 33 | ::Digest::MD5.hexdigest([ @timestamp, self.class.private_key ] * ':') 34 | end 35 | 36 | def valid? 37 | digest == @given_digest 38 | end 39 | 40 | def stale? 41 | !self.class.time_limit.nil? && (@timestamp - Time.now.to_i) < self.class.time_limit 42 | end 43 | 44 | def fresh? 45 | !stale? 46 | end 47 | 48 | end 49 | end 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/auth/digest/params.rb: -------------------------------------------------------------------------------- 1 | module Rack 2 | module Auth 3 | module Digest 4 | class Params < Hash 5 | 6 | def self.parse(str) 7 | split_header_value(str).inject(new) do |header, param| 8 | k, v = param.split('=', 2) 9 | header[k] = dequote(v) 10 | header 11 | end 12 | end 13 | 14 | def self.dequote(str) # From WEBrick::HTTPUtils 15 | ret = (/\A"(.*)"\Z/ =~ str) ? $1 : str.dup 16 | ret.gsub!(/\\(.)/, "\\1") 17 | ret 18 | end 19 | 20 | def self.split_header_value(str) 21 | str.scan( /(\w+\=(?:"[^\"]+"|[^,]+))/n ).collect{ |v| v[0] } 22 | end 23 | 24 | def initialize 25 | super 26 | 27 | yield self if block_given? 28 | end 29 | 30 | def [](k) 31 | super k.to_s 32 | end 33 | 34 | def []=(k, v) 35 | super k.to_s, v.to_s 36 | end 37 | 38 | UNQUOTED = ['qop', 'nc', 'stale'] 39 | 40 | def to_s 41 | inject([]) do |parts, (k, v)| 42 | parts << "#{k}=" + (UNQUOTED.include?(k) ? v.to_s : quote(v)) 43 | parts 44 | end.join(', ') 45 | end 46 | 47 | def quote(str) # From WEBrick::HTTPUtils 48 | '"' << str.gsub(/[\\\"]/o, "\\\1") << '"' 49 | end 50 | 51 | end 52 | end 53 | end 54 | end 55 | 56 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/auth/digest/request.rb: -------------------------------------------------------------------------------- 1 | require 'rack/auth/abstract/request' 2 | require 'rack/auth/digest/params' 3 | require 'rack/auth/digest/nonce' 4 | 5 | module Rack 6 | module Auth 7 | module Digest 8 | class Request < Auth::AbstractRequest 9 | 10 | def method 11 | @env['rack.methodoverride.original_method'] || @env['REQUEST_METHOD'] 12 | end 13 | 14 | def digest? 15 | :digest == scheme 16 | end 17 | 18 | def correct_uri? 19 | (@env['SCRIPT_NAME'].to_s + @env['PATH_INFO'].to_s) == uri 20 | end 21 | 22 | def nonce 23 | @nonce ||= Nonce.parse(params['nonce']) 24 | end 25 | 26 | def params 27 | @params ||= Params.parse(parts.last) 28 | end 29 | 30 | def method_missing(sym) 31 | if params.has_key? key = sym.to_s 32 | return params[key] 33 | end 34 | super 35 | end 36 | 37 | end 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/builder.rb: -------------------------------------------------------------------------------- 1 | module Rack 2 | # Rack::Builder implements a small DSL to iteratively construct Rack 3 | # applications. 4 | # 5 | # Example: 6 | # 7 | # app = Rack::Builder.new { 8 | # use Rack::CommonLogger 9 | # use Rack::ShowExceptions 10 | # map "/lobster" do 11 | # use Rack::Lint 12 | # run Rack::Lobster.new 13 | # end 14 | # } 15 | # 16 | # Or 17 | # 18 | # app = Rack::Builder.app do 19 | # use Rack::CommonLogger 20 | # lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'OK'] } 21 | # end 22 | # 23 | # +use+ adds a middleware to the stack, +run+ dispatches to an application. 24 | # You can use +map+ to construct a Rack::URLMap in a convenient way. 25 | 26 | class Builder 27 | def initialize(&block) 28 | @ins = [] 29 | instance_eval(&block) if block_given? 30 | end 31 | 32 | def self.app(&block) 33 | self.new(&block).to_app 34 | end 35 | 36 | def use(middleware, *args, &block) 37 | @ins << lambda { |app| middleware.new(app, *args, &block) } 38 | end 39 | 40 | def run(app) 41 | @ins << app #lambda { |nothing| app } 42 | end 43 | 44 | def map(path, &block) 45 | if @ins.last.kind_of? Hash 46 | @ins.last[path] = self.class.new(&block).to_app 47 | else 48 | @ins << {} 49 | map(path, &block) 50 | end 51 | end 52 | 53 | def to_app 54 | @ins[-1] = Rack::URLMap.new(@ins.last) if Hash === @ins.last 55 | inner_app = @ins.last 56 | @ins[0...-1].reverse.inject(inner_app) { |a, e| e.call(a) } 57 | end 58 | 59 | def call(env) 60 | to_app.call(env) 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/cascade.rb: -------------------------------------------------------------------------------- 1 | module Rack 2 | # Rack::Cascade tries an request on several apps, and returns the 3 | # first response that is not 404 (or in a list of configurable 4 | # status codes). 5 | 6 | class Cascade 7 | attr_reader :apps 8 | 9 | def initialize(apps, catch=404) 10 | @apps = apps 11 | @catch = [*catch] 12 | end 13 | 14 | def call(env) 15 | status = headers = body = nil 16 | raise ArgumentError, "empty cascade" if @apps.empty? 17 | @apps.each { |app| 18 | begin 19 | status, headers, body = app.call(env) 20 | break unless @catch.include?(status.to_i) 21 | end 22 | } 23 | [status, headers, body] 24 | end 25 | 26 | def add app 27 | @apps << app 28 | end 29 | 30 | def include? app 31 | @apps.include? app 32 | end 33 | 34 | alias_method :<<, :add 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/chunked.rb: -------------------------------------------------------------------------------- 1 | require 'rack/utils' 2 | 3 | module Rack 4 | 5 | # Middleware that applies chunked transfer encoding to response bodies 6 | # when the response does not include a Content-Length header. 7 | class Chunked 8 | include Rack::Utils 9 | 10 | def initialize(app) 11 | @app = app 12 | end 13 | 14 | def call(env) 15 | status, headers, body = @app.call(env) 16 | headers = HeaderHash.new(headers) 17 | 18 | if env['HTTP_VERSION'] == 'HTTP/1.0' || 19 | STATUS_WITH_NO_ENTITY_BODY.include?(status) || 20 | headers['Content-Length'] || 21 | headers['Transfer-Encoding'] 22 | [status, headers.to_hash, body] 23 | else 24 | dup.chunk(status, headers, body) 25 | end 26 | end 27 | 28 | def chunk(status, headers, body) 29 | @body = body 30 | headers.delete('Content-Length') 31 | headers['Transfer-Encoding'] = 'chunked' 32 | [status, headers.to_hash, self] 33 | end 34 | 35 | def each 36 | term = "\r\n" 37 | @body.each do |chunk| 38 | size = bytesize(chunk) 39 | next if size == 0 40 | yield [size.to_s(16), term, chunk, term].join 41 | end 42 | yield ["0", term, "", term].join 43 | end 44 | 45 | def close 46 | @body.close if @body.respond_to?(:close) 47 | end 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/commonlogger.rb: -------------------------------------------------------------------------------- 1 | module Rack 2 | # Rack::CommonLogger forwards every request to an +app+ given, and 3 | # logs a line in the Apache common log format to the +logger+, or 4 | # rack.errors by default. 5 | 6 | class CommonLogger 7 | def initialize(app, logger=nil) 8 | @app = app 9 | @logger = logger 10 | end 11 | 12 | def call(env) 13 | dup._call(env) 14 | end 15 | 16 | def _call(env) 17 | @env = env 18 | @logger ||= self 19 | @time = Time.now 20 | @status, @header, @body = @app.call(env) 21 | [@status, @header, self] 22 | end 23 | 24 | def close 25 | @body.close if @body.respond_to? :close 26 | end 27 | 28 | # By default, log to rack.errors. 29 | def <<(str) 30 | @env["rack.errors"].write(str) 31 | @env["rack.errors"].flush 32 | end 33 | 34 | def each 35 | length = 0 36 | @body.each { |part| 37 | length += part.size 38 | yield part 39 | } 40 | 41 | @now = Time.now 42 | 43 | # Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common 44 | # lilith.local - - [07/Aug/2006 23:58:02] "GET / HTTP/1.1" 500 - 45 | # %{%s - %s [%s] "%s %s%s %s" %d %s\n} % 46 | @logger << %{%s - %s [%s] "%s %s%s %s" %d %s %0.4f\n} % 47 | [ 48 | @env['HTTP_X_FORWARDED_FOR'] || @env["REMOTE_ADDR"] || "-", 49 | @env["REMOTE_USER"] || "-", 50 | @now.strftime("%d/%b/%Y %H:%M:%S"), 51 | @env["REQUEST_METHOD"], 52 | @env["PATH_INFO"], 53 | @env["QUERY_STRING"].empty? ? "" : "?"+@env["QUERY_STRING"], 54 | @env["HTTP_VERSION"], 55 | @status.to_s[0..3], 56 | (length.zero? ? "-" : length.to_s), 57 | @now - @time 58 | ] 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/conditionalget.rb: -------------------------------------------------------------------------------- 1 | require 'rack/utils' 2 | 3 | module Rack 4 | 5 | # Middleware that enables conditional GET using If-None-Match and 6 | # If-Modified-Since. The application should set either or both of the 7 | # Last-Modified or Etag response headers according to RFC 2616. When 8 | # either of the conditions is met, the response body is set to be zero 9 | # length and the response status is set to 304 Not Modified. 10 | # 11 | # Applications that defer response body generation until the body's each 12 | # message is received will avoid response body generation completely when 13 | # a conditional GET matches. 14 | # 15 | # Adapted from Michael Klishin's Merb implementation: 16 | # http://github.com/wycats/merb-core/tree/master/lib/merb-core/rack/middleware/conditional_get.rb 17 | class ConditionalGet 18 | def initialize(app) 19 | @app = app 20 | end 21 | 22 | def call(env) 23 | return @app.call(env) unless %w[GET HEAD].include?(env['REQUEST_METHOD']) 24 | 25 | status, headers, body = @app.call(env) 26 | headers = Utils::HeaderHash.new(headers) 27 | if etag_matches?(env, headers) || modified_since?(env, headers) 28 | status = 304 29 | headers.delete('Content-Type') 30 | headers.delete('Content-Length') 31 | body = [] 32 | end 33 | [status, headers, body] 34 | end 35 | 36 | private 37 | def etag_matches?(env, headers) 38 | etag = headers['Etag'] and etag == env['HTTP_IF_NONE_MATCH'] 39 | end 40 | 41 | def modified_since?(env, headers) 42 | last_modified = headers['Last-Modified'] and 43 | last_modified == env['HTTP_IF_MODIFIED_SINCE'] 44 | end 45 | end 46 | 47 | end 48 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/content_length.rb: -------------------------------------------------------------------------------- 1 | require 'rack/utils' 2 | 3 | module Rack 4 | # Sets the Content-Length header on responses with fixed-length bodies. 5 | class ContentLength 6 | include Rack::Utils 7 | 8 | def initialize(app) 9 | @app = app 10 | end 11 | 12 | def call(env) 13 | status, headers, body = @app.call(env) 14 | headers = HeaderHash.new(headers) 15 | 16 | if !STATUS_WITH_NO_ENTITY_BODY.include?(status) && 17 | !headers['Content-Length'] && 18 | !headers['Transfer-Encoding'] && 19 | (body.respond_to?(:to_ary) || body.respond_to?(:to_str)) 20 | 21 | body = [body] if body.respond_to?(:to_str) # rack 0.4 compat 22 | length = body.to_ary.inject(0) { |len, part| len + bytesize(part) } 23 | headers['Content-Length'] = length.to_s 24 | end 25 | 26 | [status, headers, body] 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/content_type.rb: -------------------------------------------------------------------------------- 1 | require 'rack/utils' 2 | 3 | module Rack 4 | 5 | # Sets the Content-Type header on responses which don't have one. 6 | # 7 | # Builder Usage: 8 | # use Rack::ContentType, "text/plain" 9 | # 10 | # When no content type argument is provided, "text/html" is assumed. 11 | class ContentType 12 | def initialize(app, content_type = "text/html") 13 | @app, @content_type = app, content_type 14 | end 15 | 16 | def call(env) 17 | status, headers, body = @app.call(env) 18 | headers = Utils::HeaderHash.new(headers) 19 | headers['Content-Type'] ||= @content_type 20 | [status, headers.to_hash, body] 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/file.rb: -------------------------------------------------------------------------------- 1 | require 'time' 2 | require 'rack/utils' 3 | require 'rack/mime' 4 | 5 | module Rack 6 | # Rack::File serves files below the +root+ given, according to the 7 | # path info of the Rack request. 8 | # 9 | # Handlers can detect if bodies are a Rack::File, and use mechanisms 10 | # like sendfile on the +path+. 11 | 12 | class File 13 | attr_accessor :root 14 | attr_accessor :path 15 | 16 | alias :to_path :path 17 | 18 | def initialize(root) 19 | @root = root 20 | end 21 | 22 | def call(env) 23 | dup._call(env) 24 | end 25 | 26 | F = ::File 27 | 28 | def _call(env) 29 | @path_info = Utils.unescape(env["PATH_INFO"]) 30 | return forbidden if @path_info.include? ".." 31 | 32 | @path = F.join(@root, @path_info) 33 | 34 | begin 35 | if F.file?(@path) && F.readable?(@path) 36 | serving 37 | else 38 | raise Errno::EPERM 39 | end 40 | rescue SystemCallError 41 | not_found 42 | end 43 | end 44 | 45 | def forbidden 46 | body = "Forbidden\n" 47 | [403, {"Content-Type" => "text/plain", 48 | "Content-Length" => body.size.to_s}, 49 | [body]] 50 | end 51 | 52 | # NOTE: 53 | # We check via File::size? whether this file provides size info 54 | # via stat (e.g. /proc files often don't), otherwise we have to 55 | # figure it out by reading the whole file into memory. And while 56 | # we're at it we also use this as body then. 57 | 58 | def serving 59 | if size = F.size?(@path) 60 | body = self 61 | else 62 | body = [F.read(@path)] 63 | size = Utils.bytesize(body.first) 64 | end 65 | 66 | [200, { 67 | "Last-Modified" => F.mtime(@path).httpdate, 68 | "Content-Type" => Mime.mime_type(F.extname(@path), 'text/plain'), 69 | "Content-Length" => size.to_s 70 | }, body] 71 | end 72 | 73 | def not_found 74 | body = "File not found: #{@path_info}\n" 75 | [404, {"Content-Type" => "text/plain", 76 | "Content-Length" => body.size.to_s}, 77 | [body]] 78 | end 79 | 80 | def each 81 | F.open(@path, "rb") { |file| 82 | while part = file.read(8192) 83 | yield part 84 | end 85 | } 86 | end 87 | end 88 | end 89 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/handler/cgi.rb: -------------------------------------------------------------------------------- 1 | require 'rack/content_length' 2 | 3 | module Rack 4 | module Handler 5 | class CGI 6 | def self.run(app, options=nil) 7 | serve app 8 | end 9 | 10 | def self.serve(app) 11 | app = ContentLength.new(app) 12 | 13 | env = ENV.to_hash 14 | env.delete "HTTP_CONTENT_LENGTH" 15 | 16 | env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/" 17 | 18 | env.update({"rack.version" => [0,1], 19 | "rack.input" => $stdin, 20 | "rack.errors" => $stderr, 21 | 22 | "rack.multithread" => false, 23 | "rack.multiprocess" => true, 24 | "rack.run_once" => true, 25 | 26 | "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http" 27 | }) 28 | 29 | env["QUERY_STRING"] ||= "" 30 | env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] 31 | env["REQUEST_PATH"] ||= "/" 32 | 33 | status, headers, body = app.call(env) 34 | begin 35 | send_headers status, headers 36 | send_body body 37 | ensure 38 | body.close if body.respond_to? :close 39 | end 40 | end 41 | 42 | def self.send_headers(status, headers) 43 | STDOUT.print "Status: #{status}\r\n" 44 | headers.each { |k, vs| 45 | vs.split("\n").each { |v| 46 | STDOUT.print "#{k}: #{v}\r\n" 47 | } 48 | } 49 | STDOUT.print "\r\n" 50 | STDOUT.flush 51 | end 52 | 53 | def self.send_body(body) 54 | body.each { |part| 55 | STDOUT.print part 56 | STDOUT.flush 57 | } 58 | end 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/handler/evented_mongrel.rb: -------------------------------------------------------------------------------- 1 | require 'swiftcore/evented_mongrel' 2 | 3 | module Rack 4 | module Handler 5 | class EventedMongrel < Handler::Mongrel 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/handler/lsws.rb: -------------------------------------------------------------------------------- 1 | require 'lsapi' 2 | require 'rack/content_length' 3 | 4 | module Rack 5 | module Handler 6 | class LSWS 7 | def self.run(app, options=nil) 8 | while LSAPI.accept != nil 9 | serve app 10 | end 11 | end 12 | def self.serve(app) 13 | app = Rack::ContentLength.new(app) 14 | 15 | env = ENV.to_hash 16 | env.delete "HTTP_CONTENT_LENGTH" 17 | env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/" 18 | env.update({"rack.version" => [0,1], 19 | "rack.input" => StringIO.new($stdin.read.to_s), 20 | "rack.errors" => $stderr, 21 | "rack.multithread" => false, 22 | "rack.multiprocess" => true, 23 | "rack.run_once" => false, 24 | "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http" 25 | }) 26 | env["QUERY_STRING"] ||= "" 27 | env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] 28 | env["REQUEST_PATH"] ||= "/" 29 | status, headers, body = app.call(env) 30 | begin 31 | send_headers status, headers 32 | send_body body 33 | ensure 34 | body.close if body.respond_to? :close 35 | end 36 | end 37 | def self.send_headers(status, headers) 38 | print "Status: #{status}\r\n" 39 | headers.each { |k, vs| 40 | vs.split("\n").each { |v| 41 | print "#{k}: #{v}\r\n" 42 | } 43 | } 44 | print "\r\n" 45 | STDOUT.flush 46 | end 47 | def self.send_body(body) 48 | body.each { |part| 49 | print part 50 | STDOUT.flush 51 | } 52 | end 53 | end 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/handler/scgi.rb: -------------------------------------------------------------------------------- 1 | require 'scgi' 2 | require 'stringio' 3 | require 'rack/content_length' 4 | require 'rack/chunked' 5 | 6 | module Rack 7 | module Handler 8 | class SCGI < ::SCGI::Processor 9 | attr_accessor :app 10 | 11 | def self.run(app, options=nil) 12 | new(options.merge(:app=>app, 13 | :host=>options[:Host], 14 | :port=>options[:Port], 15 | :socket=>options[:Socket])).listen 16 | end 17 | 18 | def initialize(settings = {}) 19 | @app = Rack::Chunked.new(Rack::ContentLength.new(settings[:app])) 20 | @log = Object.new 21 | def @log.info(*args); end 22 | def @log.error(*args); end 23 | super(settings) 24 | end 25 | 26 | def process_request(request, input_body, socket) 27 | env = {}.replace(request) 28 | env.delete "HTTP_CONTENT_TYPE" 29 | env.delete "HTTP_CONTENT_LENGTH" 30 | env["REQUEST_PATH"], env["QUERY_STRING"] = env["REQUEST_URI"].split('?', 2) 31 | env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] 32 | env["PATH_INFO"] = env["REQUEST_PATH"] 33 | env["QUERY_STRING"] ||= "" 34 | env["SCRIPT_NAME"] = "" 35 | env.update({"rack.version" => [0,1], 36 | "rack.input" => StringIO.new(input_body), 37 | "rack.errors" => $stderr, 38 | 39 | "rack.multithread" => true, 40 | "rack.multiprocess" => true, 41 | "rack.run_once" => false, 42 | 43 | "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http" 44 | }) 45 | status, headers, body = app.call(env) 46 | begin 47 | socket.write("Status: #{status}\r\n") 48 | headers.each do |k, vs| 49 | vs.split("\n").each { |v| socket.write("#{k}: #{v}\r\n")} 50 | end 51 | socket.write("\r\n") 52 | body.each {|s| socket.write(s)} 53 | ensure 54 | body.close if body.respond_to? :close 55 | end 56 | end 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/handler/swiftiplied_mongrel.rb: -------------------------------------------------------------------------------- 1 | require 'swiftcore/swiftiplied_mongrel' 2 | 3 | module Rack 4 | module Handler 5 | class SwiftipliedMongrel < Handler::Mongrel 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/handler/thin.rb: -------------------------------------------------------------------------------- 1 | require "thin" 2 | require "rack/content_length" 3 | require "rack/chunked" 4 | 5 | module Rack 6 | module Handler 7 | class Thin 8 | def self.run(app, options={}) 9 | app = Rack::Chunked.new(Rack::ContentLength.new(app)) 10 | server = ::Thin::Server.new(options[:Host] || '0.0.0.0', 11 | options[:Port] || 8080, 12 | app) 13 | yield server if block_given? 14 | server.start 15 | end 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/handler/webrick.rb: -------------------------------------------------------------------------------- 1 | require 'webrick' 2 | require 'stringio' 3 | require 'rack/content_length' 4 | 5 | module Rack 6 | module Handler 7 | class WEBrick < ::WEBrick::HTTPServlet::AbstractServlet 8 | def self.run(app, options={}) 9 | server = ::WEBrick::HTTPServer.new(options) 10 | server.mount "/", Rack::Handler::WEBrick, app 11 | trap(:INT) { server.shutdown } 12 | yield server if block_given? 13 | server.start 14 | end 15 | 16 | def initialize(server, app) 17 | super server 18 | @app = Rack::ContentLength.new(app) 19 | end 20 | 21 | def service(req, res) 22 | env = req.meta_vars 23 | env.delete_if { |k, v| v.nil? } 24 | 25 | env.update({"rack.version" => [0,1], 26 | "rack.input" => StringIO.new(req.body.to_s), 27 | "rack.errors" => $stderr, 28 | 29 | "rack.multithread" => true, 30 | "rack.multiprocess" => false, 31 | "rack.run_once" => false, 32 | 33 | "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http" 34 | }) 35 | 36 | env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] 37 | env["QUERY_STRING"] ||= "" 38 | env["REQUEST_PATH"] ||= "/" 39 | if env["PATH_INFO"] == "" 40 | env.delete "PATH_INFO" 41 | else 42 | path, n = req.request_uri.path, env["SCRIPT_NAME"].length 43 | env["PATH_INFO"] = path[n, path.length-n] 44 | end 45 | 46 | status, headers, body = @app.call(env) 47 | begin 48 | res.status = status.to_i 49 | headers.each { |k, vs| 50 | if k.downcase == "set-cookie" 51 | res.cookies.concat vs.split("\n") 52 | else 53 | vs.split("\n").each { |v| 54 | res[k] = v 55 | } 56 | end 57 | } 58 | body.each { |part| 59 | res.body << part 60 | } 61 | ensure 62 | body.close if body.respond_to? :close 63 | end 64 | end 65 | end 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/head.rb: -------------------------------------------------------------------------------- 1 | module Rack 2 | 3 | class Head 4 | def initialize(app) 5 | @app = app 6 | end 7 | 8 | def call(env) 9 | status, headers, body = @app.call(env) 10 | 11 | if env["REQUEST_METHOD"] == "HEAD" 12 | [status, headers, []] 13 | else 14 | [status, headers, body] 15 | end 16 | end 17 | end 18 | 19 | end 20 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/lobster.rb: -------------------------------------------------------------------------------- 1 | require 'zlib' 2 | 3 | require 'rack/request' 4 | require 'rack/response' 5 | 6 | module Rack 7 | # Paste has a Pony, Rack has a Lobster! 8 | class Lobster 9 | LobsterString = Zlib::Inflate.inflate("eJx9kEEOwyAMBO99xd7MAcytUhPlJyj2 10 | P6jy9i4k9EQyGAnBarEXeCBqSkntNXsi/ZCvC48zGQoZKikGrFMZvgS5ZHd+aGWVuWwhVF0 11 | t1drVmiR42HcWNz5w3QanT+2gIvTVCiE1lm1Y0eU4JGmIIbaKwextKn8rvW+p5PIwFl8ZWJ 12 | I8jyiTlhTcYXkekJAzTyYN6E08A+dk8voBkAVTJQ==".delete("\n ").unpack("m*")[0]) 13 | 14 | LambdaLobster = lambda { |env| 15 | if env["QUERY_STRING"].include?("flip") 16 | lobster = LobsterString.split("\n"). 17 | map { |line| line.ljust(42).reverse }. 18 | join("\n") 19 | href = "?" 20 | else 21 | lobster = LobsterString 22 | href = "?flip" 23 | end 24 | 25 | content = ["Lobstericious!", 26 | "
", lobster, "
", 27 | "flip!"] 28 | length = content.inject(0) { |a,e| a+e.size }.to_s 29 | [200, {"Content-Type" => "text/html", "Content-Length" => length}, content] 30 | } 31 | 32 | def call(env) 33 | req = Request.new(env) 34 | if req.GET["flip"] == "left" 35 | lobster = LobsterString.split("\n"). 36 | map { |line| line.ljust(42).reverse }. 37 | join("\n") 38 | href = "?flip=right" 39 | elsif req.GET["flip"] == "crash" 40 | raise "Lobster crashed" 41 | else 42 | lobster = LobsterString 43 | href = "?flip=left" 44 | end 45 | 46 | res = Response.new 47 | res.write "Lobstericious!" 48 | res.write "
"
49 |       res.write lobster
50 |       res.write "
" 51 | res.write "

flip!

" 52 | res.write "

crash!

" 53 | res.finish 54 | end 55 | 56 | end 57 | end 58 | 59 | if $0 == __FILE__ 60 | require 'rack' 61 | require 'rack/showexceptions' 62 | Rack::Handler::WEBrick.run \ 63 | Rack::ShowExceptions.new(Rack::Lint.new(Rack::Lobster.new)), 64 | :Port => 9292 65 | end 66 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/lock.rb: -------------------------------------------------------------------------------- 1 | module Rack 2 | class Lock 3 | FLAG = 'rack.multithread'.freeze 4 | 5 | def initialize(app, lock = Mutex.new) 6 | @app, @lock = app, lock 7 | end 8 | 9 | def call(env) 10 | old, env[FLAG] = env[FLAG], false 11 | @lock.synchronize { @app.call(env) } 12 | ensure 13 | env[FLAG] = old 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/methodoverride.rb: -------------------------------------------------------------------------------- 1 | module Rack 2 | class MethodOverride 3 | HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS) 4 | 5 | METHOD_OVERRIDE_PARAM_KEY = "_method".freeze 6 | HTTP_METHOD_OVERRIDE_HEADER = "HTTP_X_HTTP_METHOD_OVERRIDE".freeze 7 | 8 | def initialize(app) 9 | @app = app 10 | end 11 | 12 | def call(env) 13 | if env["REQUEST_METHOD"] == "POST" 14 | req = Request.new(env) 15 | method = req.POST[METHOD_OVERRIDE_PARAM_KEY] || 16 | env[HTTP_METHOD_OVERRIDE_HEADER] 17 | method = method.to_s.upcase 18 | if HTTP_METHODS.include?(method) 19 | env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"] 20 | env["REQUEST_METHOD"] = method 21 | end 22 | end 23 | 24 | @app.call(env) 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/recursive.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | 3 | module Rack 4 | # Rack::ForwardRequest gets caught by Rack::Recursive and redirects 5 | # the current request to the app at +url+. 6 | # 7 | # raise ForwardRequest.new("/not-found") 8 | # 9 | 10 | class ForwardRequest < Exception 11 | attr_reader :url, :env 12 | 13 | def initialize(url, env={}) 14 | @url = URI(url) 15 | @env = env 16 | 17 | @env["PATH_INFO"] = @url.path 18 | @env["QUERY_STRING"] = @url.query if @url.query 19 | @env["HTTP_HOST"] = @url.host if @url.host 20 | @env["HTTP_PORT"] = @url.port if @url.port 21 | @env["rack.url_scheme"] = @url.scheme if @url.scheme 22 | 23 | super "forwarding to #{url}" 24 | end 25 | end 26 | 27 | # Rack::Recursive allows applications called down the chain to 28 | # include data from other applications (by using 29 | # rack['rack.recursive.include'][...] or raise a 30 | # ForwardRequest to redirect internally. 31 | 32 | class Recursive 33 | def initialize(app) 34 | @app = app 35 | end 36 | 37 | def call(env) 38 | @script_name = env["SCRIPT_NAME"] 39 | @app.call(env.merge('rack.recursive.include' => method(:include))) 40 | rescue ForwardRequest => req 41 | call(env.merge(req.env)) 42 | end 43 | 44 | def include(env, path) 45 | unless path.index(@script_name) == 0 && (path[@script_name.size] == ?/ || 46 | path[@script_name.size].nil?) 47 | raise ArgumentError, "can only include below #{@script_name}, not #{path}" 48 | end 49 | 50 | env = env.merge("PATH_INFO" => path, "SCRIPT_NAME" => @script_name, 51 | "REQUEST_METHOD" => "GET", 52 | "CONTENT_LENGTH" => "0", "CONTENT_TYPE" => "", 53 | "rack.input" => StringIO.new("")) 54 | @app.call(env) 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/static.rb: -------------------------------------------------------------------------------- 1 | module Rack 2 | 3 | # The Rack::Static middleware intercepts requests for static files 4 | # (javascript files, images, stylesheets, etc) based on the url prefixes 5 | # passed in the options, and serves them using a Rack::File object. This 6 | # allows a Rack stack to serve both static and dynamic content. 7 | # 8 | # Examples: 9 | # use Rack::Static, :urls => ["/media"] 10 | # will serve all requests beginning with /media from the "media" folder 11 | # located in the current directory (ie media/*). 12 | # 13 | # use Rack::Static, :urls => ["/css", "/images"], :root => "public" 14 | # will serve all requests beginning with /css or /images from the folder 15 | # "public" in the current directory (ie public/css/* and public/images/*) 16 | 17 | class Static 18 | 19 | def initialize(app, options={}) 20 | @app = app 21 | @urls = options[:urls] || ["/favicon.ico"] 22 | root = options[:root] || Dir.pwd 23 | @file_server = Rack::File.new(root) 24 | end 25 | 26 | def call(env) 27 | path = env["PATH_INFO"] 28 | can_serve = @urls.any? { |url| path.index(url) == 0 } 29 | 30 | if can_serve 31 | @file_server.call(env) 32 | else 33 | @app.call(env) 34 | end 35 | end 36 | 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/lib/rack/urlmap.rb: -------------------------------------------------------------------------------- 1 | module Rack 2 | # Rack::URLMap takes a hash mapping urls or paths to apps, and 3 | # dispatches accordingly. Support for HTTP/1.1 host names exists if 4 | # the URLs start with http:// or https://. 5 | # 6 | # URLMap modifies the SCRIPT_NAME and PATH_INFO such that the part 7 | # relevant for dispatch is in the SCRIPT_NAME, and the rest in the 8 | # PATH_INFO. This should be taken care of when you need to 9 | # reconstruct the URL in order to create links. 10 | # 11 | # URLMap dispatches in such a way that the longest paths are tried 12 | # first, since they are most specific. 13 | 14 | class URLMap 15 | def initialize(map = {}) 16 | remap(map) 17 | end 18 | 19 | def remap(map) 20 | @mapping = map.map { |location, app| 21 | if location =~ %r{\Ahttps?://(.*?)(/.*)} 22 | host, location = $1, $2 23 | else 24 | host = nil 25 | end 26 | 27 | unless location[0] == ?/ 28 | raise ArgumentError, "paths need to start with /" 29 | end 30 | location = location.chomp('/') 31 | 32 | [host, location, app] 33 | }.sort_by { |(h, l, a)| [h ? -h.size : (-1.0 / 0.0), -l.size] } # Longest path first 34 | end 35 | 36 | def call(env) 37 | path = env["PATH_INFO"].to_s.squeeze("/") 38 | script_name = env['SCRIPT_NAME'] 39 | hHost, sName, sPort = env.values_at('HTTP_HOST','SERVER_NAME','SERVER_PORT') 40 | @mapping.each { |host, location, app| 41 | next unless (hHost == host || sName == host \ 42 | || (host.nil? && (hHost == sName || hHost == sName+':'+sPort))) 43 | next unless location == path[0, location.size] 44 | next unless path[location.size] == nil || path[location.size] == ?/ 45 | 46 | return app.call( 47 | env.merge( 48 | 'SCRIPT_NAME' => (script_name + location), 49 | 'PATH_INFO' => path[location.size..-1])) 50 | } 51 | [404, {"Content-Type" => "text/plain"}, ["Not Found: #{path}"]] 52 | end 53 | end 54 | end 55 | 56 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/cgi/lighttpd.conf: -------------------------------------------------------------------------------- 1 | server.modules = ("mod_fastcgi", "mod_cgi") 2 | server.document-root = "." 3 | server.errorlog = "lighttpd.errors" 4 | server.port = 9203 5 | 6 | server.event-handler = "select" 7 | 8 | cgi.assign = ("/test" => "", 9 | # ".ru" => "" 10 | ) 11 | 12 | fastcgi.server = ("test.fcgi" => ("localhost" => 13 | ("min-procs" => 1, 14 | "socket" => "/tmp/rack-test-fcgi", 15 | "bin-path" => "test.fcgi")), 16 | "test.ru" => ("localhost" => 17 | ("min-procs" => 1, 18 | "socket" => "/tmp/rack-test-ru-fcgi", 19 | "bin-path" => "test.ru")), 20 | ) 21 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/cgi/test: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # -*- ruby -*- 3 | 4 | $: << File.join(File.dirname(__FILE__), "..", "..", "lib") 5 | 6 | require 'rack' 7 | require '../testrequest' 8 | 9 | Rack::Handler::CGI.run(Rack::Lint.new(TestRequest.new)) 10 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/cgi/test.fcgi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # -*- ruby -*- 3 | 4 | $:.unshift '../../lib' 5 | require 'rack' 6 | require '../testrequest' 7 | 8 | Rack::Handler::FastCGI.run(Rack::Lint.new(TestRequest.new)) 9 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/cgi/test.ru: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ../../bin/rackup 2 | #\ -E deployment -I ../../lib 3 | # -*- ruby -*- 4 | 5 | require '../testrequest' 6 | 7 | run TestRequest.new 8 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/multipart/binary: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehsanul/Sinatra-Authlogic-Template/3c43548960d34f39d35d7102ba422f26e282586f/vendor/rack-1.0.0/test/multipart/binary -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/multipart/empty: -------------------------------------------------------------------------------- 1 | --AaB03x 2 | Content-Disposition: form-data; name="submit-name" 3 | 4 | Larry 5 | --AaB03x 6 | Content-Disposition: form-data; name="files"; filename="file1.txt" 7 | Content-Type: text/plain 8 | 9 | 10 | --AaB03x-- 11 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/multipart/ie: -------------------------------------------------------------------------------- 1 | --AaB03x 2 | Content-Disposition: form-data; name="files"; filename="C:\Documents and Settings\Administrator\Desktop\file1.txt" 3 | Content-Type: text/plain 4 | 5 | contents 6 | --AaB03x-- 7 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/multipart/nested: -------------------------------------------------------------------------------- 1 | --AaB03x 2 | Content-Disposition: form-data; name="foo[submit-name]" 3 | 4 | Larry 5 | --AaB03x 6 | Content-Disposition: form-data; name="foo[files]"; filename="file1.txt" 7 | Content-Type: text/plain 8 | 9 | contents 10 | --AaB03x-- 11 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/multipart/none: -------------------------------------------------------------------------------- 1 | --AaB03x 2 | Content-Disposition: form-data; name="submit-name" 3 | 4 | Larry 5 | --AaB03x 6 | Content-Disposition: form-data; name="files"; filename="" 7 | 8 | 9 | --AaB03x-- 10 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/multipart/text: -------------------------------------------------------------------------------- 1 | --AaB03x 2 | Content-Disposition: form-data; name="submit-name" 3 | 4 | Larry 5 | --AaB03x 6 | Content-Disposition: form-data; name="files"; filename="file1.txt" 7 | Content-Type: text/plain 8 | 9 | contents 10 | --AaB03x-- -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_auth_basic.rb: -------------------------------------------------------------------------------- 1 | require 'test/spec' 2 | 3 | require 'rack/auth/basic' 4 | require 'rack/mock' 5 | 6 | context 'Rack::Auth::Basic' do 7 | 8 | def realm 9 | 'WallysWorld' 10 | end 11 | 12 | def unprotected_app 13 | lambda { |env| [ 200, {'Content-Type' => 'text/plain'}, ["Hi #{env['REMOTE_USER']}"] ] } 14 | end 15 | 16 | def protected_app 17 | app = Rack::Auth::Basic.new(unprotected_app) { |username, password| 'Boss' == username } 18 | app.realm = realm 19 | app 20 | end 21 | 22 | setup do 23 | @request = Rack::MockRequest.new(protected_app) 24 | end 25 | 26 | def request_with_basic_auth(username, password, &block) 27 | request 'HTTP_AUTHORIZATION' => 'Basic ' + ["#{username}:#{password}"].pack("m*"), &block 28 | end 29 | 30 | def request(headers = {}) 31 | yield @request.get('/', headers) 32 | end 33 | 34 | def assert_basic_auth_challenge(response) 35 | response.should.be.a.client_error 36 | response.status.should.equal 401 37 | response.should.include 'WWW-Authenticate' 38 | response.headers['WWW-Authenticate'].should =~ /Basic realm="#{Regexp.escape(realm)}"/ 39 | response.body.should.be.empty 40 | end 41 | 42 | specify 'should challenge correctly when no credentials are specified' do 43 | request do |response| 44 | assert_basic_auth_challenge response 45 | end 46 | end 47 | 48 | specify 'should rechallenge if incorrect credentials are specified' do 49 | request_with_basic_auth 'joe', 'password' do |response| 50 | assert_basic_auth_challenge response 51 | end 52 | end 53 | 54 | specify 'should return application output if correct credentials are specified' do 55 | request_with_basic_auth 'Boss', 'password' do |response| 56 | response.status.should.equal 200 57 | response.body.to_s.should.equal 'Hi Boss' 58 | end 59 | end 60 | 61 | specify 'should return 400 Bad Request if different auth scheme used' do 62 | request 'HTTP_AUTHORIZATION' => 'Digest params' do |response| 63 | response.should.be.a.client_error 64 | response.status.should.equal 400 65 | response.should.not.include 'WWW-Authenticate' 66 | end 67 | end 68 | 69 | specify 'realm as optional constructor arg' do 70 | app = Rack::Auth::Basic.new(unprotected_app, realm) { true } 71 | assert_equal realm, app.realm 72 | end 73 | end 74 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_camping.rb: -------------------------------------------------------------------------------- 1 | require 'test/spec' 2 | require 'stringio' 3 | require 'uri' 4 | 5 | begin 6 | require 'rack/mock' 7 | 8 | $-w, w = nil, $-w # yuck 9 | require 'camping' 10 | require 'rack/adapter/camping' 11 | 12 | Camping.goes :CampApp 13 | module CampApp 14 | module Controllers 15 | class HW < R('/') 16 | def get 17 | @headers["X-Served-By"] = URI("http://rack.rubyforge.org") 18 | "Camping works!" 19 | end 20 | 21 | def post 22 | "Data: #{input.foo}" 23 | end 24 | end 25 | end 26 | end 27 | $-w = w 28 | 29 | context "Rack::Adapter::Camping" do 30 | specify "works with GET" do 31 | res = Rack::MockRequest.new(Rack::Adapter::Camping.new(CampApp)). 32 | get("/") 33 | 34 | res.should.be.ok 35 | res["Content-Type"].should.equal "text/html" 36 | res["X-Served-By"].should.equal "http://rack.rubyforge.org" 37 | 38 | res.body.should.equal "Camping works!" 39 | end 40 | 41 | specify "works with POST" do 42 | res = Rack::MockRequest.new(Rack::Adapter::Camping.new(CampApp)). 43 | post("/", :input => "foo=bar") 44 | 45 | res.should.be.ok 46 | res.body.should.equal "Data: bar" 47 | end 48 | end 49 | rescue LoadError 50 | $stderr.puts "Skipping Rack::Adapter::Camping tests (Camping is required). `gem install camping` and try again." 51 | end 52 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_cascade.rb: -------------------------------------------------------------------------------- 1 | require 'test/spec' 2 | 3 | require 'rack/cascade' 4 | require 'rack/mock' 5 | 6 | require 'rack/urlmap' 7 | require 'rack/file' 8 | 9 | context "Rack::Cascade" do 10 | docroot = File.expand_path(File.dirname(__FILE__)) 11 | app1 = Rack::File.new(docroot) 12 | 13 | app2 = Rack::URLMap.new("/crash" => lambda { |env| raise "boom" }) 14 | 15 | app3 = Rack::URLMap.new("/foo" => lambda { |env| 16 | [200, { "Content-Type" => "text/plain"}, [""]]}) 17 | 18 | specify "should dispatch onward on 404 by default" do 19 | cascade = Rack::Cascade.new([app1, app2, app3]) 20 | Rack::MockRequest.new(cascade).get("/cgi/test").should.be.ok 21 | Rack::MockRequest.new(cascade).get("/foo").should.be.ok 22 | Rack::MockRequest.new(cascade).get("/toobad").should.be.not_found 23 | Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.forbidden 24 | end 25 | 26 | specify "should dispatch onward on whatever is passed" do 27 | cascade = Rack::Cascade.new([app1, app2, app3], [404, 403]) 28 | Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.not_found 29 | end 30 | 31 | specify "should fail if empty" do 32 | lambda { Rack::MockRequest.new(Rack::Cascade.new([])).get("/") }. 33 | should.raise(ArgumentError) 34 | end 35 | 36 | specify "should append new app" do 37 | cascade = Rack::Cascade.new([], [404, 403]) 38 | lambda { Rack::MockRequest.new(cascade).get('/cgi/test') }. 39 | should.raise(ArgumentError) 40 | cascade << app2 41 | Rack::MockRequest.new(cascade).get('/cgi/test').should.be.not_found 42 | Rack::MockRequest.new(cascade).get('/cgi/../bla').should.be.not_found 43 | cascade << app1 44 | Rack::MockRequest.new(cascade).get('/cgi/test').should.be.ok 45 | Rack::MockRequest.new(cascade).get('/cgi/../bla').should.be.forbidden 46 | Rack::MockRequest.new(cascade).get('/foo').should.be.not_found 47 | cascade << app3 48 | Rack::MockRequest.new(cascade).get('/foo').should.be.ok 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_commonlogger.rb: -------------------------------------------------------------------------------- 1 | require 'test/spec' 2 | require 'stringio' 3 | 4 | require 'rack/commonlogger' 5 | require 'rack/lobster' 6 | require 'rack/mock' 7 | 8 | context "Rack::CommonLogger" do 9 | app = lambda { |env| 10 | [200, 11 | {"Content-Type" => "text/html"}, 12 | ["foo"]]} 13 | 14 | specify "should log to rack.errors by default" do 15 | log = StringIO.new 16 | res = Rack::MockRequest.new(Rack::CommonLogger.new(app)).get("/") 17 | 18 | res.errors.should.not.be.empty 19 | res.errors.should =~ /GET / 20 | res.errors.should =~ / 200 / # status 21 | res.errors.should =~ / 3 / # length 22 | end 23 | 24 | specify "should log to anything with <<" do 25 | log = "" 26 | res = Rack::MockRequest.new(Rack::CommonLogger.new(app, log)).get("/") 27 | 28 | log.should =~ /GET / 29 | log.should =~ / 200 / # status 30 | log.should =~ / 3 / # length 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_conditionalget.rb: -------------------------------------------------------------------------------- 1 | require 'test/spec' 2 | require 'time' 3 | 4 | require 'rack/mock' 5 | require 'rack/conditionalget' 6 | 7 | context "Rack::ConditionalGet" do 8 | specify "should set a 304 status and truncate body when If-Modified-Since hits" do 9 | timestamp = Time.now.httpdate 10 | app = Rack::ConditionalGet.new(lambda { |env| 11 | [200, {'Last-Modified'=>timestamp}, ['TEST']] }) 12 | 13 | response = Rack::MockRequest.new(app). 14 | get("/", 'HTTP_IF_MODIFIED_SINCE' => timestamp) 15 | 16 | response.status.should.equal 304 17 | response.body.should.be.empty 18 | end 19 | 20 | specify "should set a 304 status and truncate body when If-None-Match hits" do 21 | app = Rack::ConditionalGet.new(lambda { |env| 22 | [200, {'Etag'=>'1234'}, ['TEST']] }) 23 | 24 | response = Rack::MockRequest.new(app). 25 | get("/", 'HTTP_IF_NONE_MATCH' => '1234') 26 | 27 | response.status.should.equal 304 28 | response.body.should.be.empty 29 | end 30 | 31 | specify "should not affect non-GET/HEAD requests" do 32 | app = Rack::ConditionalGet.new(lambda { |env| 33 | [200, {'Etag'=>'1234'}, ['TEST']] }) 34 | 35 | response = Rack::MockRequest.new(app). 36 | post("/", 'HTTP_IF_NONE_MATCH' => '1234') 37 | 38 | response.status.should.equal 200 39 | response.body.should.equal 'TEST' 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_content_length.rb: -------------------------------------------------------------------------------- 1 | require 'rack/mock' 2 | require 'rack/content_length' 3 | 4 | context "Rack::ContentLength" do 5 | specify "sets Content-Length on String bodies if none is set" do 6 | app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] } 7 | response = Rack::ContentLength.new(app).call({}) 8 | response[1]['Content-Length'].should.equal '13' 9 | end 10 | 11 | specify "sets Content-Length on Array bodies if none is set" do 12 | app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] } 13 | response = Rack::ContentLength.new(app).call({}) 14 | response[1]['Content-Length'].should.equal '13' 15 | end 16 | 17 | specify "does not set Content-Length on variable length bodies" do 18 | body = lambda { "Hello World!" } 19 | def body.each ; yield call ; end 20 | 21 | app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] } 22 | response = Rack::ContentLength.new(app).call({}) 23 | response[1]['Content-Length'].should.be.nil 24 | end 25 | 26 | specify "does not change Content-Length if it is already set" do 27 | app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Content-Length' => '1'}, "Hello, World!"] } 28 | response = Rack::ContentLength.new(app).call({}) 29 | response[1]['Content-Length'].should.equal '1' 30 | end 31 | 32 | specify "does not set Content-Length on 304 responses" do 33 | app = lambda { |env| [304, {'Content-Type' => 'text/plain'}, []] } 34 | response = Rack::ContentLength.new(app).call({}) 35 | response[1]['Content-Length'].should.equal nil 36 | end 37 | 38 | specify "does not set Content-Length when Transfer-Encoding is chunked" do 39 | app = lambda { |env| [200, {'Transfer-Encoding' => 'chunked'}, []] } 40 | response = Rack::ContentLength.new(app).call({}) 41 | response[1]['Content-Length'].should.equal nil 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_content_type.rb: -------------------------------------------------------------------------------- 1 | require 'rack/mock' 2 | require 'rack/content_type' 3 | 4 | context "Rack::ContentType" do 5 | specify "sets Content-Type to default text/html if none is set" do 6 | app = lambda { |env| [200, {}, "Hello, World!"] } 7 | status, headers, body = Rack::ContentType.new(app).call({}) 8 | headers['Content-Type'].should.equal 'text/html' 9 | end 10 | 11 | specify "sets Content-Type to chosen default if none is set" do 12 | app = lambda { |env| [200, {}, "Hello, World!"] } 13 | status, headers, body = 14 | Rack::ContentType.new(app, 'application/octet-stream').call({}) 15 | headers['Content-Type'].should.equal 'application/octet-stream' 16 | end 17 | 18 | specify "does not change Content-Type if it is already set" do 19 | app = lambda { |env| [200, {'Content-Type' => 'foo/bar'}, "Hello, World!"] } 20 | status, headers, body = Rack::ContentType.new(app).call({}) 21 | headers['Content-Type'].should.equal 'foo/bar' 22 | end 23 | 24 | specify "case insensitive detection of Content-Type" do 25 | app = lambda { |env| [200, {'CONTENT-Type' => 'foo/bar'}, "Hello, World!"] } 26 | status, headers, body = Rack::ContentType.new(app).call({}) 27 | headers.to_a.select { |k,v| k.downcase == "content-type" }. 28 | should.equal [["CONTENT-Type","foo/bar"]] 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_directory.rb: -------------------------------------------------------------------------------- 1 | require 'test/spec' 2 | 3 | require 'rack/directory' 4 | require 'rack/lint' 5 | 6 | require 'rack/mock' 7 | 8 | context "Rack::Directory" do 9 | DOCROOT = File.expand_path(File.dirname(__FILE__)) 10 | FILE_CATCH = proc{|env| [200, {'Content-Type'=>'text/plain', "Content-Length" => "7"}, ['passed!']] } 11 | app = Rack::Directory.new DOCROOT, FILE_CATCH 12 | 13 | specify "serves directory indices" do 14 | res = Rack::MockRequest.new(Rack::Lint.new(app)). 15 | get("/cgi/") 16 | 17 | res.should.be.ok 18 | res.should =~ // 19 | end 20 | 21 | specify "passes to app if file found" do 22 | res = Rack::MockRequest.new(Rack::Lint.new(app)). 23 | get("/cgi/test") 24 | 25 | res.should.be.ok 26 | res.should =~ /passed!/ 27 | end 28 | 29 | specify "serves uri with URL encoded filenames" do 30 | res = Rack::MockRequest.new(Rack::Lint.new(app)). 31 | get("/%63%67%69/") # "/cgi/test" 32 | 33 | res.should.be.ok 34 | res.should =~ // 35 | 36 | res = Rack::MockRequest.new(Rack::Lint.new(app)). 37 | get("/cgi/%74%65%73%74") # "/cgi/test" 38 | 39 | res.should.be.ok 40 | res.should =~ /passed!/ 41 | end 42 | 43 | specify "does not allow directory traversal" do 44 | res = Rack::MockRequest.new(Rack::Lint.new(app)). 45 | get("/cgi/../test") 46 | 47 | res.should.be.forbidden 48 | 49 | res = Rack::MockRequest.new(Rack::Lint.new(app)). 50 | get("/cgi/%2E%2E/test") 51 | 52 | res.should.be.forbidden 53 | end 54 | 55 | specify "404s if it can't find the file" do 56 | res = Rack::MockRequest.new(Rack::Lint.new(app)). 57 | get("/cgi/blubb") 58 | 59 | res.should.be.not_found 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_file.rb: -------------------------------------------------------------------------------- 1 | require 'test/spec' 2 | 3 | require 'rack/file' 4 | require 'rack/lint' 5 | 6 | require 'rack/mock' 7 | 8 | context "Rack::File" do 9 | DOCROOT = File.expand_path(File.dirname(__FILE__)) 10 | 11 | specify "serves files" do 12 | res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). 13 | get("/cgi/test") 14 | 15 | res.should.be.ok 16 | res.should =~ /ruby/ 17 | end 18 | 19 | specify "sets Last-Modified header" do 20 | res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). 21 | get("/cgi/test") 22 | 23 | path = File.join(DOCROOT, "/cgi/test") 24 | 25 | res.should.be.ok 26 | res["Last-Modified"].should.equal File.mtime(path).httpdate 27 | end 28 | 29 | specify "serves files with URL encoded filenames" do 30 | res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). 31 | get("/cgi/%74%65%73%74") # "/cgi/test" 32 | 33 | res.should.be.ok 34 | res.should =~ /ruby/ 35 | end 36 | 37 | specify "does not allow directory traversal" do 38 | res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). 39 | get("/cgi/../test") 40 | 41 | res.should.be.forbidden 42 | end 43 | 44 | specify "does not allow directory traversal with encoded periods" do 45 | res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). 46 | get("/%2E%2E/README") 47 | 48 | res.should.be.forbidden 49 | end 50 | 51 | specify "404s if it can't find the file" do 52 | res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). 53 | get("/cgi/blubb") 54 | 55 | res.should.be.not_found 56 | end 57 | 58 | specify "detects SystemCallErrors" do 59 | res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). 60 | get("/cgi") 61 | 62 | res.should.be.not_found 63 | end 64 | 65 | specify "returns bodies that respond to #to_path" do 66 | env = Rack::MockRequest.env_for("/cgi/test") 67 | status, headers, body = Rack::File.new(DOCROOT).call(env) 68 | 69 | path = File.join(DOCROOT, "/cgi/test") 70 | 71 | status.should.equal 200 72 | body.should.respond_to :to_path 73 | body.to_path.should.equal path 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_handler.rb: -------------------------------------------------------------------------------- 1 | require 'test/spec' 2 | 3 | require 'rack/handler' 4 | 5 | class Rack::Handler::Lobster; end 6 | class RockLobster; end 7 | 8 | context "Rack::Handler" do 9 | specify "has registered default handlers" do 10 | Rack::Handler.get('cgi').should.equal Rack::Handler::CGI 11 | Rack::Handler.get('fastcgi').should.equal Rack::Handler::FastCGI 12 | Rack::Handler.get('mongrel').should.equal Rack::Handler::Mongrel 13 | Rack::Handler.get('webrick').should.equal Rack::Handler::WEBrick 14 | end 15 | 16 | specify "handler that doesn't exist should raise a NameError" do 17 | lambda { 18 | Rack::Handler.get('boom') 19 | }.should.raise(NameError) 20 | end 21 | 22 | specify "should get unregistered, but already required, handler by name" do 23 | Rack::Handler.get('Lobster').should.equal Rack::Handler::Lobster 24 | end 25 | 26 | specify "should register custom handler" do 27 | Rack::Handler.register('rock_lobster', 'RockLobster') 28 | Rack::Handler.get('rock_lobster').should.equal RockLobster 29 | end 30 | 31 | specify "should not need registration for properly coded handlers even if not already required" do 32 | begin 33 | $:.push "test/unregistered_handler" 34 | Rack::Handler.get('Unregistered').should.equal Rack::Handler::Unregistered 35 | lambda { 36 | Rack::Handler.get('UnRegistered') 37 | }.should.raise(NameError) 38 | Rack::Handler.get('UnregisteredLongOne').should.equal Rack::Handler::UnregisteredLongOne 39 | ensure 40 | $:.delete "test/unregistered_handler" 41 | end 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_head.rb: -------------------------------------------------------------------------------- 1 | require 'rack/head' 2 | require 'rack/mock' 3 | 4 | context "Rack::Head" do 5 | def test_response(headers = {}) 6 | app = lambda { |env| [200, {"Content-type" => "test/plain", "Content-length" => "3"}, ["foo"]] } 7 | request = Rack::MockRequest.env_for("/", headers) 8 | response = Rack::Head.new(app).call(request) 9 | 10 | return response 11 | end 12 | 13 | specify "passes GET, POST, PUT, DELETE, OPTIONS, TRACE requests" do 14 | %w[GET POST PUT DELETE OPTIONS TRACE].each do |type| 15 | resp = test_response("REQUEST_METHOD" => type) 16 | 17 | resp[0].should.equal(200) 18 | resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"}) 19 | resp[2].should.equal(["foo"]) 20 | end 21 | end 22 | 23 | specify "removes body from HEAD requests" do 24 | resp = test_response("REQUEST_METHOD" => "HEAD") 25 | 26 | resp[0].should.equal(200) 27 | resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"}) 28 | resp[2].should.equal([]) 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_lobster.rb: -------------------------------------------------------------------------------- 1 | require 'test/spec' 2 | 3 | require 'rack/lobster' 4 | require 'rack/mock' 5 | 6 | context "Rack::Lobster::LambdaLobster" do 7 | specify "should be a single lambda" do 8 | Rack::Lobster::LambdaLobster.should.be.kind_of Proc 9 | end 10 | 11 | specify "should look like a lobster" do 12 | res = Rack::MockRequest.new(Rack::Lobster::LambdaLobster).get("/") 13 | res.should.be.ok 14 | res.body.should.include "(,(,,(,,,(" 15 | res.body.should.include "?flip" 16 | end 17 | 18 | specify "should be flippable" do 19 | res = Rack::MockRequest.new(Rack::Lobster::LambdaLobster).get("/?flip") 20 | res.should.be.ok 21 | res.body.should.include "(,,,(,,(,(" 22 | end 23 | end 24 | 25 | context "Rack::Lobster" do 26 | specify "should look like a lobster" do 27 | res = Rack::MockRequest.new(Rack::Lobster.new).get("/") 28 | res.should.be.ok 29 | res.body.should.include "(,(,,(,,,(" 30 | res.body.should.include "?flip" 31 | res.body.should.include "crash" 32 | end 33 | 34 | specify "should be flippable" do 35 | res = Rack::MockRequest.new(Rack::Lobster.new).get("/?flip=left") 36 | res.should.be.ok 37 | res.body.should.include "(,,,(,,(,(" 38 | end 39 | 40 | specify "should provide crashing for testing purposes" do 41 | lambda { 42 | Rack::MockRequest.new(Rack::Lobster.new).get("/?flip=crash") 43 | }.should.raise 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_lock.rb: -------------------------------------------------------------------------------- 1 | require 'test/spec' 2 | 3 | require 'rack/mock' 4 | require 'rack/lock' 5 | 6 | context "Rack::Lock" do 7 | class Lock 8 | attr_reader :synchronized 9 | 10 | def initialize 11 | @synchronized = false 12 | end 13 | 14 | def synchronize 15 | @synchronized = true 16 | yield 17 | end 18 | end 19 | 20 | specify "should call synchronize on lock" do 21 | lock = Lock.new 22 | env = Rack::MockRequest.env_for("/") 23 | app = Rack::Lock.new(lambda { |env| }, lock) 24 | lock.synchronized.should.equal false 25 | app.call(env) 26 | lock.synchronized.should.equal true 27 | end 28 | 29 | specify "should set multithread flag to false" do 30 | app = Rack::Lock.new(lambda { |env| env['rack.multithread'] }) 31 | app.call(Rack::MockRequest.env_for("/")).should.equal false 32 | end 33 | 34 | specify "should reset original multithread flag when exiting lock" do 35 | app = Rack::Lock.new(lambda { |env| env }) 36 | app.call(Rack::MockRequest.env_for("/"))['rack.multithread'].should.equal true 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_methodoverride.rb: -------------------------------------------------------------------------------- 1 | require 'test/spec' 2 | 3 | require 'rack/mock' 4 | require 'rack/methodoverride' 5 | require 'stringio' 6 | 7 | context "Rack::MethodOverride" do 8 | specify "should not affect GET requests" do 9 | env = Rack::MockRequest.env_for("/?_method=delete", :method => "GET") 10 | app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) 11 | req = app.call(env) 12 | 13 | req.env["REQUEST_METHOD"].should.equal "GET" 14 | end 15 | 16 | specify "_method parameter should modify REQUEST_METHOD for POST requests" do 17 | env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=put") 18 | app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) 19 | req = app.call(env) 20 | 21 | req.env["REQUEST_METHOD"].should.equal "PUT" 22 | end 23 | 24 | specify "X-HTTP-Method-Override header should modify REQUEST_METHOD for POST requests" do 25 | env = Rack::MockRequest.env_for("/", 26 | :method => "POST", 27 | "HTTP_X_HTTP_METHOD_OVERRIDE" => "PUT" 28 | ) 29 | app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) 30 | req = app.call(env) 31 | 32 | req.env["REQUEST_METHOD"].should.equal "PUT" 33 | end 34 | 35 | specify "should not modify REQUEST_METHOD if the method is unknown" do 36 | env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=foo") 37 | app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) 38 | req = app.call(env) 39 | 40 | req.env["REQUEST_METHOD"].should.equal "POST" 41 | end 42 | 43 | specify "should not modify REQUEST_METHOD when _method is nil" do 44 | env = Rack::MockRequest.env_for("/", :method => "POST", :input => "foo=bar") 45 | app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) 46 | req = app.call(env) 47 | 48 | req.env["REQUEST_METHOD"].should.equal "POST" 49 | end 50 | 51 | specify "should store the original REQUEST_METHOD prior to overriding" do 52 | env = Rack::MockRequest.env_for("/", 53 | :method => "POST", 54 | :input => "_method=options") 55 | app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) 56 | req = app.call(env) 57 | 58 | req.env["rack.methodoverride.original_method"].should.equal "POST" 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_showexceptions.rb: -------------------------------------------------------------------------------- 1 | require 'test/spec' 2 | 3 | require 'rack/showexceptions' 4 | require 'rack/mock' 5 | 6 | context "Rack::ShowExceptions" do 7 | specify "catches exceptions" do 8 | res = nil 9 | req = Rack::MockRequest.new(Rack::ShowExceptions.new(lambda { |env| 10 | raise RuntimeError 11 | })) 12 | lambda { 13 | res = req.get("/") 14 | }.should.not.raise 15 | res.should.be.a.server_error 16 | res.status.should.equal 500 17 | 18 | res.should =~ /RuntimeError/ 19 | res.should =~ /ShowExceptions/ 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/spec_rack_static.rb: -------------------------------------------------------------------------------- 1 | require 'test/spec' 2 | 3 | require 'rack/static' 4 | require 'rack/mock' 5 | 6 | class DummyApp 7 | def call(env) 8 | [200, {}, ["Hello World"]] 9 | end 10 | end 11 | 12 | context "Rack::Static" do 13 | root = File.expand_path(File.dirname(__FILE__)) 14 | OPTIONS = {:urls => ["/cgi"], :root => root} 15 | 16 | setup do 17 | @request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, OPTIONS)) 18 | end 19 | 20 | specify "serves files" do 21 | res = @request.get("/cgi/test") 22 | res.should.be.ok 23 | res.body.should =~ /ruby/ 24 | end 25 | 26 | specify "404s if url root is known but it can't find the file" do 27 | res = @request.get("/cgi/foo") 28 | res.should.be.not_found 29 | end 30 | 31 | specify "calls down the chain if url root is not known" do 32 | res = @request.get("/something/else") 33 | res.should.be.ok 34 | res.body.should == "Hello World" 35 | end 36 | 37 | end 38 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/testrequest.rb: -------------------------------------------------------------------------------- 1 | require 'yaml' 2 | require 'net/http' 3 | 4 | class TestRequest 5 | def call(env) 6 | status = env["QUERY_STRING"] =~ /secret/ ? 403 : 200 7 | env["test.postdata"] = env["rack.input"].read 8 | body = env.to_yaml 9 | size = body.respond_to?(:bytesize) ? body.bytesize : body.size 10 | [status, {"Content-Type" => "text/yaml", "Content-Length" => size.to_s}, [body]] 11 | end 12 | 13 | module Helpers 14 | attr_reader :status, :response 15 | 16 | def GET(path, header={}) 17 | Net::HTTP.start(@host, @port) { |http| 18 | user = header.delete(:user) 19 | passwd = header.delete(:passwd) 20 | 21 | get = Net::HTTP::Get.new(path, header) 22 | get.basic_auth user, passwd if user && passwd 23 | http.request(get) { |response| 24 | @status = response.code.to_i 25 | @response = YAML.load(response.body) 26 | } 27 | } 28 | end 29 | 30 | def POST(path, formdata={}, header={}) 31 | Net::HTTP.start(@host, @port) { |http| 32 | user = header.delete(:user) 33 | passwd = header.delete(:passwd) 34 | 35 | post = Net::HTTP::Post.new(path, header) 36 | post.form_data = formdata 37 | post.basic_auth user, passwd if user && passwd 38 | http.request(post) { |response| 39 | @status = response.code.to_i 40 | @response = YAML.load(response.body) 41 | } 42 | } 43 | end 44 | end 45 | end 46 | 47 | class StreamingRequest 48 | def self.call(env) 49 | [200, {"Content-Type" => "text/plain"}, new] 50 | end 51 | 52 | def each 53 | yield "hello there!\n" 54 | sleep 5 55 | yield "that is all.\n" 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/unregistered_handler/rack/handler/unregistered.rb: -------------------------------------------------------------------------------- 1 | module Rack 2 | module Handler 3 | # this class doesn't do anything, we're just seeing if we get it. 4 | class Unregistered 5 | end 6 | end 7 | end -------------------------------------------------------------------------------- /vendor/rack-1.0.0/test/unregistered_handler/rack/handler/unregistered_long_one.rb: -------------------------------------------------------------------------------- 1 | module Rack 2 | module Handler 3 | # this class doesn't do anything, we're just seeing if we get it. 4 | class UnregisteredLongOne 5 | end 6 | end 7 | end -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007, 2008, 2009 Blake Mizerany 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/compat_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | context "Compat" do 4 | setup do 5 | Sinatra.application = nil 6 | @app = Sinatra.application 7 | end 8 | 9 | specify "makes EventContext available" do 10 | assert_same Sinatra::Default, Sinatra::EventContext 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/custom_error_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | context "Custom Errors" do 4 | 5 | setup do 6 | Sinatra.application = nil 7 | end 8 | 9 | specify "override the default 404" do 10 | 11 | get_it '/' 12 | should.be.not_found 13 | body.should.equal '

Not Found

' 14 | 15 | error Sinatra::NotFound do 16 | 'Custom 404' 17 | end 18 | 19 | get_it '/' 20 | should.be.not_found 21 | body.should.equal 'Custom 404' 22 | 23 | end 24 | 25 | specify "override the default 500" do 26 | Sinatra.application.options.raise_errors = false 27 | 28 | get '/' do 29 | raise 'asdf' 30 | end 31 | 32 | get_it '/' 33 | status.should.equal 500 34 | body.should.equal '

Internal Server Error

' 35 | 36 | 37 | error do 38 | 'Custom 500 for ' + request.env['sinatra.error'].message 39 | end 40 | 41 | get_it '/' 42 | 43 | get_it '/' 44 | status.should.equal 500 45 | body.should.equal 'Custom 500 for asdf' 46 | 47 | Sinatra.application.options.raise_errors = true 48 | end 49 | 50 | class UnmappedError < RuntimeError; end 51 | 52 | specify "should bring unmapped error back to the top" do 53 | get '/' do 54 | raise UnmappedError, 'test' 55 | end 56 | 57 | assert_raises(UnmappedError) do 58 | get_it '/' 59 | end 60 | end 61 | 62 | end 63 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/filter_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | context "before filters" do 4 | 5 | setup do 6 | Sinatra.application = nil 7 | @app = Sinatra.application 8 | end 9 | 10 | specify "should be executed in the order defined" do 11 | invoked = 0x0 12 | @app.before { invoked = 0x01 } 13 | @app.before { invoked |= 0x02 } 14 | @app.get('/') { 'Hello World' } 15 | get_it '/' 16 | should.be.ok 17 | body.should.be == 'Hello World' 18 | invoked.should.be == 0x03 19 | end 20 | 21 | specify "should be capable of modifying the request" do 22 | @app.get('/foo') { 'foo' } 23 | @app.get('/bar') { 'bar' } 24 | @app.before { request.path_info = '/bar' } 25 | get_it '/foo' 26 | should.be.ok 27 | body.should.be == 'bar' 28 | end 29 | 30 | end 31 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/helper.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'mocha' 3 | 4 | # disable warnings in compat specs. 5 | $VERBOSE = nil 6 | 7 | $:.unshift File.dirname(File.dirname(__FILE__)) + "/lib" 8 | 9 | ENV['RACK_ENV'] ||= 'test' 10 | 11 | require 'sinatra' 12 | require 'sinatra/test' 13 | require 'sinatra/test/unit' 14 | require 'sinatra/test/spec' 15 | 16 | module Sinatra::Test 17 | # we need to remove the new test helper methods since they conflict with 18 | # the top-level methods of the same name. 19 | %w(get head post put delete).each do |verb| 20 | remove_method verb 21 | end 22 | include Sinatra::Delegator 23 | end 24 | 25 | class Test::Unit::TestCase 26 | include Sinatra::Test 27 | 28 | PASSTHROUGH_EXCEPTIONS = [] unless const_defined?(:PASSTHROUGH_EXCEPTIONS) 29 | 30 | def setup 31 | @app = lambda { |env| Sinatra::Application.call(env) } 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/mapped_error_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | class FooError < RuntimeError; end 4 | 5 | context "Mapped errors" do 6 | 7 | setup do 8 | Sinatra.application = nil 9 | Sinatra.application.options.raise_errors = false 10 | end 11 | 12 | specify "are rescued and run in context" do 13 | 14 | error FooError do 15 | 'MAPPED ERROR!' 16 | end 17 | 18 | get '/' do 19 | raise FooError 20 | end 21 | 22 | get_it '/' 23 | 24 | should.be.server_error 25 | body.should.equal 'MAPPED ERROR!' 26 | 27 | end 28 | 29 | specify "renders empty if no each method on result" do 30 | 31 | error FooError do 32 | nil 33 | end 34 | 35 | get '/' do 36 | raise FooError 37 | end 38 | 39 | get_it '/' 40 | 41 | should.be.server_error 42 | body.should.be.empty 43 | 44 | end 45 | 46 | specify "doesn't override status if set" do 47 | 48 | error FooError do 49 | status(200) 50 | end 51 | 52 | get '/' do 53 | raise FooError 54 | end 55 | 56 | get_it '/' 57 | 58 | should.be.ok 59 | 60 | end 61 | 62 | specify "raises errors when the raise_errors option is set" do 63 | Sinatra.application.options.raise_errors = true 64 | error FooError do 65 | end 66 | get '/' do 67 | raise FooError 68 | end 69 | assert_raises(FooError) { get_it('/') } 70 | end 71 | 72 | end 73 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/pipeline_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | class UpcaseMiddleware 4 | def initialize(app, *args, &block) 5 | @app = app 6 | @args = args 7 | @block = block 8 | end 9 | def call(env) 10 | env['PATH_INFO'] = env['PATH_INFO'].to_s.upcase 11 | @app.call(env) 12 | end 13 | end 14 | 15 | context "Middleware Pipelines" do 16 | 17 | setup do 18 | Sinatra.application = nil 19 | @app = Sinatra.application 20 | end 21 | 22 | teardown do 23 | Sinatra.application = nil 24 | end 25 | 26 | specify "should add middleware with use" do 27 | block = Proc.new { |env| } 28 | @app.use UpcaseMiddleware 29 | @app.use UpcaseMiddleware, "foo", "bar" 30 | @app.use UpcaseMiddleware, "foo", "bar", &block 31 | @app.send(:middleware).should.include([UpcaseMiddleware, [], nil]) 32 | @app.send(:middleware).should.include([UpcaseMiddleware, ["foo", "bar"], nil]) 33 | @app.send(:middleware).should.include([UpcaseMiddleware, ["foo", "bar"], block]) 34 | end 35 | 36 | specify "should run middleware added with use" do 37 | get('/foo') { "FAIL!" } 38 | get('/FOO') { "PASS!" } 39 | use UpcaseMiddleware 40 | get_it '/foo' 41 | should.be.ok 42 | body.should.equal "PASS!" 43 | end 44 | 45 | end 46 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/public/foo.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/sass_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | context "Sass" do 4 | 5 | setup do 6 | Sinatra.application = nil 7 | end 8 | 9 | context "Templates (in general)" do 10 | 11 | setup do 12 | Sinatra.application = nil 13 | end 14 | 15 | specify "are read from files if Symbols" do 16 | 17 | get '/from_file' do 18 | sass :foo, :views_directory => File.dirname(__FILE__) + "/views" 19 | end 20 | 21 | get_it '/from_file' 22 | should.be.ok 23 | body.should.equal "#sass {\n background_color: #FFF; }\n" 24 | 25 | end 26 | 27 | specify "raise an error if template not found" do 28 | get '/' do 29 | sass :not_found 30 | end 31 | 32 | lambda { get_it '/' }.should.raise(Errno::ENOENT) 33 | end 34 | 35 | specify "ignore default layout file with .sass extension" do 36 | get '/' do 37 | sass :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test" 38 | end 39 | 40 | get_it '/' 41 | should.be.ok 42 | body.should.equal "#sass {\n background_color: #FFF; }\n" 43 | end 44 | 45 | specify "ignore explicitly specified layout file" do 46 | get '/' do 47 | sass :foo, :layout => :layout, :views_directory => File.dirname(__FILE__) + "/views/layout_test" 48 | end 49 | 50 | get_it '/' 51 | should.be.ok 52 | body.should.equal "#sass {\n background_color: #FFF; }\n" 53 | end 54 | 55 | it "passes :sass option to the Sass engine" do 56 | get '/' do 57 | sass "#sass\n :background-color #FFF\n :color #000\n", :sass => {:style => :compact} 58 | end 59 | 60 | get_it '/' 61 | should.be.ok 62 | body.should.equal "#sass { background-color: #FFF; color: #000; }\n" 63 | end 64 | 65 | end 66 | 67 | end 68 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/sessions_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | context "Sessions" do 4 | 5 | setup { Sinatra.application = nil } 6 | 7 | specify "should be off by default" do 8 | get '/asdf' do 9 | session[:test] = true 10 | "asdf" 11 | end 12 | 13 | get '/test' do 14 | session[:test] == true ? "true" : "false" 15 | end 16 | 17 | get_it '/asdf', {}, 'HTTP_HOST' => 'foo.sinatrarb.com' 18 | assert ok? 19 | assert !include?('Set-Cookie') 20 | end 21 | 22 | specify "should be able to store data accross requests" do 23 | set_option :sessions, true 24 | set_option :environment, :not_test # necessary because sessions are disabled 25 | 26 | get '/foo' do 27 | session[:test] = true 28 | "asdf" 29 | end 30 | 31 | get '/bar' do 32 | session[:test] == true ? "true" : "false" 33 | end 34 | 35 | get_it '/foo', :env => { :host => 'foo.sinatrarb.com' } 36 | assert ok? 37 | assert include?('Set-Cookie') 38 | 39 | set_option :environment, :test 40 | end 41 | 42 | end 43 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/sym_params_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | context "Symbol Params" do 4 | 5 | setup do 6 | Sinatra.application = nil 7 | end 8 | 9 | specify "should be accessable as Strings or Symbols" do 10 | get '/' do 11 | params[:foo] + params['foo'] 12 | end 13 | 14 | get_it '/', :foo => "X" 15 | assert_equal('XX', body) 16 | end 17 | 18 | end 19 | 20 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/template_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | context "Templates" do 4 | 5 | specify "are read from files if Symbols" do 6 | 7 | get '/from_file' do 8 | @name = 'Alena' 9 | erb :foo, :views_directory => File.dirname(__FILE__) + "/views" 10 | end 11 | 12 | get_it '/from_file' 13 | 14 | body.should.equal 'You rock Alena!' 15 | 16 | end 17 | 18 | specify "use layout.ext by default if available" do 19 | 20 | get '/layout_from_file' do 21 | erb :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test" 22 | end 23 | 24 | get_it '/layout_from_file' 25 | should.be.ok 26 | body.should.equal "x This is foo! x \n" 27 | 28 | end 29 | 30 | end 31 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/use_in_file_templates_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | context "Rendering in file templates" do 4 | 5 | setup do 6 | Sinatra.application = nil 7 | use_in_file_templates! 8 | end 9 | 10 | specify "should set template" do 11 | assert Sinatra.application.templates[:foo] 12 | end 13 | 14 | specify "should set layout" do 15 | assert Sinatra.application.templates[:layout] 16 | end 17 | 18 | specify "should render without layout if specified" do 19 | get '/' do 20 | haml :foo, :layout => false 21 | end 22 | 23 | get_it '/' 24 | assert_equal "this is foo\n", body 25 | end 26 | 27 | specify "should render with layout if specified" do 28 | get '/' do 29 | haml :foo 30 | end 31 | 32 | get_it '/' 33 | assert_equal "X\nthis is foo\nX\n", body 34 | end 35 | 36 | end 37 | 38 | __END__ 39 | 40 | @@ foo 41 | this is foo 42 | 43 | @@ layout 44 | X 45 | = yield 46 | X 47 | 48 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/foo.builder: -------------------------------------------------------------------------------- 1 | xml.exclaim "You rock #{@name}!" 2 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/foo.erb: -------------------------------------------------------------------------------- 1 | You rock <%= @name %>! -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/foo.haml: -------------------------------------------------------------------------------- 1 | == You rock #{@name}! -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/foo.sass: -------------------------------------------------------------------------------- 1 | #sass 2 | :background_color #FFF -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/foo_layout.erb: -------------------------------------------------------------------------------- 1 | <%= @title %> 2 | Hi <%= yield %> 3 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/foo_layout.haml: -------------------------------------------------------------------------------- 1 | == #{@title} 2 | == Hi #{yield} 3 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/layout_test/foo.builder: -------------------------------------------------------------------------------- 1 | xml.this "is foo!" 2 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/layout_test/foo.erb: -------------------------------------------------------------------------------- 1 | This is foo! -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/layout_test/foo.haml: -------------------------------------------------------------------------------- 1 | This is foo! -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/layout_test/foo.sass: -------------------------------------------------------------------------------- 1 | #sass 2 | :background_color #FFF -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/layout_test/layout.builder: -------------------------------------------------------------------------------- 1 | xml.layout do 2 | xml << yield 3 | end 4 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/layout_test/layout.erb: -------------------------------------------------------------------------------- 1 | x <%= yield %> x 2 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/layout_test/layout.haml: -------------------------------------------------------------------------------- 1 | == x #{yield} x 2 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/layout_test/layout.sass: -------------------------------------------------------------------------------- 1 | b0rked! 2 | = yield -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/no_layout/no_layout.builder: -------------------------------------------------------------------------------- 1 | xml.foo "No Layout!" 2 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/compat/views/no_layout/no_layout.haml: -------------------------------------------------------------------------------- 1 | %h1 No Layout! -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/lib/sinatra.rb: -------------------------------------------------------------------------------- 1 | libdir = File.dirname(__FILE__) 2 | $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) 3 | 4 | require 'sinatra/base' 5 | require 'sinatra/main' 6 | require 'sinatra/compat' 7 | 8 | use_in_file_templates! 9 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/lib/sinatra/images/404.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehsanul/Sinatra-Authlogic-Template/3c43548960d34f39d35d7102ba422f26e282586f/vendor/sinatra-0.9.4/lib/sinatra/images/404.png -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/lib/sinatra/images/500.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehsanul/Sinatra-Authlogic-Template/3c43548960d34f39d35d7102ba422f26e282586f/vendor/sinatra-0.9.4/lib/sinatra/images/500.png -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/lib/sinatra/main.rb: -------------------------------------------------------------------------------- 1 | require 'sinatra/base' 2 | 3 | module Sinatra 4 | class Default < Base 5 | 6 | # we assume that the first file that requires 'sinatra' is the 7 | # app_file. all other path related options are calculated based 8 | # on this path by default. 9 | set :app_file, caller_files.first || $0 10 | 11 | set :run, Proc.new { $0 == app_file } 12 | 13 | if run? && ARGV.any? 14 | require 'optparse' 15 | OptionParser.new { |op| 16 | op.on('-x') { set :lock, true } 17 | op.on('-e env') { |val| set :environment, val.to_sym } 18 | op.on('-s server') { |val| set :server, val } 19 | op.on('-p port') { |val| set :port, val.to_i } 20 | }.parse!(ARGV.dup) 21 | end 22 | end 23 | end 24 | 25 | include Sinatra::Delegator 26 | 27 | def mime(ext, type) 28 | ext = ".#{ext}" unless ext.to_s[0] == ?. 29 | Rack::Mime::MIME_TYPES[ext.to_s] = type 30 | end 31 | 32 | at_exit do 33 | raise $! if $! 34 | Sinatra::Application.run! if Sinatra::Application.run? 35 | end 36 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/lib/sinatra/test/bacon.rb: -------------------------------------------------------------------------------- 1 | require 'bacon' 2 | require 'sinatra/test' 3 | 4 | Sinatra::Test.deprecate('Bacon') 5 | 6 | Sinatra::Default.set( 7 | :environment => :test, 8 | :run => false, 9 | :raise_errors => true, 10 | :logging => false 11 | ) 12 | 13 | module Sinatra::Test 14 | def should 15 | @response.should 16 | end 17 | end 18 | 19 | Bacon::Context.send(:include, Sinatra::Test) 20 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/lib/sinatra/test/rspec.rb: -------------------------------------------------------------------------------- 1 | require 'sinatra/test' 2 | require 'sinatra/test/unit' 3 | require 'spec' 4 | require 'spec/interop/test' 5 | 6 | Sinatra::Test.deprecate('RSpec') 7 | 8 | Sinatra::Default.set( 9 | :environment => :test, 10 | :run => false, 11 | :raise_errors => true, 12 | :logging => false 13 | ) 14 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/lib/sinatra/test/spec.rb: -------------------------------------------------------------------------------- 1 | require 'test/spec' 2 | require 'sinatra/test' 3 | require 'sinatra/test/unit' 4 | 5 | Sinatra::Test.deprecate('test/spec') 6 | 7 | module Sinatra::Test 8 | def should 9 | @response.should 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/lib/sinatra/test/unit.rb: -------------------------------------------------------------------------------- 1 | require 'sinatra/test' 2 | require 'test/unit' 3 | 4 | Sinatra::Test.deprecate('test/unit') 5 | 6 | Test::Unit::TestCase.send :include, Sinatra::Test 7 | 8 | Sinatra::Default.set( 9 | :environment => :test, 10 | :run => false, 11 | :raise_errors => true, 12 | :logging => false 13 | ) 14 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/builder_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | require 'builder' 3 | 4 | class BuilderTest < Test::Unit::TestCase 5 | def builder_app(&block) 6 | mock_app { 7 | set :views, File.dirname(__FILE__) + '/views' 8 | get '/', &block 9 | } 10 | get '/' 11 | end 12 | 13 | it 'renders inline Builder strings' do 14 | builder_app { builder 'xml.instruct!' } 15 | assert ok? 16 | assert_equal %{\n}, body 17 | end 18 | 19 | it 'renders inline blocks' do 20 | builder_app { 21 | @name = "Frank & Mary" 22 | builder do |xml| 23 | xml.couple @name 24 | end 25 | } 26 | assert ok? 27 | assert_equal "Frank & Mary\n", body 28 | end 29 | 30 | it 'renders .builder files in views path' do 31 | builder_app { 32 | @name = "Blue" 33 | builder :hello 34 | } 35 | assert ok? 36 | assert_equal %(You're my boy, Blue!\n), body 37 | end 38 | 39 | it "renders with inline layouts" do 40 | mock_app { 41 | layout do 42 | %(xml.layout { xml << yield }) 43 | end 44 | get('/') { builder %(xml.em 'Hello World') } 45 | } 46 | get '/' 47 | assert ok? 48 | assert_equal "\nHello World\n\n", body 49 | end 50 | 51 | it "renders with file layouts" do 52 | builder_app { 53 | builder %(xml.em 'Hello World'), :layout => :layout2 54 | } 55 | assert ok? 56 | assert_equal "\nHello World\n\n", body 57 | end 58 | 59 | it "raises error if template not found" do 60 | mock_app { 61 | get('/') { builder :no_such_template } 62 | } 63 | assert_raise(Errno::ENOENT) { get('/') } 64 | end 65 | end 66 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/contest.rb: -------------------------------------------------------------------------------- 1 | require "test/unit" 2 | 3 | # Test::Unit loads a default test if the suite is empty, and the only 4 | # purpose of that test is to fail. As having empty contexts is a common 5 | # practice, we decided to overwrite TestSuite#empty? in order to 6 | # allow them. Having a failure when no tests have been defined seems 7 | # counter-intuitive. 8 | class Test::Unit::TestSuite 9 | unless method_defined?(:empty?) 10 | def empty? 11 | false 12 | end 13 | end 14 | end 15 | 16 | # We added setup, test and context as class methods, and the instance 17 | # method setup now iterates on the setup blocks. Note that all setup 18 | # blocks must be defined with the block syntax. Adding a setup instance 19 | # method defeats the purpose of this library. 20 | class Test::Unit::TestCase 21 | def self.setup(&block) 22 | setup_blocks << block 23 | end 24 | 25 | def setup 26 | self.class.setup_blocks.each do |block| 27 | instance_eval(&block) 28 | end 29 | end 30 | 31 | def self.context(name, &block) 32 | subclass = Class.new(self.superclass) 33 | subclass.setup_blocks.unshift(*setup_blocks) 34 | subclass.class_eval(&block) 35 | const_set(context_name(name), subclass) 36 | end 37 | 38 | def self.test(name, &block) 39 | define_method(test_name(name), &block) 40 | end 41 | 42 | class << self 43 | alias_method :should, :test 44 | alias_method :describe, :context 45 | end 46 | 47 | private 48 | 49 | def self.setup_blocks 50 | @setup_blocks ||= [] 51 | end 52 | 53 | def self.context_name(name) 54 | "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym 55 | end 56 | 57 | def self.test_name(name) 58 | "test_#{sanitize_name(name).gsub(/\s+/,'_')}".to_sym 59 | end 60 | 61 | def self.sanitize_name(name) 62 | name.gsub(/\W+/, ' ').strip 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/data/reload_app_file.rb: -------------------------------------------------------------------------------- 1 | $reload_count += 1 2 | 3 | $reload_app.get('/') { 'Hello from reload file' } 4 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/erb_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | class ERBTest < Test::Unit::TestCase 4 | def erb_app(&block) 5 | mock_app { 6 | set :views, File.dirname(__FILE__) + '/views' 7 | get '/', &block 8 | } 9 | get '/' 10 | end 11 | 12 | it 'renders inline ERB strings' do 13 | erb_app { erb '<%= 1 + 1 %>' } 14 | assert ok? 15 | assert_equal '2', body 16 | end 17 | 18 | it 'renders .erb files in views path' do 19 | erb_app { erb :hello } 20 | assert ok? 21 | assert_equal "Hello World\n", body 22 | end 23 | 24 | it 'takes a :locals option' do 25 | erb_app { 26 | locals = {:foo => 'Bar'} 27 | erb '<%= foo %>', :locals => locals 28 | } 29 | assert ok? 30 | assert_equal 'Bar', body 31 | end 32 | 33 | it "renders with inline layouts" do 34 | mock_app { 35 | layout { 'THIS. IS. <%= yield.upcase %>!' } 36 | get('/') { erb 'Sparta' } 37 | } 38 | get '/' 39 | assert ok? 40 | assert_equal 'THIS. IS. SPARTA!', body 41 | end 42 | 43 | it "renders with file layouts" do 44 | erb_app { 45 | erb 'Hello World', :layout => :layout2 46 | } 47 | assert ok? 48 | assert_equal "ERB Layout!\nHello World\n", body 49 | end 50 | 51 | it "renders erb with blocks" do 52 | mock_app { 53 | def container 54 | @_out_buf << "THIS." 55 | yield 56 | @_out_buf << "SPARTA!" 57 | end 58 | def is; "IS." end 59 | get '/' do 60 | erb '<% container do %> <%= is %> <% end %>' 61 | end 62 | } 63 | get '/' 64 | assert ok? 65 | assert_equal 'THIS. IS. SPARTA!', body 66 | end 67 | 68 | it "can be used in a nested fashion for partials and whatnot" do 69 | mock_app { 70 | template(:inner) { "<%= 'hi' %>" } 71 | template(:outer) { "<%= erb :inner %>" } 72 | get '/' do 73 | erb :outer 74 | end 75 | } 76 | 77 | get '/' 78 | assert ok? 79 | assert_equal 'hi', body 80 | end 81 | end 82 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/helper.rb: -------------------------------------------------------------------------------- 1 | ENV['RACK_ENV'] = 'test' 2 | 3 | begin 4 | require 'rack' 5 | rescue LoadError 6 | require 'rubygems' 7 | require 'rack' 8 | end 9 | 10 | testdir = File.dirname(__FILE__) 11 | $LOAD_PATH.unshift testdir unless $LOAD_PATH.include?(testdir) 12 | 13 | libdir = File.dirname(File.dirname(__FILE__)) + '/lib' 14 | $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir) 15 | 16 | require 'contest' 17 | require 'rack/test' 18 | require 'sinatra/base' 19 | 20 | class Sinatra::Base 21 | # Allow assertions in request context 22 | include Test::Unit::Assertions 23 | end 24 | 25 | Sinatra::Base.set :environment, :test 26 | 27 | class Test::Unit::TestCase 28 | include Rack::Test::Methods 29 | 30 | class << self 31 | alias_method :it, :test 32 | end 33 | 34 | alias_method :response, :last_response 35 | 36 | setup do 37 | Sinatra::Base.set :environment, :test 38 | end 39 | 40 | # Sets up a Sinatra::Base subclass defined with the block 41 | # given. Used in setup or individual spec methods to establish 42 | # the application. 43 | def mock_app(base=Sinatra::Base, &block) 44 | @app = Sinatra.new(base, &block) 45 | end 46 | 47 | def app 48 | Rack::Lint.new(@app) 49 | end 50 | 51 | def body 52 | response.body.to_s 53 | end 54 | 55 | # Delegate other missing methods to response. 56 | def method_missing(name, *args, &block) 57 | if response && response.respond_to?(name) 58 | response.send(name, *args, &block) 59 | else 60 | super 61 | end 62 | end 63 | 64 | # Also check response since we delegate there. 65 | def respond_to?(symbol, include_private=false) 66 | super || (response && response.respond_to?(symbol, include_private)) 67 | end 68 | 69 | # Do not output warnings for the duration of the block. 70 | def silence_warnings 71 | $VERBOSE, v = nil, $VERBOSE 72 | yield 73 | ensure 74 | $VERBOSE = v 75 | end 76 | end 77 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/middleware_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | class MiddlewareTest < Test::Unit::TestCase 4 | setup do 5 | @app = mock_app(Sinatra::Default) { 6 | get '/*' do 7 | response.headers['X-Tests'] = env['test.ran']. 8 | map { |n| n.split('::').last }. 9 | join(', ') 10 | env['PATH_INFO'] 11 | end 12 | } 13 | end 14 | 15 | class MockMiddleware < Struct.new(:app) 16 | def call(env) 17 | (env['test.ran'] ||= []) << self.class.to_s 18 | app.call(env) 19 | end 20 | end 21 | 22 | class UpcaseMiddleware < MockMiddleware 23 | def call(env) 24 | env['PATH_INFO'] = env['PATH_INFO'].upcase 25 | super 26 | end 27 | end 28 | 29 | it "is added with Sinatra::Application.use" do 30 | @app.use UpcaseMiddleware 31 | get '/hello-world' 32 | assert ok? 33 | assert_equal '/HELLO-WORLD', body 34 | end 35 | 36 | class DowncaseMiddleware < MockMiddleware 37 | def call(env) 38 | env['PATH_INFO'] = env['PATH_INFO'].downcase 39 | super 40 | end 41 | end 42 | 43 | it "runs in the order defined" do 44 | @app.use UpcaseMiddleware 45 | @app.use DowncaseMiddleware 46 | get '/Foo' 47 | assert_equal "/foo", body 48 | assert_equal "UpcaseMiddleware, DowncaseMiddleware", response['X-Tests'] 49 | end 50 | 51 | it "resets the prebuilt pipeline when new middleware is added" do 52 | @app.use UpcaseMiddleware 53 | get '/Foo' 54 | assert_equal "/FOO", body 55 | @app.use DowncaseMiddleware 56 | get '/Foo' 57 | assert_equal '/foo', body 58 | assert_equal "UpcaseMiddleware, DowncaseMiddleware", response['X-Tests'] 59 | end 60 | 61 | it "works when app is used as middleware" do 62 | @app.use UpcaseMiddleware 63 | @app = @app.new 64 | get '/Foo' 65 | assert_equal "/FOO", body 66 | assert_equal "UpcaseMiddleware", response['X-Tests'] 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/request_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | class RequestTest < Test::Unit::TestCase 4 | it 'responds to #user_agent' do 5 | request = Sinatra::Request.new({'HTTP_USER_AGENT' => 'Test'}) 6 | assert request.respond_to?(:user_agent) 7 | assert_equal 'Test', request.user_agent 8 | end 9 | 10 | it 'parses POST params when Content-Type is form-dataish' do 11 | request = Sinatra::Request.new( 12 | 'REQUEST_METHOD' => 'PUT', 13 | 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', 14 | 'rack.input' => StringIO.new('foo=bar') 15 | ) 16 | assert_equal 'bar', request.params['foo'] 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/response_test.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require File.dirname(__FILE__) + '/helper' 4 | 5 | class ResponseTest < Test::Unit::TestCase 6 | setup do 7 | @response = Sinatra::Response.new 8 | end 9 | 10 | it "initializes with 200, text/html, and empty body" do 11 | assert_equal 200, @response.status 12 | assert_equal 'text/html', @response['Content-Type'] 13 | assert_equal [], @response.body 14 | end 15 | 16 | it 'uses case insensitive headers' do 17 | @response['content-type'] = 'application/foo' 18 | assert_equal 'application/foo', @response['Content-Type'] 19 | assert_equal 'application/foo', @response['CONTENT-TYPE'] 20 | end 21 | 22 | it 'writes to body' do 23 | @response.body = 'Hello' 24 | @response.write ' World' 25 | assert_equal 'Hello World', @response.body 26 | end 27 | 28 | [204, 304].each do |status_code| 29 | it "removes the Content-Type header and body when response status is #{status_code}" do 30 | @response.status = status_code 31 | @response.body = ['Hello World'] 32 | assert_equal [status_code, {}, []], @response.finish 33 | end 34 | end 35 | 36 | it 'Calculates the Content-Length using the bytesize of the body' do 37 | @response.body = ['Hello', 'World!', '✈'] 38 | status, headers, body = @response.finish 39 | assert_equal '14', headers['Content-Length'] 40 | assert_equal @response.body, body 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/result_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | class ResultTest < Test::Unit::TestCase 4 | it "sets response.body when result is a String" do 5 | mock_app { 6 | get '/' do 7 | 'Hello World' 8 | end 9 | } 10 | 11 | get '/' 12 | assert ok? 13 | assert_equal 'Hello World', body 14 | end 15 | 16 | it "sets response.body when result is an Array of Strings" do 17 | mock_app { 18 | get '/' do 19 | ['Hello', 'World'] 20 | end 21 | } 22 | 23 | get '/' 24 | assert ok? 25 | assert_equal 'HelloWorld', body 26 | end 27 | 28 | it "sets response.body when result responds to #each" do 29 | mock_app { 30 | get '/' do 31 | res = lambda { 'Hello World' } 32 | def res.each ; yield call ; end 33 | res 34 | end 35 | } 36 | 37 | get '/' 38 | assert ok? 39 | assert_equal 'Hello World', body 40 | end 41 | 42 | it "sets response.body to [] when result is nil" do 43 | mock_app { 44 | get '/' do 45 | nil 46 | end 47 | } 48 | 49 | get '/' 50 | assert ok? 51 | assert_equal '', body 52 | end 53 | 54 | it "sets status, headers, and body when result is a Rack response tuple" do 55 | mock_app { 56 | get '/' do 57 | [205, {'Content-Type' => 'foo/bar'}, 'Hello World'] 58 | end 59 | } 60 | 61 | get '/' 62 | assert_equal 205, status 63 | assert_equal 'foo/bar', response['Content-Type'] 64 | assert_equal 'Hello World', body 65 | end 66 | 67 | it "sets status and body when result is a two-tuple" do 68 | mock_app { 69 | get '/' do 70 | [409, 'formula of'] 71 | end 72 | } 73 | 74 | get '/' 75 | assert_equal 409, status 76 | assert_equal 'formula of', body 77 | end 78 | 79 | it "raises a TypeError when result is a non two or three tuple Array" do 80 | mock_app { 81 | get '/' do 82 | [409, 'formula of', 'something else', 'even more'] 83 | end 84 | } 85 | 86 | assert_raise(TypeError) { get '/' } 87 | end 88 | 89 | it "sets status when result is a Fixnum status code" do 90 | mock_app { 91 | get('/') { 205 } 92 | } 93 | 94 | get '/' 95 | assert_equal 205, status 96 | assert_equal '', body 97 | end 98 | end 99 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/route_added_hook_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | module RouteAddedTest 4 | @routes, @procs = [], [] 5 | def self.routes ; @routes ; end 6 | def self.procs ; @procs ; end 7 | def self.route_added(verb, path, proc) 8 | @routes << [verb, path] 9 | @procs << proc 10 | end 11 | end 12 | 13 | class RouteAddedHookTest < Test::Unit::TestCase 14 | setup { 15 | RouteAddedTest.routes.clear 16 | RouteAddedTest.procs.clear 17 | } 18 | 19 | it "should be notified of an added route" do 20 | mock_app(Class.new(Sinatra::Base)) { 21 | register RouteAddedTest 22 | get('/') {} 23 | } 24 | 25 | assert_equal [["GET", "/"], ["HEAD", "/"]], 26 | RouteAddedTest.routes 27 | end 28 | 29 | it "should include hooks from superclass" do 30 | a = Class.new(Class.new(Sinatra::Base)) 31 | b = Class.new(a) 32 | 33 | a.register RouteAddedTest 34 | b.class_eval { post("/sub_app_route") {} } 35 | 36 | assert_equal [["POST", "/sub_app_route"]], 37 | RouteAddedTest.routes 38 | end 39 | 40 | it "should only run once per extension" do 41 | mock_app(Class.new(Sinatra::Base)) { 42 | register RouteAddedTest 43 | register RouteAddedTest 44 | get('/') {} 45 | } 46 | 47 | assert_equal [["GET", "/"], ["HEAD", "/"]], 48 | RouteAddedTest.routes 49 | end 50 | 51 | it "should pass route blocks as an argument" do 52 | mock_app(Class.new(Sinatra::Base)) { 53 | register RouteAddedTest 54 | get('/') {} 55 | } 56 | 57 | assert_kind_of Proc, RouteAddedTest.procs.first 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/server_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | module Rack::Handler 4 | class Mock 5 | extend Test::Unit::Assertions 6 | 7 | def self.run(app, options={}) 8 | assert(app < Sinatra::Base) 9 | assert_equal 9001, options[:Port] 10 | assert_equal 'foo.local', options[:Host] 11 | yield new 12 | end 13 | 14 | def stop 15 | end 16 | end 17 | 18 | register 'mock', 'Rack::Handler::Mock' 19 | end 20 | 21 | class ServerTest < Test::Unit::TestCase 22 | setup do 23 | mock_app { 24 | set :server, 'mock' 25 | set :host, 'foo.local' 26 | set :port, 9001 27 | } 28 | $stdout = File.open('/dev/null', 'wb') 29 | end 30 | 31 | def teardown 32 | $stdout = STDOUT 33 | end 34 | 35 | it "locates the appropriate Rack handler and calls ::run" do 36 | @app.run! 37 | end 38 | 39 | it "sets options on the app before running" do 40 | @app.run! :sessions => true 41 | assert @app.sessions? 42 | end 43 | 44 | it "falls back on the next server handler when not found" do 45 | @app.run! :server => %w[foo bar mock] 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/sinatra_test.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/helper' 2 | 3 | class SinatraTest < Test::Unit::TestCase 4 | it 'creates a new Sinatra::Base subclass on new' do 5 | app = 6 | Sinatra.new do 7 | get '/' do 8 | 'Hello World' 9 | end 10 | end 11 | assert_same Sinatra::Base, app.superclass 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/views/error.builder: -------------------------------------------------------------------------------- 1 | xml.error do 2 | raise "goodbye" 3 | end 4 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/views/error.erb: -------------------------------------------------------------------------------- 1 | Hello <%= 'World' %> 2 | <% raise 'Goodbye' unless defined?(french) && french %> 3 | <% raise 'Au revoir' if defined?(french) && french %> 4 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/views/error.haml: -------------------------------------------------------------------------------- 1 | %h1 Hello From Haml 2 | = raise 'goodbye' unless defined?(french) && french 3 | = raise 'au revoir' if defined?(french) && french 4 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/views/error.sass: -------------------------------------------------------------------------------- 1 | #sass 2 | +argle-bargle 3 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/views/foo/hello.test: -------------------------------------------------------------------------------- 1 | from another views directory 2 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/views/hello.builder: -------------------------------------------------------------------------------- 1 | xml.exclaim "You're my boy, #{@name}!" 2 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/views/hello.erb: -------------------------------------------------------------------------------- 1 | Hello <%= 'World' %> 2 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/views/hello.haml: -------------------------------------------------------------------------------- 1 | %h1 Hello From Haml 2 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/views/hello.sass: -------------------------------------------------------------------------------- 1 | #sass 2 | :background-color #FFF 3 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/views/hello.test: -------------------------------------------------------------------------------- 1 | Hello World! 2 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/views/layout2.builder: -------------------------------------------------------------------------------- 1 | xml.layout do 2 | xml << yield 3 | end 4 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/views/layout2.erb: -------------------------------------------------------------------------------- 1 | ERB Layout! 2 | <%= yield %> 3 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/views/layout2.haml: -------------------------------------------------------------------------------- 1 | %h1 HAML Layout! 2 | %p= yield 3 | -------------------------------------------------------------------------------- /vendor/sinatra-0.9.4/test/views/layout2.test: -------------------------------------------------------------------------------- 1 | Layout 2! 2 | -------------------------------------------------------------------------------- /views/activate.haml: -------------------------------------------------------------------------------- 1 | Select a password and activate your account below. 2 | %br/ 3 | %br/ 4 | %form{ :method => "post", :action => '/activate' } 5 | Password: 6 | %input{ :type => 'text', :size => 20, :name => 'password' } 7 | %br/ 8 | Confirm Password: 9 | %input{ :type => 'text', :size => 20, :name => 'password_confirmation' } 10 | %br/ 11 | %input{ :type => 'hidden', :value => @user.perishable_token, :name => 'token' } 12 | %input{ :type => 'submit', :value => 'Activate' } 13 | -------------------------------------------------------------------------------- /views/forgot_password.haml: -------------------------------------------------------------------------------- 1 | = "Forgot your password? Enter your email address, and we'll email you a link to reset your password." 2 | %br/ 3 | %br/ 4 | %form{:method => "post"} 5 | Email: 6 | %br/ 7 | %input{:type=>'text', :size=>20, :name=>'email'} 8 | %br/ 9 | %input{:type=>'submit', :value=>'Email me'} 10 | 11 | -------------------------------------------------------------------------------- /views/index.haml: -------------------------------------------------------------------------------- 1 | Home page 2 | %br/ 3 | You're 4 | = current_user ? "logged in" : "not logged in" 5 | -------------------------------------------------------------------------------- /views/layout.haml: -------------------------------------------------------------------------------- 1 | !!! 2 | %html 3 | %head 4 | 5 | 6 | %body 7 | = link 'Home', '/' 8 | - if current_user 9 | = link 'Logout', '/logout' 10 | - else 11 | = link 'Signup', '/signup' 12 | = link 'Login', '/login' 13 | = link 'Show', '/show' 14 | = link 'Restricted', '/restricted' 15 | %br/ 16 | %br/ 17 | - if msg = notice 18 | = msg 19 | %br/ 20 | %br/ 21 | #container 22 | = yield 23 | -------------------------------------------------------------------------------- /views/login.haml: -------------------------------------------------------------------------------- 1 | Login 2 | %br/ 3 | %br/ 4 | %form{:method => "post"} 5 | Email: 6 | %input{:type=>'text', :size=>20, :name=>'user[email]'} 7 | %br/ 8 | Password: 9 | %input{:type=>'password', :size=>20, :name=>'user[password]'} 10 | %br/ 11 | Remember Me 12 | %input{:type=>'checkbox', :value => '1', :name => 'user[remember_me]'} 13 | %br/ 14 | %input{:type=>'submit', :value=>'Login'} 15 | %br/ 16 | %br/ 17 | = link('Forgot your password?', '/forgot-password') -------------------------------------------------------------------------------- /views/resend_activation.haml: -------------------------------------------------------------------------------- 1 | Resend Activation 2 | %br/ 3 | %br/ 4 | %form{:method => "post"} 5 | Email: 6 | %br/ 7 | %input{:type=>'text', :size=>20, :name=>'email'} 8 | %br/ 9 | %input{:type=>'submit', :value=>'Resend Activation Email'} 10 | -------------------------------------------------------------------------------- /views/reset_password.haml: -------------------------------------------------------------------------------- 1 | Reset Password 2 | %br/ 3 | %br/ 4 | %form{ :method => "post", :action => '/reset_password' } 5 | Password: 6 | %input{ :type => 'text', :size => 20, :name => 'password' } 7 | %br/ 8 | Confirm Password: 9 | %input{ :type => 'text', :size => 20, :name => 'password_confirmation' } 10 | %br/ 11 | %input{ :type => 'hidden', :value => @user.perishable_token, :name => 'token' } 12 | %input{ :type => 'submit', :value => 'Reset' } 13 | -------------------------------------------------------------------------------- /views/show.haml: -------------------------------------------------------------------------------- 1 | Email: 2 | = @user.email 3 | %br/ 4 | Login count: 5 | = @user.login_count 6 | %br/ 7 | Last request at: 8 | = @user.last_request_at 9 | %br/ 10 | Last login at: 11 | = @user.last_login_at 12 | %br/ 13 | Current login at: 14 | = @user.current_login_at 15 | %br/ 16 | Last login ip: 17 | = @user.last_login_ip 18 | %br/ 19 | Current login ip: 20 | = @user.current_login_ip 21 | 22 | -------------------------------------------------------------------------------- /views/signup.haml: -------------------------------------------------------------------------------- 1 | Sign up 2 | %br/ 3 | %br/ 4 | %form{:method => "post"} 5 | Email: 6 | %br/ 7 | %input{:type=>'text', :size=>20, :name=>'email'} 8 | %br/ 9 | %input{:type=>'submit', :value=>'Sign up'} 10 | --------------------------------------------------------------------------------