mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 21:03:46 +08:00
cf21de0e7a
This commit adds an additional find_user_by_email hook to ManagedAuthenticator so that GitHub login can continue to support secondary email addresses
The github_user_infos table will be dropped in a follow-up commit.
This is the last core authenticator to be migrated to ManagedAuthenticator 🎉
71 lines
2.0 KiB
Ruby
71 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
def github_auth(email_valid)
|
|
{
|
|
email: "user53@discourse.org",
|
|
username: "joedoe546",
|
|
email_valid: email_valid,
|
|
omit_username: nil,
|
|
name: "Joe Doe 546",
|
|
authenticator_name: "github",
|
|
extra_data: {
|
|
provider: "github",
|
|
uid: "100"
|
|
},
|
|
skip_email_validation: false
|
|
}
|
|
end
|
|
|
|
describe UserAuthenticator do
|
|
context "#finish" do
|
|
fab!(:group) { Fabricate(:group, automatic_membership_email_domains: "discourse.org") }
|
|
|
|
before do
|
|
SiteSetting.enable_github_logins = true
|
|
end
|
|
|
|
it "confirms email and adds the user to appropraite groups based on email" do
|
|
user = Fabricate(:user, email: "user53@discourse.org")
|
|
expect(group.usernames).not_to include(user.username)
|
|
|
|
authentication = github_auth(true)
|
|
|
|
UserAuthenticator.new(user, authentication: authentication).finish
|
|
expect(user.email_confirmed?).to be_truthy
|
|
expect(group.usernames).to include(user.username)
|
|
end
|
|
|
|
it "doesn't confirm email if email is invalid" do
|
|
user = Fabricate(:user, email: "user53@discourse.org")
|
|
|
|
authentication = github_auth(false)
|
|
|
|
UserAuthenticator.new(user, authentication: authentication).finish
|
|
expect(user.email_confirmed?).to be_falsey
|
|
expect(group.usernames).not_to include(user.username)
|
|
end
|
|
|
|
it "doesn't confirm email if it was changed" do
|
|
user = Fabricate(:user, email: "changed@discourse.org")
|
|
|
|
authentication = github_auth(true)
|
|
|
|
UserAuthenticator.new(user, authentication: authentication).finish
|
|
expect(user.email_confirmed?).to be_falsey
|
|
expect(group.usernames).not_to include(user.username)
|
|
end
|
|
|
|
it "clears the authentication info from the session" do
|
|
user = Fabricate(:user, email: "user53@discourse.org")
|
|
session = { authentication: github_auth(true) }
|
|
|
|
UserAuthenticator.new(user, session).finish
|
|
expect(user.email_confirmed?).to be_truthy
|
|
|
|
expect(session[:authentication]).to eq(nil)
|
|
end
|
|
end
|
|
end
|