Skip to content

Commit

Permalink
Test against 7.2 and 8
Browse files Browse the repository at this point in the history
  • Loading branch information
MaicolBen committed Oct 26, 2024
1 parent b7fcfdf commit 6fc0c0f
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 25 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
- gemfiles/rails_5_2.gemfile
- gemfiles/rails_6_0.gemfile
- gemfiles/rails_7_0.gemfile
- gemfiles/rails_7_2.gemfile
- gemfiles/rails_8_0.gemfile
db:
- sqlite
- mysql
Expand Down Expand Up @@ -51,6 +53,7 @@ jobs:
- ruby: 3.2
gemfile: gemfiles/rails_7_0_mongoid_7.gemfile
devise-token-auth-orm: mongoid
# TODO: add mongoid for rails 7.2
exclude:
- ruby: 2.7
gemfile: gemfiles/rails_4_2.gemfile
Expand All @@ -60,6 +63,10 @@ jobs:
gemfile: gemfiles/rails_5_1.gemfile
- ruby: 2.7
gemfile: gemfiles/rails_5_2.gemfile
- ruby: 2.7
gemfile: gemfiles/rails_7_2.gemfile
- ruby: 2.7
gemfile: gemfiles/rails_8_0.gemfile
- ruby: '3.0'
gemfile: gemfiles/rails_4_2.gemfile
- ruby: '3.0'
Expand All @@ -70,6 +77,10 @@ jobs:
gemfile: gemfiles/rails_5_2.gemfile
- ruby: '3.0'
gemfile: gemfiles/rails_6_0.gemfile
- ruby: '3.0'
gemfile: gemfiles/rails_7_2.gemfile
- ruby: '3.0'
gemfile: gemfiles/rails_8_0.gemfile
- ruby: 3.1
gemfile: gemfiles/rails_4_2.gemfile
- ruby: 3.1
Expand Down
20 changes: 16 additions & 4 deletions app/controllers/devise_token_auth/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class OmniauthCallbacksController < DeviseTokenAuth::ApplicationController
skip_before_action :set_user_by_token, raise: false
skip_after_action :update_auth_header

before_action do
puts "before_action omniauth_params"
puts params
end

# intermediary route for successful omniauth authentication. omniauth does
# not support multiple models, so we must resort to this terrible hack.
def redirect_callbacks
Expand Down Expand Up @@ -55,21 +60,23 @@ def default_devise_mapping
end

def omniauth_success
puts "omniauth_success"
get_resource_from_auth_hash
puts "get_resource_from_auth_hash"
set_token_on_resource
create_auth_params

if confirmable_enabled?
# don't send confirmation email!!!
@resource.skip_confirmation!
end

puts "before sign in"
sign_in(:user, @resource, store: false, bypass: false)

@resource.save!
puts "after sign in"
puts @resource.save!

yield @resource if block_given?

puts "after yield"
if DeviseTokenAuth.cookie_enabled
set_token_in_cookie(@resource, @token)
end
Expand Down Expand Up @@ -105,6 +112,7 @@ def omniauth_params
@_omniauth_params ||= session.delete('dta.omniauth.params')
@_omniauth_params
elsif params['omniauth_window_type']

@_omniauth_params = params.slice('omniauth_window_type', 'auth_origin_url', 'resource_class', 'origin')
else
@_omniauth_params = {}
Expand Down Expand Up @@ -221,7 +229,11 @@ def render_data_or_redirect(message, data, user_data = {})
# See app/views/devise_token_auth/omniauth_external_window.html.erb to understand
# why we can handle these both the same. The view is setup to handle both cases
# at the same time.
puts "render_data_or_redirect #{omniauth_window_type}"
puts params
if ['inAppBrowser', 'newWindow'].include?(omniauth_window_type)
puts message
puts user_data
render_data(message, user_data.merge(data))

elsif auth_origin_url # default to same-window implementation, which forwards back to auth_origin_url
Expand Down
2 changes: 1 addition & 1 deletion devise_token_auth.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ Gem::Specification.new do |s|
s.add_development_dependency 'sqlite3', '~> 1.4'
s.add_development_dependency 'pg'
s.add_development_dependency 'mysql2'
s.add_development_dependency 'mongoid', '>= 4', '< 8'
s.add_development_dependency 'mongoid', '>= 4', '< 10'
s.add_development_dependency 'mongoid-locker', '~> 2.0'
end
47 changes: 47 additions & 0 deletions gemfiles/rails_7_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "omniauth", "~> 2.0"
gem "omniauth-rails_csrf_protection"
gem 'rails', '~> 7.2.1.2'
gem "sqlite3", "~> 1.4.1"
gem "mysql2"
gem "pg"

group :development, :test do
gem "attr_encrypted"
gem "figaro", "~> 1.2"
gem "omniauth-facebook"
gem "omniauth-github"
gem "omniauth-google-oauth2"
gem 'omniauth-apple'
gem "rack-cors"
gem "thor", "~> 1.2"
gem "database_cleaner"
gem "factory_bot_rails"
gem "faker", "~> 2.16"
gem "fuzz_ball"
gem "guard"
gem "guard-minitest"
gem "minitest"
gem "minitest-focus"
gem "minitest-rails", "~> 7"
gem "minitest-reporters"
gem "mocha", ">= 1.5"
gem "pry"
gem "pry-byebug"
gem "pry-remote"
gem "rubocop", require: false
end

group :test do
gem "rails-controller-testing"
gem "simplecov", require: false
end

group :development do
gem "github_changelog_generator"
end

gemspec path: "../"
48 changes: 48 additions & 0 deletions gemfiles/rails_8_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "omniauth", "~> 2.0"
gem "omniauth-rails_csrf_protection"
gem "rails", "~> 8.0.0.rc1"
gem "sqlite3", "~> 1.4.1"
gem "mysql2"
gem "pg"
gem "mongoid", git: "https://github.com/comandeo-mongo/mongoid/5818-rails-8"

group :development, :test do
gem "attr_encrypted"
gem "figaro", "~> 1.2"
gem "omniauth-facebook"
gem "omniauth-github"
gem "omniauth-google-oauth2"
gem 'omniauth-apple'
gem "rack-cors"
gem "thor", "~> 1.2"
gem "database_cleaner"
gem "factory_bot_rails"
gem "faker", "~> 2.16"
gem "fuzz_ball"
gem "guard"
gem "guard-minitest"
gem "minitest"
gem "minitest-focus"
gem "minitest-rails", "~> 7"
gem "minitest-reporters"
gem "mocha", ">= 1.5"
gem "pry"
gem "pry-byebug"
gem "pry-remote"
gem "rubocop", require: false
end

group :test do
gem "rails-controller-testing"
gem "simplecov", require: false
end

group :development do
gem "github_changelog_generator"
end

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_parsed_data_json
params: {
auth_origin_url: @redirect_url,
omniauth_window_type: 'newWindow'
}
}, as: :json

follow_all_redirects!

Expand All @@ -123,11 +123,13 @@ def get_parsed_data_json
before do
@fav_color = 'alizarin crimson'
@unpermitted_param = 'M. Bison'
post '/auth/facebook',
params: { auth_origin_url: @redirect_url,
favorite_color: @fav_color,
name: @unpermitted_param,
omniauth_window_type: 'newWindow' }
params = { auth_origin_url: @redirect_url,
favorite_color: @fav_color,
name: @unpermitted_param,
omniauth_window_type: 'newWindow' }
puts(params)
puts "pass additional params"
post '/auth/facebook', params: params, as: :json

follow_all_redirects!

Expand Down Expand Up @@ -162,7 +164,7 @@ def get_parsed_data_json
test 'response contains oauth_registration attr' do
post '/auth/facebook',
params: { auth_origin_url: @redirect_url,
omniauth_window_type: 'newWindow' }
omniauth_window_type: 'newWindow' }, as: :json

follow_all_redirects!

Expand All @@ -178,7 +180,7 @@ def get_parsed_data_json
test 'response does not contain oauth_registration attr' do
post '/auth/facebook',
params: { auth_origin_url: @redirect_url,
omniauth_window_type: 'newWindow' }
omniauth_window_type: 'newWindow' }, as: :json

follow_all_redirects!

Expand All @@ -191,7 +193,7 @@ def get_parsed_data_json
before do
post '/api/v1/auth/facebook',
params: { auth_origin_url: @redirect_url,
omniauth_window_type: 'newWindow' }
omniauth_window_type: 'newWindow' }, as: :json

follow_all_redirects!

Expand Down Expand Up @@ -236,7 +238,7 @@ def assert_expected_data_in_new_window
test 'redirects to auth_origin_url with all expected query params' do
post '/auth/facebook',
params: { auth_origin_url: '/auth_origin',
omniauth_window_type: 'sameWindow' }
omniauth_window_type: 'sameWindow' }, as: :json

follow_all_redirects!

Expand All @@ -262,7 +264,7 @@ def get_success(params = {})
params: {
auth_origin_url: @redirect_url,
omniauth_window_type: 'newWindow'
}.merge(params)
}.merge(params), as: :json

follow_all_redirects!

Expand All @@ -284,7 +286,7 @@ def get_success(params = {})
silence_omniauth do
post '/auth/facebook',
params: { auth_origin_url: @redirect_url,
omniauth_window_type: 'newWindow' }
omniauth_window_type: 'newWindow' }, as: :json

follow_all_redirects!
end
Expand All @@ -310,7 +312,7 @@ def get_success(params = {})
test 'OnlyEmailUser should not be able to use OAuth' do
assert_raises(ActionController::RoutingError) do
get '/only_email_auth/facebook',
params: { auth_origin_url: @redirect_url }
params: { auth_origin_url: @redirect_url }, as: :json
follow_all_redirects!
end
end
Expand Down Expand Up @@ -341,7 +343,7 @@ def get_success(params = {})
test 'request using non-whitelisted redirect fail' do
post '/auth/facebook',
params: { auth_origin_url: @bad_redirect_url,
omniauth_window_type: 'newWindow' }
omniauth_window_type: 'newWindow' }, as: :json

follow_all_redirects!

Expand All @@ -355,7 +357,7 @@ def get_success(params = {})
params: {
auth_origin_url: @good_redirect_url,
omniauth_window_type: 'newWindow'
}
}, as: :json

follow_all_redirects!

Expand All @@ -367,7 +369,7 @@ def get_success(params = {})
DeviseTokenAuth.redirect_whitelist = ["#{@good_redirect_url[0..8]}*"]
post '/auth/facebook',
params: { auth_origin_url: @good_redirect_url,
omniauth_window_type: 'newWindow' }
omniauth_window_type: 'newWindow' }, as: :json

follow_all_redirects!

Expand Down Expand Up @@ -399,7 +401,7 @@ def get_success(params = {})
test 'request using non-whitelisted redirect fail' do
post '/auth/facebook',
params: { auth_origin_url: @bad_redirect_url,
omniauth_window_type: 'sameWindow' }
omniauth_window_type: 'sameWindow' }, as: :json

follow_all_redirects!

Expand All @@ -426,7 +428,7 @@ def get_success(params = {})
params: {
auth_origin_url: '/auth_origin',
omniauth_window_type: 'sameWindow'
}
}, as: :json

follow_all_redirects!

Expand Down
2 changes: 1 addition & 1 deletion test/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
(config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }) :
(config.static_cache_control = 'public, max-age=3600')

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

Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def follow_all_redirects!
class ActiveSupport::TestCase
include FactoryBot::Syntax::Methods

ActiveRecord::Migration.check_pending! if DEVISE_TOKEN_AUTH_ORM == :active_record
# ActiveRecord::Migration.check_pending! if DEVISE_TOKEN_AUTH_ORM == :active_record

strategies = { active_record: :transaction,
mongoid: :deletion }
Expand Down

0 comments on commit 6fc0c0f

Please sign in to comment.