Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

renamed plugin to a little more original name

  • Loading branch information...
commit 5fd1c29cfd665f98e993ee1a544da0c341b7b4ee 1 parent 1efa7b2
@NoamB authored
Showing with 410 additions and 410 deletions.
  1. +3 −3 README.rdoc
  2. +3 −3 Rakefile
  3. +1 −1  features/support/env.rb
  4. +0 −26 lib/simple_auth.rb
  5. +0 −18 lib/simple_auth/engine.rb
  6. +26 −0 lib/sorcery.rb
  7. +2 −2 lib/{simple_auth → sorcery}/controller.rb
  8. +3 −3 lib/{simple_auth → sorcery}/crypto_providers/aes256.rb
  9. +4 −4 lib/{simple_auth → sorcery}/crypto_providers/bcrypt.rb
  10. +2 −2 lib/{simple_auth → sorcery}/crypto_providers/md5.rb
  11. +2 −2 lib/{simple_auth → sorcery}/crypto_providers/sha1.rb
  12. +2 −2 lib/{simple_auth → sorcery}/crypto_providers/sha256.rb
  13. +2 −2 lib/{simple_auth → sorcery}/crypto_providers/sha512.rb
  14. +18 −0 lib/sorcery/engine.rb
  15. +18 −18 lib/{simple_auth → sorcery}/model.rb
  16. +7 −7 lib/{simple_auth → sorcery}/model/submodules/password_confirmation.rb
  17. +16 −16 lib/{simple_auth → sorcery}/model/submodules/password_encryption.rb
  18. +9 −9 lib/{simple_auth → sorcery}/model/submodules/password_reset.rb
  19. +5 −5 lib/{simple_auth → sorcery}/model/submodules/remember_me.rb
  20. +11 −11 lib/{simple_auth → sorcery}/model/submodules/user_activation.rb
  21. +1 −1  spec/Gemfile
  22. +2 −2 spec/Gemfile.lock
  23. +1 −1  spec/rails3/Gemfile
  24. +2 −2 spec/rails3/Gemfile.lock
  25. +1 −1  spec/rails3/app_root/app/mailers/{simple_auth_mailer.rb → sorcery_mailer.rb}
  26. +1 −1  spec/rails3/app_root/app/models/user.rb
  27. 0  spec/rails3/app_root/app/views/{simple_auth_mailer → sorcery_mailer}/activation_email.html.erb
  28. 0  spec/rails3/app_root/app/views/{simple_auth_mailer → sorcery_mailer}/activation_email.text.erb
  29. 0  spec/rails3/app_root/app/views/{simple_auth_mailer → sorcery_mailer}/activation_success_email.html.erb
  30. 0  spec/rails3/app_root/app/views/{simple_auth_mailer → sorcery_mailer}/activation_success_email.text.erb
  31. 0  spec/rails3/app_root/app/views/{simple_auth_mailer → sorcery_mailer}/reset_password_email.html.erb
  32. 0  spec/rails3/app_root/app/views/{simple_auth_mailer → sorcery_mailer}/reset_password_email.text.erb
  33. +11 −11 spec/rails3/application_controller_spec.rb
  34. +5 −5 spec/rails3/password_reset_spec.rb
  35. +3 −3 spec/rails3/remember_me_spec.rb
  36. +8 −8 spec/rails3/spec_helper.rb
  37. +13 −13 spec/rails3/user_activation_spec.rb
  38. +29 −29 spec/rails3/user_password_encryption_spec.rb
  39. +16 −16 spec/rails3/user_spec.rb
  40. +0 −182 spec/simple_auth_crypto_providers_spec.rb
  41. +182 −0 spec/sorcery_crypto_providers_spec.rb
  42. +1 −1  spec/spec_helper.rb
View
6 README.rdoc
@@ -1,4 +1,4 @@
-= simple_auth
+= sorcery
Inspired by restful_authentication, Authlogic and Devise (in that order).
Crypto code taken almost unchanged from Authlogic.
@@ -8,11 +8,11 @@ Crypto code taken almost unchanged from Authlogic.
* Simple interface, but don't kill simplicity with syntactic sugar.
* Easy Configuration, customization and extending.
* Keep MVC cleanly separated - DB is for models, sessions are for controllers. Models stay unaware of sessions.
-* Minimal amounts of magic - keeps code easy to understand and maintain.
+* Magic, not voodoo.
* No generated code polluting the developer's code.
* No tons of configuration code needed to add to the User model or Controller
-== Contributing to simple_auth
+== Contributing to sorcery
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
View
6 Rakefile
@@ -11,10 +11,10 @@ require 'rake'
require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
- gem.name = "simple_auth"
- gem.homepage = "http://github.com/NoamB/simple_auth"
+ gem.name = "sorcery"
+ gem.homepage = "http://github.com/NoamB/sorcery"
gem.license = "MIT"
- gem.summary = "Simple authentication for Rails 3 applications"
+ gem.summary = "Magical authentication for Rails 3 applications"
gem.description = "Provides common authentication needs such as signing in/out, activating by email, resetting password and deleting accounts."
gem.email = "nbenari@gmail.com"
gem.authors = ["Noam"]
View
2  features/support/env.rb
@@ -8,6 +8,6 @@
end
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
-require 'simple_auth'
+require 'sorcery'
require 'rspec/expectations'
View
26 lib/simple_auth.rb
@@ -1,26 +0,0 @@
-module SimpleAuth
- autoload :Model, 'simple_auth/model'
- module Model
- module Submodules
- autoload :PasswordConfirmation, 'simple_auth/model/submodules/password_confirmation'
- autoload :PasswordEncryption, 'simple_auth/model/submodules/password_encryption'
- autoload :UserActivation, 'simple_auth/model/submodules/user_activation'
- autoload :PasswordReset, 'simple_auth/model/submodules/password_reset'
- autoload :RememberMe, 'simple_auth/model/submodules/remember_me'
- end
- module Adapters
- autoload :ActiveRecord, 'simple_auth/model/adapters/active_record'
- end
- end
- autoload :Controller, 'simple_auth/controller'
- module CryptoProviders
- autoload :AES256, 'simple_auth/crypto_providers/aes256'
- autoload :BCrypt, 'simple_auth/crypto_providers/bcrypt'
- autoload :MD5, 'simple_auth/crypto_providers/md5'
- autoload :SHA1, 'simple_auth/crypto_providers/sha1'
- autoload :SHA256, 'simple_auth/crypto_providers/sha256'
- autoload :SHA512, 'simple_auth/crypto_providers/sha512'
- end
-
- require 'simple_auth/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
-end
View
18 lib/simple_auth/engine.rb
@@ -1,18 +0,0 @@
-require 'simple_auth'
-require 'rails'
-
-module SimpleAuth
- # The SimpleAuth engine takes care of extending ActiveRecord (if used) and ActionController,
- # With the plugin logic.
- # ActionController is also automatically activated with the plugin to save you the trouble.
- class Engine < Rails::Engine
- initializer "extend Model with simple_auth" do |app|
- ActiveRecord::Base.send(:include, SimpleAuth::Model) if defined?(ActiveRecord)
- end
-
- initializer "extend Controller with simple_auth" do |app|
- ActionController::Base.send(:include, SimpleAuth::Controller)
- ActionController::Base.activate_simple_auth!
- end
- end
-end
View
26 lib/sorcery.rb
@@ -0,0 +1,26 @@
+module Sorcery
+ autoload :Model, 'sorcery/model'
+ module Model
+ module Submodules
+ autoload :PasswordConfirmation, 'sorcery/model/submodules/password_confirmation'
+ autoload :PasswordEncryption, 'sorcery/model/submodules/password_encryption'
+ autoload :UserActivation, 'sorcery/model/submodules/user_activation'
+ autoload :PasswordReset, 'sorcery/model/submodules/password_reset'
+ autoload :RememberMe, 'sorcery/model/submodules/remember_me'
+ end
+ module Adapters
+ autoload :ActiveRecord, 'sorcery/model/adapters/active_record'
+ end
+ end
+ autoload :Controller, 'sorcery/controller'
+ module CryptoProviders
+ autoload :AES256, 'sorcery/crypto_providers/aes256'
+ autoload :BCrypt, 'sorcery/crypto_providers/bcrypt'
+ autoload :MD5, 'sorcery/crypto_providers/md5'
+ autoload :SHA1, 'sorcery/crypto_providers/sha1'
+ autoload :SHA256, 'sorcery/crypto_providers/sha256'
+ autoload :SHA512, 'sorcery/crypto_providers/sha512'
+ end
+
+ require 'sorcery/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
+end
View
4 lib/simple_auth/controller.rb → lib/sorcery/controller.rb
@@ -1,4 +1,4 @@
-module SimpleAuth
+module Sorcery
module Controller
def self.included(klass)
klass.class_eval do
@@ -7,7 +7,7 @@ def self.included(klass)
end
module ClassMethods
- def activate_simple_auth!(*submodules)
+ def activate_sorcery!(*submodules)
Config.submodules = submodules
yield Config if block_given?
View
6 lib/simple_auth/crypto_providers/aes256.rb → lib/sorcery/crypto_providers/aes256.rb
@@ -1,11 +1,11 @@
require "openssl"
-module SimpleAuth
+module Sorcery
module CryptoProviders
# 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.
# In an initializer, or before your application initializes, you should do the following:
#
- # SimpleAuth::Model::ConfigAES256.key = "my 32 bytes long key"
+ # Sorcery::Model::ConfigAES256.key = "my 32 bytes long key"
#
# 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
# then you should consider Sha512 or BCrypt instead.
@@ -35,7 +35,7 @@ def matches?(crypted, *tokens)
private
def aes
- raise ArgumentError.new("#{name} expects a 32 bytes long key. Please use SimpleAuth::Model::Config.encryption_key to set it.") if ( @key.nil? || @key == "" )
+ raise ArgumentError.new("#{name} expects a 32 bytes long key. Please use Sorcery::Model::Config.encryption_key to set it.") if ( @key.nil? || @key == "" )
@aes ||= OpenSSL::Cipher::Cipher.new("AES-256-ECB")
end
end
View
8 lib/simple_auth/crypto_providers/bcrypt.rb → lib/sorcery/crypto_providers/bcrypt.rb
@@ -4,7 +4,7 @@
"sudo gem install bcrypt-ruby"
end
-module SimpleAuth
+module Sorcery
module CryptoProviders
# For most apps Sha512 is plenty secure, but if you are building an app that stores nuclear launch codes you might want to consier BCrypt. This is an extremely
# secure hashing algorithm, mainly because it is slow. A brute force attack on a BCrypt encrypted password would take much longer than a brute force attack on a
@@ -34,9 +34,9 @@ module CryptoProviders
#
# gem install bcrypt-ruby
#
- # Tell activate_simple_auth! to use it:
+ # Tell activate_sorcery! to use it:
#
- # activate_simple_auth! do |c|
+ # activate_sorcery! do |c|
# c.encryption_algorithm = :bcrypt
# end
#
@@ -62,7 +62,7 @@ def matches?(hash, *tokens)
hash == join_tokens(tokens)
end
- # This method is used as a flag to tell SimpleAuth to "resave" the password upon a successful login, using the new cost
+ # This method is used as a flag to tell Sorcery to "resave" the password upon a successful login, using the new cost
def cost_matches?(hash)
hash = new_from_hash(hash)
if hash.nil? || hash == {}
View
4 lib/simple_auth/crypto_providers/md5.rb → lib/sorcery/crypto_providers/md5.rb
@@ -1,12 +1,12 @@
require "digest/md5"
-module SimpleAuth
+module Sorcery
module CryptoProviders
# This class was made for the users transitioning from md5 based systems.
# I highly discourage using this crypto provider as it superbly inferior
# to your other options.
#
- # Please use any other provider offered by SimpleAuth.
+ # Please use any other provider offered by Sorcery.
class MD5
class << self
attr_accessor :join_token
View
4 lib/simple_auth/crypto_providers/sha1.rb → lib/sorcery/crypto_providers/sha1.rb
@@ -1,9 +1,9 @@
require "digest/sha1"
-module SimpleAuth
+module Sorcery
module CryptoProviders
# This class was made for the users transitioning from restful_authentication. I highly discourage using this
- # crypto provider as it inferior to your other options. Please use any other provider offered by SimpleAuth.
+ # crypto provider as it inferior to your other options. Please use any other provider offered by Sorcery.
class SHA1
class << self
def join_token
View
4 lib/simple_auth/crypto_providers/sha256.rb → lib/sorcery/crypto_providers/sha256.rb
@@ -1,7 +1,7 @@
require "digest/sha2"
-module SimpleAuth
- # The activate_simple_auth method has a custom_crypto_provider configuration option. This allows you to use any type of encryption you like.
+module Sorcery
+ # The activate_sorcery method has a custom_crypto_provider configuration option. This allows you to use any type of encryption you like.
# Just create a class with a class level encrypt and matches? method. See example below.
#
# === Example
View
4 lib/simple_auth/crypto_providers/sha512.rb → lib/sorcery/crypto_providers/sha512.rb
@@ -1,7 +1,7 @@
require "digest/sha2"
-module SimpleAuth
- # The activate_simple_auth method has a custom_crypto_provider configuration option. This allows you to use any type of encryption you like.
+module Sorcery
+ # The activate_sorcery method has a custom_crypto_provider configuration option. This allows you to use any type of encryption you like.
# Just create a class with a class level encrypt and matches? method. See example below.
#
# === Example
View
18 lib/sorcery/engine.rb
@@ -0,0 +1,18 @@
+require 'sorcery'
+require 'rails'
+
+module Sorcery
+ # The Sorcery engine takes care of extending ActiveRecord (if used) and ActionController,
+ # With the plugin logic.
+ # ActionController is also automatically activated with the plugin to save you the trouble.
+ class Engine < Rails::Engine
+ initializer "extend Model with sorcery" do |app|
+ ActiveRecord::Base.send(:include, Sorcery::Model) if defined?(ActiveRecord)
+ end
+
+ initializer "extend Controller with sorcery" do |app|
+ ActionController::Base.send(:include, Sorcery::Controller)
+ ActionController::Base.activate_sorcery!
+ end
+ end
+end
View
36 lib/simple_auth/model.rb → lib/sorcery/model.rb
@@ -1,28 +1,28 @@
-module SimpleAuth
+module Sorcery
# This module handles all plugin operations which are related to the Model layer in the MVC pattern.
# It should be included into the ORM base class.
# In the case of Rails this is usually ActiveRecord (actually, in that case, the plugin does this automatically).
#
- # When included it defines a single method: 'activate_simple_auth!' which when called adds the other capabilities to the class.
+ # When included it defines a single method: 'activate_sorcery!' which when called adds the other capabilities to the class.
# This method is also the place to configure the plugin in the Model layer.
module Model
def self.included(klass)
klass.class_eval do
class << self
- def activate_simple_auth!
- @simple_auth_config = Config.new
+ def activate_sorcery!
+ @sorcery_config = Config.new
self.class_eval do
extend ClassMethods # included here, before submodules, so they can be overriden by them.
include InstanceMethods
- @simple_auth_config.submodules = ::SimpleAuth::Controller::Config.submodules
- @simple_auth_config.submodules.each do |mod|
+ @sorcery_config.submodules = ::Sorcery::Controller::Config.submodules
+ @sorcery_config.submodules.each do |mod|
include Submodules.const_get(mod.to_s.split("_").map {|p| p.capitalize}.join(""))
end
end
- yield @simple_auth_config if block_given?
+ yield @sorcery_config if block_given?
- @simple_auth_config.post_config_validations.each { |pcv| pcv.call(@simple_auth_config) }
+ @sorcery_config.post_config_validations.each { |pcv| pcv.call(@sorcery_config) }
end
end
end
@@ -30,16 +30,16 @@ def activate_simple_auth!
module InstanceMethods
# Returns the class instance variable for configuration, when called by an instance.
- def simple_auth_config
- self.class.simple_auth_config
+ def sorcery_config
+ self.class.sorcery_config
end
protected
def generic_send_email(method)
- config = simple_auth_config
- mail = config.simple_auth_mailer.send(config.send(method),self)
- if defined?(ActionMailer) and config.simple_auth_mailer.superclass == ActionMailer::Base
+ config = sorcery_config
+ mail = config.sorcery_mailer.send(config.send(method),self)
+ if defined?(ActionMailer) and config.sorcery_mailer.superclass == ActionMailer::Base
mail.deliver
end
end
@@ -47,8 +47,8 @@ def generic_send_email(method)
module ClassMethods
# Returns the class instance variable for configuration, when called by the class itself.
- def simple_auth_config
- @simple_auth_config
+ def sorcery_config
+ @sorcery_config
end
# The default authentication method.
@@ -56,12 +56,12 @@ def simple_auth_config
# Finds the user by the username and compares the user's password to the one supplied to the method.
# returns the user if success, nil otherwise.
def authenticate(username, password)
- user = where("#{@simple_auth_config.username_attribute_name} = ?", username).first
- user if user && @simple_auth_config.pre_authenticate_validations.all? {|proc| proc.call(user, @simple_auth_config)} && (user.send(@simple_auth_config.password_attribute_name) == password)
+ user = where("#{@sorcery_config.username_attribute_name} = ?", username).first
+ user if user && @sorcery_config.pre_authenticate_validations.all? {|proc| proc.call(user, @sorcery_config)} && (user.send(@sorcery_config.password_attribute_name) == password)
end
end
- # Each class which calls 'activate_simple_auth!' receives an instance of this class.
+ # Each class which calls 'activate_sorcery!' receives an instance of this class.
# This enables two different classes to use this plugin with different configurations.
# Every submodule which gets loaded may add accessors to this class so that all options will be configure from a single place.
class Config
View
14 ...le_auth/model/submodules/password_confirmation.rb → ...sorcery/model/submodules/password_confirmation.rb
@@ -1,24 +1,24 @@
-module SimpleAuth
+module Sorcery
module Model
module Submodules
# This submodule adds the ability to verify that the user filled the password twice,
# and that both times were the same string.
module PasswordConfirmation
def self.included(base)
- # changes to the SimpleAuth::Model::Config class
- base.simple_auth_config.class_eval do
+ # changes to the Sorcery::Model::Config class
+ base.sorcery_config.class_eval do
attr_accessor :password_confirmation_attribute_name
end
- # changes to simple_auth_config class instance variable
- base.simple_auth_config.instance_eval do
+ # changes to sorcery_config class instance variable
+ base.sorcery_config.instance_eval do
@defaults.merge!(:@password_confirmation_attribute_name => :password_confirmation)
reset!
end
# changes to the actual model
base.class_eval do
- attr_accessor @simple_auth_config.password_confirmation_attribute_name
+ attr_accessor @sorcery_config.password_confirmation_attribute_name
validate :password_confirmed
end
@@ -29,7 +29,7 @@ module InstanceMethods
protected
def password_confirmed
- config = simple_auth_config
+ config = sorcery_config
if self.send(config.password_attribute_name) && self.send(config.password_attribute_name) != self.send(config.password_confirmation_attribute_name)
self.errors.add(:base,"password and password_confirmation do not match!")
end
View
32 ...mple_auth/model/submodules/password_encryption.rb → lib/sorcery/model/submodules/password_encryption.rb
@@ -1,11 +1,11 @@
-module SimpleAuth
+module Sorcery
module Model
module Submodules
module PasswordEncryption
def self.included(base)
base.extend ClassMethods
- base.simple_auth_config.class_eval do
+ base.sorcery_config.class_eval do
attr_accessor :crypted_password_attribute_name,
:salt_join_token,
:salt_attribute_name,
@@ -36,7 +36,7 @@ def custom_encryption_provider=(provider)
end
end
- base.simple_auth_config.instance_eval do
+ base.sorcery_config.instance_eval do
@defaults.merge!(:@crypted_password_attribute_name => :crypted_password,
:@encryption_algorithm => :sha256,
:@custom_encryption_provider => nil,
@@ -48,9 +48,9 @@ def custom_encryption_provider=(provider)
end
base.class_eval do
- attr_accessor @simple_auth_config.password_attribute_name
- before_save :encrypt_password, :if => Proc.new {|record| record.new_record? || record.send(simple_auth_config.password_attribute_name)}
- after_save :clear_virtual_password, :if => Proc.new {|record| record.valid? && record.send(simple_auth_config.password_attribute_name)}
+ attr_accessor @sorcery_config.password_attribute_name
+ before_save :encrypt_password, :if => Proc.new {|record| record.new_record? || record.send(sorcery_config.password_attribute_name)}
+ after_save :clear_virtual_password, :if => Proc.new {|record| record.valid? && record.send(sorcery_config.password_attribute_name)}
end
base.send(:include, InstanceMethods)
end
@@ -60,7 +60,7 @@ module InstanceMethods
protected
def encrypt_password
- config = simple_auth_config
+ config = sorcery_config
salt = ""
if !config.salt_attribute_name.nil?
salt = Time.now.to_s
@@ -70,27 +70,27 @@ def encrypt_password
end
def clear_virtual_password
- config = simple_auth_config
+ config = sorcery_config
self.send(:"#{config.password_attribute_name}=", nil)
end
end
module ClassMethods
def authenticate(username, password)
- user = where("#{@simple_auth_config.username_attribute_name} = ?", username).first
+ user = where("#{@sorcery_config.username_attribute_name} = ?", username).first
if user
- salt = user.send(@simple_auth_config.salt_attribute_name) if !@simple_auth_config.salt_attribute_name.nil?
+ salt = user.send(@sorcery_config.salt_attribute_name) if !@sorcery_config.salt_attribute_name.nil?
end
- user if user && @simple_auth_config.pre_authenticate_validations.all? {|proc| proc.call(user, @simple_auth_config)} && (user.send(@simple_auth_config.crypted_password_attribute_name)) == encrypt(password,salt)
+ user if user && @sorcery_config.pre_authenticate_validations.all? {|proc| proc.call(user, @sorcery_config)} && (user.send(@sorcery_config.crypted_password_attribute_name)) == encrypt(password,salt)
end
def encrypt(*tokens)
- return tokens.first if @simple_auth_config.encryption_provider.nil?
+ return tokens.first if @sorcery_config.encryption_provider.nil?
- @simple_auth_config.encryption_provider.stretches = @simple_auth_config.stretches if @simple_auth_config.encryption_provider.respond_to?(:stretches) && @simple_auth_config.stretches
- @simple_auth_config.encryption_provider.join_token = @simple_auth_config.salt_join_token if @simple_auth_config.encryption_provider.respond_to?(:join_token) && @simple_auth_config.salt_join_token
- CryptoProviders::AES256.key = @simple_auth_config.encryption_key if @simple_auth_config.encryption_algorithm == :aes256
- @simple_auth_config.encryption_provider.encrypt(*tokens)
+ @sorcery_config.encryption_provider.stretches = @sorcery_config.stretches if @sorcery_config.encryption_provider.respond_to?(:stretches) && @sorcery_config.stretches
+ @sorcery_config.encryption_provider.join_token = @sorcery_config.salt_join_token if @sorcery_config.encryption_provider.respond_to?(:join_token) && @sorcery_config.salt_join_token
+ CryptoProviders::AES256.key = @sorcery_config.encryption_key if @sorcery_config.encryption_algorithm == :aes256
+ @sorcery_config.encryption_provider.encrypt(*tokens)
end
end
end
View
18 lib/simple_auth/model/submodules/password_reset.rb → lib/sorcery/model/submodules/password_reset.rb
@@ -1,19 +1,19 @@
-module SimpleAuth
+module Sorcery
module Model
module Submodules
# This submodule adds the ability to reset his password.
module PasswordReset
def self.included(base)
- base.simple_auth_config.class_eval do
+ base.sorcery_config.class_eval do
attr_accessor :reset_password_code_attribute_name,
- :simple_auth_mailer,
+ :sorcery_mailer,
:reset_password_email_method_name
end
- base.simple_auth_config.instance_eval do
+ base.sorcery_config.instance_eval do
@defaults.merge!(:@reset_password_code_attribute_name => :reset_password_code,
- :@simple_auth_mailer => nil,
+ :@sorcery_mailer => nil,
:@reset_password_email_method_name => :reset_password_email)
reset!
@@ -22,9 +22,9 @@ def self.included(base)
base.class_eval do
clear_reset_password_code_proc = Proc.new do |record|
begin
- record.valid? && record.send(:"#{simple_auth_config.password_attribute_name}_changed?")
+ record.valid? && record.send(:"#{sorcery_config.password_attribute_name}_changed?")
rescue
- record.valid? && record.send(simple_auth_config.password_attribute_name)
+ record.valid? && record.send(sorcery_config.password_attribute_name)
end
end
@@ -36,7 +36,7 @@ def self.included(base)
module InstanceMethods
def reset_password!
- config = simple_auth_config
+ config = sorcery_config
self.send(:"#{config.reset_password_code_attribute_name}=", generate_random_code)
self.class.transaction do
self.save!
@@ -47,7 +47,7 @@ def reset_password!
protected
def clear_reset_password_code
- config = simple_auth_config
+ config = sorcery_config
self.send(:"#{config.reset_password_code_attribute_name}=", nil)
end
View
10 lib/simple_auth/model/submodules/remember_me.rb → lib/sorcery/model/submodules/remember_me.rb
@@ -1,16 +1,16 @@
-module SimpleAuth
+module Sorcery
module Model
module Submodules
module RememberMe
def self.included(base)
- base.simple_auth_config.class_eval do
+ base.sorcery_config.class_eval do
attr_accessor :remember_me_token_attribute_name,
:remember_me_token_expires_at_attribute_name,
:remember_me_for
end
- base.simple_auth_config.instance_eval do
+ base.sorcery_config.instance_eval do
@defaults.merge!(:@remember_me_token_attribute_name => :remember_me_token,
:@remember_me_token_expires_at_attribute_name => :remember_me_token_expires_at,
:@remember_me_for => 7 * 60 * 60 * 24)
@@ -23,14 +23,14 @@ def self.included(base)
module InstanceMethods
def remember_me!
- config = simple_auth_config
+ config = sorcery_config
self.send(:"#{config.remember_me_token_attribute_name}=", generate_random_code)
self.send(:"#{config.remember_me_token_expires_at_attribute_name}=", Time.now + config.remember_me_for)
self.save!
end
def forget_me!
- config = simple_auth_config
+ config = sorcery_config
self.send(:"#{config.remember_me_token_attribute_name}=", nil)
self.send(:"#{config.remember_me_token_expires_at_attribute_name}=", nil)
self.save!
View
22 lib/simple_auth/model/submodules/user_activation.rb → lib/sorcery/model/submodules/user_activation.rb
@@ -1,4 +1,4 @@
-module SimpleAuth
+module Sorcery
module Model
module Submodules
# This submodule adds the ability to make the user activate his account via email
@@ -7,19 +7,19 @@ module Submodules
# When using this submodule, supplying a mailer is mandatory.
module UserActivation
def self.included(base)
- base.simple_auth_config.class_eval do
+ base.sorcery_config.class_eval do
attr_accessor :activation_state_attribute_name,
:activation_code_attribute_name,
- :simple_auth_mailer,
+ :sorcery_mailer,
:activation_needed_email_method_name,
:activation_success_email_method_name,
:prevent_non_active_users_to_login
end
- base.simple_auth_config.instance_eval do
+ base.sorcery_config.instance_eval do
@defaults.merge!(:@activation_state_attribute_name => :activation_state,
:@activation_code_attribute_name => :activation_code,
- :@simple_auth_mailer => nil,
+ :@sorcery_mailer => nil,
:@activation_needed_email_method_name => :activation_needed_email,
:@activation_success_email_method_name => :activation_success_email,
:@prevent_non_active_users_to_login => true)
@@ -33,23 +33,23 @@ def self.included(base)
# make sure a mailer is defined
post_validation_proc = Proc.new do |config|
- msg = "To use user_activation submodule, you must define a mailer (config.simple_auth_mailer = YourMailerClass)."
- raise ArgumentError, msg if config.simple_auth_mailer == nil
+ msg = "To use user_activation submodule, you must define a mailer (config.sorcery_mailer = YourMailerClass)."
+ raise ArgumentError, msg if config.sorcery_mailer == nil
end
- base.simple_auth_config.add_post_config_validation(post_validation_proc)
+ base.sorcery_config.add_post_config_validation(post_validation_proc)
# prevent or allow the login of non-active users
pre_authenticate_proc = Proc.new do |user, config|
config.prevent_non_active_users_to_login ? user.send(config.activation_state_attribute_name) == "active" : true
end
- base.simple_auth_config.add_pre_authenticate_validation(pre_authenticate_proc)
+ base.sorcery_config.add_pre_authenticate_validation(pre_authenticate_proc)
base.send(:include, InstanceMethods)
end
module InstanceMethods
def activate!
- config = simple_auth_config
+ config = sorcery_config
self.send(:"#{config.activation_code_attribute_name}=", nil)
self.send(:"#{config.activation_state_attribute_name}=", "active")
send_activation_success_email!
@@ -58,7 +58,7 @@ def activate!
protected
def setup_activation
- config = simple_auth_config
+ config = sorcery_config
generated_activation_code = CryptoProviders::SHA1.encrypt( Time.now.to_s.split(//).sort_by {rand}.join )
self.send(:"#{config.activation_code_attribute_name}=", generated_activation_code)
self.send(:"#{config.activation_state_attribute_name}=", "pending")
View
2  spec/Gemfile
@@ -1,7 +1,7 @@
source 'http://rubygems.org'
gem "rails", '3.0.3'
-gem "simple_auth", '0.1.0', :path => '../../../'
+gem "sorcery", '0.1.0', :path => '../../../'
group :development do
gem 'bcrypt-ruby', :require => 'bcrypt'
View
4 spec/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: ../../../
specs:
- simple_auth (0.1.0)
+ sorcery (0.1.0)
GEM
remote: http://rubygems.org/
@@ -104,5 +104,5 @@ DEPENDENCIES
rails (= 3.0.3)
rspec
ruby-debug19
- simple_auth (= 0.1.0)!
simplecov (>= 0.3.8)
+ sorcery (= 0.1.0)!
View
2  spec/rails3/Gemfile
@@ -2,7 +2,7 @@ source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'
-gem "simple_auth", '0.1.0', :path => '../../../'
+gem "sorcery", '0.1.0', :path => '../../../'
group :development do
gem 'rspec'
View
4 spec/rails3/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: ../../../
specs:
- simple_auth (0.1.0)
+ sorcery (0.1.0)
GEM
remote: http://rubygems.org/
@@ -109,6 +109,6 @@ DEPENDENCIES
rspec
rspec-rails
ruby-debug19
- simple_auth (= 0.1.0)!
simplecov (>= 0.3.8)
+ sorcery (= 0.1.0)!
sqlite3-ruby
View
2  ...rails3/app_root/app/mailers/simple_auth_mailer.rb → spec/rails3/app_root/app/mailers/sorcery_mailer.rb
@@ -1,4 +1,4 @@
-class SimpleAuthMailer < ActionMailer::Base
+class SorceryMailer < ActionMailer::Base
default :from => "notifications@example.com"
View
2  spec/rails3/app_root/app/models/user.rb
@@ -1,3 +1,3 @@
class User < ActiveRecord::Base
- #activate_simple_auth!
+ #activate_sorcery!
end
View
0  ...iews/simple_auth_mailer/activation_email.html.erb → ...pp/views/sorcery_mailer/activation_email.html.erb
File renamed without changes
View
0  ...iews/simple_auth_mailer/activation_email.text.erb → ...pp/views/sorcery_mailer/activation_email.text.erb
File renamed without changes
View
0  ...ple_auth_mailer/activation_success_email.html.erb → .../sorcery_mailer/activation_success_email.html.erb
File renamed without changes
View
0  ...ple_auth_mailer/activation_success_email.text.erb → .../sorcery_mailer/activation_success_email.text.erb
File renamed without changes
View
0  .../simple_auth_mailer/reset_password_email.html.erb → ...iews/sorcery_mailer/reset_password_email.html.erb
File renamed without changes
View
0  .../simple_auth_mailer/reset_password_email.text.erb → ...iews/sorcery_mailer/reset_password_email.text.erb
File renamed without changes
View
22 spec/rails3/application_controller_spec.rb
@@ -12,18 +12,18 @@
# ----------------- PLUGIN LOADED -----------------------
describe ApplicationController, "when app has plugin loaded" do
it "should respond to the plugin activation class method" do
- ActionController::Base.should respond_to(:activate_simple_auth!)
- ApplicationController.should respond_to(:activate_simple_auth!)
+ ActionController::Base.should respond_to(:activate_sorcery!)
+ ApplicationController.should respond_to(:activate_sorcery!)
end
it "plugin activation should yield config to block" do
- ApplicationController.activate_simple_auth! do |config|
- config.should == ::SimpleAuth::Controller::Config
+ ApplicationController.activate_sorcery! do |config|
+ config.should == ::Sorcery::Controller::Config
end
end
it "config.should respond to 'submodules='" do
- ApplicationController.activate_simple_auth! do |config|
+ ApplicationController.activate_sorcery! do |config|
config.should respond_to(:submodules=)
end
end
@@ -36,34 +36,34 @@
end
after(:each) do
- SimpleAuth::Controller::Config.reset!
+ Sorcery::Controller::Config.reset!
plugin_model_configure
end
it "submodule configuration should effect model" do
- ApplicationController.activate_simple_auth! do |config|
+ ApplicationController.activate_sorcery! do |config|
config.submodules = [:test_submodule]
end
User.class_eval do
- activate_simple_auth!
+ activate_sorcery!
end
User.new.should respond_to(:my_instance_method)
end
it "should enable configuration option 'session_attribute_name'" do
plugin_set_controller_config_property(:session_attribute_name, :my_session)
- SimpleAuth::Controller::Config.session_attribute_name.should equal(:my_session)
+ Sorcery::Controller::Config.session_attribute_name.should equal(:my_session)
end
it "should enable configuration option 'cookies_attribute_name'" do
plugin_set_controller_config_property(:cookies_attribute_name, :my_cookies)
- SimpleAuth::Controller::Config.cookies_attribute_name.should equal(:my_cookies)
+ Sorcery::Controller::Config.cookies_attribute_name.should equal(:my_cookies)
end
end
# ----------------- PLUGIN ACTIVATED -----------------------
- describe ApplicationController, "when activated with simple_auth" do
+ describe ApplicationController, "when activated with sorcery" do
before(:all) do
create_new_user
end
View
10 spec/rails3/password_reset_spec.rb
@@ -52,7 +52,7 @@
end
after(:each) do
- User.simple_auth_config.reset!
+ User.sorcery_config.reset!
end
it "should respond to 'reset_password!'" do
@@ -62,10 +62,10 @@
end
# ----------------- PLUGIN ACTIVATED -----------------------
- describe User, "when activated with simple_auth" do
+ describe User, "when activated with sorcery" do
before(:all) do
- plugin_model_configure([:password_reset], :simple_auth_mailer => ::SimpleAuthMailer)
+ plugin_model_configure([:password_reset], :sorcery_mailer => ::SorceryMailer)
end
before(:each) do
@@ -89,10 +89,10 @@
end
# ----------------- PLUGIN ACTIVATED -----------------------
- describe User, "when activated with simple_auth" do
+ describe User, "when activated with sorcery" do
before(:all) do
- plugin_model_configure([:password_reset, :password_encryption], :simple_auth_mailer => ::SimpleAuthMailer)
+ plugin_model_configure([:password_reset, :password_encryption], :sorcery_mailer => ::SorceryMailer)
end
before(:each) do
View
6 spec/rails3/remember_me_spec.rb
@@ -18,17 +18,17 @@
end
after(:each) do
- User.simple_auth_config.reset!
+ User.sorcery_config.reset!
end
it "should allow configuration option 'remember_me_token_attribute_name'" do
plugin_set_model_config_property(:remember_me_token_attribute_name, :my_token)
- User.simple_auth_config.remember_me_token_attribute_name.should equal(:my_token)
+ User.sorcery_config.remember_me_token_attribute_name.should equal(:my_token)
end
it "should allow configuration option 'remember_me_token_expires_at_attribute_name'" do
plugin_set_model_config_property(:remember_me_token_expires_at_attribute_name, :my_expires)
- User.simple_auth_config.remember_me_token_expires_at_attribute_name.should equal(:my_expires)
+ User.sorcery_config.remember_me_token_expires_at_attribute_name.should equal(:my_expires)
end
it "should respond to 'remember_me!'" do
View
16 spec/rails3/spec_helper.rb
@@ -35,14 +35,14 @@
require File.join(File.dirname(__FILE__), 'app_root','app','models','user')
class TestUser < ActiveRecord::Base
- activate_simple_auth!
+ activate_sorcery!
end
class TestMailer < ActionMailer::Base
end
-module SimpleAuth
+module Sorcery
module Model
module Submodules
module TestSubmodule
@@ -55,17 +55,17 @@ def my_instance_method
def create_new_user
user_attributes_hash = {:username => 'gizmo', :email => "bla@bla.com", :password => 'secret'}
- user_attributes_hash.merge!(:password_confirmation => 'secret') if User.simple_auth_config.submodules.include?(:password_confirmation)
+ user_attributes_hash.merge!(:password_confirmation => 'secret') if User.sorcery_config.submodules.include?(:password_confirmation)
@user = User.new(user_attributes_hash)
@user.save!
end
def plugin_model_configure(submodules = [], options = {})
- ::SimpleAuth::Controller::Config.submodules = submodules
+ ::Sorcery::Controller::Config.submodules = submodules
reload_user_class
- User.activate_simple_auth! do |config|
+ User.activate_sorcery! do |config|
options.each do |property,value|
config.send(:"#{property}=", value)
end
@@ -74,19 +74,19 @@ def plugin_model_configure(submodules = [], options = {})
def plugin_set_model_config_property(property, *values)
User.class_eval do
- simple_auth_config.send(:"#{property}=", *values)
+ sorcery_config.send(:"#{property}=", *values)
end
end
def plugin_set_controller_config_property(property, value)
ApplicationController.class_eval do
- ::SimpleAuth::Controller::Config.send(:"#{property}=", value)
+ ::Sorcery::Controller::Config.send(:"#{property}=", value)
end
end
def plugin_controller_configure(submodules = [], options = {})
ApplicationController.class_eval do
- activate_simple_auth!(*submodules) do |config|
+ activate_sorcery!(*submodules) do |config|
options.each do |property,value|
config.send(:"#{property}=", value)
end
View
26 spec/rails3/user_activation_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-require File.expand_path(File.dirname(__FILE__) + '/app_root/app/mailers/simple_auth_mailer')
+require File.expand_path(File.dirname(__FILE__) + '/app_root/app/mailers/sorcery_mailer')
describe "User with activation submodule" do
before(:all) do
@@ -15,37 +15,37 @@
# ----------------- PLUGIN CONFIGURATION -----------------------
describe User, "loaded plugin configuration" do
before(:all) do
- plugin_model_configure([:user_activation], :simple_auth_mailer => ::SimpleAuthMailer)
+ plugin_model_configure([:user_activation], :sorcery_mailer => ::SorceryMailer)
end
after(:each) do
- User.simple_auth_config.reset!
- plugin_model_configure([:user_activation], :simple_auth_mailer => ::SimpleAuthMailer)
+ User.sorcery_config.reset!
+ plugin_model_configure([:user_activation], :sorcery_mailer => ::SorceryMailer)
end
it "should enable configuration option 'activation_state_attribute_name'" do
plugin_set_model_config_property(:activation_state_attribute_name, :status)
- User.simple_auth_config.activation_state_attribute_name.should equal(:status)
+ User.sorcery_config.activation_state_attribute_name.should equal(:status)
end
it "should enable configuration option 'activation_code_attribute_name'" do
plugin_set_model_config_property(:activation_code_attribute_name, :code)
- User.simple_auth_config.activation_code_attribute_name.should equal(:code)
+ User.sorcery_config.activation_code_attribute_name.should equal(:code)
end
- it "should enable configuration option 'simple_auth_mailer'" do
- plugin_set_model_config_property(:simple_auth_mailer, TestMailer)
- User.simple_auth_config.simple_auth_mailer.should equal(TestMailer)
+ it "should enable configuration option 'sorcery_mailer'" do
+ plugin_set_model_config_property(:sorcery_mailer, TestMailer)
+ User.sorcery_config.sorcery_mailer.should equal(TestMailer)
end
it "should enable configuration option 'activation_needed_email_method_name'" do
plugin_set_model_config_property(:activation_needed_email_method_name, :my_activation_email)
- User.simple_auth_config.activation_needed_email_method_name.should equal(:my_activation_email)
+ User.sorcery_config.activation_needed_email_method_name.should equal(:my_activation_email)
end
it "should enable configuration option 'activation_success_email_method_name'" do
plugin_set_model_config_property(:activation_success_email_method_name, :my_activation_email)
- User.simple_auth_config.activation_success_email_method_name.should equal(:my_activation_email)
+ User.sorcery_config.activation_success_email_method_name.should equal(:my_activation_email)
end
it "if mailer is nil on activation, throw exception!" do
@@ -56,7 +56,7 @@
# ----------------- ACTIVATION PROCESS -----------------------
describe User, "activation process" do
before(:all) do
- plugin_model_configure([:user_activation], :simple_auth_mailer => ::SimpleAuthMailer)
+ plugin_model_configure([:user_activation], :sorcery_mailer => ::SorceryMailer)
end
it "should generate an activation code on registration" do
@@ -114,7 +114,7 @@
describe User, "prevent non-active login feature" do
before(:all) do
- plugin_model_configure([:user_activation], :simple_auth_mailer => ::SimpleAuthMailer)
+ plugin_model_configure([:user_activation], :sorcery_mailer => ::SorceryMailer)
end
it "should not allow a non-active user to authenticate" do
View
58 spec/rails3/user_password_encryption_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-require File.expand_path(File.dirname(__FILE__) + '/app_root/app/mailers/simple_auth_mailer')
+require File.expand_path(File.dirname(__FILE__) + '/app_root/app/mailers/sorcery_mailer')
describe "User with password_encryption submodule" do
before(:all) do
@@ -18,50 +18,50 @@
end
after(:each) do
- User.simple_auth_config.reset!
+ User.sorcery_config.reset!
end
it "should enable configuration option 'crypted_password_attribute_name'" do
plugin_set_model_config_property(:crypted_password_attribute_name, :password)
- User.simple_auth_config.crypted_password_attribute_name.should equal(:password)
+ User.sorcery_config.crypted_password_attribute_name.should equal(:password)
end
it "should enable configuration option 'salt_attribute_name'" do
plugin_set_model_config_property(:salt_attribute_name, :my_salt)
- User.simple_auth_config.salt_attribute_name.should equal(:my_salt)
+ User.sorcery_config.salt_attribute_name.should equal(:my_salt)
end
it "should enable configuration option 'encryption_algorithm'" do
plugin_set_model_config_property(:encryption_algorithm, :none)
- User.simple_auth_config.encryption_algorithm.should equal(:none)
+ User.sorcery_config.encryption_algorithm.should equal(:none)
end
it "should enable configuration option 'encryption_key'" do
plugin_set_model_config_property(:encryption_key, 'asdadas424234242')
- User.simple_auth_config.encryption_key.should == 'asdadas424234242'
+ User.sorcery_config.encryption_key.should == 'asdadas424234242'
end
it "should enable configuration option 'custom_encryption_provider'" do
plugin_set_model_config_property(:encryption_algorithm, :custom)
plugin_set_model_config_property(:custom_encryption_provider, Array)
- User.simple_auth_config.custom_encryption_provider.should equal(Array)
+ User.sorcery_config.custom_encryption_provider.should equal(Array)
end
it "should enable configuration option 'salt_join_token'" do
salt_join_token = "--%%*&-"
plugin_set_model_config_property(:salt_join_token, salt_join_token)
- User.simple_auth_config.salt_join_token.should equal(salt_join_token)
+ User.sorcery_config.salt_join_token.should equal(salt_join_token)
end
it "should enable configuration option 'stretches'" do
stretches = 15
plugin_set_model_config_property(:stretches, stretches)
- User.simple_auth_config.stretches.should equal(stretches)
+ User.sorcery_config.stretches.should equal(stretches)
end
end
# ----------------- PLUGIN ACTIVATED -----------------------
- describe User, "when activated with simple_auth" do
+ describe User, "when activated with sorcery" do
before(:all) do
plugin_model_configure([:password_encryption])
@@ -89,7 +89,7 @@
it "should encrypt password when a new user is saved" do
create_new_user
- @user.send(User.simple_auth_config.crypted_password_attribute_name).should == User.encrypt('secret')
+ @user.send(User.sorcery_config.crypted_password_attribute_name).should == User.encrypt('secret')
end
it "should clear the virtual password field if the encryption process worked" do
@@ -123,14 +123,14 @@
create_new_user
@user.email = "blup@bla.com"
@user.save!
- @user.send(User.simple_auth_config.crypted_password_attribute_name).should == User.encrypt('secret')
+ @user.send(User.sorcery_config.crypted_password_attribute_name).should == User.encrypt('secret')
end
it "should replace the crypted_password in case a new password is set" do
create_new_user
@user.password = 'new_secret'
@user.save!
- @user.send(User.simple_auth_config.crypted_password_attribute_name).should == User.encrypt('new_secret')
+ @user.send(User.sorcery_config.crypted_password_attribute_name).should == User.encrypt('new_secret')
end
describe "with password_confirmation module" do
@@ -140,7 +140,7 @@
@user.password = 'new_secret'
@user.password_confirmation = 'new_secret'
@user.save!
- @user.send(User.simple_auth_config.crypted_password_attribute_name).should == User.encrypt('new_secret')
+ @user.send(User.sorcery_config.crypted_password_attribute_name).should == User.encrypt('new_secret')
end
end
end
@@ -157,13 +157,13 @@
end
after(:each) do
- User.simple_auth_config.reset!
+ User.sorcery_config.reset!
end
it "should work with no password encryption" do
plugin_set_model_config_property(:encryption_algorithm, :none)
create_new_user
- User.authenticate(@user.send(User.simple_auth_config.username_attribute_name), 'secret').should be_true
+ User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'secret').should be_true
end
it "should work with custom password encryption" do
@@ -175,7 +175,7 @@ def self.encrypt(*tokens)
plugin_set_model_config_property(:encryption_algorithm, :custom)
plugin_set_model_config_property(:custom_encryption_provider, MyCrypto)
create_new_user
- User.authenticate(@user.send(User.simple_auth_config.username_attribute_name), 'secret').should be_true
+ User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'secret').should be_true
end
it "if encryption algo is aes256, it should set key to crypto provider" do
@@ -196,22 +196,22 @@ def self.encrypt(*tokens)
it "if encryption algo is md5 it should work" do
plugin_set_model_config_property(:encryption_algorithm, :md5)
- User.encrypt(@text).should == SimpleAuth::CryptoProviders::MD5.encrypt(@text)
+ User.encrypt(@text).should == Sorcery::CryptoProviders::MD5.encrypt(@text)
end
it "if encryption algo is sha1 it should work" do
plugin_set_model_config_property(:encryption_algorithm, :sha1)
- User.encrypt(@text).should == SimpleAuth::CryptoProviders::SHA1.encrypt(@text)
+ User.encrypt(@text).should == Sorcery::CryptoProviders::SHA1.encrypt(@text)
end
it "if encryption algo is sha256 it should work" do
plugin_set_model_config_property(:encryption_algorithm, :sha256)
- User.encrypt(@text).should == SimpleAuth::CryptoProviders::SHA256.encrypt(@text)
+ User.encrypt(@text).should == Sorcery::CryptoProviders::SHA256.encrypt(@text)
end
it "if encryption algo is sha512 it should work" do
plugin_set_model_config_property(:encryption_algorithm, :sha512)
- User.encrypt(@text).should == SimpleAuth::CryptoProviders::SHA512.encrypt(@text)
+ User.encrypt(@text).should == Sorcery::CryptoProviders::SHA512.encrypt(@text)
end
it "salt should be random for each user and saved in db" do
@@ -224,8 +224,8 @@ def self.encrypt(*tokens)
plugin_set_model_config_property(:salt_attribute_name, :salt)
plugin_set_model_config_property(:encryption_algorithm, :sha512)
create_new_user
- @user.crypted_password.should_not == SimpleAuth::CryptoProviders::SHA512.encrypt('secret')
- @user.crypted_password.should == SimpleAuth::CryptoProviders::SHA512.encrypt('secret',@user.salt)
+ @user.crypted_password.should_not == Sorcery::CryptoProviders::SHA512.encrypt('secret')
+ @user.crypted_password.should == Sorcery::CryptoProviders::SHA512.encrypt('secret',@user.salt)
end
it "if salt_join_token is set should use it to encrypt" do
@@ -233,11 +233,11 @@ def self.encrypt(*tokens)
plugin_set_model_config_property(:salt_join_token, "-@=>")
plugin_set_model_config_property(:encryption_algorithm, :sha512)
create_new_user
- @user.crypted_password.should_not == SimpleAuth::CryptoProviders::SHA512.encrypt('secret')
- SimpleAuth::CryptoProviders::SHA512.join_token = ""
- @user.crypted_password.should_not == SimpleAuth::CryptoProviders::SHA512.encrypt('secret',@user.salt)
- SimpleAuth::CryptoProviders::SHA512.join_token = User.simple_auth_config.salt_join_token
- @user.crypted_password.should == SimpleAuth::CryptoProviders::SHA512.encrypt('secret',@user.salt)
+ @user.crypted_password.should_not == Sorcery::CryptoProviders::SHA512.encrypt('secret')
+ Sorcery::CryptoProviders::SHA512.join_token = ""
+ @user.crypted_password.should_not == Sorcery::CryptoProviders::SHA512.encrypt('secret',@user.salt)
+ Sorcery::CryptoProviders::SHA512.join_token = User.sorcery_config.salt_join_token
+ @user.crypted_password.should == Sorcery::CryptoProviders::SHA512.encrypt('secret',@user.salt)
end
end
@@ -245,7 +245,7 @@ def self.encrypt(*tokens)
describe User, "prevent non-active login feature" do
before(:all) do
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
- plugin_model_configure([:password_encryption, :user_activation], :simple_auth_mailer => ::SimpleAuthMailer)
+ plugin_model_configure([:password_encryption, :user_activation], :sorcery_mailer => ::SorceryMailer)
end
after(:all) do
View
32 spec/rails3/user_spec.rb
@@ -12,13 +12,13 @@
describe User, "when app has plugin loaded" do
it "should respond to the plugin activation class method" do
- ActiveRecord::Base.should respond_to(:activate_simple_auth!)
- User.should respond_to(:activate_simple_auth!)
+ ActiveRecord::Base.should respond_to(:activate_sorcery!)
+ User.should respond_to(:activate_sorcery!)
end
it "plugin activation should yield config to block" do
- User.activate_simple_auth! do |config|
- config.class.should == ::SimpleAuth::Model::Config
+ User.activate_sorcery! do |config|
+ config.class.should == ::Sorcery::Model::Config
end
end
end
@@ -26,28 +26,28 @@
# ----------------- PLUGIN CONFIGURATION -----------------------
describe User, "loaded plugin configuration" do
after(:each) do
- User.simple_auth_config.reset!
+ User.sorcery_config.reset!
end
it "should enable submodules in parameters" do
plugin_model_configure([:password_confirmation])
- User.simple_auth_config.should respond_to(:password_confirmation_attribute_name)
+ User.sorcery_config.should respond_to(:password_confirmation_attribute_name)
plugin_model_configure()
end
it "should enable configuration option 'username_attribute_name'" do
plugin_set_model_config_property(:username_attribute_name, :email)
- User.simple_auth_config.username_attribute_name.should equal(:email)
+ User.sorcery_config.username_attribute_name.should equal(:email)
end
it "should enable configuration option 'password_attribute_name'" do
plugin_set_model_config_property(:password_attribute_name, :mypassword)
- User.simple_auth_config.password_attribute_name.should equal(:mypassword)
+ User.sorcery_config.password_attribute_name.should equal(:mypassword)
end
it "should enable configuration option 'email_attribute_name'" do
plugin_set_model_config_property(:email_attribute_name, :my_email)
- User.simple_auth_config.email_attribute_name.should equal(:my_email)
+ User.sorcery_config.email_attribute_name.should equal(:my_email)
end
describe "with PasswordConfirmation" do
@@ -56,24 +56,24 @@
end
after(:each) do
- User.simple_auth_config.reset!
+ User.sorcery_config.reset!
end
it "should enable configuration option 'password_confirmation_attribute_name'" do
plugin_set_model_config_property(:password_confirmation_attribute_name, :mypassword_conf)
- User.simple_auth_config.password_confirmation_attribute_name.should equal(:mypassword_conf)
+ User.sorcery_config.password_confirmation_attribute_name.should equal(:mypassword_conf)
end
end
it "should enable two classes to have different configurations" do
plugin_set_model_config_property(:username_attribute_name, :email)
- TestUser.simple_auth_config.username_attribute_name.should equal(:username)
+ TestUser.sorcery_config.username_attribute_name.should equal(:username)
end
end
# ----------------- PLUGIN ACTIVATED -----------------------
- describe User, "when activated with simple_auth" do
+ describe User, "when activated with sorcery" do
before(:all) do
plugin_model_configure
end
@@ -89,12 +89,12 @@
it "authenticate should return true if credentials are good" do
create_new_user
- User.authenticate(@user.send(User.simple_auth_config.username_attribute_name), 'secret').should be_true
+ User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'secret').should be_true
end
it "authenticate should return false if credentials are bad" do
create_new_user
- User.authenticate(@user.send(User.simple_auth_config.username_attribute_name), 'wrong!').should be_false
+ User.authenticate(@user.send(User.sorcery_config.username_attribute_name), 'wrong!').should be_false
end
end
@@ -122,7 +122,7 @@
end
after(:each) do
- User.simple_auth_config.reset!
+ User.sorcery_config.reset!
end
it "should not register a user with mismatching password fields" do
View
182 spec/simple_auth_crypto_providers_spec.rb
@@ -1,182 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-
-describe "Crypto Providers wrappers" do
-
- describe SimpleAuth::CryptoProviders::MD5 do
-
- after(:each) do
- SimpleAuth::CryptoProviders::MD5.reset!
- end
-
- it "encrypt works via wrapper like normal lib" do
- SimpleAuth::CryptoProviders::MD5.encrypt('Noam Ben-Ari').should == Digest::MD5.hexdigest('Noam Ben-Ari')
- end
-
- it "works with multiple stretches" do
- SimpleAuth::CryptoProviders::MD5.stretches = 3
- SimpleAuth::CryptoProviders::MD5.encrypt('Noam Ben-Ari').should == Digest::MD5.hexdigest(Digest::MD5.hexdigest(Digest::MD5.hexdigest('Noam Ben-Ari')))
- end
-
- it "matches? returns true when matches" do
- SimpleAuth::CryptoProviders::MD5.matches?(Digest::MD5.hexdigest('Noam Ben-Ari'), 'Noam Ben-Ari').should be_true
- end
-
- it "matches? returns false when no match" do
- SimpleAuth::CryptoProviders::MD5.matches?(Digest::MD5.hexdigest('Noam Ben-Ari'), 'Some Dude').should be_false
- end
-
- end
-
- describe SimpleAuth::CryptoProviders::SHA1 do
-
- before(:all) do
- @digest = 'Noam Ben-Ari'
- 10.times {@digest = Digest::SHA1.hexdigest(@digest)}
- end
-
- after(:each) do
- SimpleAuth::CryptoProviders::SHA1.reset!
- end
-
- it "encrypt works via wrapper like normal lib" do
- SimpleAuth::CryptoProviders::SHA1.encrypt('Noam Ben-Ari').should == @digest
- end
-
- it "works with multiple stretches" do
- SimpleAuth::CryptoProviders::SHA1.stretches = 3
- SimpleAuth::CryptoProviders::SHA1.encrypt('Noam Ben-Ari').should == Digest::SHA1.hexdigest(Digest::SHA1.hexdigest(Digest::SHA1.hexdigest('Noam Ben-Ari')))
- end
-
- it "matches? returns true when matches" do
- SimpleAuth::CryptoProviders::SHA1.matches?(@digest, 'Noam Ben-Ari').should be_true
- end
-
- it "matches? returns false when no match" do
- SimpleAuth::CryptoProviders::SHA1.matches?(@digest, 'Some Dude').should be_false
- end
-
- end
-
- describe SimpleAuth::CryptoProviders::SHA256 do
-
- before(:all) do
- @digest = 'Noam Ben-Ari'
- 20.times {@digest = Digest::SHA256.hexdigest(@digest)}
- end
-
- after(:each) do
- SimpleAuth::CryptoProviders::SHA256.reset!
- end
-
- it "encrypt works via wrapper like normal lib" do
- SimpleAuth::CryptoProviders::SHA256.encrypt('Noam Ben-Ari').should == @digest
- end
-
- it "works with multiple stretches" do
- SimpleAuth::CryptoProviders::SHA256.stretches = 3
- SimpleAuth::CryptoProviders::SHA256.encrypt('Noam Ben-Ari').should == Digest::SHA256.hexdigest(Digest::SHA256.hexdigest(Digest::SHA256.hexdigest('Noam Ben-Ari')))
- end
-
- it "matches? returns true when matches" do
- SimpleAuth::CryptoProviders::SHA256.matches?(@digest, 'Noam Ben-Ari').should be_true
- end
-
- it "matches? returns false when no match" do
- SimpleAuth::CryptoProviders::SHA256.matches?(@digest, 'Some Dude').should be_false
- end
-
- end
-
- describe SimpleAuth::CryptoProviders::SHA512 do
-
- before(:all) do
- @digest = 'Noam Ben-Ari'
- 20.times {@digest = Digest::SHA512.hexdigest(@digest)}
- end
-
- after(:each) do
- SimpleAuth::CryptoProviders::SHA512.reset!
- end
-
- it "encrypt works via wrapper like normal lib" do
- SimpleAuth::CryptoProviders::SHA512.encrypt('Noam Ben-Ari').should == @digest
- end
-
- it "works with multiple stretches" do
- SimpleAuth::CryptoProviders::SHA512.stretches = 3
- SimpleAuth::CryptoProviders::SHA512.encrypt('Noam Ben-Ari').should == Digest::SHA512.hexdigest(Digest::SHA512.hexdigest(Digest::SHA512.hexdigest('Noam Ben-Ari')))
- end
-
- it "matches? returns true when matches" do
- SimpleAuth::CryptoProviders::SHA512.matches?(@digest, 'Noam Ben-Ari').should be_true
- end
-
- it "matches? returns false when no match" do
- SimpleAuth::CryptoProviders::SHA512.matches?(@digest, 'Some Dude').should be_false
- end
-
- end
-
- describe SimpleAuth::CryptoProviders::AES256 do
-
- before(:all) do
- aes = OpenSSL::Cipher::Cipher.new("AES-256-ECB")
- aes.encrypt
- @key = "asd234dfs423fddsmndsflktsdf32343"
- aes.key = @key
- @digest = 'Noam Ben-Ari'
- @digest = [aes.update(@digest) + aes.final].pack("m").chomp
- SimpleAuth::CryptoProviders::AES256.key = @key
- end
-
- it "encrypt works via wrapper like normal lib" do
- SimpleAuth::CryptoProviders::AES256.encrypt('Noam Ben-Ari').should == @digest
- end
-
- it "matches? returns true when matches" do
- SimpleAuth::CryptoProviders::AES256.matches?(@digest, 'Noam Ben-Ari').should be_true
- end
-
- it "matches? returns false when no match" do
- SimpleAuth::CryptoProviders::AES256.matches?(@digest, 'Some Dude').should be_false
- end
-
- it "can be decrypted" do
- aes = OpenSSL::Cipher::Cipher.new("AES-256-ECB")
- aes.decrypt
- aes.key = @key
- (aes.update(@digest.unpack("m").first) + aes.final).should == "Noam Ben-Ari"
- end
-
- end
-
- describe SimpleAuth::CryptoProviders::BCrypt do
-
- before(:all) do
- @digest = BCrypt::Password.create('Noam Ben-Ari', :cost => 10)
- end
-
- after(:each) do
- SimpleAuth::CryptoProviders::BCrypt.reset!
- end
-
- it "should be comparable with original secret" do
- BCrypt::Password.new(SimpleAuth::CryptoProviders::BCrypt.encrypt('Noam Ben-Ari')).should == 'Noam Ben-Ari'
- end
-
- it "works with multiple costs" do
- SimpleAuth::CryptoProviders::BCrypt.cost = 3
- BCrypt::Password.new(SimpleAuth::CryptoProviders::BCrypt.encrypt('Noam Ben-Ari')).should == 'Noam Ben-Ari'
- end
-
- it "matches? returns true when matches" do
- SimpleAuth::CryptoProviders::BCrypt.matches?(@digest, 'Noam Ben-Ari').should be_true
- end
-
- it "matches? returns false when no match" do
- SimpleAuth::CryptoProviders::BCrypt.matches?(@digest, 'Some Dude').should be_false
- end
-
- end
-
-end
View
182 spec/sorcery_crypto_providers_spec.rb
@@ -0,0 +1,182 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe "Crypto Providers wrappers" do
+
+ describe Sorcery::CryptoProviders::MD5 do
+
+ after(:each) do
+ Sorcery::CryptoProviders::MD5.reset!
+ end
+
+ it "encrypt works via wrapper like normal lib" do
+ Sorcery::CryptoProviders::MD5.encrypt('Noam Ben-Ari').should == Digest::MD5.hexdigest('Noam Ben-Ari')
+ end
+
+ it "works with multiple stretches" do
+ Sorcery::CryptoProviders::MD5.stretches = 3
+ Sorcery::CryptoProviders::MD5.encrypt('Noam Ben-Ari').should == Digest::MD5.hexdigest(Digest::MD5.hexdigest(Digest::MD5.hexdigest('Noam Ben-Ari')))
+ end
+
+ it "matches? returns true when matches" do
+ Sorcery::CryptoProviders::MD5.matches?(Digest::MD5.hexdigest('Noam Ben-Ari'), 'Noam Ben-Ari').should be_true
+ end
+
+ it "matches? returns false when no match" do
+ Sorcery::CryptoProviders::MD5.matches?(Digest::MD5.hexdigest('Noam Ben-Ari'), 'Some Dude').should be_false
+ end
+
+ end
+
+ describe Sorcery::CryptoProviders::SHA1 do
+
+ before(:all) do
+ @digest = 'Noam Ben-Ari'
+ 10.times {@digest = Digest::SHA1.hexdigest(@digest)}
+ end
+
+ after(:each) do
+ Sorcery::CryptoProviders::SHA1.reset!
+ end
+
+ it "encrypt works via wrapper like normal lib" do
+ Sorcery::CryptoProviders::SHA1.encrypt('Noam Ben-Ari').should == @digest
+ end
+
+ it "works with multiple stretches" do
+ Sorcery::CryptoProviders::SHA1.stretches = 3
+ Sorcery::CryptoProviders::SHA1.encrypt('Noam Ben-Ari').should == Digest::SHA1.hexdigest(Digest::SHA1.hexdigest(Digest::SHA1.hexdigest('Noam Ben-Ari')))
+ end
+
+ it "matches? returns true when matches" do
+ Sorcery::CryptoProviders::SHA1.matches?(@digest, 'Noam Ben-Ari').should be_true
+ end
+
+ it "matches? returns false when no match" do
+ Sorcery::CryptoProviders::SHA1.matches?(@digest, 'Some Dude').should be_false
+ end
+
+ end
+
+ describe Sorcery::CryptoProviders::SHA256 do
+
+ before(:all) do
+ @digest = 'Noam Ben-Ari'
+ 20.times {@digest = Digest::SHA256.hexdigest(@digest)}
+ end
+
+ after(:each) do
+ Sorcery::CryptoProviders::SHA256.reset!
+ end
+
+ it "encrypt works via wrapper like normal lib" do
+ Sorcery::CryptoProviders::SHA256.encrypt('Noam Ben-Ari').should == @digest
+ end
+
+ it "works with multiple stretches" do
+ Sorcery::CryptoProviders::SHA256.stretches = 3
+ Sorcery::CryptoProviders::SHA256.encrypt('Noam Ben-Ari').should == Digest::SHA256.hexdigest(Digest::SHA256.hexdigest(Digest::SHA256.hexdigest('Noam Ben-Ari')))
+ end
+
+ it "matches? returns true when matches" do
+ Sorcery::CryptoProviders::SHA256.matches?(@digest, 'Noam Ben-Ari').should be_true
+ end
+
+ it "matches? returns false when no match" do
+ Sorcery::CryptoProviders::SHA256.matches?(@digest, 'Some Dude').should be_false
+ end
+
+ end
+
+ describe Sorcery::CryptoProviders::SHA512 do
+
+ before(:all) do
+ @digest = 'Noam Ben-Ari'
+ 20.times {@digest = Digest::SHA512.hexdigest(@digest)}
+ end
+
+ after(:each) do
+ Sorcery::CryptoProviders::SHA512.reset!
+ end
+
+ it "encrypt works via wrapper like normal lib" do
+ Sorcery::CryptoProviders::SHA512.encrypt('Noam Ben-Ari').should == @digest
+ end
+
+ it "works with multiple stretches" do
+ Sorcery::CryptoProviders::SHA512.stretches = 3
+ Sorcery::CryptoProviders::SHA512.encrypt('Noam Ben-Ari').should == Digest::SHA512.hexdigest(Digest::SHA512.hexdigest(Digest::SHA512.hexdigest('Noam Ben-Ari')))
+ end
+
+ it "matches? returns true when matches" do
+ Sorcery::CryptoProviders::SHA512.matches?(@digest, 'Noam Ben-Ari').should be_true
+ end
+
+ it "matches? returns false when no match" do
+ Sorcery::CryptoProviders::SHA512.matches?(@digest, 'Some Dude').should be_false
+ end
+
+ end
+
+ describe Sorcery::CryptoProviders::AES256 do
+
+ before(:all) do
+ aes = OpenSSL::Cipher::Cipher.new("AES-256-ECB")
+ aes.encrypt
+ @key = "asd234dfs423fddsmndsflktsdf32343"
+ aes.key = @key
+ @digest = 'Noam Ben-Ari'
+ @digest = [aes.update(@digest) + aes.final].pack("m").chomp
+ Sorcery::CryptoProviders::AES256.key = @key
+ end
+
+ it "encrypt works via wrapper like normal lib" do
+ Sorcery::CryptoProviders::AES256.encrypt('Noam Ben-Ari').should == @digest
+ end
+
+ it "matches? returns true when matches" do
+ Sorcery::CryptoProviders::AES256.matches?(@digest, 'Noam Ben-Ari').should be_true
+ end
+
+ it "matches? returns false when no match" do
+ Sorcery::CryptoProviders::AES256.matches?(@digest, 'Some Dude').should be_false
+ end
+
+ it "can be decrypted" do
+ aes = OpenSSL::Cipher::Cipher.new("AES-256-ECB")
+ aes.decrypt
+ aes.key = @key
+ (aes.update(@digest.unpack("m").first) + aes.final).should == "Noam Ben-Ari"
+ end
+
+ end
+
+ describe Sorcery::CryptoProviders::BCrypt do
+
+ before(:all) do
+ @digest = BCrypt::Password.create('Noam Ben-Ari', :cost => 10)
+ end
+
+ after(:each) do
+ Sorcery::CryptoProviders::BCrypt.reset!
+ end
+
+ it "should be comparable with original secret" do
+ BCrypt::Password.new(Sorcery::CryptoProviders::BCrypt.encrypt('Noam Ben-Ari')).should == 'Noam Ben-Ari'
+ end
+
+ it "works with multiple costs" do
+ Sorcery::CryptoProviders::BCrypt.cost = 3
+ BCrypt::Password.new(Sorcery::CryptoProviders::BCrypt.encrypt('Noam Ben-Ari')).should == 'Noam Ben-Ari'
+ end
+
+ it "matches? returns true when matches" do
+ Sorcery::CryptoProviders::BCrypt.matches?(@digest, 'Noam Ben-Ari').should be_true
+ end
+
+ it "matches? returns false when no match" do
+ Sorcery::CryptoProviders::BCrypt.matches?(@digest, 'Some Dude').should be_false
+ end
+
+ end
+
+end
View
2  spec/spec_helper.rb
@@ -7,7 +7,7 @@
require 'rspec'
-require 'simple_auth'
+require 'sorcery'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Please sign in to comment.
Something went wrong with that request. Please try again.