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,262 @@
|
|
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 DemoUserControllerTest < ActionDispatch::IntegrationTest
|
10
|
+
describe DemoUserController do
|
11
|
+
describe "Token access" do
|
12
|
+
before do
|
13
|
+
@user = users(:confirmed_email_user)
|
14
|
+
@user.skip_confirmation!
|
15
|
+
@user.save!
|
16
|
+
|
17
|
+
@auth_headers = @user.create_new_auth_token
|
18
|
+
|
19
|
+
@token = @auth_headers['access-token']
|
20
|
+
@client_id = @auth_headers['client']
|
21
|
+
@expiry = @auth_headers['expiry']
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'successful request' do
|
25
|
+
before do
|
26
|
+
# ensure that request is not treated as batch request
|
27
|
+
age_token(@user, @client_id)
|
28
|
+
|
29
|
+
get '/demo/members_only', {}, @auth_headers
|
30
|
+
|
31
|
+
@resp_token = response.headers['access-token']
|
32
|
+
@resp_client_id = response.headers['client']
|
33
|
+
@resp_expiry = response.headers['expiry']
|
34
|
+
@resp_uid = response.headers['uid']
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'devise mappings' do
|
38
|
+
it 'should define current_user' do
|
39
|
+
assert_equal @user, @controller.current_user
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should define user_signed_in?' do
|
43
|
+
assert @controller.user_signed_in?
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should not define current_mang' do
|
47
|
+
refute_equal @user, @controller.current_mang
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should return success status' do
|
52
|
+
assert_equal 200, response.status
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should receive new token after successful request' do
|
56
|
+
refute_equal @token, @resp_token
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should preserve the client id from the first request' do
|
60
|
+
assert_equal @client_id, @resp_client_id
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return the user's uid in the auth header" do
|
64
|
+
assert_equal @user.uid, @resp_uid
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should not treat this request as a batch request' do
|
68
|
+
refute assigns(:is_batch_request)
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'subsequent requests' do
|
72
|
+
before do
|
73
|
+
@user.reload
|
74
|
+
# ensure that request is not treated as batch request
|
75
|
+
age_token(@user, @client_id)
|
76
|
+
|
77
|
+
get '/demo/members_only', {}, @auth_headers.merge({'access-token' => @resp_token})
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should not treat this request as a batch request' do
|
81
|
+
refute assigns(:is_batch_request)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should allow a new request to be made using new token" do
|
85
|
+
assert_equal 200, response.status
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'failed request' do
|
91
|
+
before do
|
92
|
+
get '/demo/members_only', {}, @auth_headers.merge({'access-token' => "bogus"})
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should not return any auth headers' do
|
96
|
+
refute response.headers['access-token']
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should return error: unauthorized status' do
|
100
|
+
assert_equal 401, response.status
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'disable change_headers_on_each_request' do
|
105
|
+
before do
|
106
|
+
DeviseTokenAuth.change_headers_on_each_request = false
|
107
|
+
@user.reload
|
108
|
+
age_token(@user, @client_id)
|
109
|
+
|
110
|
+
get '/demo/members_only', {}, @auth_headers
|
111
|
+
|
112
|
+
@first_is_batch_request = assigns(:is_batch_request)
|
113
|
+
@first_user = assigns(:user).dup
|
114
|
+
@first_access_token = response.headers['access-token']
|
115
|
+
@first_response_status = response.status
|
116
|
+
|
117
|
+
@user.reload
|
118
|
+
age_token(@user, @client_id)
|
119
|
+
|
120
|
+
# use expired auth header
|
121
|
+
get '/demo/members_only', {}, @auth_headers
|
122
|
+
|
123
|
+
@second_is_batch_request = assigns(:is_batch_request)
|
124
|
+
@second_user = assigns(:user).dup
|
125
|
+
@second_access_token = response.headers['access-token']
|
126
|
+
@second_response_status = response.status
|
127
|
+
end
|
128
|
+
|
129
|
+
after do
|
130
|
+
DeviseTokenAuth.change_headers_on_each_request = true
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should allow the first request through' do
|
134
|
+
assert_equal 200, @first_response_status
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should allow the second request through' do
|
138
|
+
assert_equal 200, @second_response_status
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should return auth headers from the first request' do
|
142
|
+
assert @first_access_token
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should not treat either requests as batch requests' do
|
146
|
+
refute @first_is_batch_request
|
147
|
+
refute @second_is_batch_request
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should return auth headers from the second request' do
|
151
|
+
assert @second_access_token
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should define user during first request' do
|
155
|
+
assert @first_user
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should define user during second request' do
|
159
|
+
assert @second_user
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe 'batch requests' do
|
164
|
+
describe 'success' do
|
165
|
+
before do
|
166
|
+
age_token(@user, @client_id)
|
167
|
+
#request.headers.merge!(@auth_headers)
|
168
|
+
|
169
|
+
get '/demo/members_only', {}, @auth_headers
|
170
|
+
|
171
|
+
@first_is_batch_request = assigns(:is_batch_request)
|
172
|
+
@first_user = assigns(:user)
|
173
|
+
@first_access_token = response.headers['access-token']
|
174
|
+
|
175
|
+
get '/demo/members_only', {}, @auth_headers
|
176
|
+
|
177
|
+
@second_is_batch_request = assigns(:is_batch_request)
|
178
|
+
@second_user = assigns(:user)
|
179
|
+
@second_access_token = response.headers['access-token']
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should allow both requests through' do
|
183
|
+
assert_equal 200, response.status
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'should not treat the first request as a batch request' do
|
187
|
+
refute @first_is_batch_request
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'should treat the second request as a batch request' do
|
191
|
+
assert @second_is_batch_request
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should return access token for first (non-batch) request' do
|
195
|
+
assert @first_access_token
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'should also return auth headers for second (batched) requests' do
|
199
|
+
assert @second_access_token
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
describe 'time out' do
|
204
|
+
before do
|
205
|
+
@user.reload
|
206
|
+
age_token(@user, @client_id)
|
207
|
+
|
208
|
+
get '/demo/members_only', {}, @auth_headers
|
209
|
+
|
210
|
+
@first_is_batch_request = assigns(:is_batch_request)
|
211
|
+
@first_user = assigns(:user).dup
|
212
|
+
@first_access_token = response.headers['access-token']
|
213
|
+
@first_response_status = response.status
|
214
|
+
|
215
|
+
@user.reload
|
216
|
+
age_token(@user, @client_id)
|
217
|
+
|
218
|
+
# use expired auth header
|
219
|
+
get '/demo/members_only', {}, @auth_headers
|
220
|
+
|
221
|
+
@second_is_batch_request = assigns(:is_batch_request)
|
222
|
+
@second_user = assigns(:user)
|
223
|
+
@second_access_token = response.headers['access-token']
|
224
|
+
@second_response_status = response.status
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'should allow the first request through' do
|
228
|
+
assert_equal 200, @first_response_status
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'should not allow the second request through' do
|
232
|
+
assert_equal 401, @second_response_status
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'should not treat first request as batch request' do
|
236
|
+
refute @secord_is_batch_request
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'should return auth headers from the first request' do
|
240
|
+
assert @first_access_token
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'should not treat second request as batch request' do
|
244
|
+
refute @secord_is_batch_request
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'should not return auth headers from the second request' do
|
248
|
+
refute @second_access_token
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'should define user during first request' do
|
252
|
+
assert @first_user
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'should not define user during second request' do
|
256
|
+
refute @second_user
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
@@ -0,0 +1,107 @@
|
|
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::ConfirmationsControllerTest < ActionController::TestCase
|
10
|
+
describe DeviseTokenAuth::ConfirmationsController do
|
11
|
+
describe "Confirmation" do
|
12
|
+
before do
|
13
|
+
@redirect_url = Faker::Internet.url
|
14
|
+
@new_user = users(:unconfirmed_email_user)
|
15
|
+
@new_user.send_confirmation_instructions({
|
16
|
+
redirect_url: @redirect_url
|
17
|
+
})
|
18
|
+
@mail = ActionMailer::Base.deliveries.last
|
19
|
+
@token = @mail.body.match(/confirmation_token=([^&]*)&/)[1]
|
20
|
+
@client_config = @mail.body.match(/config=([^&]*)&/)[1]
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'should generate raw token' do
|
24
|
+
assert @token
|
25
|
+
end
|
26
|
+
|
27
|
+
test "should include config name as 'default' in confirmation link" do
|
28
|
+
assert_equal "default", @client_config
|
29
|
+
end
|
30
|
+
|
31
|
+
test "should store token hash in user" do
|
32
|
+
assert @new_user.confirmation_token
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "success" do
|
36
|
+
before do
|
37
|
+
xhr :get, :show, {confirmation_token: @token, redirect_url: @redirect_url}
|
38
|
+
@user = assigns(:user)
|
39
|
+
end
|
40
|
+
|
41
|
+
test "user should now be confirmed" do
|
42
|
+
assert @user.confirmed?
|
43
|
+
end
|
44
|
+
|
45
|
+
test "should redirect to success url" do
|
46
|
+
assert_redirected_to(/^#{@redirect_url}/)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "failure" do
|
51
|
+
test "user should not be confirmed" do
|
52
|
+
assert_raises(ActionController::RoutingError) {
|
53
|
+
xhr :get, :show, {confirmation_token: "bogus"}
|
54
|
+
}
|
55
|
+
@user = assigns(:user)
|
56
|
+
refute @user.confirmed?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# test with non-standard user class
|
62
|
+
describe "Alternate user model" do
|
63
|
+
setup do
|
64
|
+
@request.env['devise.mapping'] = Devise.mappings[:mang]
|
65
|
+
end
|
66
|
+
|
67
|
+
teardown do
|
68
|
+
@request.env['devise.mapping'] = Devise.mappings[:user]
|
69
|
+
end
|
70
|
+
|
71
|
+
before do
|
72
|
+
@config_name = "altUser"
|
73
|
+
@new_user = mangs(:unconfirmed_email_user)
|
74
|
+
|
75
|
+
@new_user.send_confirmation_instructions(client_config: @config_name)
|
76
|
+
|
77
|
+
@mail = ActionMailer::Base.deliveries.last
|
78
|
+
@token = @mail.body.match(/confirmation_token=(.*)\"/)[1]
|
79
|
+
@client_config = @mail.body.match(/config=(.*)\&/)[1]
|
80
|
+
end
|
81
|
+
|
82
|
+
test 'should generate raw token' do
|
83
|
+
assert @token
|
84
|
+
end
|
85
|
+
|
86
|
+
test "should include config name in confirmation link" do
|
87
|
+
assert_equal @config_name, @client_config
|
88
|
+
end
|
89
|
+
|
90
|
+
test "should store token hash in user" do
|
91
|
+
assert @new_user.confirmation_token
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "success" do
|
95
|
+
before do
|
96
|
+
@redirect_url = Faker::Internet.url
|
97
|
+
xhr :get, :show, {confirmation_token: @token, redirect_url: @redirect_url}
|
98
|
+
@user = assigns(:user)
|
99
|
+
end
|
100
|
+
|
101
|
+
test "user should now be confirmed" do
|
102
|
+
assert @user.confirmed?
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,144 @@
|
|
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 OmniauthTest < ActionDispatch::IntegrationTest
|
10
|
+
setup do
|
11
|
+
OmniAuth.config.test_mode = true
|
12
|
+
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({
|
13
|
+
:provider => 'facebook',
|
14
|
+
:uid => '123545',
|
15
|
+
:info => {
|
16
|
+
name: 'chong',
|
17
|
+
email: 'chongbong@aol.com'
|
18
|
+
}
|
19
|
+
})
|
20
|
+
end
|
21
|
+
|
22
|
+
before do
|
23
|
+
@redirect_url = "http://ng-token-auth.dev/"
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'default user model' do
|
27
|
+
describe 'from api to provider' do
|
28
|
+
before do
|
29
|
+
get_via_redirect '/auth/facebook', {
|
30
|
+
auth_origin_url: @redirect_url
|
31
|
+
}
|
32
|
+
|
33
|
+
@user = assigns(:user)
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'status should be success' do
|
37
|
+
assert_equal 200, response.status
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'request should determine the correct resource_class' do
|
41
|
+
assert_equal 'User', controller.omniauth_params['resource_class']
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'request should pass correct redirect_url' do
|
45
|
+
assert_equal @redirect_url, controller.omniauth_params['auth_origin_url']
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'user should have been created' do
|
49
|
+
assert @user
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'user should be assigned info from provider' do
|
53
|
+
assert_equal 'chongbong@aol.com', @user.email
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'user should be of the correct class' do
|
57
|
+
assert_equal User, @user.class
|
58
|
+
end
|
59
|
+
|
60
|
+
test 'response contains all serializable attributes for user' do
|
61
|
+
post_message = JSON.parse(/postMessage\((?<data>.*), '\*'\);/m.match(response.body)[:data])
|
62
|
+
|
63
|
+
assert post_message["id"]
|
64
|
+
assert post_message["email"]
|
65
|
+
assert post_message["uid"]
|
66
|
+
assert post_message["name"]
|
67
|
+
assert post_message["favorite_color"]
|
68
|
+
assert post_message["message"]
|
69
|
+
assert post_message["client_id"]
|
70
|
+
assert post_message["auth_token"]
|
71
|
+
refute post_message["tokens"]
|
72
|
+
refute post_message["password"]
|
73
|
+
end
|
74
|
+
|
75
|
+
test 'session vars have been cleared' do
|
76
|
+
refute request.session['dta.omniauth.auth']
|
77
|
+
refute request.session['dta.omniauth.params']
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'pass additional params' do
|
82
|
+
before do
|
83
|
+
@fav_color = 'alizarin crimson'
|
84
|
+
@unpermitted_param = "M. Bison"
|
85
|
+
get_via_redirect '/auth/facebook', {
|
86
|
+
auth_origin_url: @redirect_url,
|
87
|
+
favorite_color: @fav_color,
|
88
|
+
name: @unpermitted_param
|
89
|
+
}
|
90
|
+
|
91
|
+
@user = assigns(:user)
|
92
|
+
end
|
93
|
+
|
94
|
+
test 'status shows success' do
|
95
|
+
assert_equal 200, response.status
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'additional attribute was passed' do
|
99
|
+
assert_equal @fav_color, @user.favorite_color
|
100
|
+
end
|
101
|
+
|
102
|
+
test 'non-whitelisted attributes are ignored' do
|
103
|
+
refute_equal @unpermitted_param, @user.name
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
describe 'alternate user model' do
|
110
|
+
describe 'from api to provider' do
|
111
|
+
before do
|
112
|
+
get_via_redirect '/mangs/facebook', {
|
113
|
+
auth_origin_url: @redirect_url
|
114
|
+
}
|
115
|
+
|
116
|
+
@user = assigns(:user)
|
117
|
+
end
|
118
|
+
|
119
|
+
test 'status should be success' do
|
120
|
+
assert_equal 200, response.status
|
121
|
+
end
|
122
|
+
|
123
|
+
test 'request should determine the correct resource_class' do
|
124
|
+
assert_equal 'Mang', controller.omniauth_params['resource_class']
|
125
|
+
end
|
126
|
+
|
127
|
+
test 'request should pass correct redirect_url' do
|
128
|
+
assert_equal @redirect_url, controller.omniauth_params['auth_origin_url']
|
129
|
+
end
|
130
|
+
|
131
|
+
test 'user should have been created' do
|
132
|
+
assert @user
|
133
|
+
end
|
134
|
+
|
135
|
+
test 'user should be assigned info from provider' do
|
136
|
+
assert_equal 'chongbong@aol.com', @user.email
|
137
|
+
end
|
138
|
+
|
139
|
+
test 'user should be of the correct class' do
|
140
|
+
assert_equal Mang, @user.class
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|