Skip to content

Commit e68dc0c

Browse files
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.
1 parent aa00960 commit e68dc0c

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

spec/models/discourse_single_sign_on_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,52 @@ def test_parsed(parsed, sso)
346346
expect(admin.name).to eq "Louis C.K."
347347
end
348348

349+
it "can override username with a number at the end to a simpler username without a number" do
350+
SiteSetting.auth_overrides_username = true
351+
352+
user = Fabricate(:user)
353+
sso = new_discourse_sso
354+
sso.external_id = "A"
355+
sso.email = user.email
356+
357+
username_with_number = "bob1"
358+
username_without_number = "bob"
359+
360+
sso.username = username_with_number
361+
sso.lookup_or_create_user(ip_address)
362+
user.reload
363+
expect(user.username).to eq username_with_number
364+
365+
sso.username = username_without_number
366+
sso.lookup_or_create_user(ip_address)
367+
user.reload
368+
expect(user.username).to eq username_without_number
369+
end
370+
371+
it "can override username after min_username_length was made smaller" do
372+
SiteSetting.auth_overrides_username = true
373+
374+
user = Fabricate(:user)
375+
sso = new_discourse_sso
376+
sso.external_id = "A"
377+
sso.email = user.email
378+
379+
long_username = "bob"
380+
short_username = "bo"
381+
382+
SiteSetting.min_username_length = 3
383+
sso.username = long_username
384+
sso.lookup_or_create_user(ip_address)
385+
user.reload
386+
expect(user.username).to eq long_username
387+
388+
SiteSetting.min_username_length = 2
389+
sso.username = short_username
390+
sso.lookup_or_create_user(ip_address)
391+
user.reload
392+
expect(user.username).to eq short_username
393+
end
394+
349395
it "can fill in data on way back" do
350396
sso = make_sso
351397

0 commit comments

Comments
 (0)