refactor: improve SSO provider management and logging

- Simplified `name_id_format` selection logic in SSO provider form.
- Switched raw database query to sanitized SQL in client secret tests.
- Added condition to log JIT account creation only when identity persists.
- Sanitized failure reasons in SSO login failure handling.
- Added SSO provider connection test policy tests for super admin and regular users.
This commit is contained in:
Josh Waldrep
2026-01-03 21:13:24 -05:00
parent d3055b2e0b
commit b2ecc6bc67
5 changed files with 28 additions and 13 deletions

View File

@@ -96,9 +96,11 @@ class SsoProviderTest < ActiveSupport::TestCase
assert_equal "super_secret_value", provider.client_secret
# Raw database value should be encrypted (not plain text)
raw_value = ActiveRecord::Base.connection.execute(
"SELECT client_secret FROM sso_providers WHERE id = '#{provider.id}'"
).first["client_secret"]
raw_value = ActiveRecord::Base.connection.select_value(
ActiveRecord::Base.sanitize_sql_array(
[ "SELECT client_secret FROM sso_providers WHERE id = ?", provider.id ]
)
)
assert_not_equal "super_secret_value", raw_value
end

View File

@@ -86,6 +86,14 @@ class SsoProviderPolicyTest < ActiveSupport::TestCase
assert_not SsoProviderPolicy.new(@regular_user, @provider).toggle?
end
test "super admin can test connection" do
assert SsoProviderPolicy.new(@super_admin, @provider).test_connection?
end
test "regular user cannot test connection" do
assert_not SsoProviderPolicy.new(@regular_user, @provider).test_connection?
end
test "scope returns all providers for super admin" do
SsoProvider.create!(
strategy: "google_oauth2",