devise_token_auth 0.1.32.beta10 → 0.1.32
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 +4 -4
- data/README.md +33 -31
- data/app/controllers/devise_token_auth/confirmations_controller.rb +2 -0
- data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +2 -0
- data/app/controllers/devise_token_auth/passwords_controller.rb +25 -14
- data/app/controllers/devise_token_auth/registrations_controller.rb +22 -11
- data/app/controllers/devise_token_auth/sessions_controller.rb +15 -9
- data/app/controllers/devise_token_auth/token_validations_controller.rb +2 -1
- data/app/models/devise_token_auth/concerns/user.rb +19 -14
- data/app/validators/email_validator.rb +1 -1
- data/config/locales/en.yml +30 -0
- data/config/locales/es.yml +30 -0
- data/config/locales/fr.yml +30 -0
- data/lib/devise_token_auth/engine.rb +10 -8
- data/lib/devise_token_auth/version.rb +1 -1
- data/lib/generators/devise_token_auth/install_generator.rb +28 -0
- data/lib/generators/devise_token_auth/templates/devise_token_auth.rb +6 -0
- data/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb +2 -2
- data/test/controllers/custom/custom_confirmations_controller_test.rb +26 -0
- data/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb +29 -0
- data/test/controllers/custom/custom_passwords_controller_test.rb +66 -0
- data/test/controllers/custom/custom_registrations_controller_test.rb +1 -1
- data/test/controllers/custom/custom_sessions_controller_test.rb +30 -0
- data/test/controllers/custom/custom_token_validations_controller_test.rb +29 -0
- data/test/controllers/devise_token_auth/passwords_controller_test.rb +159 -10
- data/test/controllers/devise_token_auth/registrations_controller_test.rb +249 -58
- data/test/controllers/devise_token_auth/sessions_controller_test.rb +80 -1
- data/test/controllers/devise_token_auth/token_validations_controller_test.rb +17 -0
- data/test/dummy/app/controllers/application_controller.rb +1 -0
- data/test/dummy/app/controllers/custom/confirmations_controller.rb +13 -0
- data/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb +13 -0
- data/test/dummy/app/controllers/custom/passwords_controller.rb +35 -0
- data/test/dummy/app/controllers/custom/sessions_controller.rb +23 -0
- data/test/dummy/app/controllers/custom/token_validations_controller.rb +13 -0
- data/test/dummy/app/models/unconfirmable_user.rb +8 -0
- data/test/dummy/config/application.rb +1 -0
- data/test/dummy/config/routes.rb +8 -1
- data/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +7 -1
- data/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +7 -1
- data/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb +7 -1
- data/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb +7 -1
- data/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb +7 -1
- data/test/dummy/db/migrate/20150409095712_devise_token_auth_create_nice_users.rb +7 -1
- data/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb +60 -0
- data/test/dummy/db/schema.rb +89 -64
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/lib/migration_database_helper.rb +29 -0
- data/test/dummy/log/test.log +41319 -29566
- data/test/dummy/tmp/generators/config/initializers/devise_token_auth.rb +6 -0
- data/test/dummy/tmp/generators/config/routes.rb +4 -0
- data/test/dummy/tmp/generators/db/migrate/{20150617175802_devise_token_auth_create_users.rb → 20150729144233_devise_token_auth_create_users.rb} +1 -1
- data/test/fixtures/unconfirmable_users.yml +9 -0
- data/test/fixtures/users.yml +12 -0
- data/test/models/user_test.rb +21 -0
- metadata +39 -13
- data/config/locales/devise.en.yml +0 -59
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -473
- data/test/dummy/tmp/generators/app/controllers/application_controller.rb +0 -6
@@ -73,6 +73,24 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
describe 'get sign_in is not supported' do
|
77
|
+
before do
|
78
|
+
xhr :get, :new, {
|
79
|
+
nickname: @existing_user.nickname,
|
80
|
+
password: 'secret123'
|
81
|
+
}
|
82
|
+
@data = JSON.parse(response.body)
|
83
|
+
end
|
84
|
+
|
85
|
+
test 'user is notified that they should use post sign_in to authenticate' do
|
86
|
+
assert_equal 405, response.status
|
87
|
+
end
|
88
|
+
test "response should contain errors" do
|
89
|
+
assert @data['errors']
|
90
|
+
assert_equal @data['errors'], [I18n.t("devise_token_auth.sessions.not_supported")]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
76
94
|
describe 'alt auth keys' do
|
77
95
|
before do
|
78
96
|
xhr :post, :create, {
|
@@ -115,11 +133,17 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
115
133
|
before do
|
116
134
|
@auth_headers = @existing_user.create_new_auth_token
|
117
135
|
xhr :delete, :destroy, format: :json
|
136
|
+
@data = JSON.parse(response.body)
|
118
137
|
end
|
119
138
|
|
120
139
|
test "unauthed request returns 404" do
|
121
140
|
assert_equal 404, response.status
|
122
141
|
end
|
142
|
+
|
143
|
+
test "response should contain errors" do
|
144
|
+
assert @data['errors']
|
145
|
+
assert_equal @data['errors'], [I18n.t("devise_token_auth.sessions.user_not_found")]
|
146
|
+
end
|
123
147
|
end
|
124
148
|
|
125
149
|
describe 'failure' do
|
@@ -139,6 +163,7 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
139
163
|
|
140
164
|
test "response should contain errors" do
|
141
165
|
assert @data['errors']
|
166
|
+
assert_equal @data['errors'], [I18n.t("devise_token_auth.sessions.bad_credentials")]
|
142
167
|
end
|
143
168
|
end
|
144
169
|
|
@@ -146,7 +171,7 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
146
171
|
before do
|
147
172
|
DeviseTokenAuth.change_headers_on_each_request = false
|
148
173
|
|
149
|
-
# accessing current_user calls through set_user_by_token,
|
174
|
+
# accessing current_user calls through set_user_by_token,
|
150
175
|
# which initializes client_id
|
151
176
|
@controller.current_user
|
152
177
|
|
@@ -165,6 +190,7 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
165
190
|
|
166
191
|
test "response should contain errors" do
|
167
192
|
assert @data['errors']
|
193
|
+
assert_equal @data['errors'], [I18n.t("devise_token_auth.sessions.bad_credentials")]
|
168
194
|
end
|
169
195
|
|
170
196
|
after do
|
@@ -212,6 +238,59 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
212
238
|
assert_equal 401, response.status
|
213
239
|
end
|
214
240
|
|
241
|
+
test "response should contain errors" do
|
242
|
+
assert @data['errors']
|
243
|
+
assert_equal @data['errors'], [I18n.t("devise_token_auth.sessions.not_confirmed", email: @unconfirmed_user.email)]
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
describe "Unconfirmed user with allowed unconfirmed access" do
|
248
|
+
before do
|
249
|
+
@original_duration = Devise.allow_unconfirmed_access_for
|
250
|
+
Devise.allow_unconfirmed_access_for = 3.days
|
251
|
+
@recent_unconfirmed_user = users(:recent_unconfirmed_email_user)
|
252
|
+
xhr :post, :create, {
|
253
|
+
email: @recent_unconfirmed_user.email,
|
254
|
+
password: 'secret123'
|
255
|
+
}
|
256
|
+
@resource = assigns(:resource)
|
257
|
+
@data = JSON.parse(response.body)
|
258
|
+
end
|
259
|
+
|
260
|
+
after do
|
261
|
+
Devise.allow_unconfirmed_access_for = @original_duration
|
262
|
+
end
|
263
|
+
|
264
|
+
test "request should succeed" do
|
265
|
+
assert_equal 200, response.status
|
266
|
+
end
|
267
|
+
|
268
|
+
test "request should return user data" do
|
269
|
+
assert_equal @recent_unconfirmed_user.email, @data['data']['email']
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
describe "Unconfirmed user with expired unconfirmed access" do
|
274
|
+
before do
|
275
|
+
@original_duration = Devise.allow_unconfirmed_access_for
|
276
|
+
Devise.allow_unconfirmed_access_for = 3.days
|
277
|
+
@unconfirmed_user = users(:unconfirmed_email_user)
|
278
|
+
xhr :post, :create, {
|
279
|
+
email: @unconfirmed_user.email,
|
280
|
+
password: 'secret123'
|
281
|
+
}
|
282
|
+
@resource = assigns(:resource)
|
283
|
+
@data = JSON.parse(response.body)
|
284
|
+
end
|
285
|
+
|
286
|
+
after do
|
287
|
+
Devise.allow_unconfirmed_access_for = @original_duration
|
288
|
+
end
|
289
|
+
|
290
|
+
test "request should fail" do
|
291
|
+
assert_equal 401, response.status
|
292
|
+
end
|
293
|
+
|
215
294
|
test "response should contain errors" do
|
216
295
|
assert @data['errors']
|
217
296
|
end
|
@@ -45,5 +45,22 @@ class DeviseTokenAuth::TokenValidationsControllerTest < ActionDispatch::Integrat
|
|
45
45
|
assert_equal 200, response.status
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
describe 'failure' do
|
50
|
+
before do
|
51
|
+
get '/api/v1/auth/validate_token', {}, @auth_headers.merge({"access-token" => "12345"})
|
52
|
+
@resp = JSON.parse(response.body)
|
53
|
+
end
|
54
|
+
|
55
|
+
test "request should fail" do
|
56
|
+
assert_equal 401, response.status
|
57
|
+
end
|
58
|
+
|
59
|
+
test "response should contain errors" do
|
60
|
+
assert @resp['errors']
|
61
|
+
assert_equal @resp['errors'], [I18n.t("devise_token_auth.token_validations.invalid")]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
48
65
|
end
|
49
66
|
end
|
@@ -10,5 +10,6 @@ class ApplicationController < ActionController::Base
|
|
10
10
|
devise_parameter_sanitizer.for(:sign_up) << :favorite_color
|
11
11
|
devise_parameter_sanitizer.for(:account_update) << :operating_thetan
|
12
12
|
devise_parameter_sanitizer.for(:account_update) << :favorite_color
|
13
|
+
devise_parameter_sanitizer.for(:account_update) << :current_password
|
13
14
|
end
|
14
15
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Custom::OmniauthCallbacksController < DeviseTokenAuth::OmniauthCallbacksController
|
2
|
+
|
3
|
+
def omniauth_success
|
4
|
+
super do |resource|
|
5
|
+
@omniauth_success_block_called = true
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def omniauth_success_block_called?
|
10
|
+
@omniauth_success_block_called == true
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Custom::PasswordsController < DeviseTokenAuth::PasswordsController
|
2
|
+
|
3
|
+
def create
|
4
|
+
super do |resource|
|
5
|
+
@create_block_called = true
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def edit
|
10
|
+
super do |resource|
|
11
|
+
@edit_block_called = true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def update
|
16
|
+
super do |resource|
|
17
|
+
@update_block_called = true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_block_called?
|
22
|
+
@create_block_called == true
|
23
|
+
end
|
24
|
+
|
25
|
+
def edit_block_called?
|
26
|
+
@edit_block_called == true
|
27
|
+
end
|
28
|
+
|
29
|
+
def update_block_called?
|
30
|
+
@update_block_called == true
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Custom::SessionsController < DeviseTokenAuth::SessionsController
|
2
|
+
|
3
|
+
def create
|
4
|
+
super do |resource|
|
5
|
+
@create_block_called = true
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def destroy
|
10
|
+
super do |resource|
|
11
|
+
@destroy_block_called = true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_block_called?
|
16
|
+
@create_block_called == true
|
17
|
+
end
|
18
|
+
|
19
|
+
def destroy_block_called?
|
20
|
+
@destroy_block_called == true
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Custom::TokenValidationsController < DeviseTokenAuth::TokenValidationsController
|
2
|
+
|
3
|
+
def validate_token
|
4
|
+
super do |resource|
|
5
|
+
@validate_token_block_called = true
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def validate_token_block_called?
|
10
|
+
@validate_token_block_called == true
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -19,5 +19,6 @@ module Dummy
|
|
19
19
|
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
20
20
|
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
21
21
|
# config.i18n.default_locale = :de
|
22
|
+
config.autoload_paths << Rails.root.join('lib')
|
22
23
|
end
|
23
24
|
end
|
data/test/dummy/config/routes.rb
CHANGED
@@ -20,13 +20,20 @@ Rails.application.routes.draw do
|
|
20
20
|
}
|
21
21
|
|
22
22
|
mount_devise_token_auth_for 'NiceUser', at: 'nice_user_auth', controllers: {
|
23
|
-
registrations: 'custom/registrations'
|
23
|
+
registrations: 'custom/registrations',
|
24
|
+
confirmations: 'custom/confirmations',
|
25
|
+
passwords: 'custom/passwords',
|
26
|
+
sessions: 'custom/sessions',
|
27
|
+
token_validations: 'custom/token_validations',
|
28
|
+
omniauth_callbacks: 'custom/omniauth_callbacks'
|
24
29
|
}
|
25
30
|
|
26
31
|
mount_devise_token_auth_for 'OnlyEmailUser', at: 'only_email_auth', skip: [:omniauth_callbacks]
|
27
32
|
|
28
33
|
mount_devise_token_auth_for 'UnregisterableUser', at: 'unregisterable_user_auth', skip: [:registrations]
|
29
34
|
|
35
|
+
mount_devise_token_auth_for 'UnconfirmableUser', at: 'unconfirmable_user_auth'
|
36
|
+
|
30
37
|
# test namespacing
|
31
38
|
namespace :api do
|
32
39
|
scope :v1 do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
include MigrationDatabaseHelper
|
2
|
+
|
1
3
|
class DeviseTokenAuthCreateUsers < ActiveRecord::Migration
|
2
4
|
def change
|
3
5
|
create_table(:users) do |t|
|
@@ -42,7 +44,11 @@ class DeviseTokenAuthCreateUsers < ActiveRecord::Migration
|
|
42
44
|
t.string :uid, :null => false, :default => ""
|
43
45
|
|
44
46
|
## Tokens
|
45
|
-
|
47
|
+
if json_supported_database?
|
48
|
+
t.json :tokens
|
49
|
+
else
|
50
|
+
t.text :tokens
|
51
|
+
end
|
46
52
|
|
47
53
|
t.timestamps
|
48
54
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
include MigrationDatabaseHelper
|
2
|
+
|
1
3
|
class DeviseTokenAuthCreateMangs < ActiveRecord::Migration
|
2
4
|
def change
|
3
5
|
create_table(:mangs) do |t|
|
@@ -42,7 +44,11 @@ class DeviseTokenAuthCreateMangs < ActiveRecord::Migration
|
|
42
44
|
t.string :uid, :null => false, :default => ""
|
43
45
|
|
44
46
|
## Tokens
|
45
|
-
|
47
|
+
if json_supported_database?
|
48
|
+
t.json :tokens
|
49
|
+
else
|
50
|
+
t.text :tokens
|
51
|
+
end
|
46
52
|
|
47
53
|
t.timestamps
|
48
54
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
include MigrationDatabaseHelper
|
2
|
+
|
1
3
|
class DeviseTokenAuthCreateEvilUsers < ActiveRecord::Migration
|
2
4
|
def change
|
3
5
|
create_table(:evil_users) do |t|
|
@@ -40,7 +42,11 @@ class DeviseTokenAuthCreateEvilUsers < ActiveRecord::Migration
|
|
40
42
|
t.string :uid, :null => false, :default => ""
|
41
43
|
|
42
44
|
## Tokens
|
43
|
-
|
45
|
+
if json_supported_database?
|
46
|
+
t.json :tokens
|
47
|
+
else
|
48
|
+
t.text :tokens
|
49
|
+
end
|
44
50
|
|
45
51
|
## etc.
|
46
52
|
t.string :favorite_color
|
@@ -1,3 +1,5 @@
|
|
1
|
+
include MigrationDatabaseHelper
|
2
|
+
|
1
3
|
class DeviseTokenAuthCreateOnlyEmailUsers < ActiveRecord::Migration
|
2
4
|
def change
|
3
5
|
create_table(:only_email_users) do |t|
|
@@ -40,7 +42,11 @@ class DeviseTokenAuthCreateOnlyEmailUsers < ActiveRecord::Migration
|
|
40
42
|
t.string :email
|
41
43
|
|
42
44
|
## Tokens
|
43
|
-
|
45
|
+
if json_supported_database?
|
46
|
+
t.json :tokens
|
47
|
+
else
|
48
|
+
t.text :tokens
|
49
|
+
end
|
44
50
|
|
45
51
|
t.timestamps
|
46
52
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
include MigrationDatabaseHelper
|
2
|
+
|
1
3
|
class DeviseTokenAuthCreateUnregisterableUsers < ActiveRecord::Migration
|
2
4
|
def change
|
3
5
|
create_table(:unregisterable_users) do |t|
|
@@ -40,7 +42,11 @@ class DeviseTokenAuthCreateUnregisterableUsers < ActiveRecord::Migration
|
|
40
42
|
t.string :email
|
41
43
|
|
42
44
|
## Tokens
|
43
|
-
|
45
|
+
if json_supported_database?
|
46
|
+
t.json :tokens
|
47
|
+
else
|
48
|
+
t.text :tokens
|
49
|
+
end
|
44
50
|
|
45
51
|
t.timestamps
|
46
52
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
include MigrationDatabaseHelper
|
2
|
+
|
1
3
|
class DeviseTokenAuthCreateNiceUsers < ActiveRecord::Migration
|
2
4
|
def change
|
3
5
|
create_table(:nice_users) do |t|
|
@@ -40,7 +42,11 @@ class DeviseTokenAuthCreateNiceUsers < ActiveRecord::Migration
|
|
40
42
|
t.string :email
|
41
43
|
|
42
44
|
## Tokens
|
43
|
-
|
45
|
+
if json_supported_database?
|
46
|
+
t.json :tokens
|
47
|
+
else
|
48
|
+
t.text :tokens
|
49
|
+
end
|
44
50
|
|
45
51
|
t.timestamps
|
46
52
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
include MigrationDatabaseHelper
|
2
|
+
|
3
|
+
class DeviseTokenAuthCreateUnconfirmableUsers < ActiveRecord::Migration
|
4
|
+
def change
|
5
|
+
create_table(:unconfirmable_users) do |t|
|
6
|
+
## Required
|
7
|
+
t.string :provider, :null => false
|
8
|
+
t.string :uid, :null => false, :default => ""
|
9
|
+
|
10
|
+
## Database authenticatable
|
11
|
+
t.string :encrypted_password, :null => false, :default => ""
|
12
|
+
|
13
|
+
## Recoverable
|
14
|
+
t.string :reset_password_token
|
15
|
+
t.datetime :reset_password_sent_at
|
16
|
+
|
17
|
+
## Rememberable
|
18
|
+
t.datetime :remember_created_at
|
19
|
+
|
20
|
+
## Trackable
|
21
|
+
t.integer :sign_in_count, :default => 0, :null => false
|
22
|
+
t.datetime :current_sign_in_at
|
23
|
+
t.datetime :last_sign_in_at
|
24
|
+
t.string :current_sign_in_ip
|
25
|
+
t.string :last_sign_in_ip
|
26
|
+
|
27
|
+
## Confirmable
|
28
|
+
# t.string :confirmation_token
|
29
|
+
# t.datetime :confirmed_at
|
30
|
+
# t.datetime :confirmation_sent_at
|
31
|
+
# t.string :unconfirmed_email # Only if using reconfirmable
|
32
|
+
|
33
|
+
## Lockable
|
34
|
+
# t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
|
35
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
36
|
+
# t.datetime :locked_at
|
37
|
+
|
38
|
+
## User Info
|
39
|
+
t.string :name
|
40
|
+
t.string :nickname
|
41
|
+
t.string :image
|
42
|
+
t.string :email
|
43
|
+
|
44
|
+
## Tokens
|
45
|
+
if json_supported_database?
|
46
|
+
t.json :tokens
|
47
|
+
else
|
48
|
+
t.text :tokens
|
49
|
+
end
|
50
|
+
|
51
|
+
t.timestamps
|
52
|
+
end
|
53
|
+
|
54
|
+
add_index :unconfirmable_users, :email
|
55
|
+
add_index :unconfirmable_users, [:uid, :provider], :unique => true
|
56
|
+
add_index :unconfirmable_users, :reset_password_token, :unique => true
|
57
|
+
# add_index :nice_users, :confirmation_token, :unique => true
|
58
|
+
# add_index :nice_users, :unlock_token, :unique => true
|
59
|
+
end
|
60
|
+
end
|