mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Rework usage of OIDC auto-registration and email/password registration settings to use constants instead of direct ENV access.
This commit is contained in:
parent
f8be3ecdca
commit
52eb80503d
8 changed files with 22 additions and 44 deletions
|
|
@ -62,9 +62,6 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||||
end
|
end
|
||||||
|
|
||||||
def oidc_auto_register_enabled?
|
def oidc_auto_register_enabled?
|
||||||
env_value = ENV['OIDC_AUTO_REGISTER']
|
OIDC_AUTO_REGISTER
|
||||||
return true if env_value.nil?
|
|
||||||
|
|
||||||
ActiveModel::Type::Boolean.new.cast(env_value)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -99,9 +99,6 @@ class Users::RegistrationsController < Devise::RegistrationsController
|
||||||
end
|
end
|
||||||
|
|
||||||
def email_password_registration_allowed?
|
def email_password_registration_allowed?
|
||||||
env_value = ENV['ALLOW_EMAIL_PASSWORD_REGISTRATION']
|
ALLOW_EMAIL_PASSWORD_REGISTRATION
|
||||||
return false if env_value.nil?
|
|
||||||
|
|
||||||
ActiveModel::Type::Boolean.new.cast(env_value)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -140,9 +140,6 @@ module ApplicationHelper
|
||||||
def email_password_registration_enabled?
|
def email_password_registration_enabled?
|
||||||
return true unless DawarichSettings.self_hosted?
|
return true unless DawarichSettings.self_hosted?
|
||||||
|
|
||||||
env_value = ENV['ALLOW_EMAIL_PASSWORD_REGISTRATION']
|
ALLOW_EMAIL_PASSWORD_REGISTRATION
|
||||||
return false if env_value.nil?
|
|
||||||
|
|
||||||
ActiveModel::Type::Boolean.new.cast(env_value)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,7 @@ module Omniauthable
|
||||||
private
|
private
|
||||||
|
|
||||||
def oidc_auto_register_enabled?
|
def oidc_auto_register_enabled?
|
||||||
# Default to true for backward compatibility
|
OIDC_AUTO_REGISTER
|
||||||
env_value = ENV['OIDC_AUTO_REGISTER']
|
|
||||||
return true if env_value.nil?
|
|
||||||
|
|
||||||
ActiveModel::Type::Boolean.new.cast(env_value)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -56,3 +56,9 @@ OMNIAUTH_PROVIDERS =
|
||||||
|
|
||||||
# Custom OIDC provider display name
|
# Custom OIDC provider display name
|
||||||
OIDC_PROVIDER_NAME = ENV.fetch('OIDC_PROVIDER_NAME', 'Openid Connect').freeze
|
OIDC_PROVIDER_NAME = ENV.fetch('OIDC_PROVIDER_NAME', 'Openid Connect').freeze
|
||||||
|
|
||||||
|
# OIDC auto-registration setting (default: true for backward compatibility)
|
||||||
|
OIDC_AUTO_REGISTER = ENV.fetch('OIDC_AUTO_REGISTER', 'true') == 'true'
|
||||||
|
|
||||||
|
# Email/password registration setting (default: false for self-hosted, true for cloud)
|
||||||
|
ALLOW_EMAIL_PASSWORD_REGISTRATION = ENV.fetch('ALLOW_EMAIL_PASSWORD_REGISTRATION', 'false') == 'true'
|
||||||
|
|
|
||||||
|
|
@ -46,11 +46,8 @@ RSpec.describe ApplicationHelper, type: :helper do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when ALLOW_EMAIL_PASSWORD_REGISTRATION is true' do
|
context 'when ALLOW_EMAIL_PASSWORD_REGISTRATION is true' do
|
||||||
around do |example|
|
before do
|
||||||
original_value = ENV['ALLOW_EMAIL_PASSWORD_REGISTRATION']
|
stub_const('ALLOW_EMAIL_PASSWORD_REGISTRATION', true)
|
||||||
ENV['ALLOW_EMAIL_PASSWORD_REGISTRATION'] = 'true'
|
|
||||||
example.run
|
|
||||||
ENV['ALLOW_EMAIL_PASSWORD_REGISTRATION'] = original_value
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns true' do
|
it 'returns true' do
|
||||||
|
|
@ -59,11 +56,8 @@ RSpec.describe ApplicationHelper, type: :helper do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when ALLOW_EMAIL_PASSWORD_REGISTRATION is false' do
|
context 'when ALLOW_EMAIL_PASSWORD_REGISTRATION is false' do
|
||||||
around do |example|
|
before do
|
||||||
original_value = ENV['ALLOW_EMAIL_PASSWORD_REGISTRATION']
|
stub_const('ALLOW_EMAIL_PASSWORD_REGISTRATION', false)
|
||||||
ENV['ALLOW_EMAIL_PASSWORD_REGISTRATION'] = 'false'
|
|
||||||
example.run
|
|
||||||
ENV['ALLOW_EMAIL_PASSWORD_REGISTRATION'] = original_value
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns false' do
|
it 'returns false' do
|
||||||
|
|
@ -71,12 +65,9 @@ RSpec.describe ApplicationHelper, type: :helper do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when ALLOW_EMAIL_PASSWORD_REGISTRATION is not set' do
|
context 'when ALLOW_EMAIL_PASSWORD_REGISTRATION is not set (default)' do
|
||||||
around do |example|
|
before do
|
||||||
original_value = ENV['ALLOW_EMAIL_PASSWORD_REGISTRATION']
|
stub_const('ALLOW_EMAIL_PASSWORD_REGISTRATION', false)
|
||||||
ENV.delete('ALLOW_EMAIL_PASSWORD_REGISTRATION')
|
|
||||||
example.run
|
|
||||||
ENV['ALLOW_EMAIL_PASSWORD_REGISTRATION'] = original_value
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns false (default)' do
|
it 'returns false (default)' do
|
||||||
|
|
|
||||||
|
|
@ -65,11 +65,8 @@ RSpec.describe 'Users::OmniauthCallbacks', type: :request do
|
||||||
include_examples 'successful OAuth authentication', :openid_connect, 'OpenID Connect'
|
include_examples 'successful OAuth authentication', :openid_connect, 'OpenID Connect'
|
||||||
|
|
||||||
context 'when OIDC auto-registration is disabled' do
|
context 'when OIDC auto-registration is disabled' do
|
||||||
around do |example|
|
before do
|
||||||
original_value = ENV['OIDC_AUTO_REGISTER']
|
stub_const('OIDC_AUTO_REGISTER', false)
|
||||||
ENV['OIDC_AUTO_REGISTER'] = 'false'
|
|
||||||
example.run
|
|
||||||
ENV['OIDC_AUTO_REGISTER'] = original_value
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when user doesn't exist" do
|
context "when user doesn't exist" do
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ RSpec.describe 'Users::Registrations', type: :request do
|
||||||
|
|
||||||
context 'when accessing registration without invitation token and email/password registration disabled' do
|
context 'when accessing registration without invitation token and email/password registration disabled' do
|
||||||
before do
|
before do
|
||||||
allow(ENV).to receive(:[]).with('ALLOW_EMAIL_PASSWORD_REGISTRATION').and_return(nil)
|
stub_const('ALLOW_EMAIL_PASSWORD_REGISTRATION', false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirects to root with error message' do
|
it 'redirects to root with error message' do
|
||||||
|
|
@ -169,11 +169,8 @@ RSpec.describe 'Users::Registrations', type: :request do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when email/password registration is enabled' do
|
context 'when email/password registration is enabled' do
|
||||||
around do |example|
|
before do
|
||||||
original_value = ENV['ALLOW_EMAIL_PASSWORD_REGISTRATION']
|
stub_const('ALLOW_EMAIL_PASSWORD_REGISTRATION', true)
|
||||||
ENV['ALLOW_EMAIL_PASSWORD_REGISTRATION'] = 'true'
|
|
||||||
example.run
|
|
||||||
ENV['ALLOW_EMAIL_PASSWORD_REGISTRATION'] = original_value
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'allows registration page access' do
|
it 'allows registration page access' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue