1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-28 09:24:24 +01:00

(bug) updating the current provider must be reflected in yml

This commit is contained in:
Sylvain 2023-03-30 17:17:02 +02:00
parent 3811e7a6d5
commit 48d0957bac
5 changed files with 31 additions and 17 deletions

View File

@ -7,7 +7,7 @@ class SessionsController < Devise::SessionsController
if active_provider.providable_type == 'DatabaseProvider' if active_provider.providable_type == 'DatabaseProvider'
super super
else else
redirect_post "/users/auth/#{active_provider.strategy_name}", params: { authenticity_token: form_authenticity_token } redirect_post "/users/auth/#{active_provider.strategy_name}"
end end
end end
end end

View File

@ -30,6 +30,7 @@ class AuthProvider < ApplicationRecord
validates_with UserUidMappedValidator, if: -> { %w[OAuth2Provider OpenIdConnectProvider].include?(providable_type) } validates_with UserUidMappedValidator, if: -> { %w[OAuth2Provider OpenIdConnectProvider].include?(providable_type) }
before_create :set_initial_state before_create :set_initial_state
after_update :write_config
def build_providable(params) def build_providable(params)
raise "Unknown providable_type: #{providable_type}" unless PROVIDABLE_TYPES.include?(providable_type) raise "Unknown providable_type: #{providable_type}" unless PROVIDABLE_TYPES.include?(providable_type)
@ -114,4 +115,10 @@ class AuthProvider < ApplicationRecord
# no providers in the database, he we will be 'active' (see seeds.rb) # no providers in the database, he we will be 'active' (see seeds.rb)
self.status = 'pending' unless AuthProvider.count.zero? self.status = 'pending' unless AuthProvider.count.zero?
end end
def write_config
return unless status == 'active'
ProviderConfig.write_active_provider
end
end end

View File

@ -41,7 +41,7 @@ module AuthProviderHelper
issuer: 'https://sso.sleede.dev/auth/realms/master', issuer: 'https://sso.sleede.dev/auth/realms/master',
discovery: true, discovery: true,
client_auth_method: 'basic', client_auth_method: 'basic',
scope: %w[openid profile email toto], scope: %w[openid profile email],
prompt: 'consent', prompt: 'consent',
send_scope_to_token_endpoint: true, send_scope_to_token_endpoint: true,
profile_url: 'https://sso.sleede.dev/auth/realms/master/account/', profile_url: 'https://sso.sleede.dev/auth/realms/master/account/',

View File

@ -13,6 +13,9 @@ class AuthProvidersTest < ActionDispatch::IntegrationTest
end end
test 'create an auth external provider and activate it' do test 'create an auth external provider and activate it' do
# clean any existing auth provider config
FileUtils.rm('config/auth_provider.yml', force: true)
name = 'GitHub' name = 'GitHub'
post '/api/auth_providers', post '/api/auth_providers',
params: { params: {
@ -43,6 +46,15 @@ class AuthProvidersTest < ActionDispatch::IntegrationTest
User.find_each do |u| User.find_each do |u|
assert_not_nil u.auth_token assert_not_nil u.auth_token
end end
# Check the configuration file
assert File.exist?('config/auth_provider.yml')
config = ProviderConfig.new
assert_equal 'OAuth2Provider', config.providable_type
assert_equal name, config.name
# clean test provider config
FileUtils.rm('config/auth_provider.yml', force: true)
end end
test 'update an authentication provider' do test 'update an authentication provider' do

View File

@ -13,6 +13,9 @@ class OpenIdConnectTest < ActionDispatch::IntegrationTest
end end
test 'create and activate an OIDC provider' do test 'create and activate an OIDC provider' do
# clean any existing auth provider config
FileUtils.rm('config/auth_provider.yml', force: true)
name = 'Sleede' name = 'Sleede'
post '/api/auth_providers', post '/api/auth_providers',
params: { params: {
@ -42,21 +45,13 @@ class OpenIdConnectTest < ActionDispatch::IntegrationTest
assert_equal 'active', db_provider&.status assert_equal 'active', db_provider&.status
assert_equal AuthProvider.active.id, db_provider&.id assert_equal AuthProvider.active.id, db_provider&.id
# TODO, login with the SSO (need debugging) # Check the configuration file
## The following doesn't work but I can't find out why... Maybe configuring Devise like this is not the right way, assert File.exist?('config/auth_provider.yml')
## but when testing the process with Capybara, I always fall with the message "Not found. Authentication passthru." config = ProviderConfig.new
assert_equal 'OpenIdConnectProvider', config.providable_type
assert_equal name, config.name
# Simulate an application restart (reload routes and change devise setup) # clean test provider config
# logout FileUtils.rm('config/auth_provider.yml', force: true)
# Devise.setup do |config|
# require_relative '../../lib/omni_auth/openid_connect'
# config.omniauth OmniAuth::Strategies::SsoOpenidConnectProvider.name&.to_sym,
# db_provider&.providable&.config
# end
# User.devise :omniauthable, omniauth_providers: [db_provider&.strategy_name&.to_sym]
# Rails.application.reload_routes!
#
# === OR === (need to try)
# Rails.application.reloader.reload!
end end
end end