digix_devise_token_auth 0.1.44
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +13 -0
- data/README.md +952 -0
- data/Rakefile +35 -0
- data/app/controllers/devise_token_auth/application_controller.rb +76 -0
- data/app/controllers/devise_token_auth/concerns/resource_finder.rb +43 -0
- data/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +165 -0
- data/app/controllers/devise_token_auth/confirmations_controller.rb +30 -0
- data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +243 -0
- data/app/controllers/devise_token_auth/passwords_controller.rb +202 -0
- data/app/controllers/devise_token_auth/registrations_controller.rb +205 -0
- data/app/controllers/devise_token_auth/sessions_controller.rb +133 -0
- data/app/controllers/devise_token_auth/token_validations_controller.rb +29 -0
- data/app/controllers/devise_token_auth/unlocks_controller.rb +89 -0
- data/app/models/devise_token_auth/concerns/user.rb +260 -0
- data/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb +26 -0
- data/app/validators/email_validator.rb +21 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/devise_token_auth/omniauth_external_window.html.erb +38 -0
- data/config/initializers/devise.rb +196 -0
- data/config/locales/da-DK.yml +50 -0
- data/config/locales/de.yml +49 -0
- data/config/locales/en.yml +50 -0
- data/config/locales/es.yml +49 -0
- data/config/locales/fr.yml +49 -0
- data/config/locales/it.yml +46 -0
- data/config/locales/ja.yml +46 -0
- data/config/locales/nl.yml +30 -0
- data/config/locales/pl.yml +48 -0
- data/config/locales/pt-BR.yml +46 -0
- data/config/locales/pt.yml +48 -0
- data/config/locales/ro.yml +46 -0
- data/config/locales/ru.yml +50 -0
- data/config/locales/sq.yml +46 -0
- data/config/locales/uk.yml +59 -0
- data/config/locales/vi.yml +50 -0
- data/config/locales/zh-CN.yml +46 -0
- data/config/locales/zh-HK.yml +48 -0
- data/config/locales/zh-TW.yml +48 -0
- data/lib/devise_token_auth.rb +8 -0
- data/lib/devise_token_auth/controllers/helpers.rb +149 -0
- data/lib/devise_token_auth/controllers/url_helpers.rb +8 -0
- data/lib/devise_token_auth/engine.rb +90 -0
- data/lib/devise_token_auth/rails/routes.rb +114 -0
- data/lib/devise_token_auth/url.rb +37 -0
- data/lib/devise_token_auth/version.rb +3 -0
- data/lib/generators/devise_token_auth/USAGE +31 -0
- data/lib/generators/devise_token_auth/install_generator.rb +160 -0
- data/lib/generators/devise_token_auth/install_views_generator.rb +16 -0
- data/lib/generators/devise_token_auth/templates/devise_token_auth.rb +48 -0
- data/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb +55 -0
- data/lib/generators/devise_token_auth/templates/user.rb +7 -0
- data/lib/tasks/devise_token_auth_tasks.rake +4 -0
- data/test/controllers/custom/custom_confirmations_controller_test.rb +21 -0
- data/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb +29 -0
- data/test/controllers/custom/custom_passwords_controller_test.rb +75 -0
- data/test/controllers/custom/custom_registrations_controller_test.rb +54 -0
- data/test/controllers/custom/custom_sessions_controller_test.rb +37 -0
- data/test/controllers/custom/custom_token_validations_controller_test.rb +40 -0
- data/test/controllers/demo_group_controller_test.rb +153 -0
- data/test/controllers/demo_mang_controller_test.rb +284 -0
- data/test/controllers/demo_user_controller_test.rb +601 -0
- data/test/controllers/devise_token_auth/confirmations_controller_test.rb +129 -0
- data/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +371 -0
- data/test/controllers/devise_token_auth/passwords_controller_test.rb +649 -0
- data/test/controllers/devise_token_auth/registrations_controller_test.rb +878 -0
- data/test/controllers/devise_token_auth/sessions_controller_test.rb +500 -0
- data/test/controllers/devise_token_auth/token_validations_controller_test.rb +90 -0
- data/test/controllers/devise_token_auth/unlocks_controller_test.rb +194 -0
- data/test/controllers/overrides/confirmations_controller_test.rb +43 -0
- data/test/controllers/overrides/omniauth_callbacks_controller_test.rb +49 -0
- data/test/controllers/overrides/passwords_controller_test.rb +66 -0
- data/test/controllers/overrides/registrations_controller_test.rb +40 -0
- data/test/controllers/overrides/sessions_controller_test.rb +33 -0
- data/test/controllers/overrides/token_validations_controller_test.rb +41 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/app/controllers/application_controller.rb +16 -0
- data/test/dummy/app/controllers/auth_origin_controller.rb +5 -0
- data/test/dummy/app/controllers/custom/confirmations_controller.rb +13 -0
- data/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb +11 -0
- data/test/dummy/app/controllers/custom/passwords_controller.rb +40 -0
- data/test/dummy/app/controllers/custom/registrations_controller.rb +39 -0
- data/test/dummy/app/controllers/custom/sessions_controller.rb +29 -0
- data/test/dummy/app/controllers/custom/token_validations_controller.rb +19 -0
- data/test/dummy/app/controllers/demo_group_controller.rb +13 -0
- data/test/dummy/app/controllers/demo_mang_controller.rb +12 -0
- data/test/dummy/app/controllers/demo_user_controller.rb +25 -0
- data/test/dummy/app/controllers/overrides/confirmations_controller.rb +26 -0
- data/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb +14 -0
- data/test/dummy/app/controllers/overrides/passwords_controller.rb +33 -0
- data/test/dummy/app/controllers/overrides/registrations_controller.rb +27 -0
- data/test/dummy/app/controllers/overrides/sessions_controller.rb +36 -0
- data/test/dummy/app/controllers/overrides/token_validations_controller.rb +23 -0
- data/test/dummy/app/helpers/application_helper.rb +1065 -0
- data/test/dummy/app/models/evil_user.rb +3 -0
- data/test/dummy/app/models/lockable_user.rb +5 -0
- data/test/dummy/app/models/mang.rb +3 -0
- data/test/dummy/app/models/nice_user.rb +7 -0
- data/test/dummy/app/models/only_email_user.rb +5 -0
- data/test/dummy/app/models/scoped_user.rb +7 -0
- data/test/dummy/app/models/unconfirmable_user.rb +8 -0
- data/test/dummy/app/models/unregisterable_user.rb +7 -0
- data/test/dummy/app/models/user.rb +18 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +16 -0
- data/test/dummy/config/application.rb +24 -0
- data/test/dummy/config/application.yml.bk +0 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +44 -0
- data/test/dummy/config/environments/production.rb +82 -0
- data/test/dummy/config/environments/test.rb +48 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/devise.rb +3 -0
- data/test/dummy/config/initializers/devise_token_auth.rb +22 -0
- data/test/dummy/config/initializers/figaro.rb +1 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/omniauth.rb +8 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/routes.rb +72 -0
- data/test/dummy/config/spring.rb +1 -0
- data/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +63 -0
- data/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +62 -0
- data/test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb +6 -0
- data/test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb +5 -0
- data/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb +64 -0
- data/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb +60 -0
- data/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb +61 -0
- data/test/dummy/db/migrate/20150409095712_devise_token_auth_create_nice_users.rb +61 -0
- data/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb +61 -0
- data/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb +61 -0
- data/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb +61 -0
- data/test/dummy/db/schema.rb +258 -0
- data/test/dummy/lib/migration_database_helper.rb +29 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/lib/devise_token_auth/url_test.rb +24 -0
- data/test/lib/generators/devise_token_auth/install_generator_test.rb +187 -0
- data/test/lib/generators/devise_token_auth/install_views_generator_test.rb +23 -0
- data/test/models/only_email_user_test.rb +35 -0
- data/test/models/user_test.rb +169 -0
- data/test/test_helper.rb +77 -0
- metadata +342 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# was the web request successful?
|
4
|
+
# was the user redirected to the right page?
|
5
|
+
# was the user successfully authenticated?
|
6
|
+
# was the correct object stored in the response?
|
7
|
+
# was the appropriate message delivered in the json payload?
|
8
|
+
|
9
|
+
class DeviseTokenAuth::TokenValidationsControllerTest < ActionDispatch::IntegrationTest
|
10
|
+
describe DeviseTokenAuth::TokenValidationsController do
|
11
|
+
before do
|
12
|
+
@resource = users(:confirmed_email_user)
|
13
|
+
@resource.skip_confirmation!
|
14
|
+
@resource.save!
|
15
|
+
|
16
|
+
@auth_headers = @resource.create_new_auth_token
|
17
|
+
|
18
|
+
@token = @auth_headers['access-token']
|
19
|
+
@client_id = @auth_headers['client']
|
20
|
+
@expiry = @auth_headers['expiry']
|
21
|
+
|
22
|
+
# ensure that request is not treated as batch request
|
23
|
+
age_token(@resource, @client_id)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'vanilla user' do
|
27
|
+
before do
|
28
|
+
get '/auth/validate_token', params: {}, headers: @auth_headers
|
29
|
+
@resp = JSON.parse(response.body)
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'token valid' do
|
33
|
+
assert_equal 200, response.status
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'using namespaces' do
|
38
|
+
before do
|
39
|
+
get '/api/v1/auth/validate_token', params: {}, headers: @auth_headers
|
40
|
+
@resp = JSON.parse(response.body)
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'token valid' do
|
44
|
+
assert_equal 200, response.status
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'failure' do
|
49
|
+
before do
|
50
|
+
get '/api/v1/auth/validate_token',
|
51
|
+
params: {},
|
52
|
+
headers: @auth_headers.merge('access-token' => '12345')
|
53
|
+
@resp = JSON.parse(response.body)
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'request should fail' do
|
57
|
+
assert_equal 401, response.status
|
58
|
+
end
|
59
|
+
|
60
|
+
test 'response should contain errors' do
|
61
|
+
assert @resp['errors']
|
62
|
+
assert_equal @resp['errors'], [I18n.t('devise_token_auth.token_validations.invalid')]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'using namespaces with unused resource' do
|
68
|
+
before do
|
69
|
+
@resource = scoped_users(:confirmed_email_user)
|
70
|
+
@resource.skip_confirmation!
|
71
|
+
@resource.save!
|
72
|
+
|
73
|
+
@auth_headers = @resource.create_new_auth_token
|
74
|
+
|
75
|
+
@token = @auth_headers['access-token']
|
76
|
+
@client_id = @auth_headers['client']
|
77
|
+
@expiry = @auth_headers['expiry']
|
78
|
+
|
79
|
+
# ensure that request is not treated as batch request
|
80
|
+
age_token(@resource, @client_id)
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'should be successful' do
|
84
|
+
get '/api_v2/auth/validate_token',
|
85
|
+
params: {},
|
86
|
+
headers: @auth_headers
|
87
|
+
assert_equal 200, response.status
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# was the web request successful?
|
4
|
+
# was the user redirected to the right page?
|
5
|
+
# was the user successfully authenticated?
|
6
|
+
# was the correct object stored in the response?
|
7
|
+
# was the appropriate message delivered in the json payload?
|
8
|
+
|
9
|
+
class DeviseTokenAuth::UnlocksControllerTest < ActionController::TestCase
|
10
|
+
describe DeviseTokenAuth::UnlocksController do
|
11
|
+
setup do
|
12
|
+
@request.env['devise.mapping'] = Devise.mappings[:lockable_user]
|
13
|
+
end
|
14
|
+
|
15
|
+
teardown do
|
16
|
+
@request.env['devise.mapping'] = Devise.mappings[:user]
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
@original_lock_strategy = Devise.lock_strategy
|
21
|
+
@original_unlock_strategy = Devise.unlock_strategy
|
22
|
+
@original_maximum_attempts = Devise.maximum_attempts
|
23
|
+
Devise.lock_strategy = :failed_attempts
|
24
|
+
Devise.unlock_strategy = :email
|
25
|
+
Devise.maximum_attempts = 5
|
26
|
+
end
|
27
|
+
|
28
|
+
after do
|
29
|
+
Devise.lock_strategy = @original_lock_strategy
|
30
|
+
Devise.maximum_attempts = @original_maximum_attempts
|
31
|
+
Devise.unlock_strategy = @original_unlock_strategy
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'Unlocking user' do
|
35
|
+
before do
|
36
|
+
@resource = lockable_users(:unlocked_user)
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'request unlock without email' do
|
40
|
+
before do
|
41
|
+
@auth_headers = @resource.create_new_auth_token
|
42
|
+
@new_password = Faker::Internet.password
|
43
|
+
|
44
|
+
post :create
|
45
|
+
@data = JSON.parse(response.body)
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'response should fail' do
|
49
|
+
assert_equal 401, response.status
|
50
|
+
end
|
51
|
+
test 'error message should be returned' do
|
52
|
+
assert @data['errors']
|
53
|
+
assert_equal @data['errors'], [I18n.t('devise_token_auth.passwords.missing_email')]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'request unlock' do
|
58
|
+
describe 'unknown user should return 404' do
|
59
|
+
before do
|
60
|
+
post :create, params: { email: 'chester@cheet.ah' }
|
61
|
+
@data = JSON.parse(response.body)
|
62
|
+
end
|
63
|
+
test 'unknown user should return 404' do
|
64
|
+
assert_equal 404, response.status
|
65
|
+
end
|
66
|
+
|
67
|
+
test 'errors should be returned' do
|
68
|
+
assert @data['errors']
|
69
|
+
assert_equal @data['errors'],
|
70
|
+
[I18n.t('devise_token_auth.passwords.user_not_found',
|
71
|
+
email: 'chester@cheet.ah')]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'successfully requested unlock' do
|
76
|
+
before do
|
77
|
+
post :create, params: { email: @resource.email }
|
78
|
+
|
79
|
+
@data = JSON.parse(response.body)
|
80
|
+
end
|
81
|
+
|
82
|
+
test 'response should not contain extra data' do
|
83
|
+
assert_nil @data['data']
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'case-sensitive email' do
|
88
|
+
before do
|
89
|
+
post :create, params: { email: @resource.email }
|
90
|
+
|
91
|
+
@mail = ActionMailer::Base.deliveries.last
|
92
|
+
@resource.reload
|
93
|
+
@data = JSON.parse(response.body)
|
94
|
+
|
95
|
+
@mail_config_name = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
|
96
|
+
@mail_reset_token = @mail.body.match(/unlock_token=(.*)\"/)[1]
|
97
|
+
end
|
98
|
+
|
99
|
+
test 'response should return success status' do
|
100
|
+
assert_equal 200, response.status
|
101
|
+
end
|
102
|
+
|
103
|
+
test 'response should contains message' do
|
104
|
+
assert_equal @data['message'], I18n.t('devise_token_auth.unlocks.sended', email: @resource.email)
|
105
|
+
end
|
106
|
+
|
107
|
+
test 'action should send an email' do
|
108
|
+
assert @mail
|
109
|
+
end
|
110
|
+
|
111
|
+
test 'the email should be addressed to the user' do
|
112
|
+
assert_equal @mail.to.first, @resource.email
|
113
|
+
end
|
114
|
+
|
115
|
+
test 'the client config name should fall back to "default"' do
|
116
|
+
assert_equal 'default', @mail_config_name
|
117
|
+
end
|
118
|
+
|
119
|
+
test 'the email body should contain a link with reset token as a query param' do
|
120
|
+
user = LockableUser.unlock_access_by_token(@mail_reset_token)
|
121
|
+
assert_equal user.id, @resource.id
|
122
|
+
end
|
123
|
+
|
124
|
+
describe 'unlock link failure' do
|
125
|
+
test 'response should return 404' do
|
126
|
+
assert_raises(ActionController::RoutingError) do
|
127
|
+
get :show, params: { unlock_token: 'bogus' }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe 'password reset link success' do
|
133
|
+
before do
|
134
|
+
get :show, params: { unlock_token: @mail_reset_token }
|
135
|
+
|
136
|
+
@resource.reload
|
137
|
+
|
138
|
+
raw_qs = response.location.split('?')[1]
|
139
|
+
@qs = Rack::Utils.parse_nested_query(raw_qs)
|
140
|
+
|
141
|
+
@access_token = @qs['access-token']
|
142
|
+
@client = @qs['client']
|
143
|
+
@client_id = @qs['client_id']
|
144
|
+
@expiry = @qs['expiry']
|
145
|
+
@token = @qs['token']
|
146
|
+
@uid = @qs['uid']
|
147
|
+
@unlock = @qs['unlock']
|
148
|
+
end
|
149
|
+
|
150
|
+
test 'respones should have success redirect status' do
|
151
|
+
assert_equal 302, response.status
|
152
|
+
end
|
153
|
+
|
154
|
+
test 'response should contain auth params' do
|
155
|
+
assert @access_token
|
156
|
+
assert @client
|
157
|
+
assert @client_id
|
158
|
+
assert @expiry
|
159
|
+
assert @token
|
160
|
+
assert @uid
|
161
|
+
assert @unlock
|
162
|
+
end
|
163
|
+
|
164
|
+
test 'response auth params should be valid' do
|
165
|
+
assert @resource.valid_token?(@token, @client_id)
|
166
|
+
assert @resource.valid_token?(@access_token, @client)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe 'case-insensitive email' do
|
172
|
+
before do
|
173
|
+
@resource_class = LockableUser
|
174
|
+
@request_params = {
|
175
|
+
email: @resource.email.upcase
|
176
|
+
}
|
177
|
+
end
|
178
|
+
|
179
|
+
test 'response should return success status if configured' do
|
180
|
+
@resource_class.case_insensitive_keys = [:email]
|
181
|
+
post :create, params: @request_params
|
182
|
+
assert_equal 200, response.status
|
183
|
+
end
|
184
|
+
|
185
|
+
test 'response should return failure status if not configured' do
|
186
|
+
@resource_class.case_insensitive_keys = []
|
187
|
+
post :create, params: @request_params
|
188
|
+
assert_equal 404, response.status
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# was the web request successful?
|
4
|
+
# was the user redirected to the right page?
|
5
|
+
# was the user successfully authenticated?
|
6
|
+
# was the correct object stored in the response?
|
7
|
+
# was the appropriate message delivered in the json payload?
|
8
|
+
|
9
|
+
class Overrides::ConfirmationsControllerTest < ActionDispatch::IntegrationTest
|
10
|
+
describe Overrides::ConfirmationsController do
|
11
|
+
before do
|
12
|
+
@redirect_url = Faker::Internet.url
|
13
|
+
@new_user = evil_users(:unconfirmed_email_user)
|
14
|
+
|
15
|
+
# generate + send email
|
16
|
+
@new_user.send_confirmation_instructions(redirect_url: @redirect_url)
|
17
|
+
|
18
|
+
@mail = ActionMailer::Base.deliveries.last
|
19
|
+
@confirmation_path = @mail.body.match(/localhost([^\"]*)\"/)[1]
|
20
|
+
|
21
|
+
# visit confirmation link
|
22
|
+
get @confirmation_path
|
23
|
+
|
24
|
+
# reload user from db
|
25
|
+
@new_user.reload
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'user is confirmed' do
|
29
|
+
assert @new_user.confirmed?
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'user can be authenticated via confirmation link' do
|
33
|
+
# hard coded in override controller
|
34
|
+
override_proof_str = '(^^,)'
|
35
|
+
|
36
|
+
# ensure present in redirect URL
|
37
|
+
override_proof_param = URI.unescape(response.headers['Location']
|
38
|
+
.match(/override_proof=([^&]*)&/)[1])
|
39
|
+
|
40
|
+
assert_equal override_proof_str, override_proof_param
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# was the web request successful?
|
4
|
+
# was the user redirected to the right page?
|
5
|
+
# was the user successfully authenticated?
|
6
|
+
# was the correct object stored in the response?
|
7
|
+
# was the appropriate message delivered in the json payload?
|
8
|
+
|
9
|
+
class Overrides::OmniauthCallbacksControllerTest < ActionDispatch::IntegrationTest
|
10
|
+
describe Overrides::OmniauthCallbacksController do
|
11
|
+
setup do
|
12
|
+
OmniAuth.config.test_mode = true
|
13
|
+
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new(
|
14
|
+
provider: 'facebook',
|
15
|
+
uid: '123545',
|
16
|
+
info: {
|
17
|
+
name: 'chong',
|
18
|
+
email: 'chongbong@aol.com'
|
19
|
+
}
|
20
|
+
)
|
21
|
+
|
22
|
+
@favorite_color = 'gray'
|
23
|
+
|
24
|
+
get '/evil_user_auth/facebook',
|
25
|
+
params: {
|
26
|
+
auth_origin_url: Faker::Internet.url,
|
27
|
+
favorite_color: @favorite_color,
|
28
|
+
omniauth_window_type: 'newWindow'
|
29
|
+
}
|
30
|
+
|
31
|
+
follow_all_redirects!
|
32
|
+
|
33
|
+
@resource = assigns(:resource)
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'request is successful' do
|
37
|
+
assert_equal 200, response.status
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'controller was overridden' do
|
41
|
+
assert_equal @resource.nickname,
|
42
|
+
Overrides::OmniauthCallbacksController::DEFAULT_NICKNAME
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'whitelisted param was allowed' do
|
46
|
+
assert_equal @favorite_color, @resource.favorite_color
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# was the web request successful?
|
4
|
+
# was the user redirected to the right page?
|
5
|
+
# was the user successfully authenticated?
|
6
|
+
# was the correct object stored in the response?
|
7
|
+
# was the appropriate message delivered in the json payload?
|
8
|
+
|
9
|
+
class Overrides::PasswordsControllerTest < ActionDispatch::IntegrationTest
|
10
|
+
describe Overrides::PasswordsController do
|
11
|
+
before do
|
12
|
+
@resource = evil_users(:confirmed_email_user)
|
13
|
+
@redirect_url = Faker::Internet.url
|
14
|
+
|
15
|
+
post '/evil_user_auth/password',
|
16
|
+
params: {
|
17
|
+
email: @resource.email,
|
18
|
+
redirect_url: @redirect_url
|
19
|
+
}
|
20
|
+
|
21
|
+
@mail = ActionMailer::Base.deliveries.last
|
22
|
+
@resource.reload
|
23
|
+
|
24
|
+
@mail_config_name = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
|
25
|
+
@mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1])
|
26
|
+
@mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1]
|
27
|
+
|
28
|
+
get '/evil_user_auth/password/edit',
|
29
|
+
params: { reset_password_token: @mail_reset_token,
|
30
|
+
redirect_url: @mail_redirect_url }
|
31
|
+
|
32
|
+
@resource.reload
|
33
|
+
|
34
|
+
raw_qs = response.location.split('?')[1]
|
35
|
+
@qs = Rack::Utils.parse_nested_query(raw_qs)
|
36
|
+
|
37
|
+
@access_token = @qs['access-token']
|
38
|
+
@client = @qs['client']
|
39
|
+
@client_id = @qs['client_id']
|
40
|
+
@expiry = @qs['expiry']
|
41
|
+
@override_proof = @qs['override_proof']
|
42
|
+
@reset_password = @qs['reset_password']
|
43
|
+
@token = @qs['token']
|
44
|
+
@uid = @qs['uid']
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'response should have success redirect status' do
|
48
|
+
assert_equal 302, response.status
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'response should contain auth params + override proof' do
|
52
|
+
assert @access_token
|
53
|
+
assert @client
|
54
|
+
assert @client_id
|
55
|
+
assert @expiry
|
56
|
+
assert @override_proof
|
57
|
+
assert @reset_password
|
58
|
+
assert @token
|
59
|
+
assert @uid
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'override proof is correct' do
|
63
|
+
assert_equal @override_proof, Overrides::PasswordsController::OVERRIDE_PROOF
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# was the web request successful?
|
4
|
+
# was the user redirected to the right page?
|
5
|
+
# was the user successfully authenticated?
|
6
|
+
# was the correct object stored in the response?
|
7
|
+
# was the appropriate message delivered in the json payload?
|
8
|
+
|
9
|
+
class Overrides::RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
10
|
+
describe Overrides::RegistrationsController do
|
11
|
+
setup do
|
12
|
+
@existing_user = evil_users(:confirmed_email_user)
|
13
|
+
@auth_headers = @existing_user.create_new_auth_token
|
14
|
+
@client_id = @auth_headers['client']
|
15
|
+
@favorite_color = 'pink'
|
16
|
+
|
17
|
+
# ensure request is not treated as batch request
|
18
|
+
age_token(@existing_user, @client_id)
|
19
|
+
|
20
|
+
# test valid update param
|
21
|
+
@new_operating_thetan = 1_000_000
|
22
|
+
|
23
|
+
put '/evil_user_auth',
|
24
|
+
params: { favorite_color: @favorite_color },
|
25
|
+
headers: @auth_headers
|
26
|
+
|
27
|
+
@data = JSON.parse(response.body)
|
28
|
+
@existing_user.reload
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'user was updated' do
|
32
|
+
assert_equal @favorite_color, @existing_user.favorite_color
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'controller was overridden' do
|
36
|
+
assert_equal Overrides::RegistrationsController::OVERRIDE_PROOF,
|
37
|
+
@data['override_proof']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|