xing_backend_token_auth 0.1.31
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/LICENSE +13 -0
- data/README.md +679 -0
- data/Rakefile +34 -0
- data/app/controllers/devise_token_auth/application_controller.rb +22 -0
- data/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +110 -0
- data/app/controllers/devise_token_auth/confirmations_controller.rb +31 -0
- data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +169 -0
- data/app/controllers/devise_token_auth/passwords_controller.rb +107 -0
- data/app/controllers/devise_token_auth/registrations_controller.rb +99 -0
- data/app/controllers/devise_token_auth/sessions_controller.rb +50 -0
- data/app/controllers/devise_token_auth/token_validations_controller.rb +22 -0
- data/app/serializers/devise_token_auth/error_messages_serializer.rb +16 -0
- data/app/serializers/devise_token_auth/resource_errors_serializer.rb +24 -0
- data/app/serializers/devise_token_auth/resource_serializer.rb +17 -0
- data/app/serializers/devise_token_auth/success_message_serializer.rb +15 -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_failure.html.erb +2 -0
- data/app/views/devise_token_auth/omniauth_success.html.erb +8 -0
- data/app/views/layouts/omniauth_response.html.erb +31 -0
- data/config/initializers/devise.rb +207 -0
- data/config/initializers/token_auth_failure_app.rb +7 -0
- data/config/locales/devise.en.yml +59 -0
- data/config/routes.rb +5 -0
- data/lib/devise_token_auth.rb +9 -0
- data/lib/devise_token_auth/controllers/helpers.rb +129 -0
- data/lib/devise_token_auth/controllers/url_helpers.rb +8 -0
- data/lib/devise_token_auth/engine.rb +32 -0
- data/lib/devise_token_auth/models/token_authenticatable.rb +195 -0
- data/lib/devise_token_auth/rails/routes.rb +65 -0
- data/lib/generators/devise_token_auth/USAGE +31 -0
- data/lib/generators/devise_token_auth/install_generator.rb +100 -0
- data/lib/generators/devise_token_auth/install_views_generator.rb +16 -0
- data/lib/generators/devise_token_auth/templates/devise_token_auth.rb +22 -0
- data/lib/generators/devise_token_auth/templates/devise_token_auth_add_token_info_to_users.rb.erb +14 -0
- data/lib/tasks/devise_token_auth_tasks.rake +4 -0
- data/lib/xing_backend_token_auth.rb +1 -0
- data/test/controllers/demo_group_controller_test.rb +126 -0
- data/test/controllers/demo_mang_controller_test.rb +263 -0
- data/test/controllers/demo_user_controller_test.rb +262 -0
- data/test/controllers/devise_token_auth/confirmations_controller_test.rb +107 -0
- data/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +144 -0
- data/test/controllers/devise_token_auth/passwords_controller_test.rb +275 -0
- data/test/controllers/devise_token_auth/registrations_controller_test.rb +405 -0
- data/test/controllers/devise_token_auth/registrations_controller_test.rb.orig +494 -0
- data/test/controllers/devise_token_auth/sessions_controller_test.rb +169 -0
- data/test/controllers/overrides/confirmations_controller_test.rb +44 -0
- data/test/controllers/overrides/omniauth_callbacks_controller_test.rb +44 -0
- data/test/controllers/overrides/passwords_controller_test.rb +64 -0
- data/test/controllers/overrides/registrations_controller_test.rb +42 -0
- data/test/controllers/overrides/sessions_controller_test.rb +35 -0
- data/test/controllers/overrides/token_validations_controller_test.rb +38 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/images/logo.jpg +0 -0
- data/test/dummy/app/assets/images/omniauth-provider-settings.png +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +16 -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 +12 -0
- data/test/dummy/app/controllers/overrides/confirmations_controller.rb +32 -0
- data/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb +14 -0
- data/test/dummy/app/controllers/overrides/passwords_controller.rb +39 -0
- data/test/dummy/app/controllers/overrides/registrations_controller.rb +27 -0
- data/test/dummy/app/controllers/overrides/sessions_controller.rb +26 -0
- data/test/dummy/app/controllers/overrides/token_validations_controller.rb +23 -0
- data/test/dummy/app/controllers/registrations_controller.rb +2 -0
- data/test/dummy/app/helpers/application_helper.rb +1065 -0
- data/test/dummy/app/models/evil_user.rb +5 -0
- data/test/dummy/app/models/mang.rb +5 -0
- data/test/dummy/app/models/user.rb +20 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +8 -0
- data/test/dummy/bin/rake +8 -0
- data/test/dummy/bin/spring +18 -0
- data/test/dummy/config.ru +16 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +31 -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 +40 -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_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/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +32 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/spring.rb +1 -0
- data/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +56 -0
- data/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +56 -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 +57 -0
- data/test/dummy/db/schema.rb +111 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/evil_users.yml +29 -0
- data/test/fixtures/mangs.yml +29 -0
- data/test/fixtures/users.yml +29 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/lib/generators/devise_token_auth/install_generator_test.rb +131 -0
- data/test/lib/generators/devise_token_auth/install_views_generator_test.rb +23 -0
- data/test/models/user_test.rb +81 -0
- data/test/test_helper.rb +60 -0
- metadata +320 -0
@@ -0,0 +1,275 @@
|
|
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::PasswordsControllerTest < ActionController::TestCase
|
10
|
+
describe DeviseTokenAuth::PasswordsController do
|
11
|
+
describe "Password reset" do
|
12
|
+
before do
|
13
|
+
@user = users(:confirmed_email_user)
|
14
|
+
@redirect_url = 'http://ng-token-auth.dev'
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'request password reset' do
|
18
|
+
before do
|
19
|
+
xhr :post, :create, {
|
20
|
+
user: {
|
21
|
+
email: @user.email
|
22
|
+
},
|
23
|
+
redirect_url: @redirect_url
|
24
|
+
}
|
25
|
+
|
26
|
+
@mail = ActionMailer::Base.deliveries.last
|
27
|
+
@user.reload
|
28
|
+
|
29
|
+
@mail_config_name = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
|
30
|
+
@mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1])
|
31
|
+
@mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1]
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'response should return success status' do
|
35
|
+
assert_equal 200, response.status
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'action should send an email' do
|
39
|
+
assert @mail
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'the email should be addressed to the user' do
|
43
|
+
assert_equal @mail.to.first, @user.email
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'the email body should contain a link with redirect url as a query param' do
|
47
|
+
assert_equal @redirect_url, @mail_redirect_url
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'the client config name should fall back to "default"' do
|
51
|
+
assert_equal 'default', @mail_config_name
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'the email body should contain a link with reset token as a query param' do
|
55
|
+
user = User.reset_password_by_token({
|
56
|
+
reset_password_token: @mail_reset_token
|
57
|
+
})
|
58
|
+
|
59
|
+
assert_equal user.id, @user.id
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'password reset link failure' do
|
63
|
+
test 'request should not be authorized' do
|
64
|
+
assert_raises(ActionController::RoutingError) {
|
65
|
+
xhr :get, :edit, {
|
66
|
+
reset_password_token: 'bogus',
|
67
|
+
redirect_url: @mail_redirect_url
|
68
|
+
}
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'password reset link success' do
|
74
|
+
before do
|
75
|
+
xhr :get, :edit, {
|
76
|
+
reset_password_token: @mail_reset_token,
|
77
|
+
redirect_url: @mail_redirect_url
|
78
|
+
}
|
79
|
+
|
80
|
+
@user.reload
|
81
|
+
|
82
|
+
raw_qs = response.location.split('?')[1]
|
83
|
+
@qs = Rack::Utils.parse_nested_query(raw_qs)
|
84
|
+
|
85
|
+
@client_id = @qs["client_id"]
|
86
|
+
@expiry = @qs["expiry"]
|
87
|
+
@reset_password = @qs["reset_password"]
|
88
|
+
@token = @qs["token"]
|
89
|
+
@uid = @qs["uid"]
|
90
|
+
end
|
91
|
+
|
92
|
+
test 'respones should have success redirect status' do
|
93
|
+
assert_equal 302, response.status
|
94
|
+
end
|
95
|
+
|
96
|
+
test 'response should contain auth params' do
|
97
|
+
assert @client_id
|
98
|
+
assert @expiry
|
99
|
+
assert @reset_password
|
100
|
+
assert @token
|
101
|
+
assert @uid
|
102
|
+
end
|
103
|
+
|
104
|
+
test 'response auth params should be valid' do
|
105
|
+
assert @user.valid_token?(@token, @client_id)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "change password" do
|
111
|
+
describe 'success' do
|
112
|
+
before do
|
113
|
+
@auth_headers = @user.create_new_auth_token
|
114
|
+
request.headers.merge!(@auth_headers)
|
115
|
+
@new_password = Faker::Internet.password
|
116
|
+
|
117
|
+
xhr :put, :update, {
|
118
|
+
user: {
|
119
|
+
password: @new_password,
|
120
|
+
password_confirmation: @new_password
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
@user.reload
|
125
|
+
end
|
126
|
+
|
127
|
+
test "request should be successful" do
|
128
|
+
assert_equal 200, response.status
|
129
|
+
end
|
130
|
+
|
131
|
+
test "new password should authenticate user" do
|
132
|
+
assert @user.valid_password?(@new_password)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe 'password mismatch error' do
|
137
|
+
before do
|
138
|
+
@auth_headers = @user.create_new_auth_token
|
139
|
+
request.headers.merge!(@auth_headers)
|
140
|
+
@new_password = Faker::Internet.password
|
141
|
+
|
142
|
+
xhr :put, :update, {
|
143
|
+
user: {
|
144
|
+
password: 'chong',
|
145
|
+
password_confirmation: 'bong'
|
146
|
+
}
|
147
|
+
}
|
148
|
+
end
|
149
|
+
|
150
|
+
test 'response should fail' do
|
151
|
+
assert_equal 422, response.status
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe 'unauthorized user' do
|
156
|
+
before do
|
157
|
+
@auth_headers = @user.create_new_auth_token
|
158
|
+
@new_password = Faker::Internet.password
|
159
|
+
|
160
|
+
xhr :put, :update, {
|
161
|
+
user: {
|
162
|
+
password: @new_password,
|
163
|
+
password_confirmation: @new_password
|
164
|
+
}
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
168
|
+
test 'response should fail' do
|
169
|
+
assert_equal 401, response.status
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "Alternate user class" do
|
176
|
+
setup do
|
177
|
+
@request.env['devise.mapping'] = Devise.mappings[:mang]
|
178
|
+
end
|
179
|
+
|
180
|
+
teardown do
|
181
|
+
@request.env['devise.mapping'] = Devise.mappings[:user]
|
182
|
+
end
|
183
|
+
|
184
|
+
before do
|
185
|
+
@user = mangs(:confirmed_email_user)
|
186
|
+
@redirect_url = 'http://ng-token-auth.dev'
|
187
|
+
|
188
|
+
xhr :post, :create, {
|
189
|
+
mang: {
|
190
|
+
email: @user.email,
|
191
|
+
},
|
192
|
+
redirect_url: @redirect_url
|
193
|
+
}
|
194
|
+
|
195
|
+
@mail = ActionMailer::Base.deliveries.last
|
196
|
+
@user.reload
|
197
|
+
|
198
|
+
@mail_config_name = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
|
199
|
+
@mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1])
|
200
|
+
@mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1]
|
201
|
+
end
|
202
|
+
|
203
|
+
test 'response should return success status' do
|
204
|
+
assert_equal 200, response.status
|
205
|
+
end
|
206
|
+
|
207
|
+
test 'the email body should contain a link with reset token as a query param' do
|
208
|
+
user = Mang.reset_password_by_token({
|
209
|
+
reset_password_token: @mail_reset_token
|
210
|
+
})
|
211
|
+
|
212
|
+
assert_equal user.id, @user.id
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe 'unconfirmed user' do
|
217
|
+
before do
|
218
|
+
@user = users(:unconfirmed_email_user)
|
219
|
+
@redirect_url = 'http://ng-token-auth.dev'
|
220
|
+
|
221
|
+
xhr :post, :create, {
|
222
|
+
user: {
|
223
|
+
email: @user.email
|
224
|
+
},
|
225
|
+
redirect_url: @redirect_url
|
226
|
+
}
|
227
|
+
|
228
|
+
@mail = ActionMailer::Base.deliveries.last
|
229
|
+
@user.reload
|
230
|
+
|
231
|
+
@mail_config_name = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
|
232
|
+
@mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1])
|
233
|
+
@mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1]
|
234
|
+
|
235
|
+
xhr :get, :edit, {
|
236
|
+
reset_password_token: @mail_reset_token,
|
237
|
+
redirect_url: @mail_redirect_url
|
238
|
+
}
|
239
|
+
|
240
|
+
@user.reload
|
241
|
+
end
|
242
|
+
|
243
|
+
test 'unconfirmed email user should now be confirmed' do
|
244
|
+
assert @user.confirmed_at
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
describe 'alternate user type' do
|
249
|
+
before do
|
250
|
+
@user = users(:confirmed_email_user)
|
251
|
+
@redirect_url = 'http://ng-token-auth.dev'
|
252
|
+
@config_name = "altUser"
|
253
|
+
|
254
|
+
xhr :post, :create, {
|
255
|
+
user: {
|
256
|
+
email: @user.email
|
257
|
+
},
|
258
|
+
redirect_url: @redirect_url,
|
259
|
+
config_name: @config_name
|
260
|
+
}
|
261
|
+
|
262
|
+
@mail = ActionMailer::Base.deliveries.last
|
263
|
+
@user.reload
|
264
|
+
|
265
|
+
@mail_config_name = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
|
266
|
+
@mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1])
|
267
|
+
@mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1]
|
268
|
+
end
|
269
|
+
|
270
|
+
test 'config_name param is included in the confirmation email link' do
|
271
|
+
assert_equal @config_name, @mail_config_name
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
@@ -0,0 +1,405 @@
|
|
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
|
+
|
10
|
+
class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
11
|
+
describe DeviseTokenAuth::RegistrationsController do
|
12
|
+
describe "Successful registration" do
|
13
|
+
before do
|
14
|
+
@mails_sent = ActionMailer::Base.deliveries.count
|
15
|
+
post '/auth', {
|
16
|
+
confirm_success_url: Faker::Internet.url,
|
17
|
+
user: {
|
18
|
+
email: Faker::Internet.email,
|
19
|
+
password: "secret123",
|
20
|
+
password_confirmation: "secret123",
|
21
|
+
unpermitted_param: '(x_x)'
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
@user = assigns(:user)
|
26
|
+
@data = JSON.parse(response.body)
|
27
|
+
@mail = ActionMailer::Base.deliveries.last
|
28
|
+
end
|
29
|
+
|
30
|
+
test "request should be successful" do
|
31
|
+
assert_equal 200, response.status
|
32
|
+
end
|
33
|
+
|
34
|
+
test "user should have been created" do
|
35
|
+
assert @user.id
|
36
|
+
end
|
37
|
+
|
38
|
+
test "user should not be confirmed" do
|
39
|
+
assert_nil @user.confirmed_at
|
40
|
+
end
|
41
|
+
|
42
|
+
test "new user data should be returned as json" do
|
43
|
+
assert @data['data']['email']
|
44
|
+
end
|
45
|
+
|
46
|
+
test "new user should receive confirmation email" do
|
47
|
+
assert_equal @user.email, @mail['to'].to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
test "new user password should not be returned" do
|
51
|
+
assert_nil @data['data']['password']
|
52
|
+
end
|
53
|
+
|
54
|
+
test "only one email was sent" do
|
55
|
+
assert_equal @mails_sent + 1, ActionMailer::Base.deliveries.count
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "Adding extra params" do
|
60
|
+
before do
|
61
|
+
@redirect_url = Faker::Internet.url
|
62
|
+
@operating_thetan = 2
|
63
|
+
|
64
|
+
post '/auth', {
|
65
|
+
confirm_success_url: @redirect_url,
|
66
|
+
user: {
|
67
|
+
email: Faker::Internet.email,
|
68
|
+
password: "secret123",
|
69
|
+
password_confirmation: "secret123",
|
70
|
+
favorite_color: @fav_color,
|
71
|
+
operating_thetan: @operating_thetan
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
@user = assigns(:user)
|
76
|
+
@data = JSON.parse(response.body)
|
77
|
+
@mail = ActionMailer::Base.deliveries.last
|
78
|
+
|
79
|
+
@mail_reset_token = @mail.body.match(/confirmation_token=([^&]*)&/)[1]
|
80
|
+
@mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=(.*)\"/)[1])
|
81
|
+
@mail_config_name = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
|
82
|
+
end
|
83
|
+
|
84
|
+
test 'redirect_url is included as param in email' do
|
85
|
+
assert_equal @redirect_url, @mail_redirect_url
|
86
|
+
end
|
87
|
+
|
88
|
+
test "additional sign_up params should be considered" do
|
89
|
+
assert_equal @operating_thetan, @user.operating_thetan
|
90
|
+
end
|
91
|
+
|
92
|
+
test 'config_name param is included in the confirmation email link' do
|
93
|
+
assert @mail_config_name
|
94
|
+
end
|
95
|
+
|
96
|
+
test "client config name falls back to 'default'" do
|
97
|
+
assert_equal "default", @mail_config_name
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "Mismatched passwords" do
|
102
|
+
before do
|
103
|
+
post '/auth', {
|
104
|
+
confirm_success_url: Faker::Internet.url,
|
105
|
+
user: {
|
106
|
+
email: Faker::Internet.email,
|
107
|
+
password: "secret123",
|
108
|
+
password_confirmation: "bogus"
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
@user = assigns(:user)
|
113
|
+
@data = JSON.parse(response.body)
|
114
|
+
end
|
115
|
+
|
116
|
+
test "request should not be successful" do
|
117
|
+
assert_equal 403, response.status
|
118
|
+
end
|
119
|
+
|
120
|
+
test "user should have been created" do
|
121
|
+
assert_nil @user.id
|
122
|
+
end
|
123
|
+
|
124
|
+
test "error should be returned in the response" do
|
125
|
+
assert @data['errors'].length
|
126
|
+
end
|
127
|
+
|
128
|
+
test "full_messages should be included in error hash" do
|
129
|
+
assert @data['errors']['full_messages'].length
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "Existing users" do
|
134
|
+
before do
|
135
|
+
@existing_user = users(:confirmed_email_user)
|
136
|
+
|
137
|
+
post '/auth', {
|
138
|
+
confirm_success_url: Faker::Internet.url,
|
139
|
+
user: {
|
140
|
+
email: @existing_user.email,
|
141
|
+
password: "secret123",
|
142
|
+
password_confirmation: "secret123"
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
@user = assigns(:user)
|
147
|
+
@data = JSON.parse(response.body)
|
148
|
+
end
|
149
|
+
|
150
|
+
test "request should not be successful" do
|
151
|
+
assert_equal 403, response.status
|
152
|
+
end
|
153
|
+
|
154
|
+
test "user should have been created" do
|
155
|
+
assert_nil @user.id
|
156
|
+
end
|
157
|
+
|
158
|
+
test "error should be returned in the response" do
|
159
|
+
assert @data['errors'].length
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
describe "Destroy user account" do
|
165
|
+
describe "success" do
|
166
|
+
before do
|
167
|
+
@existing_user = users(:confirmed_email_user)
|
168
|
+
@auth_headers = @existing_user.create_new_auth_token
|
169
|
+
@client_id = @auth_headers['client']
|
170
|
+
|
171
|
+
# ensure request is not treated as batch request
|
172
|
+
age_token(@existing_user, @client_id)
|
173
|
+
|
174
|
+
delete "/auth", {}, @auth_headers
|
175
|
+
|
176
|
+
@data = JSON.parse(response.body)
|
177
|
+
end
|
178
|
+
|
179
|
+
test 'request is successful' do
|
180
|
+
assert_equal 200, response.status
|
181
|
+
end
|
182
|
+
|
183
|
+
test "existing user should be deleted" do
|
184
|
+
refute User.where(id: @existing_user.id).first
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe 'failure: no auth headers' do
|
189
|
+
before do
|
190
|
+
delete "/auth", {}
|
191
|
+
@data = JSON.parse(response.body)
|
192
|
+
end
|
193
|
+
|
194
|
+
test 'request returns 404 (not found) status' do
|
195
|
+
assert_equal 404, response.status
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
describe "Update user account" do
|
202
|
+
describe "existing user" do
|
203
|
+
before do
|
204
|
+
@existing_user = users(:confirmed_email_user)
|
205
|
+
@auth_headers = @existing_user.create_new_auth_token
|
206
|
+
@client_id = @auth_headers['client']
|
207
|
+
|
208
|
+
# ensure request is not treated as batch request
|
209
|
+
age_token(@existing_user, @client_id)
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "success" do
|
213
|
+
before do
|
214
|
+
# test valid update param
|
215
|
+
@new_operating_thetan = 1000000
|
216
|
+
|
217
|
+
put "/auth", {
|
218
|
+
user: {
|
219
|
+
operating_thetan: @new_operating_thetan
|
220
|
+
}
|
221
|
+
}, @auth_headers
|
222
|
+
|
223
|
+
@data = JSON.parse(response.body)
|
224
|
+
@existing_user.reload
|
225
|
+
end
|
226
|
+
|
227
|
+
test "Request was successful" do
|
228
|
+
assert_equal 200, response.status
|
229
|
+
end
|
230
|
+
|
231
|
+
test "User attribute was updated" do
|
232
|
+
assert_equal @new_operating_thetan, @existing_user.operating_thetan
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe "error" do
|
237
|
+
before do
|
238
|
+
# test invalid update param
|
239
|
+
@new_operating_thetan = "blegh"
|
240
|
+
put "/auth", {
|
241
|
+
user: {
|
242
|
+
operating_thetan: @new_operating_thetan
|
243
|
+
}
|
244
|
+
}, @auth_headers
|
245
|
+
|
246
|
+
@data = JSON.parse(response.body)
|
247
|
+
@existing_user.reload
|
248
|
+
end
|
249
|
+
|
250
|
+
test "Request was NOT successful" do
|
251
|
+
assert_equal 403, response.status
|
252
|
+
end
|
253
|
+
|
254
|
+
test "Errors were provided with response" do
|
255
|
+
assert @data["errors"].length
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
describe "invalid user" do
|
261
|
+
before do
|
262
|
+
@existing_user = users(:confirmed_email_user)
|
263
|
+
@auth_headers = @existing_user.create_new_auth_token
|
264
|
+
@client_id = @auth_headers['client']
|
265
|
+
|
266
|
+
# ensure request is not treated as batch request
|
267
|
+
expire_token(@existing_user, @client_id)
|
268
|
+
|
269
|
+
# test valid update param
|
270
|
+
@new_operating_thetan = 3
|
271
|
+
|
272
|
+
put "/auth", {
|
273
|
+
user: {
|
274
|
+
operating_thetan: @new_operating_thetan
|
275
|
+
}
|
276
|
+
}, @auth_headers
|
277
|
+
|
278
|
+
@data = JSON.parse(response.body)
|
279
|
+
@existing_user.reload
|
280
|
+
end
|
281
|
+
|
282
|
+
test "Response should return 404 status" do
|
283
|
+
assert_equal 404, response.status
|
284
|
+
end
|
285
|
+
|
286
|
+
test "User should not be updated" do
|
287
|
+
refute_equal @new_operating_thetan, @existing_user.operating_thetan
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
describe "Alternate user class" do
|
293
|
+
before do
|
294
|
+
post "/mangs", {
|
295
|
+
confirm_success_url: Faker::Internet.url,
|
296
|
+
mang: {
|
297
|
+
email: Faker::Internet.email,
|
298
|
+
password: "secret123",
|
299
|
+
password_confirmation: "secret123"
|
300
|
+
}
|
301
|
+
}
|
302
|
+
|
303
|
+
@user = assigns(:mang)
|
304
|
+
@data = JSON.parse(response.body)
|
305
|
+
@mail = ActionMailer::Base.deliveries.last
|
306
|
+
end
|
307
|
+
|
308
|
+
test "request should be successful" do
|
309
|
+
assert_equal 200, response.status
|
310
|
+
end
|
311
|
+
|
312
|
+
test "use should be a Mang" do
|
313
|
+
assert_equal "Mang", @user.class.name
|
314
|
+
end
|
315
|
+
|
316
|
+
test "Mang should be destroyed" do
|
317
|
+
@user.confirm!
|
318
|
+
@auth_headers = @user.create_new_auth_token
|
319
|
+
@client_id = @auth_headers['client']
|
320
|
+
|
321
|
+
# ensure request is not treated as batch request
|
322
|
+
age_token(@user, @client_id)
|
323
|
+
|
324
|
+
delete "/mangs", {}, @auth_headers
|
325
|
+
|
326
|
+
assert_equal 200, response.status
|
327
|
+
refute Mang.where(id: @user.id).first
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
describe "Passing client config name" do
|
332
|
+
before do
|
333
|
+
@config_name = 'altUser'
|
334
|
+
|
335
|
+
post "/mangs", {
|
336
|
+
confirm_success_url: Faker::Internet.url,
|
337
|
+
config_name: @config_name,
|
338
|
+
mang: {
|
339
|
+
email: Faker::Internet.email,
|
340
|
+
password: "secret123",
|
341
|
+
password_confirmation: "secret123"
|
342
|
+
|
343
|
+
}
|
344
|
+
}
|
345
|
+
|
346
|
+
@user = assigns(:mang)
|
347
|
+
@data = JSON.parse(response.body)
|
348
|
+
@mail = ActionMailer::Base.deliveries.last
|
349
|
+
|
350
|
+
@user.reload
|
351
|
+
|
352
|
+
@mail_reset_token = @mail.body.match(/confirmation_token=([^&]*)&/)[1]
|
353
|
+
@mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=(.*)\"/)[1])
|
354
|
+
@mail_config_name = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1])
|
355
|
+
end
|
356
|
+
|
357
|
+
test 'config_name param is included in the confirmation email link' do
|
358
|
+
assert_equal @config_name, @mail_config_name
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
describe "Skipped confirmation" do
|
363
|
+
setup do
|
364
|
+
User.set_callback(:create, :before, :skip_confirmation!)
|
365
|
+
|
366
|
+
post "/auth", {
|
367
|
+
user: {
|
368
|
+
email: Faker::Internet.email,
|
369
|
+
password: "secret123",
|
370
|
+
password_confirmation: "secret123"
|
371
|
+
},
|
372
|
+
confirm_success_url: Faker::Internet.url
|
373
|
+
}
|
374
|
+
|
375
|
+
@user = assigns(:user)
|
376
|
+
@token = response.headers["access-token"]
|
377
|
+
@client_id = response.headers["client"]
|
378
|
+
end
|
379
|
+
|
380
|
+
teardown do
|
381
|
+
User.skip_callback(:create, :before, :skip_confirmation!)
|
382
|
+
end
|
383
|
+
|
384
|
+
test "user was created" do
|
385
|
+
assert @user
|
386
|
+
end
|
387
|
+
|
388
|
+
test "user was confirmed" do
|
389
|
+
assert @user.confirmed?
|
390
|
+
end
|
391
|
+
|
392
|
+
test "auth headers were returned in response" do
|
393
|
+
assert response.headers["access-token"]
|
394
|
+
assert response.headers["token-type"]
|
395
|
+
assert response.headers["client"]
|
396
|
+
assert response.headers["expiry"]
|
397
|
+
assert response.headers["uid"]
|
398
|
+
end
|
399
|
+
|
400
|
+
test "response token is valid" do
|
401
|
+
assert @user.valid_token?(@token, @client_id)
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|