fix(signup): normalize account signup config checks

This commit is contained in:
Shivam Mishra
2026-03-10 14:04:33 +05:30
parent 9e918e0a9f
commit a94e252fdc
5 changed files with 81 additions and 4 deletions
@@ -100,7 +100,7 @@ class Api::V1::AccountsController < Api::BaseController
end
def check_signup_enabled
raise ActionController::RoutingError, 'Not Found' if GlobalConfigService.load('ENABLE_ACCOUNT_SIGNUP', 'false') == 'false'
raise ActionController::RoutingError, 'Not Found' unless GlobalConfigService.account_signup_enabled?
end
def validate_captcha
@@ -58,7 +58,7 @@ class Api::V2::AccountsController < Api::BaseController
end
def check_signup_enabled
raise ActionController::RoutingError, 'Not Found' if GlobalConfigService.load('ENABLE_ACCOUNT_SIGNUP', 'false') == 'false'
raise ActionController::RoutingError, 'Not Found' unless GlobalConfigService.account_signup_enabled?
end
def validate_captcha
@@ -51,8 +51,7 @@ class DeviseOverrides::OmniauthCallbacksController < DeviseTokenAuth::OmniauthCa
end
def account_signup_allowed?
# set it to true by default, this is the behaviour across the app
GlobalConfigService.load('ENABLE_ACCOUNT_SIGNUP', 'false') != 'false'
GlobalConfigService.account_signup_enabled?
end
def resource_class(_mapping = nil)
+4
View File
@@ -14,4 +14,8 @@ class GlobalConfigService
GlobalConfig.clear_cache
i.value
end
def self.account_signup_enabled?
load('ENABLE_ACCOUNT_SIGNUP', 'false').to_s != 'false'
end
end
+74
View File
@@ -0,0 +1,74 @@
require 'rails_helper'
RSpec.describe 'Signup enforcement', type: :request do
let(:signup_config_name) { 'ENABLE_ACCOUNT_SIGNUP' }
before do
GlobalConfig.clear_cache
InstallationConfig.where(name: signup_config_name).delete_all
InstallationConfig.create!(name: signup_config_name, value: false, locked: false)
end
after do
InstallationConfig.where(name: signup_config_name).delete_all
GlobalConfig.clear_cache
OmniAuth.config.mock_auth[:google_oauth2] = nil
end
describe 'POST /api/v1/accounts' do
it 'blocks signup when the config is stored as boolean false' do
post api_v1_accounts_url,
params: {
account_name: 'verify',
user_full_name: 'Verify User',
email: "verify-#{SecureRandom.hex(4)}@example.com",
password: 'Password1!'
},
as: :json
expect(response).to have_http_status(:not_found)
end
end
describe 'POST /api/v2/accounts' do
it 'blocks signup when the config is stored as boolean false' do
post api_v2_accounts_url,
params: {
email: "verify-#{SecureRandom.hex(4)}@example.com",
password: 'Password1!'
},
as: :json
expect(response).to have_http_status(:not_found)
end
end
describe 'GET /omniauth/google_oauth2/callback' do
let(:email_validation_service) { instance_double(Account::SignUpEmailValidationService, perform: true) }
before do
OmniAuth.config.test_mode = true
allow(Account::SignUpEmailValidationService).to receive(:new).and_return(email_validation_service)
end
it 'redirects to no-account-found when the config is stored as boolean false' do
OmniAuth.config.mock_auth[:google_oauth2] = OmniAuth::AuthHash.new(
provider: 'google',
uid: '123545',
info: {
name: 'test',
email: "verify-#{SecureRandom.hex(4)}@example.com",
image: 'https://example.com/image.jpg'
}
)
with_modified_env FRONTEND_URL: 'http://www.example.com' do
get '/omniauth/google_oauth2/callback'
expect(response).to redirect_to('http://www.example.com/auth/google_oauth2/callback')
follow_redirect!
expect(response).to redirect_to(%r{/app/login\?error=no-account-found$})
end
end
end
end