Skip to content

Commit c3792a3

Browse files
committed
Test against 7.2 and 8
1 parent b7fcfdf commit c3792a3

File tree

9 files changed

+142
-21
lines changed

9 files changed

+142
-21
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
- gemfiles/rails_5_2.gemfile
2222
- gemfiles/rails_6_0.gemfile
2323
- gemfiles/rails_7_0.gemfile
24+
- gemfiles/rails_7_2.gemfile
25+
- gemfiles/rails_8_0.gemfile
2426
db:
2527
- sqlite
2628
- mysql
@@ -51,6 +53,7 @@ jobs:
5153
- ruby: 3.2
5254
gemfile: gemfiles/rails_7_0_mongoid_7.gemfile
5355
devise-token-auth-orm: mongoid
56+
# TODO: add mongoid for rails 7.2
5457
exclude:
5558
- ruby: 2.7
5659
gemfile: gemfiles/rails_4_2.gemfile
@@ -60,6 +63,10 @@ jobs:
6063
gemfile: gemfiles/rails_5_1.gemfile
6164
- ruby: 2.7
6265
gemfile: gemfiles/rails_5_2.gemfile
66+
- ruby: 2.7
67+
gemfile: gemfiles/rails_7_2.gemfile
68+
- ruby: 2.7
69+
gemfile: gemfiles/rails_8_0.gemfile
6370
- ruby: '3.0'
6471
gemfile: gemfiles/rails_4_2.gemfile
6572
- ruby: '3.0'
@@ -70,6 +77,10 @@ jobs:
7077
gemfile: gemfiles/rails_5_2.gemfile
7178
- ruby: '3.0'
7279
gemfile: gemfiles/rails_6_0.gemfile
80+
- ruby: '3.0'
81+
gemfile: gemfiles/rails_7_2.gemfile
82+
- ruby: '3.0'
83+
gemfile: gemfiles/rails_8_0.gemfile
7384
- ruby: 3.1
7485
gemfile: gemfiles/rails_4_2.gemfile
7586
- ruby: 3.1

app/controllers/devise_token_auth/omniauth_callbacks_controller.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ class OmniauthCallbacksController < DeviseTokenAuth::ApplicationController
99
skip_before_action :set_user_by_token, raise: false
1010
skip_after_action :update_auth_header
1111

12+
# before_action do
13+
# puts "OMNIAUTH AUTH HASH:"
14+
# puts request.env['omniauth.auth'].to_json
15+
# puts "\nOMNIAUTH PARAMS:"
16+
# puts request.env['omniauth.params'].to_json
17+
# end
18+
1219
# intermediary route for successful omniauth authentication. omniauth does
1320
# not support multiple models, so we must resort to this terrible hack.
1421
def redirect_callbacks
@@ -55,21 +62,23 @@ def default_devise_mapping
5562
end
5663

5764
def omniauth_success
65+
puts "omniauth_success"
5866
get_resource_from_auth_hash
67+
puts "get_resource_from_auth_hash"
5968
set_token_on_resource
6069
create_auth_params
6170

6271
if confirmable_enabled?
6372
# don't send confirmation email!!!
6473
@resource.skip_confirmation!
6574
end
66-
75+
puts "before sign in"
6776
sign_in(:user, @resource, store: false, bypass: false)
68-
69-
@resource.save!
77+
puts "after sign in"
78+
puts @resource.save!
7079

7180
yield @resource if block_given?
72-
81+
puts "after yield"
7382
if DeviseTokenAuth.cookie_enabled
7483
set_token_in_cookie(@resource, @token)
7584
end
@@ -105,6 +114,7 @@ def omniauth_params
105114
@_omniauth_params ||= session.delete('dta.omniauth.params')
106115
@_omniauth_params
107116
elsif params['omniauth_window_type']
117+
108118
@_omniauth_params = params.slice('omniauth_window_type', 'auth_origin_url', 'resource_class', 'origin')
109119
else
110120
@_omniauth_params = {}
@@ -221,7 +231,11 @@ def render_data_or_redirect(message, data, user_data = {})
221231
# See app/views/devise_token_auth/omniauth_external_window.html.erb to understand
222232
# why we can handle these both the same. The view is setup to handle both cases
223233
# at the same time.
234+
# puts "render_data_or_redirect #{omniauth_window_type}"
235+
# puts params
224236
if ['inAppBrowser', 'newWindow'].include?(omniauth_window_type)
237+
# puts message
238+
# puts user_data
225239
render_data(message, user_data.merge(data))
226240

227241
elsif auth_origin_url # default to same-window implementation, which forwards back to auth_origin_url

devise_token_auth.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ Gem::Specification.new do |s|
3030
s.add_development_dependency 'sqlite3', '~> 1.4'
3131
s.add_development_dependency 'pg'
3232
s.add_development_dependency 'mysql2'
33-
s.add_development_dependency 'mongoid', '>= 4', '< 8'
33+
s.add_development_dependency 'mongoid', '>= 4', '< 10'
3434
s.add_development_dependency 'mongoid-locker', '~> 2.0'
3535
end

gemfiles/rails_7_2.gemfile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "omniauth", "~> 2.0"
6+
gem "omniauth-rails_csrf_protection"
7+
gem 'rails', '~> 7.2.1.2'
8+
gem "sqlite3", "~> 1.4.1"
9+
gem "mysql2"
10+
gem "pg"
11+
12+
group :development, :test do
13+
gem "attr_encrypted"
14+
gem "figaro", "~> 1.2"
15+
gem "omniauth-facebook"
16+
gem "omniauth-github"
17+
gem "omniauth-google-oauth2"
18+
gem 'omniauth-apple'
19+
gem "rack-cors"
20+
gem "thor", "~> 1.2"
21+
gem "database_cleaner"
22+
gem "factory_bot_rails"
23+
gem "faker", "~> 2.16"
24+
gem "fuzz_ball"
25+
gem "guard"
26+
gem "guard-minitest"
27+
gem "minitest"
28+
gem "minitest-focus"
29+
gem "minitest-rails", "~> 7"
30+
gem "minitest-reporters"
31+
gem "mocha", ">= 1.5"
32+
gem "pry"
33+
gem "pry-byebug"
34+
gem "pry-remote"
35+
gem "rubocop", require: false
36+
end
37+
38+
group :test do
39+
gem "rails-controller-testing"
40+
gem "simplecov", require: false
41+
end
42+
43+
group :development do
44+
gem "github_changelog_generator"
45+
end
46+
47+
gemspec path: "../"

gemfiles/rails_8_0.gemfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "omniauth", "~> 2.0"
6+
gem "omniauth-rails_csrf_protection"
7+
gem "rails", "~> 8.0.0.rc1"
8+
gem "sqlite3", "~> 1.4.1"
9+
gem "mysql2"
10+
gem "pg"
11+
gem "mongoid", git: "https://github.com/comandeo-mongo/mongoid/5818-rails-8"
12+
13+
group :development, :test do
14+
gem "attr_encrypted"
15+
gem "figaro", "~> 1.2"
16+
gem "omniauth-facebook"
17+
gem "omniauth-github"
18+
gem "omniauth-google-oauth2"
19+
gem 'omniauth-apple'
20+
gem "rack-cors"
21+
gem "thor", "~> 1.2"
22+
gem "database_cleaner"
23+
gem "factory_bot_rails"
24+
gem "faker", "~> 2.16"
25+
gem "fuzz_ball"
26+
gem "guard"
27+
gem "guard-minitest"
28+
gem "minitest"
29+
gem "minitest-focus"
30+
gem "minitest-rails", "~> 7"
31+
gem "minitest-reporters"
32+
gem "mocha", ">= 1.5"
33+
gem "pry"
34+
gem "pry-byebug"
35+
gem "pry-remote"
36+
gem "rubocop", require: false
37+
end
38+
39+
group :test do
40+
gem "rails-controller-testing"
41+
gem "simplecov", require: false
42+
end
43+
44+
group :development do
45+
gem "github_changelog_generator"
46+
end
47+
48+
gemspec path: "../"

test/controllers/devise_token_auth/confirmations_controller_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ def token_and_client_config_from(body)
7272
sign_out(@new_user)
7373
get :show,
7474
params: { confirmation_token: @token,
75-
redirect_url: @redirect_url },
76-
xhr: true
75+
redirect_url: @redirect_url }, headers: { 'CONTENT_TYPE' => 'application/json' }
7776
@resource = assigns(:resource)
7877
end
7978

test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ def get_parsed_data_json
123123
before do
124124
@fav_color = 'alizarin crimson'
125125
@unpermitted_param = 'M. Bison'
126-
post '/auth/facebook',
127-
params: { auth_origin_url: @redirect_url,
128-
favorite_color: @fav_color,
129-
name: @unpermitted_param,
130-
omniauth_window_type: 'newWindow' }
126+
params = { auth_origin_url: @redirect_url,
127+
favorite_color: @fav_color,
128+
name: @unpermitted_param,
129+
omniauth_window_type: 'newWindow' }
130+
puts(params)
131+
puts "pass additional params"
132+
post '/auth/facebook', params: params, headers: { 'CONTENT_TYPE' => 'application/json' }
131133

132134
follow_all_redirects!
133135

@@ -178,7 +180,7 @@ def get_parsed_data_json
178180
test 'response does not contain oauth_registration attr' do
179181
post '/auth/facebook',
180182
params: { auth_origin_url: @redirect_url,
181-
omniauth_window_type: 'newWindow' }
183+
omniauth_window_type: 'newWindow' }, headers: { 'CONTENT_TYPE' => 'application/json' }
182184

183185
follow_all_redirects!
184186

@@ -191,7 +193,7 @@ def get_parsed_data_json
191193
before do
192194
post '/api/v1/auth/facebook',
193195
params: { auth_origin_url: @redirect_url,
194-
omniauth_window_type: 'newWindow' }
196+
omniauth_window_type: 'newWindow' }, headers: { 'CONTENT_TYPE' => 'application/json' }
195197

196198
follow_all_redirects!
197199

@@ -236,7 +238,7 @@ def assert_expected_data_in_new_window
236238
test 'redirects to auth_origin_url with all expected query params' do
237239
post '/auth/facebook',
238240
params: { auth_origin_url: '/auth_origin',
239-
omniauth_window_type: 'sameWindow' }
241+
omniauth_window_type: 'sameWindow' }, headers: { 'CONTENT_TYPE' => 'application/json' }
240242

241243
follow_all_redirects!
242244

@@ -262,7 +264,7 @@ def get_success(params = {})
262264
params: {
263265
auth_origin_url: @redirect_url,
264266
omniauth_window_type: 'newWindow'
265-
}.merge(params)
267+
}.merge(params), headers: { 'CONTENT_TYPE' => 'application/json' }
266268

267269
follow_all_redirects!
268270

@@ -284,7 +286,7 @@ def get_success(params = {})
284286
silence_omniauth do
285287
post '/auth/facebook',
286288
params: { auth_origin_url: @redirect_url,
287-
omniauth_window_type: 'newWindow' }
289+
omniauth_window_type: 'newWindow' }, headers: { 'CONTENT_TYPE' => 'application/json' }
288290

289291
follow_all_redirects!
290292
end
@@ -341,7 +343,7 @@ def get_success(params = {})
341343
test 'request using non-whitelisted redirect fail' do
342344
post '/auth/facebook',
343345
params: { auth_origin_url: @bad_redirect_url,
344-
omniauth_window_type: 'newWindow' }
346+
omniauth_window_type: 'newWindow' }, headers: { 'CONTENT_TYPE' => 'application/json' }
345347

346348
follow_all_redirects!
347349

@@ -355,7 +357,7 @@ def get_success(params = {})
355357
params: {
356358
auth_origin_url: @good_redirect_url,
357359
omniauth_window_type: 'newWindow'
358-
}
360+
}#, headers: { 'CONTENT_TYPE' => 'application/json' }
359361

360362
follow_all_redirects!
361363

test/dummy/config/environments/test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }) :
2424
(config.static_cache_control = 'public, max-age=3600')
2525

26-
if Rails::VERSION::MAJOR > 6 && ENV['DEVISE_TOKEN_AUTH_ORM'] != 'mongoid'
26+
if Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 0 && ENV['DEVISE_TOKEN_AUTH_ORM'] != 'mongoid'
2727
config.active_record.legacy_connection_handling = false
2828
end
2929

test/test_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def follow_all_redirects!
3838
class ActiveSupport::TestCase
3939
include FactoryBot::Syntax::Methods
4040

41-
ActiveRecord::Migration.check_pending! if DEVISE_TOKEN_AUTH_ORM == :active_record
41+
# ActiveRecord::Migration.check_pending! if DEVISE_TOKEN_AUTH_ORM == :active_record
4242

4343
strategies = { active_record: :transaction,
4444
mongoid: :deletion }

0 commit comments

Comments
 (0)