DEV: add test cases that prove that sso can override username from "bob1" to "bob" (#14555)

The problem was reported a long time ago (https://meta.discourse.org/t/cannot-change-username-with-sso-enabled/31307). It's hard to say if this bag didn't exist or was fixed later, but test cases in this PR prove that this works now.
This commit is contained in:
Andrei Prigorshnev 2021-10-07 22:29:24 +04:00 committed by GitHub
parent aa00960638
commit e68dc0c598
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -346,6 +346,52 @@ describe DiscourseSingleSignOn do
expect(admin.name).to eq "Louis C.K."
end
it "can override username with a number at the end to a simpler username without a number" do
SiteSetting.auth_overrides_username = true
user = Fabricate(:user)
sso = new_discourse_sso
sso.external_id = "A"
sso.email = user.email
username_with_number = "bob1"
username_without_number = "bob"
sso.username = username_with_number
sso.lookup_or_create_user(ip_address)
user.reload
expect(user.username).to eq username_with_number
sso.username = username_without_number
sso.lookup_or_create_user(ip_address)
user.reload
expect(user.username).to eq username_without_number
end
it "can override username after min_username_length was made smaller" do
SiteSetting.auth_overrides_username = true
user = Fabricate(:user)
sso = new_discourse_sso
sso.external_id = "A"
sso.email = user.email
long_username = "bob"
short_username = "bo"
SiteSetting.min_username_length = 3
sso.username = long_username
sso.lookup_or_create_user(ip_address)
user.reload
expect(user.username).to eq long_username
SiteSetting.min_username_length = 2
sso.username = short_username
sso.lookup_or_create_user(ip_address)
user.reload
expect(user.username).to eq short_username
end
it "can fill in data on way back" do
sso = make_sso