FIX: Don't error out on empty reserved_usernames setting (#29305)

We're seeing errors in logs due to some sites setting the reserved_usernames setting to nil. This is causing multiple use cases upstream of User#reserved_username? to error out.

This commit changes from using the raw #reserved_usernames to using the #reserved_usernames_map helper which exists on list-type site settings. It returns an empty array if the raw value is nil or empty string.
This commit is contained in:
Ted Johansson
2024-10-21 14:38:37 +08:00
committed by GitHub
parent 6f55457652
commit 56df077931
5 changed files with 19 additions and 11 deletions

View File

@ -12,6 +12,8 @@ RSpec.describe DiscourseConnect do
Jobs.run_immediately!
end
let(:fallback_username) { I18n.t("fallback_username") + "1" }
def make_sso
sso = DiscourseConnectBase.new
sso.sso_url = "http://meta.discorse.org/topics/111"
@ -576,7 +578,7 @@ RSpec.describe DiscourseConnect do
sso.email = "mail@mail.com"
user = sso.lookup_or_create_user(ip_address)
expect(user.username).to eq "user"
expect(user.username).to eq(fallback_username)
end
it "doesn't use email as a source for username suggestions by default" do
@ -589,7 +591,7 @@ RSpec.describe DiscourseConnect do
sso.email = "mail@mail.com"
user = sso.lookup_or_create_user(ip_address)
expect(user.username).to eq I18n.t("fallback_username")
expect(user.username).to eq(fallback_username)
end
it "uses email as a source for username suggestions if enabled" do