forked from AsteriskLabs/devise_google_authenticator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
350 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class ActiveSupport::TestCase | ||
|
||
# Helpers for creating new users | ||
# | ||
def generate_unique_email | ||
@@email_count ||= 0 | ||
@@email_count += 1 | ||
"test#{@@email_count}@email.com" | ||
end | ||
|
||
def valid_attributes(attributes={}) | ||
{ :email => generate_unique_email, | ||
:password => '123456', | ||
:password_confirmation => '123456' }.update(attributes) | ||
end | ||
|
||
def new_user(attributes={}) | ||
User.new(valid_attributes(attributes)).save | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require 'test_helper' | ||
require 'model_tests_helper' | ||
|
||
class GoogleAuthenticatableTest < ActiveSupport::TestCase | ||
|
||
def setup | ||
new_user | ||
end | ||
|
||
test 'new users have a non-nil secret set' do | ||
assert_not_nil User.find(1).gauth_secret | ||
end | ||
|
||
test 'new users should have gauth_enabled disabled by default' do | ||
assert_equal 0, User.find(1).gauth_enabled.to_i | ||
end | ||
|
||
test 'get_qr method works' do | ||
assert_not_nil User.find(1).get_qr | ||
end | ||
|
||
test 'updating gauth_enabled to true' do | ||
User.find(1).set_gauth_enabled(:gauth_enabled => 1) | ||
assert_equal 1, User.find(1).gauth_enabled.to_i | ||
end | ||
|
||
test 'updating gauth_enabled back to false' do | ||
User.find(1).set_gauth_enabled(:gauth_enabled => 0) | ||
assert_equal 0, User.find(1).gauth_enabled.to_i | ||
end | ||
|
||
test 'updating the gauth_tmp key' do | ||
User.find(1).assign_tmp | ||
|
||
assert_not_nil User.find(1).gauth_tmp | ||
assert_not_nil User.find(1).gauth_tmp_datetime | ||
|
||
sleep(1) | ||
|
||
old_tmp = User.find(1).gauth_tmp | ||
old_dt = User.find(1).gauth_tmp_datetime | ||
|
||
User.find(1).assign_tmp | ||
|
||
assert_not_equal old_tmp, User.find(1).gauth_tmp | ||
assert_not_equal old_dt, User.find(1).gauth_tmp_datetime | ||
end | ||
|
||
test 'testing class method for finding by tmp key' do | ||
assert User.find_by_gauth_tmp('invalid').nil? | ||
assert !User.find_by_gauth_tmp(User.find(1).gauth_tmp).nil? | ||
end | ||
|
||
test 'testing token validation' do | ||
assert !User.find(1).validate_token('1') | ||
assert !User.find(1).validate_token(ROTP::TOTP.new(User.find(1).get_qr).at(Time.now)) | ||
|
||
User.find(1).assign_tmp | ||
|
||
assert !User.find(1).validate_token('1') | ||
assert User.find(1).validate_token(ROTP::TOTP.new(User.find(1).get_qr).at(Time.now)) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'test_helper' | ||
|
||
class ModelsTest < ActiveSupport::TestCase | ||
def include_module?(klass, mod) | ||
klass.devise_modules.include?(mod) && | ||
klass.included_modules.include?(Devise::Models::const_get(mod.to_s.classify)) | ||
end | ||
|
||
def assert_include_modules(klass, *modules) | ||
modules.each do |mod| | ||
assert include_module?(klass, mod), "#{klass} not include #{mod}" | ||
end | ||
|
||
(Devise::ALL - modules).each do |mod| | ||
assert !include_module?(klass, mod), "#{klass} include #{mod}" | ||
end | ||
end | ||
|
||
test 'should include Devise modules' do | ||
assert_include_modules User, :database_authenticatable, :registerable, :validatable, :rememberable, :trackable, :google_authenticatable, :recoverable | ||
end | ||
|
||
test 'should have a default value for ga_timeout' do | ||
assert_equal 3.minutes, User.ga_timeout | ||
end | ||
|
||
test 'should have a default value for ga_timedrift' do | ||
assert_equal 3, User.ga_timedrift | ||
end | ||
|
||
test 'should set a new value for ga_timeout' do | ||
old_ga_timeout = User.ga_timeout | ||
User.ga_timeout = 1.minutes | ||
|
||
assert_equal 1.minutes, User.ga_timeout | ||
|
||
User.ga_timeout = old_ga_timeout | ||
end | ||
|
||
test 'should set a new value for ga_timedrift' do | ||
old_ga_timedrift = User.ga_timedrift | ||
User.ga_timedrift = 2 | ||
|
||
assert_equal 2, User.ga_timedrift | ||
|
||
User.ga_timedrift = old_ga_timedrift | ||
end | ||
|
||
test 'google_authenticatable attributes' do | ||
assert_equal 'f', User.new.gauth_enabled | ||
assert_nil User.new.gauth_tmp | ||
assert_nil User.new.gauth_tmp_datetime | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
WARNING: Can't mass-assign protected attributes: user | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
WARNING: Can't mass-assign protected attributes: user | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
WARNING: Can't mass-assign protected attributes: user | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
WARNING: Can't mass-assign protected attributes: user | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` | ||
Binary data inserted for `string` type on column `encrypted_password` |