mirror of
https://github.com/discourse/discourse.git
synced 2026-03-03 23:54:20 +08:00
When `use_email_for_username_and_name_suggestions` is disabled, the username suggester was falling back to generic usernames like "user1", "user2", etc. These suggestions are rarely helpful as they create indistinct usernames that users often accept without modification, resulting in forums populated with "user763", "user764", etc. This change adds an `allow_generic_fallback` option to `UserNameSuggester.suggest()`. When set to false, it returns nil instead of falling back to generic "userN" usernames. The OAuth authentication flow now uses this option, leaving the username field blank so users must choose their own meaningful username. Ref - https://meta.discourse.org/t/391542
60 lines
1.8 KiB
Ruby
60 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe "discourse login client auth" do
|
|
include OmniauthHelpers
|
|
|
|
before do
|
|
OmniAuth.config.test_mode = true
|
|
SiteSetting.discourse_id_client_id = "asdasd"
|
|
SiteSetting.discourse_id_client_secret = "wadayathink"
|
|
SiteSetting.enable_discourse_id = true
|
|
|
|
OmniAuth.config.mock_auth[:discourse_id] = OmniAuth::AuthHash.new(
|
|
provider: "discourse_id",
|
|
uid: OmniauthHelpers::UID,
|
|
info:
|
|
OmniAuth::AuthHash::InfoHash.new(
|
|
email: OmniauthHelpers::EMAIL,
|
|
nickname: OmniauthHelpers::USERNAME,
|
|
),
|
|
)
|
|
end
|
|
|
|
after { reset_omniauth_config(:discourse_id) }
|
|
|
|
let(:signup_form) { PageObjects::Pages::Signup.new }
|
|
|
|
context "when user does not exist" do
|
|
context "when auth_skip_create_confirm is false" do
|
|
before { SiteSetting.auth_skip_create_confirm = false }
|
|
|
|
it "skips the signup form and creates the account directly" do
|
|
visit("/")
|
|
signup_form.open.click_social_button("discourse_id")
|
|
expect(page).to have_css(".login-welcome-header")
|
|
end
|
|
end
|
|
|
|
context "when auth_skip_create_confirm is true" do
|
|
before { SiteSetting.auth_skip_create_confirm = true }
|
|
|
|
it "skips the signup form and creates the account directly" do
|
|
visit("/")
|
|
signup_form.open.click_social_button("discourse_id")
|
|
expect(page).to have_css(".header-dropdown-toggle.current-user")
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when user exists" do
|
|
fab!(:user) do
|
|
Fabricate(:user, email: OmniauthHelpers::EMAIL, username: OmniauthHelpers::USERNAME)
|
|
end
|
|
|
|
it "logs in user" do
|
|
visit("/")
|
|
signup_form.open.click_social_button("discourse_id")
|
|
expect(page).to have_css(".header-dropdown-toggle.current-user")
|
|
end
|
|
end
|
|
end
|