piko-clean-kit 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/devise_token_auth-1.2.6/LICENSE +13 -0
- data/devise_token_auth-1.2.6/README.md +97 -0
- data/devise_token_auth-1.2.6/Rakefile +42 -0
- data/devise_token_auth-1.2.6/app/controllers/devise_token_auth/application_controller.rb +100 -0
- data/devise_token_auth-1.2.6/app/controllers/devise_token_auth/concerns/resource_finder.rb +58 -0
- data/devise_token_auth-1.2.6/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +199 -0
- data/devise_token_auth-1.2.6/app/controllers/devise_token_auth/confirmations_controller.rb +89 -0
- data/devise_token_auth-1.2.6/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +284 -0
- data/devise_token_auth-1.2.6/app/controllers/devise_token_auth/passwords_controller.rb +216 -0
- data/devise_token_auth-1.2.6/app/controllers/devise_token_auth/registrations_controller.rb +205 -0
- data/devise_token_auth-1.2.6/app/controllers/devise_token_auth/sessions_controller.rb +153 -0
- data/devise_token_auth-1.2.6/app/controllers/devise_token_auth/token_validations_controller.rb +31 -0
- data/devise_token_auth-1.2.6/app/controllers/devise_token_auth/unlocks_controller.rb +94 -0
- data/devise_token_auth-1.2.6/app/models/devise_token_auth/concerns/active_record_support.rb +18 -0
- data/devise_token_auth-1.2.6/app/models/devise_token_auth/concerns/confirmable_support.rb +28 -0
- data/devise_token_auth-1.2.6/app/models/devise_token_auth/concerns/mongoid_support.rb +19 -0
- data/devise_token_auth-1.2.6/app/models/devise_token_auth/concerns/tokens_serialization.rb +31 -0
- data/devise_token_auth-1.2.6/app/models/devise_token_auth/concerns/user.rb +282 -0
- data/devise_token_auth-1.2.6/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb +35 -0
- data/devise_token_auth-1.2.6/app/validators/devise_token_auth_email_validator.rb +31 -0
- data/devise_token_auth-1.2.6/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/devise_token_auth-1.2.6/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/devise_token_auth-1.2.6/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/devise_token_auth-1.2.6/app/views/devise_token_auth/omniauth_external_window.html.erb +38 -0
- data/devise_token_auth-1.2.6/config/locales/da-DK.yml +52 -0
- data/devise_token_auth-1.2.6/config/locales/de.yml +51 -0
- data/devise_token_auth-1.2.6/config/locales/en.yml +60 -0
- data/devise_token_auth-1.2.6/config/locales/es.yml +51 -0
- data/devise_token_auth-1.2.6/config/locales/fa.yml +60 -0
- data/devise_token_auth-1.2.6/config/locales/fr.yml +51 -0
- data/devise_token_auth-1.2.6/config/locales/he.yml +52 -0
- data/devise_token_auth-1.2.6/config/locales/it.yml +48 -0
- data/devise_token_auth-1.2.6/config/locales/ja.yml +60 -0
- data/devise_token_auth-1.2.6/config/locales/ko.yml +51 -0
- data/devise_token_auth-1.2.6/config/locales/nl.yml +32 -0
- data/devise_token_auth-1.2.6/config/locales/pl.yml +51 -0
- data/devise_token_auth-1.2.6/config/locales/pt-BR.yml +48 -0
- data/devise_token_auth-1.2.6/config/locales/pt.yml +51 -0
- data/devise_token_auth-1.2.6/config/locales/ro.yml +48 -0
- data/devise_token_auth-1.2.6/config/locales/ru.yml +52 -0
- data/devise_token_auth-1.2.6/config/locales/sq.yml +48 -0
- data/devise_token_auth-1.2.6/config/locales/sv.yml +52 -0
- data/devise_token_auth-1.2.6/config/locales/uk.yml +61 -0
- data/devise_token_auth-1.2.6/config/locales/vi.yml +52 -0
- data/devise_token_auth-1.2.6/config/locales/zh-CN.yml +48 -0
- data/devise_token_auth-1.2.6/config/locales/zh-HK.yml +50 -0
- data/devise_token_auth-1.2.6/config/locales/zh-TW.yml +50 -0
- data/devise_token_auth-1.2.6/lib/devise_token_auth/blacklist.rb +6 -0
- data/devise_token_auth-1.2.6/lib/devise_token_auth/controllers/helpers.rb +157 -0
- data/devise_token_auth-1.2.6/lib/devise_token_auth/controllers/url_helpers.rb +10 -0
- data/devise_token_auth-1.2.6/lib/devise_token_auth/engine.rb +105 -0
- data/devise_token_auth-1.2.6/lib/devise_token_auth/errors.rb +8 -0
- data/devise_token_auth-1.2.6/lib/devise_token_auth/rails/routes.rb +122 -0
- data/devise_token_auth-1.2.6/lib/devise_token_auth/token_factory.rb +126 -0
- data/devise_token_auth-1.2.6/lib/devise_token_auth/url.rb +44 -0
- data/devise_token_auth-1.2.6/lib/devise_token_auth/version.rb +5 -0
- data/devise_token_auth-1.2.6/lib/devise_token_auth.rb +14 -0
- data/devise_token_auth-1.2.6/lib/generators/devise_token_auth/USAGE +31 -0
- data/devise_token_auth-1.2.6/lib/generators/devise_token_auth/install_generator.rb +91 -0
- data/devise_token_auth-1.2.6/lib/generators/devise_token_auth/install_generator_helpers.rb +98 -0
- data/devise_token_auth-1.2.6/lib/generators/devise_token_auth/install_mongoid_generator.rb +46 -0
- data/devise_token_auth-1.2.6/lib/generators/devise_token_auth/install_views_generator.rb +18 -0
- data/devise_token_auth-1.2.6/lib/generators/devise_token_auth/templates/devise_token_auth.rb +66 -0
- data/devise_token_auth-1.2.6/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb +49 -0
- data/devise_token_auth-1.2.6/lib/generators/devise_token_auth/templates/user.rb.erb +9 -0
- data/devise_token_auth-1.2.6/lib/generators/devise_token_auth/templates/user_mongoid.rb.erb +56 -0
- data/devise_token_auth-1.2.6/lib/tasks/devise_token_auth_tasks.rake +6 -0
- data/devise_token_auth-1.2.6/test/controllers/custom/custom_confirmations_controller_test.rb +25 -0
- data/devise_token_auth-1.2.6/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb +33 -0
- data/devise_token_auth-1.2.6/test/controllers/custom/custom_passwords_controller_test.rb +79 -0
- data/devise_token_auth-1.2.6/test/controllers/custom/custom_registrations_controller_test.rb +63 -0
- data/devise_token_auth-1.2.6/test/controllers/custom/custom_sessions_controller_test.rb +39 -0
- data/devise_token_auth-1.2.6/test/controllers/custom/custom_token_validations_controller_test.rb +42 -0
- data/devise_token_auth-1.2.6/test/controllers/demo_group_controller_test.rb +151 -0
- data/devise_token_auth-1.2.6/test/controllers/demo_mang_controller_test.rb +313 -0
- data/devise_token_auth-1.2.6/test/controllers/demo_user_controller_test.rb +658 -0
- data/devise_token_auth-1.2.6/test/controllers/devise_token_auth/confirmations_controller_test.rb +275 -0
- data/devise_token_auth-1.2.6/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +438 -0
- data/devise_token_auth-1.2.6/test/controllers/devise_token_auth/passwords_controller_test.rb +893 -0
- data/devise_token_auth-1.2.6/test/controllers/devise_token_auth/registrations_controller_test.rb +920 -0
- data/devise_token_auth-1.2.6/test/controllers/devise_token_auth/sessions_controller_test.rb +605 -0
- data/devise_token_auth-1.2.6/test/controllers/devise_token_auth/token_validations_controller_test.rb +142 -0
- data/devise_token_auth-1.2.6/test/controllers/devise_token_auth/unlocks_controller_test.rb +235 -0
- data/devise_token_auth-1.2.6/test/controllers/overrides/confirmations_controller_test.rb +47 -0
- data/devise_token_auth-1.2.6/test/controllers/overrides/omniauth_callbacks_controller_test.rb +53 -0
- data/devise_token_auth-1.2.6/test/controllers/overrides/passwords_controller_test.rb +64 -0
- data/devise_token_auth-1.2.6/test/controllers/overrides/registrations_controller_test.rb +46 -0
- data/devise_token_auth-1.2.6/test/controllers/overrides/sessions_controller_test.rb +35 -0
- data/devise_token_auth-1.2.6/test/controllers/overrides/token_validations_controller_test.rb +43 -0
- data/devise_token_auth-1.2.6/test/dummy/README.rdoc +28 -0
- data/devise_token_auth-1.2.6/test/dummy/app/active_record/confirmable_user.rb +11 -0
- data/devise_token_auth-1.2.6/test/dummy/app/active_record/lockable_user.rb +7 -0
- data/devise_token_auth-1.2.6/test/dummy/app/active_record/mang.rb +5 -0
- data/devise_token_auth-1.2.6/test/dummy/app/active_record/only_email_user.rb +7 -0
- data/devise_token_auth-1.2.6/test/dummy/app/active_record/scoped_user.rb +9 -0
- data/devise_token_auth-1.2.6/test/dummy/app/active_record/unconfirmable_user.rb +9 -0
- data/devise_token_auth-1.2.6/test/dummy/app/active_record/unregisterable_user.rb +9 -0
- data/devise_token_auth-1.2.6/test/dummy/app/active_record/user.rb +6 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/application_controller.rb +14 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/auth_origin_controller.rb +7 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/custom/confirmations_controller.rb +13 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb +13 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/custom/passwords_controller.rb +39 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/custom/registrations_controller.rb +39 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/custom/sessions_controller.rb +29 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/custom/token_validations_controller.rb +19 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/demo_group_controller.rb +15 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/demo_mang_controller.rb +14 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/demo_user_controller.rb +27 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/overrides/confirmations_controller.rb +29 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb +16 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/overrides/passwords_controller.rb +36 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/overrides/registrations_controller.rb +29 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/overrides/sessions_controller.rb +36 -0
- data/devise_token_auth-1.2.6/test/dummy/app/controllers/overrides/token_validations_controller.rb +23 -0
- data/devise_token_auth-1.2.6/test/dummy/app/helpers/application_helper.rb +1058 -0
- data/devise_token_auth-1.2.6/test/dummy/app/models/concerns/favorite_color.rb +19 -0
- data/devise_token_auth-1.2.6/test/dummy/app/mongoid/confirmable_user.rb +52 -0
- data/devise_token_auth-1.2.6/test/dummy/app/mongoid/lockable_user.rb +38 -0
- data/devise_token_auth-1.2.6/test/dummy/app/mongoid/mang.rb +46 -0
- data/devise_token_auth-1.2.6/test/dummy/app/mongoid/only_email_user.rb +33 -0
- data/devise_token_auth-1.2.6/test/dummy/app/mongoid/scoped_user.rb +50 -0
- data/devise_token_auth-1.2.6/test/dummy/app/mongoid/unconfirmable_user.rb +44 -0
- data/devise_token_auth-1.2.6/test/dummy/app/mongoid/unregisterable_user.rb +47 -0
- data/devise_token_auth-1.2.6/test/dummy/app/mongoid/user.rb +49 -0
- data/devise_token_auth-1.2.6/test/dummy/app/views/layouts/application.html.erb +12 -0
- data/devise_token_auth-1.2.6/test/dummy/config/application.rb +48 -0
- data/devise_token_auth-1.2.6/test/dummy/config/application.yml.bk +0 -0
- data/devise_token_auth-1.2.6/test/dummy/config/boot.rb +11 -0
- data/devise_token_auth-1.2.6/test/dummy/config/environment.rb +7 -0
- data/devise_token_auth-1.2.6/test/dummy/config/environments/development.rb +36 -0
- data/devise_token_auth-1.2.6/test/dummy/config/environments/production.rb +68 -0
- data/devise_token_auth-1.2.6/test/dummy/config/environments/test.rb +58 -0
- data/devise_token_auth-1.2.6/test/dummy/config/initializers/backtrace_silencers.rb +9 -0
- data/devise_token_auth-1.2.6/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/devise_token_auth-1.2.6/test/dummy/config/initializers/devise.rb +290 -0
- data/devise_token_auth-1.2.6/test/dummy/config/initializers/devise_token_auth.rb +55 -0
- data/devise_token_auth-1.2.6/test/dummy/config/initializers/figaro.rb +3 -0
- data/devise_token_auth-1.2.6/test/dummy/config/initializers/filter_parameter_logging.rb +6 -0
- data/devise_token_auth-1.2.6/test/dummy/config/initializers/inflections.rb +18 -0
- data/devise_token_auth-1.2.6/test/dummy/config/initializers/mime_types.rb +6 -0
- data/devise_token_auth-1.2.6/test/dummy/config/initializers/omniauth.rb +11 -0
- data/devise_token_auth-1.2.6/test/dummy/config/initializers/session_store.rb +5 -0
- data/devise_token_auth-1.2.6/test/dummy/config/initializers/wrap_parameters.rb +16 -0
- data/devise_token_auth-1.2.6/test/dummy/config/routes.rb +57 -0
- data/devise_token_auth-1.2.6/test/dummy/config/spring.rb +3 -0
- data/devise_token_auth-1.2.6/test/dummy/config.ru +18 -0
- data/devise_token_auth-1.2.6/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +58 -0
- data/devise_token_auth-1.2.6/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +57 -0
- data/devise_token_auth-1.2.6/test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb +8 -0
- data/devise_token_auth-1.2.6/test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb +7 -0
- data/devise_token_auth-1.2.6/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb +55 -0
- data/devise_token_auth-1.2.6/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb +56 -0
- data/devise_token_auth-1.2.6/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb +56 -0
- data/devise_token_auth-1.2.6/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb +56 -0
- data/devise_token_auth-1.2.6/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb +56 -0
- data/devise_token_auth-1.2.6/test/dummy/db/migrate/20190924101113_devise_token_auth_create_confirmable_users.rb +49 -0
- data/devise_token_auth-1.2.6/test/dummy/db/schema.rb +198 -0
- data/devise_token_auth-1.2.6/test/dummy/lib/migration_database_helper.rb +43 -0
- data/devise_token_auth-1.2.6/test/dummy/tmp/generators/app/models/user.rb +11 -0
- data/devise_token_auth-1.2.6/test/dummy/tmp/generators/config/initializers/devise_token_auth.rb +66 -0
- data/devise_token_auth-1.2.6/test/dummy/tmp/generators/db/migrate/20240519164408_devise_token_auth_create_users.rb +49 -0
- data/devise_token_auth-1.2.6/test/factories/users.rb +41 -0
- data/devise_token_auth-1.2.6/test/lib/devise_token_auth/blacklist_test.rb +19 -0
- data/devise_token_auth-1.2.6/test/lib/devise_token_auth/rails/custom_routes_test.rb +29 -0
- data/devise_token_auth-1.2.6/test/lib/devise_token_auth/rails/routes_test.rb +87 -0
- data/devise_token_auth-1.2.6/test/lib/devise_token_auth/token_factory_test.rb +191 -0
- data/devise_token_auth-1.2.6/test/lib/devise_token_auth/url_test.rb +26 -0
- data/devise_token_auth-1.2.6/test/lib/generators/devise_token_auth/install_generator_test.rb +217 -0
- data/devise_token_auth-1.2.6/test/lib/generators/devise_token_auth/install_generator_with_namespace_test.rb +222 -0
- data/devise_token_auth-1.2.6/test/lib/generators/devise_token_auth/install_views_generator_test.rb +25 -0
- data/devise_token_auth-1.2.6/test/models/concerns/mongoid_support_test.rb +31 -0
- data/devise_token_auth-1.2.6/test/models/concerns/tokens_serialization_test.rb +104 -0
- data/devise_token_auth-1.2.6/test/models/confirmable_user_test.rb +35 -0
- data/devise_token_auth-1.2.6/test/models/only_email_user_test.rb +29 -0
- data/devise_token_auth-1.2.6/test/models/user_test.rb +224 -0
- data/devise_token_auth-1.2.6/test/support/controllers/routes.rb +43 -0
- data/devise_token_auth-1.2.6/test/test_helper.rb +134 -0
- data/piko-clean-kit.gemspec +12 -0
- metadata +220 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'generators/devise_token_auth/install_generator' if DEVISE_TOKEN_AUTH_ORM == :active_record
|
|
6
|
+
require 'generators/devise_token_auth/install_mongoid_generator' if DEVISE_TOKEN_AUTH_ORM == :mongoid
|
|
7
|
+
|
|
8
|
+
module DeviseTokenAuth
|
|
9
|
+
class InstallGeneratorTest < Rails::Generators::TestCase
|
|
10
|
+
tests InstallGenerator if DEVISE_TOKEN_AUTH_ORM == :active_record
|
|
11
|
+
tests InstallMongoidGenerator if DEVISE_TOKEN_AUTH_ORM == :mongoid
|
|
12
|
+
destination Rails.root.join('tmp/generators')
|
|
13
|
+
|
|
14
|
+
# The namespaced user model for testing
|
|
15
|
+
let(:user_class) { 'Azpire::V1::HumanResource::User' }
|
|
16
|
+
let(:namespace_path) { user_class.underscore }
|
|
17
|
+
let(:table_name) { user_class.pluralize.underscore.gsub('/','_') }
|
|
18
|
+
|
|
19
|
+
describe 'user model with namespace, clean install' do
|
|
20
|
+
setup :prepare_destination
|
|
21
|
+
|
|
22
|
+
before do
|
|
23
|
+
run_generator %W[#{user_class} auth]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
test 'user model (with namespace) is created, concern is included' do
|
|
27
|
+
assert_file "app/models/#{namespace_path}.rb" do |model|
|
|
28
|
+
assert_match(/include DeviseTokenAuth::Concerns::User/, model)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
test 'initializer is created' do
|
|
33
|
+
assert_file 'config/initializers/devise_token_auth.rb'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
test 'subsequent runs raise no errors' do
|
|
37
|
+
run_generator %W[#{user_class} auth]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
if DEVISE_TOKEN_AUTH_ORM == :active_record
|
|
41
|
+
test 'migration is created for user model with namespace' do
|
|
42
|
+
assert_migration "db/migrate/devise_token_auth_create_#{table_name}.rb"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
test 'migration file for user model with namespace contains rails version' do
|
|
46
|
+
if Rails::VERSION::MAJOR >= 5
|
|
47
|
+
assert_migration "db/migrate/devise_token_auth_create_#{table_name}.rb", /#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}/
|
|
48
|
+
else
|
|
49
|
+
assert_migration "db/migrate/devise_token_auth_create_#{table_name}.rb"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
test 'add primary key type with rails 5 when specified in rails generator' do
|
|
54
|
+
run_generator %W[#{user_class} auth --primary_key_type=uuid --force]
|
|
55
|
+
if Rails::VERSION::MAJOR >= 5
|
|
56
|
+
assert_migration "db/migrate/devise_token_auth_create_#{table_name}.rb", /create_table\(:#{table_name}, id: :uuid\) do/
|
|
57
|
+
else
|
|
58
|
+
assert_migration "db/migrate/devise_token_auth_create_#{table_name}.rb", /create_table\(:#{table_name}\) do/
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe 'existing user model' do
|
|
65
|
+
setup :prepare_destination
|
|
66
|
+
|
|
67
|
+
before do
|
|
68
|
+
@dir = File.join(destination_root, 'app', 'models')
|
|
69
|
+
|
|
70
|
+
@fname = File.join(@dir, 'user.rb')
|
|
71
|
+
|
|
72
|
+
# make dir if not exists
|
|
73
|
+
FileUtils.mkdir_p(@dir)
|
|
74
|
+
|
|
75
|
+
case DEVISE_TOKEN_AUTH_ORM
|
|
76
|
+
when :active_record
|
|
77
|
+
# account for rails version 5
|
|
78
|
+
active_record_needle = (Rails::VERSION::MAJOR >= 5) ? 'ApplicationRecord' : 'ActiveRecord::Base'
|
|
79
|
+
|
|
80
|
+
@f = File.open(@fname, 'w') do |f|
|
|
81
|
+
f.write <<-RUBY
|
|
82
|
+
class User < #{active_record_needle}
|
|
83
|
+
|
|
84
|
+
def whatever
|
|
85
|
+
puts 'whatever'
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
RUBY
|
|
89
|
+
end
|
|
90
|
+
when :mongoid
|
|
91
|
+
@f = File.open(@fname, 'w') do |f|
|
|
92
|
+
f.write <<-'RUBY'
|
|
93
|
+
class User
|
|
94
|
+
|
|
95
|
+
def whatever
|
|
96
|
+
puts 'whatever'
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
RUBY
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
run_generator
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
test 'user concern is injected into existing model' do
|
|
107
|
+
assert_file 'app/models/user.rb' do |model|
|
|
108
|
+
assert_match(/include DeviseTokenAuth::Concerns::User/, model)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
test 'subsequent runs do not modify file' do
|
|
113
|
+
run_generator
|
|
114
|
+
assert_file 'app/models/user.rb' do |model|
|
|
115
|
+
matches = model.scan(/include DeviseTokenAuth::Concerns::User/m).size
|
|
116
|
+
assert_equal 1, matches
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
describe 'routes' do
|
|
122
|
+
setup :prepare_destination
|
|
123
|
+
|
|
124
|
+
before do
|
|
125
|
+
@dir = File.join(destination_root, 'config')
|
|
126
|
+
|
|
127
|
+
@fname = File.join(@dir, 'routes.rb')
|
|
128
|
+
|
|
129
|
+
# make dir if not exists
|
|
130
|
+
FileUtils.mkdir_p(@dir)
|
|
131
|
+
|
|
132
|
+
@f = File.open(@fname, 'w') do |f|
|
|
133
|
+
f.write <<-RUBY
|
|
134
|
+
Rails.application.routes.draw do
|
|
135
|
+
patch '/chong', to: 'bong#index'
|
|
136
|
+
end
|
|
137
|
+
RUBY
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
run_generator %W[#{user_class} auth]
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
test 'route method for user model with namespace is appended to routes file' do
|
|
144
|
+
assert_file 'config/routes.rb' do |routes|
|
|
145
|
+
assert_match(/mount_devise_token_auth_for '#{user_class}', at: 'auth'/, routes)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
test 'subsequent runs do not modify file' do
|
|
150
|
+
run_generator %W[#{user_class} auth]
|
|
151
|
+
assert_file 'config/routes.rb' do |routes|
|
|
152
|
+
matches = routes.scan(/mount_devise_token_auth_for '#{user_class}', at: 'auth'/m).size
|
|
153
|
+
assert_equal 1, matches
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
describe 'subsequent models' do
|
|
158
|
+
before do
|
|
159
|
+
run_generator %w[Mang mangs]
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
test 'route method is appended to routes file' do
|
|
163
|
+
assert_file 'config/routes.rb' do |routes|
|
|
164
|
+
assert_match(/mount_devise_token_auth_for 'Mang', at: 'mangs'/, routes)
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
test 'devise_for block is appended to routes file' do
|
|
169
|
+
assert_file 'config/routes.rb' do |routes|
|
|
170
|
+
assert_match(/as :mang do/, routes)
|
|
171
|
+
assert_match(/# Define routes for Mang within this block./, routes)
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
if DEVISE_TOKEN_AUTH_ORM == :active_record
|
|
176
|
+
test 'migration is created' do
|
|
177
|
+
assert_migration 'db/migrate/devise_token_auth_create_mangs.rb'
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
describe 'application controller' do
|
|
184
|
+
setup :prepare_destination
|
|
185
|
+
|
|
186
|
+
before do
|
|
187
|
+
@dir = File.join(destination_root, 'app', 'controllers')
|
|
188
|
+
|
|
189
|
+
@fname = File.join(@dir, 'application_controller.rb')
|
|
190
|
+
|
|
191
|
+
# make dir if not exists
|
|
192
|
+
FileUtils.mkdir_p(@dir)
|
|
193
|
+
|
|
194
|
+
@f = File.open(@fname, 'w') do |f|
|
|
195
|
+
f.write <<-RUBY
|
|
196
|
+
class ApplicationController < ActionController::Base
|
|
197
|
+
def whatever
|
|
198
|
+
'whatever'
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
RUBY
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
run_generator %W[#{user_class} auth]
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
test 'controller concern is appended to application controller' do
|
|
208
|
+
assert_file 'app/controllers/application_controller.rb' do |controller|
|
|
209
|
+
assert_match(/include DeviseTokenAuth::Concerns::SetUserByToken/, controller)
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
test 'subsequent runs do not modify file' do
|
|
214
|
+
run_generator %W[#{user_class} auth]
|
|
215
|
+
assert_file 'app/controllers/application_controller.rb' do |controller|
|
|
216
|
+
matches = controller.scan(/include DeviseTokenAuth::Concerns::SetUserByToken/m).size
|
|
217
|
+
assert_equal 1, matches
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
end
|
data/devise_token_auth-1.2.6/test/lib/generators/devise_token_auth/install_views_generator_test.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'generators/devise_token_auth/install_views_generator'
|
|
6
|
+
|
|
7
|
+
module DeviseTokenAuth
|
|
8
|
+
class InstallViewsGeneratorTest < Rails::Generators::TestCase
|
|
9
|
+
tests InstallViewsGenerator
|
|
10
|
+
destination Rails.root.join('tmp/generators')
|
|
11
|
+
|
|
12
|
+
describe 'default values, clean install' do
|
|
13
|
+
setup :prepare_destination
|
|
14
|
+
|
|
15
|
+
before do
|
|
16
|
+
run_generator
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test 'files are copied' do
|
|
20
|
+
assert_file 'app/views/devise/mailer/reset_password_instructions.html.erb'
|
|
21
|
+
assert_file 'app/views/devise/mailer/confirmation_instructions.html.erb'
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
if DEVISE_TOKEN_AUTH_ORM == :mongoid
|
|
6
|
+
class DeviseTokenAuth::Concerns::MongoidSupportTest < ActiveSupport::TestCase
|
|
7
|
+
describe DeviseTokenAuth::Concerns::MongoidSupport do
|
|
8
|
+
before do
|
|
9
|
+
@user = create(:user)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe '#as_json' do
|
|
13
|
+
test 'should be defined' do
|
|
14
|
+
assert @user.methods.include?(:as_json)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test 'should except _id attribute' do
|
|
18
|
+
refute @user.as_json.key?('_id')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test 'should return with id attribute' do
|
|
22
|
+
assert_equal @user._id.to_s, @user.as_json['id']
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
test 'should accept options' do
|
|
26
|
+
refute @user.as_json(except: [:created_at]).key?('created_at')
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
if DEVISE_TOKEN_AUTH_ORM == :active_record
|
|
4
|
+
describe 'DeviseTokenAuth::Concerns::TokensSerialization' do
|
|
5
|
+
let(:ts) { DeviseTokenAuth::Concerns::TokensSerialization }
|
|
6
|
+
let(:user) { FactoryBot.create(:user) }
|
|
7
|
+
let(:tokens) do
|
|
8
|
+
# Сreate all possible token's attributes combinations
|
|
9
|
+
user.create_token
|
|
10
|
+
2.times { user.create_new_auth_token(user.tokens.first[0]) }
|
|
11
|
+
user.create_new_auth_token
|
|
12
|
+
user.create_token
|
|
13
|
+
|
|
14
|
+
user.tokens
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'is defined' do
|
|
18
|
+
assert_equal(ts.present?, true)
|
|
19
|
+
assert_kind_of(Module, ts)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe '.load(json)' do
|
|
23
|
+
|
|
24
|
+
let(:json) { JSON.generate(tokens) }
|
|
25
|
+
|
|
26
|
+
let(:default) { {} }
|
|
27
|
+
|
|
28
|
+
it 'is defined' do
|
|
29
|
+
assert_respond_to(ts, :load)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'handles nil' do
|
|
33
|
+
assert_equal(ts.load(nil), default)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'handles string' do
|
|
37
|
+
assert_equal(ts.load(json), JSON.parse(json))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'returns object of undesirable class' do
|
|
41
|
+
assert_equal(ts.load([]), [])
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe '.dump(object)' do
|
|
46
|
+
let(:default) { 'null' }
|
|
47
|
+
|
|
48
|
+
it 'is defined' do
|
|
49
|
+
assert_respond_to(ts, :dump)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'handles nil' do
|
|
53
|
+
assert_equal(ts.dump(nil), default)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'handles empty hash' do
|
|
57
|
+
assert_equal(ts.dump({}), '{}')
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'removes nil values' do
|
|
61
|
+
new_tokens = tokens.dup
|
|
62
|
+
new_tokens[new_tokens.first[0]][:kos] = nil
|
|
63
|
+
|
|
64
|
+
assert_equal(ts.dump(tokens), ts.dump(new_tokens))
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
describe 'updated_at' do
|
|
68
|
+
before do
|
|
69
|
+
@default_format = ::Time::DATE_FORMATS[:default]
|
|
70
|
+
::Time::DATE_FORMATS[:default] = 'imprecise format'
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
after do
|
|
74
|
+
::Time::DATE_FORMATS[:default] = @default_format
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def updated_ats(tokens)
|
|
78
|
+
tokens.
|
|
79
|
+
values.
|
|
80
|
+
flat_map do |token|
|
|
81
|
+
[:updated_at, 'updated_at'].map do |key|
|
|
82
|
+
token[key]
|
|
83
|
+
end
|
|
84
|
+
end.
|
|
85
|
+
compact
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'is defined' do
|
|
89
|
+
refute_empty updated_ats(tokens)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'uses iso8601' do
|
|
93
|
+
updated_ats(JSON.parse(ts.dump(tokens))).each do |updated_at|
|
|
94
|
+
Time.strptime(updated_at, '%Y-%m-%dT%H:%M:%SZ')
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'does not rely on Time#to_s' do
|
|
99
|
+
refute_includes(updated_ats(tokens), 'imprecise format')
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
class ConfirmableUserTest < ActiveSupport::TestCase
|
|
6
|
+
describe ConfirmableUser do
|
|
7
|
+
describe 'creation' do
|
|
8
|
+
test 'email should be saved' do
|
|
9
|
+
@resource = create(:confirmable_user)
|
|
10
|
+
assert @resource.email.present?
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe 'updating email' do
|
|
15
|
+
test 'new email should be saved to unconfirmed_email' do
|
|
16
|
+
@resource = create(:confirmable_user, email: 'old_address@example.com')
|
|
17
|
+
@resource.update(email: 'new_address@example.com')
|
|
18
|
+
assert @resource.unconfirmed_email == 'new_address@example.com'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test 'old email should be kept in email' do
|
|
22
|
+
@resource = create(:confirmable_user, email: 'old_address@example.com')
|
|
23
|
+
@resource.update(email: 'new_address@example.com')
|
|
24
|
+
assert @resource.email == 'old_address@example.com'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test 'confirmation_token should be changed' do
|
|
28
|
+
@resource = create(:confirmable_user, email: 'old_address@example.com')
|
|
29
|
+
old_token = @resource.confirmation_token
|
|
30
|
+
@resource.update(email: 'new_address@example.com')
|
|
31
|
+
assert @resource.confirmation_token != old_token
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
class OnlyEmailUserTest < ActiveSupport::TestCase
|
|
6
|
+
describe OnlyEmailUser do
|
|
7
|
+
test 'confirmable is disabled' do
|
|
8
|
+
refute OnlyEmailUser.method_defined?(:confirmation_token)
|
|
9
|
+
refute OnlyEmailUser.method_defined?(:confirmed_at)
|
|
10
|
+
refute OnlyEmailUser.method_defined?(:confirmation_sent_at)
|
|
11
|
+
refute OnlyEmailUser.method_defined?(:unconfirmed_email)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test 'lockable is disabled' do
|
|
15
|
+
refute OnlyEmailUser.method_defined?(:failed_attempts)
|
|
16
|
+
refute OnlyEmailUser.method_defined?(:unlock_token)
|
|
17
|
+
refute OnlyEmailUser.method_defined?(:locked_at)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test 'recoverable is disabled' do
|
|
21
|
+
refute OnlyEmailUser.method_defined?(:reset_password_token)
|
|
22
|
+
refute OnlyEmailUser.method_defined?(:reset_password_sent_at)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
test 'rememberable is disabled' do
|
|
26
|
+
refute OnlyEmailUser.method_defined?(:remember_created_at)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
class UserTest < ActiveSupport::TestCase
|
|
6
|
+
describe User do
|
|
7
|
+
describe 'serialization' do
|
|
8
|
+
test 'hash should not include sensitive info' do
|
|
9
|
+
@resource = build(:user)
|
|
10
|
+
refute @resource.as_json[:tokens]
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe 'creation' do
|
|
15
|
+
test 'save fails if uid is missing' do
|
|
16
|
+
@resource = User.new
|
|
17
|
+
@resource.uid = nil
|
|
18
|
+
@resource.save
|
|
19
|
+
|
|
20
|
+
assert @resource.errors.messages[:uid]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe 'email registration' do
|
|
25
|
+
test 'model should not save if email is blank' do
|
|
26
|
+
@resource = build(:user, email: nil)
|
|
27
|
+
|
|
28
|
+
refute @resource.save
|
|
29
|
+
assert @resource.errors.messages[:email] == [I18n.t('errors.messages.blank')]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
test 'model should not save if email is not an email' do
|
|
33
|
+
@resource = build(:user, email: '@example.com')
|
|
34
|
+
|
|
35
|
+
refute @resource.save
|
|
36
|
+
assert @resource.errors.messages[:email] == [I18n.t('errors.messages.not_email')]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe 'email uniqueness' do
|
|
41
|
+
test 'model should not save if email is taken' do
|
|
42
|
+
user_attributes = attributes_for(:user)
|
|
43
|
+
create(:user, user_attributes)
|
|
44
|
+
@resource = build(:user, user_attributes)
|
|
45
|
+
|
|
46
|
+
refute @resource.save
|
|
47
|
+
assert @resource.errors.messages[:email].first.include? 'taken'
|
|
48
|
+
assert @resource.errors.messages[:email].none? { |e| e =~ /translation missing/ }
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe 'oauth2 authentication' do
|
|
53
|
+
test 'model should save even if email is blank' do
|
|
54
|
+
@resource = build(:user, :facebook, email: nil)
|
|
55
|
+
|
|
56
|
+
assert @resource.save
|
|
57
|
+
assert @resource.errors.messages[:email].blank?
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe 'token expiry' do
|
|
62
|
+
before do
|
|
63
|
+
@resource = create(:user, :confirmed)
|
|
64
|
+
|
|
65
|
+
@auth_headers = @resource.create_new_auth_token
|
|
66
|
+
|
|
67
|
+
@token = @auth_headers['access-token']
|
|
68
|
+
@client_id = @auth_headers['client']
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
test 'should properly indicate whether token is current' do
|
|
72
|
+
assert @resource.token_is_current?(@token, @client_id)
|
|
73
|
+
# we want to update the expiry without forcing a cleanup (see below)
|
|
74
|
+
@resource.tokens[@client_id]['expiry'] = Time.zone.now.to_i - 10.seconds
|
|
75
|
+
refute @resource.token_is_current?(@token, @client_id)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe 'previous token' do
|
|
80
|
+
before do
|
|
81
|
+
@resource = create(:user, :confirmed)
|
|
82
|
+
|
|
83
|
+
@auth_headers1 = @resource.create_new_auth_token
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
test 'should properly indicate whether previous token is current' do
|
|
87
|
+
assert @resource.token_is_current?(@auth_headers1['access-token'], @auth_headers1['client'])
|
|
88
|
+
# create another token, emulating a new request
|
|
89
|
+
@auth_headers2 = @resource.create_new_auth_token
|
|
90
|
+
|
|
91
|
+
# should work for previous token
|
|
92
|
+
assert @resource.token_is_current?(@auth_headers1['access-token'], @auth_headers1['client'])
|
|
93
|
+
# should work for latest token as well
|
|
94
|
+
assert @resource.token_is_current?(@auth_headers2['access-token'], @auth_headers2['client'])
|
|
95
|
+
|
|
96
|
+
# after using latest token, previous token should not work
|
|
97
|
+
assert @resource.token_is_current?(@auth_headers1['access-token'], @auth_headers1['client'])
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe 'expired tokens are destroyed on save' do
|
|
102
|
+
before do
|
|
103
|
+
@resource = create(:user, :confirmed)
|
|
104
|
+
|
|
105
|
+
@old_auth_headers = @resource.create_new_auth_token
|
|
106
|
+
@new_auth_headers = @resource.create_new_auth_token
|
|
107
|
+
expire_token(@resource, @old_auth_headers['client'])
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
test 'expired token was removed' do
|
|
111
|
+
refute @resource.tokens[@old_auth_headers[:client]]
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
test 'current token was not removed' do
|
|
115
|
+
assert @resource.tokens[@new_auth_headers['client']]
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe 'nil tokens are handled properly' do
|
|
120
|
+
before do
|
|
121
|
+
@resource = create(:user, :confirmed)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
test 'tokens can be set to nil' do
|
|
125
|
+
@resource.tokens = nil
|
|
126
|
+
assert @resource.save
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
describe 'clean_old_tokens' do
|
|
132
|
+
before do
|
|
133
|
+
@resource = create(:user, :confirmed)
|
|
134
|
+
@token_lifespan = DeviseTokenAuth.token_lifespan
|
|
135
|
+
@max_client_count = DeviseTokenAuth.max_number_of_devices
|
|
136
|
+
DeviseTokenAuth.max_number_of_devices = 2
|
|
137
|
+
DeviseTokenAuth.token_lifespan = 1.week
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
after do
|
|
141
|
+
DeviseTokenAuth.token_lifespan = @token_lifespan
|
|
142
|
+
DeviseTokenAuth.max_number_of_devices = @max_client_count
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
test 'removes tokens with expiry beyond the maximum lifespan' do
|
|
146
|
+
# Create tokens with different expiry times
|
|
147
|
+
current_time = Time.now.to_i
|
|
148
|
+
|
|
149
|
+
max_lifespan = current_time + DeviseTokenAuth.token_lifespan.to_i
|
|
150
|
+
|
|
151
|
+
# Valid token within lifespan
|
|
152
|
+
@resource.tokens['valid_client'] = {
|
|
153
|
+
'token' => 'valid_token',
|
|
154
|
+
'expiry' => current_time + 1.day.to_i
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
# Token exactly at max lifespan (should be kept)
|
|
158
|
+
@resource.tokens['edge_client'] = {
|
|
159
|
+
'token' => 'edge_token',
|
|
160
|
+
'expiry' => max_lifespan
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
# Token beyond max lifespan (should be removed)
|
|
164
|
+
@resource.tokens['expired_client'] = {
|
|
165
|
+
'token' => 'expired_token',
|
|
166
|
+
'expiry' => max_lifespan + 1.day.to_i
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
# Call the method under test
|
|
170
|
+
@resource.send(:clean_old_tokens)
|
|
171
|
+
|
|
172
|
+
# Assert that tokens beyond lifespan were removed
|
|
173
|
+
assert @resource.tokens.key?('valid_client'), 'Valid token should be kept'
|
|
174
|
+
assert @resource.tokens.key?('edge_client'), 'Edge case token at max lifespan should be kept'
|
|
175
|
+
refute @resource.tokens.key?('expired_client'), 'Token beyond max lifespan should be removed'
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
test 'handles token lifespan reduction when creating token' do
|
|
179
|
+
# Setup: Create the maximum allowed number of tokens with a longer lifespan
|
|
180
|
+
DeviseTokenAuth.token_lifespan = 2.weeks
|
|
181
|
+
DeviseTokenAuth.max_number_of_devices = 3
|
|
182
|
+
|
|
183
|
+
# Create tokens at different times but all within the initial long lifespan
|
|
184
|
+
@resource.tokens = {}
|
|
185
|
+
@resource.tokens['client_1'] = {
|
|
186
|
+
'token' => 'token_1',
|
|
187
|
+
'expiry' => Time.now.to_i + 12.days.to_i
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
@resource.tokens['client_2'] = {
|
|
191
|
+
'token' => 'token_2',
|
|
192
|
+
'expiry' => Time.now.to_i + 10.days.to_i
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
@resource.tokens['client_3'] = {
|
|
196
|
+
'token' => 'token_3',
|
|
197
|
+
'expiry' => Time.now.to_i + 5.days.to_i
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
# We've reached the maximum number of devices/tokens
|
|
201
|
+
assert_equal 3, @resource.tokens.length
|
|
202
|
+
|
|
203
|
+
# Now reduce token lifespan - simulating a config change
|
|
204
|
+
DeviseTokenAuth.token_lifespan = 1.week
|
|
205
|
+
|
|
206
|
+
# Create a new token which should trigger clean_old_tokens
|
|
207
|
+
new_auth_headers = @resource.create_new_auth_token
|
|
208
|
+
new_client = new_auth_headers['client']
|
|
209
|
+
|
|
210
|
+
# The new token should exist
|
|
211
|
+
assert @resource.tokens.key?(new_client), 'New token should exist'
|
|
212
|
+
|
|
213
|
+
# Tokens exceeding the new reduced lifespan should be removed
|
|
214
|
+
refute @resource.tokens.key?('client_1'), 'Token with expiry > new lifespan should be removed'
|
|
215
|
+
refute @resource.tokens.key?('client_2'), 'Token with expiry > new lifespan should be removed'
|
|
216
|
+
|
|
217
|
+
# Token within new lifespan should be kept
|
|
218
|
+
assert @resource.tokens.key?('client_3'), 'Token within new reduced lifespan should be kept'
|
|
219
|
+
|
|
220
|
+
# We should have exactly 2 tokens: the new one and client_3
|
|
221
|
+
assert_equal 2, @resource.tokens.length
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
end
|