Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Get Travis CI tests green / Remove Rcov from Rakefile #376

Closed
wants to merge 11 commits into from

2 participants

@petergoldstein

This was originally intended to be a much narrower PR, but I discovered that the Travis CI tests were failing across the board. So in addition to the original intent (removing rcov from the Rakefile), I made a number of changes to get the tests green. These were:

  1. Pull scrypt out of the gemspec and make it optional, as it is only supported on MRI platforms. Update the Appraisals and Gemfile to reflect this. Tests for this feature now only run on MRI platforms
  2. Restrict scrypt to a version that is compatible with Ruby 1.8.7
  3. Restrict timecop to a version that is compatible with Ruby 1.8.7, ree, and JRuby
  4. Pull sqlite3 out of the gemspec, as this gem is not compatible with JRuby. Use it for all non JRuby platforms. Use the appropriate JDBC Sqlite gem for Rails 3 and Rails 4 when using JRuby.
  5. Update tests so that they don't depend on Test::Unit::TestCase, which no longer exists in Rails 4. Include directly against ActiveSupport::TestCase
  6. Remove the gemfiles/*.lock files from the repo, as these need to be built dynamically by Travis CI
  7. Use a different approach to set the updated_at attribute on models in tests. The previously used version was setting the wrong values in Rails 4
  8. Make the tests aware of the ActiveModel version so that they can check the correct key in the errors hash for password-related errors. Rails 4 changed where some errors are stored
  9. Added an explicit UTF-8 encoded to a file that includes Cyrillic characters

The entire test matrix is now green, and all tests run on the platforms that support them. You can find a Travis CI run here - https://travis-ci.org/petergoldstein/authlogic/builds/10251971

@binarylogic
Owner

Thanks for this. I need to merge in the new changes and review again. Also, scrypt was pull in with a previous PR.

@petergoldstein

At this point I think this PR is obsolete. I'm going to close and replace with a couple of narrower PRs that address removing rcov and JRuby spec compatibility.

@petergoldstein petergoldstein deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
6 Appraisals
@@ -1,9 +1,15 @@
appraise "rails3" do
gem "activerecord", "3.2.14"
gem "activesupport", "3.2.14"
+ gem 'scrypt', '~> 1.1.0', :platforms => :mri
+ gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
+ gem 'sqlite3', :platforms => :ruby
end
appraise "rails4" do
gem "activerecord", "4.0.0"
gem "activesupport", "4.0.0"
+ gem 'scrypt', '~> 1.1.0', :platforms => :mri
+ gem "activerecord-jdbcsqlite3-adapter", '1.3.0.rc1', :platforms=>:jruby
+ gem 'sqlite3', :platforms => :ruby
end
View
6 Gemfile
@@ -1,2 +1,6 @@
source "https://rubygems.org"
-gemspec
+gemspec
+
+gem 'scrypt', :platforms => :mri
+gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
+gem 'sqlite3', :platforms => :ruby
View
53 Gemfile.lock
@@ -8,28 +8,42 @@ PATH
GEM
remote: https://rubygems.org/
specs:
- activemodel (3.2.13)
- activesupport (= 3.2.13)
- builder (~> 3.0.0)
- activerecord (3.2.13)
- activemodel (= 3.2.13)
- activesupport (= 3.2.13)
- arel (~> 3.0.2)
- tzinfo (~> 0.3.29)
- activesupport (3.2.13)
- i18n (= 0.6.1)
- multi_json (~> 1.0)
+ activemodel (4.0.0)
+ activesupport (= 4.0.0)
+ builder (~> 3.1.0)
+ activerecord (4.0.0)
+ activemodel (= 4.0.0)
+ activerecord-deprecated_finders (~> 1.0.2)
+ activesupport (= 4.0.0)
+ arel (~> 4.0.0)
+ activerecord-deprecated_finders (1.0.3)
+ activesupport (4.0.0)
+ i18n (~> 0.6, >= 0.6.4)
+ minitest (~> 4.2)
+ multi_json (~> 1.3)
+ thread_safe (~> 0.1)
+ tzinfo (~> 0.3.37)
appraisal (0.5.2)
bundler
rake
- arel (3.0.2)
- bcrypt-ruby (3.0.1)
- builder (3.0.4)
- i18n (0.6.1)
- multi_json (1.7.1)
- rake (10.0.3)
- scrypt (1.1.0)
+ arel (4.0.0)
+ atomic (1.1.13)
+ bcrypt-ruby (3.1.1)
+ builder (3.1.4)
+ ffi (1.9.0)
+ ffi-compiler (0.1.3)
+ ffi (>= 1.0.0)
+ rake
+ i18n (0.6.5)
+ minitest (4.7.5)
+ multi_json (1.7.9)
+ rake (10.1.0)
+ scrypt (1.2.0)
+ ffi-compiler (>= 0.0.2)
+ rake
sqlite3 (1.3.7)
+ thread_safe (0.1.2)
+ atomic
timecop (0.6.1)
tzinfo (0.3.37)
@@ -37,6 +51,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ activerecord-jdbcsqlite3-adapter
appraisal
authlogic!
bcrypt-ruby
@@ -44,4 +59,4 @@ DEPENDENCIES
rake
scrypt
sqlite3
- timecop
+ timecop (<= 0.6.1)
View
13 Rakefile
@@ -12,17 +12,4 @@ Rake::TestTask.new(:test) do |test|
test.verbose = true
end
-begin
- require 'rcov/rcovtask'
- Rcov::RcovTask.new do |test|
- test.libs << 'test'
- test.pattern = 'test/**/*_test.rb'
- test.verbose = true
- end
-rescue LoadError
- task :rcov do
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
- end
-end
-
task :default => :test
View
4 authlogic.gemspec
@@ -15,9 +15,7 @@ Gem::Specification.new do |s|
s.add_dependency 'activesupport', '>= 3.2'
s.add_development_dependency 'rake'
s.add_development_dependency 'bcrypt-ruby'
- s.add_development_dependency 'scrypt'
- s.add_development_dependency 'sqlite3'
- s.add_development_dependency 'timecop'
+ s.add_development_dependency 'timecop', '<= 0.6.1'
s.add_development_dependency 'i18n'
s.add_development_dependency 'appraisal'
View
3  gemfiles/rails3.gemfile
@@ -4,5 +4,8 @@ source "https://rubygems.org"
gem "activerecord", "3.2.14"
gem "activesupport", "3.2.14"
+gem "scrypt", "~> 1.1.0", :platforms=>:mri
+gem "activerecord-jdbcsqlite3-adapter", :platforms=>:jruby
+gem "sqlite3", :platforms=>:ruby
gemspec :path=>"../"
View
49 gemfiles/rails3.gemfile.lock
@@ -1,49 +0,0 @@
-PATH
- remote: /Users/nathany/Dropbox/Development/jobber/vendor/authlogic
- specs:
- authlogic (3.3.0)
- activerecord (>= 3.2)
- activesupport (>= 3.2)
-
-GEM
- remote: https://rubygems.org/
- specs:
- activemodel (3.2.14)
- activesupport (= 3.2.14)
- builder (~> 3.0.0)
- activerecord (3.2.14)
- activemodel (= 3.2.14)
- activesupport (= 3.2.14)
- arel (~> 3.0.2)
- tzinfo (~> 0.3.29)
- activesupport (3.2.14)
- i18n (~> 0.6, >= 0.6.4)
- multi_json (~> 1.0)
- appraisal (0.5.2)
- bundler
- rake
- arel (3.0.2)
- bcrypt-ruby (3.0.1)
- builder (3.0.4)
- i18n (0.6.4)
- multi_json (1.7.7)
- rake (10.1.0)
- scrypt (1.1.0)
- sqlite3 (1.3.7)
- timecop (0.6.2.2)
- tzinfo (0.3.37)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- activerecord (= 3.2.14)
- activesupport (= 3.2.14)
- appraisal
- authlogic!
- bcrypt-ruby
- i18n
- rake
- scrypt
- sqlite3
- timecop
View
3  gemfiles/rails4.gemfile
@@ -4,5 +4,8 @@ source "https://rubygems.org"
gem "activerecord", "4.0.0"
gem "activesupport", "4.0.0"
+gem "scrypt", "~> 1.1.0", :platforms=>:mri
+gem "activerecord-jdbcsqlite3-adapter", "1.3.0.rc1", :platforms=>:jruby
+gem "sqlite3", :platforms=>:ruby
gemspec :path=>"../"
View
57 gemfiles/rails4.gemfile.lock
@@ -1,57 +0,0 @@
-PATH
- remote: /Users/nathany/Dropbox/Development/jobber/vendor/authlogic
- specs:
- authlogic (3.3.0)
- activerecord (>= 3.2)
- activesupport (>= 3.2)
-
-GEM
- remote: https://rubygems.org/
- specs:
- activemodel (4.0.0)
- activesupport (= 4.0.0)
- builder (~> 3.1.0)
- activerecord (4.0.0)
- activemodel (= 4.0.0)
- activerecord-deprecated_finders (~> 1.0.2)
- activesupport (= 4.0.0)
- arel (~> 4.0.0)
- activerecord-deprecated_finders (1.0.3)
- activesupport (4.0.0)
- i18n (~> 0.6, >= 0.6.4)
- minitest (~> 4.2)
- multi_json (~> 1.3)
- thread_safe (~> 0.1)
- tzinfo (~> 0.3.37)
- appraisal (0.5.2)
- bundler
- rake
- arel (4.0.0)
- atomic (1.1.9)
- bcrypt-ruby (3.0.1)
- builder (3.1.4)
- i18n (0.6.4)
- minitest (4.7.5)
- multi_json (1.7.7)
- rake (10.1.0)
- scrypt (1.1.0)
- sqlite3 (1.3.7)
- thread_safe (0.1.0)
- atomic
- timecop (0.6.1)
- tzinfo (0.3.37)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- activerecord (= 4.0.0)
- activesupport (= 4.0.0)
- appraisal
- authlogic!
- bcrypt-ruby
- i18n
- rake
- scrypt
- sqlite3
- timecop
View
127 lib/authlogic/crypto_providers/scrypt.rb
@@ -1,80 +1,79 @@
begin
require "scrypt"
-rescue LoadError
- "sudo gem install scrypt"
-end
-
-module Authlogic
- module CryptoProviders
- # If you want a stronger hashing algorithm, but would prefer not to use BCrypt, SCrypt is another option.
- # SCrypt is newer and less popular (and so less-tested), but it's designed specifically to avoid a theoretical
- # hardware attack against BCrypt. Just as with BCrypt, you are sacrificing performance relative to SHA2 algorithms,
- # but the increased security may well be worth it. (That performance sacrifice is the exact reason it's much, much
- # harder for an attacker to brute-force your paswords).
- # Decided SCrypt is for you? Just install the bcrypt gem:
- #
- # gem install scrypt
- #
- # Tell acts_as_authentic to use it:
- #
- # acts_as_authentic do |c|
- # c.crypto_provider = Authlogic::CryptoProviders::SCrypt
- # end
- class SCrypt
- class << self
- DEFAULTS = {:key_len => 32, :salt_size => 8, :max_time => 0.2, :max_mem => 1024 * 1024, :max_memfrac => 0.5}
- attr_writer :key_len, :salt_size, :max_time, :max_mem, :max_memfrac
- # Key length - length in bytes of generated key, from 16 to 512.
- def key_len
- @key_len ||= DEFAULTS[:key_len]
- end
+ module Authlogic
+ module CryptoProviders
+ # If you want a stronger hashing algorithm, but would prefer not to use BCrypt, SCrypt is another option.
+ # SCrypt is newer and less popular (and so less-tested), but it's designed specifically to avoid a theoretical
+ # hardware attack against BCrypt. Just as with BCrypt, you are sacrificing performance relative to SHA2 algorithms,
+ # but the increased security may well be worth it. (That performance sacrifice is the exact reason it's much, much
+ # harder for an attacker to brute-force your paswords).
+ # Decided SCrypt is for you? Just install the bcrypt gem:
+ #
+ # gem install scrypt
+ #
+ # Tell acts_as_authentic to use it:
+ #
+ # acts_as_authentic do |c|
+ # c.crypto_provider = Authlogic::CryptoProviders::SCrypt
+ # end
+ class SCrypt
+ class << self
+ DEFAULTS = {:key_len => 32, :salt_size => 8, :max_time => 0.2, :max_mem => 1024 * 1024, :max_memfrac => 0.5}
- # Salt size - size in bytes of random salt, from 8 to 32
- def salt_size
- @salt_size ||= DEFAULTS[:salt_size]
- end
+ attr_writer :key_len, :salt_size, :max_time, :max_mem, :max_memfrac
+ # Key length - length in bytes of generated key, from 16 to 512.
+ def key_len
+ @key_len ||= DEFAULTS[:key_len]
+ end
- # Max time - maximum time spent in computation
- def max_time
- @max_time ||= DEFAULTS[:max_time]
- end
+ # Salt size - size in bytes of random salt, from 8 to 32
+ def salt_size
+ @salt_size ||= DEFAULTS[:salt_size]
+ end
- # Max memory - maximum memory usage. The minimum is always 1MB
- def max_mem
- @max_mem ||= DEFAULTS[:max_mem]
- end
+ # Max time - maximum time spent in computation
+ def max_time
+ @max_time ||= DEFAULTS[:max_time]
+ end
- # Max memory fraction - maximum memory out of all available. Always greater than zero and <= 0.5.
- def max_memfrac
- @max_memfrac ||= DEFAULTS[:max_memfrac]
- end
+ # Max memory - maximum memory usage. The minimum is always 1MB
+ def max_mem
+ @max_mem ||= DEFAULTS[:max_mem]
+ end
- # Creates an SCrypt hash for the password passed.
- def encrypt(*tokens)
- ::SCrypt::Password.create(join_tokens(tokens), :key_len => key_len, :salt_size => salt_size, :max_mem => max_mem, :max_memfrac => max_memfrac, :max_time => max_time)
- end
+ # Max memory fraction - maximum memory out of all available. Always greater than zero and <= 0.5.
+ def max_memfrac
+ @max_memfrac ||= DEFAULTS[:max_memfrac]
+ end
- # Does the hash match the tokens? Uses the same tokens that were used to encrypt.
- def matches?(hash, *tokens)
- hash = new_from_hash(hash)
- return false if hash.blank?
- hash == join_tokens(tokens)
- end
+ # Creates an SCrypt hash for the password passed.
+ def encrypt(*tokens)
+ ::SCrypt::Password.create(join_tokens(tokens), :key_len => key_len, :salt_size => salt_size, :max_mem => max_mem, :max_memfrac => max_memfrac, :max_time => max_time)
+ end
- private
- def join_tokens(tokens)
- tokens.flatten.join
+ # Does the hash match the tokens? Uses the same tokens that were used to encrypt.
+ def matches?(hash, *tokens)
+ hash = new_from_hash(hash)
+ return false if hash.blank?
+ hash == join_tokens(tokens)
end
-
- def new_from_hash(hash)
- begin
- ::SCrypt::Password.new(hash)
- rescue ::SCrypt::Errors::InvalidHash
- return nil
+
+ private
+ def join_tokens(tokens)
+ tokens.flatten.join
end
- end
+
+ def new_from_hash(hash)
+ begin
+ ::SCrypt::Password.new(hash)
+ rescue ::SCrypt::Errors::InvalidHash
+ return nil
+ end
+ end
+ end
end
end
end
+rescue LoadError
end
View
1  lib/authlogic/regex.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
module Authlogic
# This is a module the contains regular expressions used throughout Authlogic. The point of extracting
# them out into their own module is to make them easily available to you for other uses. Ex:
View
2  lib/authlogic/test_case.rb
@@ -116,5 +116,5 @@ def controller
end
end
- ::Test::Unit::TestCase.send(:include, TestCase) if defined?(::Test::Unit::TestCase)
+ ::ActiveSupport::TestCase.send(:include, TestCase) if defined?(::ActiveSupport::TestCase)
end
View
18 test/acts_as_authentic_test/password_test.rb
@@ -111,7 +111,11 @@ def test_validates_length_of_password
u.password = "test"
assert !u.valid?
- assert u.errors[:password_confirmation].size == 0
+ if ActiveModel::VERSION::MAJOR >= 4
+ assert u.errors[:password].size == 0
+ else
+ assert u.errors[:password_confirmation].size == 0
+ end
end
def test_validates_confirmation_of_password
@@ -119,11 +123,19 @@ def test_validates_confirmation_of_password
u.password = "test"
u.password_confirmation = "test2"
assert !u.valid?
- assert u.errors[:password].size > 0
+ if ActiveModel::VERSION::MAJOR >= 4
+ assert u.errors[:password_confirmation].size > 0
+ else
+ assert u.errors[:password].size > 0
+ end
u.password_confirmation = "test"
assert !u.valid?
- assert u.errors[:password].size == 0
+ if ActiveModel::VERSION::MAJOR >= 4
+ assert u.errors[:password_confirmation].size == 0
+ else
+ assert u.errors[:password].size == 0
+ end
end
def test_validates_length_of_password_confirmation
View
13 test/acts_as_authentic_test/perishable_token_test.rb
@@ -60,14 +60,18 @@ def test_find_using_perishable_token
def test_find_using_perishable_token_when_perished
ben = users(:ben)
- ActiveRecord::Base.connection.execute("UPDATE users set updated_at = '#{1.week.ago.to_s(:db)}' where id = #{ben.id}")
+ User.record_timestamps = false
+ ben.update_attributes :updated_at => 1.week.ago
+ User.record_timestamps = true
assert_nil User.find_using_perishable_token(ben.perishable_token)
end
def test_find_using_perishable_token_when_perished
User.perishable_token_valid_for = 1.minute
ben = users(:ben)
- ActiveRecord::Base.connection.execute("UPDATE users set updated_at = '#{2.minutes.ago.to_s(:db)}' where id = #{ben.id}")
+ User.record_timestamps = false
+ ben.update_attributes :updated_at => 2.minutes.ago
+ User.record_timestamps = true
assert_nil User.find_using_perishable_token(ben.perishable_token)
User.perishable_token_valid_for = 10.minutes
end
@@ -75,7 +79,10 @@ def test_find_using_perishable_token_when_perished
def test_find_using_perishable_token_when_passing_threshold
User.perishable_token_valid_for = 1.minute
ben = users(:ben)
- ActiveRecord::Base.connection.execute("UPDATE users set updated_at = '#{10.minutes.ago.to_s(:db)}' where id = #{ben.id}")
+ User.record_timestamps = false
+ ben.update_attributes :updated_at => 10.minutes.ago
+ User.record_timestamps = true
+ ben.reload
assert_nil User.find_using_perishable_token(ben.perishable_token, 5.minutes)
assert_equal ben, User.find_using_perishable_token(ben.perishable_token, 20.minutes)
User.perishable_token_valid_for = 10.minutes
View
23 test/crypto_provider_test/scrypt_test.rb
@@ -1,14 +1,19 @@
require 'test_helper'
-module CryptoProviderTest
- class SCryptTest < ActiveSupport::TestCase
- def test_encrypt
- assert Authlogic::CryptoProviders::SCrypt.encrypt("mypass")
- end
-
- def test_matches
- hash = Authlogic::CryptoProviders::SCrypt.encrypt("mypass")
- assert Authlogic::CryptoProviders::SCrypt.matches?(hash, "mypass")
+if defined?(Authlogic::CryptoProviders::SCrypt)
+
+ module CryptoProviderTest
+ class SCryptTest < ActiveSupport::TestCase
+ def test_encrypt
+ assert Authlogic::CryptoProviders::SCrypt.encrypt("mypass")
+ end
+
+ def test_matches
+ hash = Authlogic::CryptoProviders::SCrypt.encrypt("mypass")
+ assert Authlogic::CryptoProviders::SCrypt.matches?(hash, "mypass")
+ end
end
end
+else
+ puts "Your platform does not appear to support SCrypt."
end
Something went wrong with that request. Please try again.