0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-05 22:42:07 +08:00
discourse/spec/system/discourse_id_spec.rb
Keegan George c4c9e1bc05
FIX: enforce full_name_requirement on Discourse ID signups (#39831)
**Previously**, when `full_name_requirement` was set to
"required_at_signup" and `auth_skip_create_confirm` was enabled,
Discourse ID signups bypassed the name requirement by auto-suggesting a
name from the username.

**In this update**, the client authenticator extracts the
provider-supplied name, and the signup flow no longer skips confirmation
when a real name is required but not provided by the auth provider.
2026-05-07 15:17:47 -07:00

92 lines
2.9 KiB
Ruby
Vendored

# 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
context "when full_name_requirement is required_at_signup" do
before { SiteSetting.full_name_requirement = "required_at_signup" }
it "shows the signup form when name is not provided by the provider" do
visit("/")
signup_form.open.click_social_button("discourse_id")
expect(signup_form).to be_open
expect(page).to have_css("#new-account-name")
end
context "when name is provided by the provider" do
before do
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,
name: "John Doe",
),
)
end
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
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