2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe DiscourseConnect do
|
2014-02-24 22:30:49 -05:00
|
|
|
before do
|
2021-02-08 05:04:33 -05:00
|
|
|
@discourse_connect_url = "http://example.com/discourse_sso"
|
|
|
|
@discourse_connect_secret = "shjkfdhsfkjh"
|
2014-02-24 22:30:49 -05:00
|
|
|
|
2021-02-08 05:04:33 -05:00
|
|
|
SiteSetting.discourse_connect_url = @discourse_connect_url
|
|
|
|
SiteSetting.enable_discourse_connect = true
|
|
|
|
SiteSetting.discourse_connect_secret = @discourse_connect_secret
|
2021-10-12 09:25:54 -04:00
|
|
|
SiteSetting.reserved_usernames = ""
|
2019-03-14 10:47:38 -04:00
|
|
|
Jobs.run_immediately!
|
2014-02-24 22:30:49 -05:00
|
|
|
end
|
|
|
|
|
2014-03-19 17:14:09 -04:00
|
|
|
def make_sso
|
2022-01-06 07:28:46 -05:00
|
|
|
sso = DiscourseConnectBase.new
|
2014-02-24 22:30:49 -05:00
|
|
|
sso.sso_url = "http://meta.discorse.org/topics/111"
|
|
|
|
sso.sso_secret = "supersecret"
|
|
|
|
sso.nonce = "testing"
|
|
|
|
sso.email = "some@email.com"
|
|
|
|
sso.username = "sam"
|
|
|
|
sso.name = "sam saffron"
|
|
|
|
sso.external_id = "100"
|
2016-08-28 21:28:19 -04:00
|
|
|
sso.avatar_url = "https://cdn.discourse.org/user_avatar.png"
|
|
|
|
sso.avatar_force_update = false
|
|
|
|
sso.bio = "about"
|
|
|
|
sso.admin = false
|
|
|
|
sso.moderator = false
|
|
|
|
sso.suppress_welcome_message = false
|
2015-05-21 09:41:36 -04:00
|
|
|
sso.require_activation = false
|
2017-01-31 19:42:27 -05:00
|
|
|
sso.title = "user title"
|
2014-04-21 23:52:13 -04:00
|
|
|
sso.custom_fields["a"] = "Aa"
|
|
|
|
sso.custom_fields["b.b"] = "B.b"
|
2018-06-19 20:30:23 -04:00
|
|
|
sso.website = "https://www.discourse.org/"
|
2020-04-28 02:06:35 -04:00
|
|
|
sso.location = "Home"
|
2014-03-19 17:14:09 -04:00
|
|
|
sso
|
|
|
|
end
|
2014-02-24 22:30:49 -05:00
|
|
|
|
2021-02-18 05:35:10 -05:00
|
|
|
def new_discourse_sso
|
2022-01-06 07:28:46 -05:00
|
|
|
DiscourseConnect.new(secure_session: secure_session)
|
2021-02-18 05:35:10 -05:00
|
|
|
end
|
|
|
|
|
2014-03-19 17:14:09 -04:00
|
|
|
def test_parsed(parsed, sso)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(parsed.nonce).to eq sso.nonce
|
|
|
|
expect(parsed.email).to eq sso.email
|
|
|
|
expect(parsed.username).to eq sso.username
|
|
|
|
expect(parsed.name).to eq sso.name
|
|
|
|
expect(parsed.external_id).to eq sso.external_id
|
2016-08-28 21:28:19 -04:00
|
|
|
expect(parsed.avatar_url).to eq sso.avatar_url
|
|
|
|
expect(parsed.avatar_force_update).to eq sso.avatar_force_update
|
|
|
|
expect(parsed.bio).to eq sso.bio
|
|
|
|
expect(parsed.admin).to eq sso.admin
|
|
|
|
expect(parsed.moderator).to eq sso.moderator
|
|
|
|
expect(parsed.suppress_welcome_message).to eq sso.suppress_welcome_message
|
2015-05-21 09:41:36 -04:00
|
|
|
expect(parsed.require_activation).to eq false
|
2017-01-31 19:42:27 -05:00
|
|
|
expect(parsed.title).to eq sso.title
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(parsed.custom_fields["a"]).to eq "Aa"
|
|
|
|
expect(parsed.custom_fields["b.b"]).to eq "B.b"
|
2018-06-19 20:30:23 -04:00
|
|
|
expect(parsed.website).to eq sso.website
|
2020-04-28 02:06:35 -04:00
|
|
|
expect(parsed.location).to eq sso.location
|
2014-03-19 17:14:09 -04:00
|
|
|
end
|
|
|
|
|
2014-12-28 21:30:54 -05:00
|
|
|
it "can do round trip parsing correctly" do
|
2022-01-06 07:28:46 -05:00
|
|
|
sso = DiscourseConnectBase.new
|
2014-12-28 21:30:54 -05:00
|
|
|
sso.sso_secret = "test"
|
|
|
|
sso.name = "sam saffron"
|
|
|
|
sso.username = "sam"
|
|
|
|
sso.email = "sam@sam.com"
|
|
|
|
|
2022-01-06 07:28:46 -05:00
|
|
|
sso = DiscourseConnectBase.parse(sso.payload, "test")
|
2014-12-28 21:30:54 -05:00
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(sso.name).to eq "sam saffron"
|
|
|
|
expect(sso.username).to eq "sam"
|
|
|
|
expect(sso.email).to eq "sam@sam.com"
|
2014-12-28 21:30:54 -05:00
|
|
|
end
|
|
|
|
|
2015-02-23 15:58:45 -05:00
|
|
|
let(:ip_address) { "127.0.0.1" }
|
2021-02-18 05:35:10 -05:00
|
|
|
let(:secure_session) { SecureSession.new("abc") }
|
2015-02-23 15:58:45 -05:00
|
|
|
|
2019-06-10 20:04:26 -04:00
|
|
|
it "bans bad external id" do
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2019-06-10 20:04:26 -04:00
|
|
|
sso.username = "test"
|
|
|
|
sso.name = ""
|
|
|
|
sso.email = "test@test.com"
|
|
|
|
sso.suppress_welcome_message = true
|
|
|
|
|
|
|
|
sso.external_id = " "
|
|
|
|
|
|
|
|
expect do sso.lookup_or_create_user(ip_address) end.to raise_error(
|
2022-01-06 07:28:46 -05:00
|
|
|
DiscourseConnect::BlankExternalId,
|
|
|
|
)
|
2019-06-10 20:04:26 -04:00
|
|
|
|
|
|
|
sso.external_id = nil
|
|
|
|
|
|
|
|
expect do sso.lookup_or_create_user(ip_address) end.to raise_error(
|
2022-01-06 07:28:46 -05:00
|
|
|
DiscourseConnect::BlankExternalId,
|
|
|
|
)
|
2019-06-10 20:04:26 -04:00
|
|
|
|
|
|
|
# going for slight duplication here so our intent is crystal clear
|
|
|
|
%w[none nil Blank null].each do |word|
|
|
|
|
sso.external_id = word
|
|
|
|
expect do sso.lookup_or_create_user(ip_address) end.to raise_error(
|
2022-01-06 07:28:46 -05:00
|
|
|
DiscourseConnect::BannedExternalId,
|
|
|
|
)
|
2019-06-10 20:04:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-02 03:32:39 -04:00
|
|
|
it "can lookup or create user when name is blank" do
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2014-06-02 03:32:39 -04:00
|
|
|
sso.username = "test"
|
|
|
|
sso.name = ""
|
|
|
|
sso.email = "test@test.com"
|
|
|
|
sso.external_id = "A"
|
2017-06-21 22:23:31 -04:00
|
|
|
sso.suppress_welcome_message = true
|
2015-02-23 15:58:45 -05:00
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
2017-06-21 22:23:31 -04:00
|
|
|
|
|
|
|
expect(user.persisted?).to eq(true)
|
2014-06-02 03:32:39 -04:00
|
|
|
end
|
2016-05-17 03:31:34 -04:00
|
|
|
|
2016-06-21 05:28:58 -04:00
|
|
|
it "unstaged users" do
|
2021-02-08 05:04:33 -05:00
|
|
|
SiteSetting.auth_overrides_name = true
|
2017-05-09 17:20:38 -04:00
|
|
|
|
2016-06-21 05:28:58 -04:00
|
|
|
email = "staged@user.com"
|
|
|
|
Fabricate(:user, staged: true, email: email)
|
|
|
|
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2016-06-21 05:28:58 -04:00
|
|
|
sso.username = "staged"
|
2017-05-09 17:20:38 -04:00
|
|
|
sso.name = "Bob O'Bob"
|
2016-06-21 05:28:58 -04:00
|
|
|
sso.email = email
|
|
|
|
sso.external_id = "B"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
|
2017-05-09 17:20:38 -04:00
|
|
|
user.reload
|
|
|
|
|
2016-06-21 05:28:58 -04:00
|
|
|
expect(user).to_not be_nil
|
|
|
|
expect(user.staged).to be(false)
|
2017-05-09 17:20:38 -04:00
|
|
|
|
|
|
|
expect(user.name).to eq("Bob O'Bob")
|
2016-06-21 05:28:58 -04:00
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "reviewables" do
|
2019-04-10 12:53:30 -04:00
|
|
|
let(:sso) do
|
2021-02-18 05:35:10 -05:00
|
|
|
new_discourse_sso.tap do |sso|
|
2019-04-10 12:53:30 -04:00
|
|
|
sso.username = "staged"
|
|
|
|
sso.name = "Bob O'Bob"
|
|
|
|
sso.email = "bob@obob.com"
|
|
|
|
sso.external_id = "B"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't create reviewables if we aren't approving users" do
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
reviewable = ReviewableUser.find_by(target: user)
|
|
|
|
expect(reviewable).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates reviewables if needed" do
|
|
|
|
SiteSetting.must_approve_users = true
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
reviewable = ReviewableUser.find_by(target: user)
|
|
|
|
expect(reviewable).to be_present
|
|
|
|
expect(reviewable).to be_pending
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-17 03:31:34 -04:00
|
|
|
it "can set admin and moderator" do
|
|
|
|
admin_group = Group[:admins]
|
|
|
|
mod_group = Group[:moderators]
|
|
|
|
staff_group = Group[:staff]
|
|
|
|
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2016-05-17 03:31:34 -04:00
|
|
|
sso.username = "misteradmin"
|
|
|
|
sso.name = "Bob Admin"
|
|
|
|
sso.email = "admin@admin.com"
|
|
|
|
sso.external_id = "id"
|
|
|
|
sso.admin = true
|
|
|
|
sso.moderator = true
|
2017-06-21 22:23:31 -04:00
|
|
|
sso.suppress_welcome_message = true
|
2016-05-17 03:31:34 -04:00
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
staff_group.reload
|
|
|
|
|
|
|
|
expect(mod_group.users.where("users.id = ?", user.id).exists?).to eq(true)
|
|
|
|
expect(staff_group.users.where("users.id = ?", user.id).exists?).to eq(true)
|
|
|
|
expect(admin_group.users.where("users.id = ?", user.id).exists?).to eq(true)
|
|
|
|
end
|
2014-06-02 03:32:39 -04:00
|
|
|
|
2018-04-09 23:17:23 -04:00
|
|
|
it "can force a list of groups with the groups attribute" do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
group1 = Fabricate(:group, name: "group1")
|
|
|
|
group2 = Fabricate(:group, name: "group2")
|
|
|
|
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2018-04-09 23:17:23 -04:00
|
|
|
sso.username = "bobsky"
|
|
|
|
sso.name = "Bob"
|
|
|
|
sso.email = user.email
|
|
|
|
sso.external_id = "A"
|
|
|
|
|
|
|
|
sso.groups = "#{group2.name.capitalize},group4,badname,trust_level_4"
|
|
|
|
sso.lookup_or_create_user(ip_address)
|
|
|
|
|
2021-02-08 05:04:33 -05:00
|
|
|
SiteSetting.discourse_connect_overrides_groups = true
|
2018-04-09 23:17:23 -04:00
|
|
|
|
|
|
|
group1.reload
|
|
|
|
expect(group1.usernames).to eq("")
|
|
|
|
expect(group2.usernames).to eq("")
|
|
|
|
|
|
|
|
group1.add(user)
|
2022-10-28 06:27:12 -04:00
|
|
|
group1.save!
|
2018-04-09 23:17:23 -04:00
|
|
|
|
|
|
|
sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(group1.usernames).to eq("")
|
|
|
|
expect(group2.usernames).to eq(user.username)
|
2018-04-10 01:30:18 -04:00
|
|
|
|
|
|
|
sso.groups = "badname,trust_level_4"
|
|
|
|
sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(group1.usernames).to eq("")
|
|
|
|
expect(group2.usernames).to eq("")
|
2022-10-28 06:27:12 -04:00
|
|
|
|
|
|
|
group1.add(user)
|
|
|
|
group1.save!
|
|
|
|
group2.add(user)
|
|
|
|
group2.save!
|
|
|
|
sso.groups = "#{group1.name},badname,trust_level_4"
|
|
|
|
|
|
|
|
sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(group1.usernames).to eq(user.username)
|
|
|
|
expect(group2.usernames).to eq("")
|
2018-04-09 23:17:23 -04:00
|
|
|
end
|
|
|
|
|
2016-11-11 00:57:31 -05:00
|
|
|
it "can specify groups" do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
|
|
|
|
add_group1 = Fabricate(:group, name: "group1")
|
|
|
|
add_group2 = Fabricate(:group, name: "group2")
|
|
|
|
existing_group = Fabricate(:group, name: "group3")
|
2017-08-11 18:09:22 -04:00
|
|
|
add_group4 = Fabricate(:group, name: "GROUP4")
|
|
|
|
existing_group2 = Fabricate(:group, name: "GRoup5")
|
2016-11-11 00:57:31 -05:00
|
|
|
|
2017-08-11 18:09:22 -04:00
|
|
|
[existing_group, existing_group2].each do |g|
|
|
|
|
g.add(user)
|
|
|
|
g.save!
|
|
|
|
end
|
2016-11-11 00:57:31 -05:00
|
|
|
|
|
|
|
add_group1.add(user)
|
|
|
|
existing_group.save!
|
|
|
|
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2016-11-11 00:57:31 -05:00
|
|
|
sso.username = "bobsky"
|
|
|
|
sso.name = "Bob"
|
|
|
|
sso.email = user.email
|
|
|
|
sso.external_id = "A"
|
|
|
|
|
2017-08-11 18:09:22 -04:00
|
|
|
sso.add_groups = "#{add_group1.name},#{add_group2.name.capitalize},group4,badname"
|
|
|
|
sso.remove_groups = "#{existing_group.name},#{existing_group2.name.downcase},badname"
|
2016-11-11 00:57:31 -05:00
|
|
|
|
|
|
|
sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
existing_group.reload
|
|
|
|
expect(existing_group.usernames).to eq("")
|
|
|
|
|
2017-08-11 18:09:22 -04:00
|
|
|
existing_group2.reload
|
|
|
|
expect(existing_group2.usernames).to eq("")
|
|
|
|
|
2016-11-11 00:57:31 -05:00
|
|
|
add_group1.reload
|
|
|
|
expect(add_group1.usernames).to eq(user.username)
|
|
|
|
|
|
|
|
add_group2.reload
|
|
|
|
expect(add_group2.usernames).to eq(user.username)
|
2017-08-11 18:09:22 -04:00
|
|
|
|
|
|
|
add_group4.reload
|
|
|
|
expect(add_group4.usernames).to eq(user.username)
|
2016-11-11 00:57:31 -05:00
|
|
|
end
|
|
|
|
|
2022-10-25 04:25:26 -04:00
|
|
|
it "creates group logs when users are added to groups" do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
group = Fabricate(:group, name: "group1")
|
|
|
|
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.username = "bobsky"
|
|
|
|
sso.name = "Bob"
|
|
|
|
sso.email = user.email
|
|
|
|
sso.external_id = "A"
|
|
|
|
sso.add_groups = "#{group.name},badname"
|
|
|
|
|
|
|
|
GroupHistory.destroy_all
|
|
|
|
|
|
|
|
sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
expect(group.reload.usernames).to eq(user.username)
|
|
|
|
expect(
|
|
|
|
GroupHistory.exists?(
|
|
|
|
target_user_id: user.id,
|
|
|
|
acting_user: Discourse.system_user.id,
|
|
|
|
action: GroupHistory.actions[:add_user_to_group],
|
2023-01-09 06:18:21 -05:00
|
|
|
),
|
2022-10-25 04:25:26 -04:00
|
|
|
).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates group logs when users are removed from groups" do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
group = Fabricate(:group, name: "group1")
|
|
|
|
group.add(user)
|
|
|
|
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.username = "bobsky"
|
|
|
|
sso.name = "Bob"
|
|
|
|
sso.email = user.email
|
|
|
|
sso.external_id = "A"
|
|
|
|
sso.remove_groups = "#{group.name},badname"
|
|
|
|
|
|
|
|
GroupHistory.destroy_all
|
|
|
|
|
|
|
|
sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
expect(group.reload.usernames).to be_blank
|
|
|
|
expect(
|
|
|
|
GroupHistory.exists?(
|
|
|
|
target_user_id: user.id,
|
|
|
|
acting_user: Discourse.system_user.id,
|
|
|
|
action: GroupHistory.actions[:remove_user_from_group],
|
2023-01-09 06:18:21 -05:00
|
|
|
),
|
2022-10-25 04:25:26 -04:00
|
|
|
).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates group logs when users are added to groups when discourse_connect_overrides_groups setting is true" do
|
|
|
|
SiteSetting.discourse_connect_overrides_groups = true
|
|
|
|
|
|
|
|
user = Fabricate(:user)
|
|
|
|
group = Fabricate(:group, name: "group1")
|
|
|
|
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.username = "bobsky"
|
|
|
|
sso.name = "Bob"
|
|
|
|
sso.email = user.email
|
|
|
|
sso.external_id = "A"
|
|
|
|
sso.groups = "#{group.name},badname"
|
|
|
|
|
|
|
|
GroupHistory.destroy_all
|
|
|
|
|
|
|
|
sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
expect(group.reload.usernames).to eq(user.username)
|
|
|
|
expect(
|
|
|
|
GroupHistory.exists?(
|
|
|
|
target_user_id: user.id,
|
|
|
|
acting_user: Discourse.system_user.id,
|
|
|
|
action: GroupHistory.actions[:add_user_to_group],
|
2023-01-09 06:18:21 -05:00
|
|
|
),
|
2022-10-25 04:25:26 -04:00
|
|
|
).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates group logs when users are removed from groups when discourse_connect_overrides_groups setting is true" do
|
|
|
|
SiteSetting.discourse_connect_overrides_groups = true
|
|
|
|
|
|
|
|
user = Fabricate(:user)
|
|
|
|
group = Fabricate(:group, name: "group1")
|
|
|
|
group.add(user)
|
|
|
|
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.username = "bobsky"
|
|
|
|
sso.name = "Bob"
|
|
|
|
sso.email = user.email
|
|
|
|
sso.external_id = "A"
|
|
|
|
sso.groups = "badname"
|
|
|
|
|
|
|
|
GroupHistory.destroy_all
|
|
|
|
|
|
|
|
sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
expect(group.reload.usernames).to be_blank
|
|
|
|
expect(
|
|
|
|
GroupHistory.exists?(
|
|
|
|
target_user_id: user.id,
|
|
|
|
acting_user: Discourse.system_user.id,
|
|
|
|
action: GroupHistory.actions[:remove_user_from_group],
|
2023-01-09 06:18:21 -05:00
|
|
|
),
|
2022-10-25 04:25:26 -04:00
|
|
|
).to eq(true)
|
|
|
|
end
|
|
|
|
|
2021-02-08 05:04:33 -05:00
|
|
|
it "behaves properly when auth_overrides_username is set but username is missing or blank" do
|
|
|
|
SiteSetting.auth_overrides_username = true
|
2018-03-13 18:39:39 -04:00
|
|
|
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2018-03-13 18:39:39 -04:00
|
|
|
sso.username = "testuser"
|
|
|
|
sso.name = "test user"
|
|
|
|
sso.email = "test@test.com"
|
|
|
|
sso.external_id = "100"
|
|
|
|
sso.bio = "This **is** the bio"
|
|
|
|
sso.suppress_welcome_message = true
|
|
|
|
|
|
|
|
# create the original user
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.username).to eq "testuser"
|
|
|
|
|
|
|
|
# remove username from payload
|
|
|
|
sso.username = nil
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.username).to eq "testuser"
|
|
|
|
|
|
|
|
# set username in payload to blank
|
|
|
|
sso.username = ""
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.username).to eq "testuser"
|
|
|
|
end
|
|
|
|
|
2015-03-26 18:39:35 -04:00
|
|
|
it "can override name / email / username" do
|
|
|
|
admin = Fabricate(:admin)
|
|
|
|
|
2017-07-09 22:12:21 -04:00
|
|
|
SiteSetting.email_editable = false
|
2021-02-08 05:04:33 -05:00
|
|
|
SiteSetting.auth_overrides_name = true
|
|
|
|
SiteSetting.auth_overrides_email = true
|
|
|
|
SiteSetting.auth_overrides_username = true
|
2015-03-26 18:39:35 -04:00
|
|
|
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2015-03-26 18:39:35 -04:00
|
|
|
sso.username = "bob%the$admin"
|
|
|
|
sso.name = "Bob Admin"
|
|
|
|
sso.email = admin.email
|
|
|
|
sso.external_id = "A"
|
|
|
|
|
|
|
|
sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
admin.reload
|
|
|
|
|
|
|
|
expect(admin.name).to eq "Bob Admin"
|
|
|
|
expect(admin.username).to eq "bob_the_admin"
|
|
|
|
expect(admin.email).to eq admin.email
|
|
|
|
|
|
|
|
sso.email = "TEST@bob.com"
|
|
|
|
|
2015-03-26 19:25:32 -04:00
|
|
|
sso.name = "Louis C.K."
|
|
|
|
|
2015-03-26 18:39:35 -04:00
|
|
|
sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
admin.reload
|
2015-03-26 19:04:16 -04:00
|
|
|
|
2015-03-26 18:39:35 -04:00
|
|
|
expect(admin.email).to eq("test@bob.com")
|
2015-03-26 19:04:16 -04:00
|
|
|
expect(admin.username).to eq "bob_the_admin"
|
2015-03-26 19:25:32 -04:00
|
|
|
expect(admin.name).to eq "Louis C.K."
|
2015-03-26 18:39:35 -04:00
|
|
|
end
|
|
|
|
|
2021-10-27 06:41:24 -04:00
|
|
|
it "can override username properly when only the case changes" do
|
|
|
|
SiteSetting.auth_overrides_username = true
|
|
|
|
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.username = "testuser"
|
|
|
|
sso.name = "test user"
|
|
|
|
sso.email = "test@test.com"
|
|
|
|
sso.external_id = "100"
|
|
|
|
sso.bio = "This **is** the bio"
|
|
|
|
sso.suppress_welcome_message = true
|
|
|
|
|
|
|
|
# create the original user
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.username).to eq "testuser"
|
|
|
|
|
|
|
|
# change the username case
|
|
|
|
sso.username = "TestUser"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.username).to eq "TestUser"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "do not override username when a new username after fixing is the same" do
|
|
|
|
SiteSetting.auth_overrides_username = true
|
|
|
|
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.username = "testuser"
|
|
|
|
sso.name = "test user"
|
|
|
|
sso.email = "test@test.com"
|
|
|
|
sso.external_id = "100"
|
|
|
|
|
|
|
|
# create the original user
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.username).to eq "testuser"
|
|
|
|
|
|
|
|
# change the username case
|
|
|
|
sso.username = "testuserგამარჯობა"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.username).to eq "testuser"
|
|
|
|
end
|
|
|
|
|
2021-12-06 11:49:04 -05:00
|
|
|
it "should preserve username when several users login with the same username" do
|
|
|
|
SiteSetting.auth_overrides_username = true
|
|
|
|
|
|
|
|
# if several users have username "bill" on the external site,
|
|
|
|
# they will have usernames bill, bill1, bill2 etc in Discourse:
|
|
|
|
Fabricate(:user, username: "bill")
|
|
|
|
Fabricate(:user, username: "bill1")
|
|
|
|
Fabricate(:user, username: "bill2")
|
|
|
|
Fabricate(:user, username: "bill4")
|
|
|
|
|
|
|
|
# the number should be preserved during subsequent logins
|
|
|
|
# bill3 should remain bill3
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.username = "bill3"
|
|
|
|
sso.email = "test@test.com"
|
|
|
|
sso.external_id = "100"
|
|
|
|
sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
sso.username = "bill"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
expect(user.username).to eq "bill3"
|
|
|
|
end
|
|
|
|
|
2021-12-16 10:44:07 -05:00
|
|
|
it "uses name if it's present in payload" do
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.external_id = "100"
|
|
|
|
|
|
|
|
name = "John"
|
|
|
|
sso.name = name
|
|
|
|
sso.email = "mail@mail.com"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
expect(user.name).to eq name
|
|
|
|
end
|
|
|
|
|
|
|
|
it "uses username for name suggestions if name isn't present in payload" do
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.external_id = "100"
|
|
|
|
|
|
|
|
sso.name = ""
|
|
|
|
sso.username = "user_john"
|
|
|
|
sso.email = "mail@mail.com"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
expect(user.name).to eq "User John"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "uses username for username suggestions if it's present in payload" do
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.external_id = "100"
|
|
|
|
|
|
|
|
username = "user_john"
|
|
|
|
sso.username = username
|
|
|
|
sso.email = "mail@mail.com"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
expect(user.username).to eq username
|
|
|
|
end
|
|
|
|
|
|
|
|
it "uses name for username suggestions if username isn't present in payload" do
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.external_id = "100"
|
|
|
|
|
|
|
|
sso.username = ""
|
|
|
|
sso.name = "John Smith"
|
|
|
|
sso.email = "mail@mail.com"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
expect(user.username).to eq "John_Smith"
|
|
|
|
end
|
|
|
|
|
2021-12-21 12:13:05 -05:00
|
|
|
it "uses name for username suggestions if username consists entirely of disallowed characters" do
|
|
|
|
SiteSetting.unicode_usernames = false
|
|
|
|
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.external_id = "100"
|
|
|
|
|
|
|
|
sso.username = "Πλάτων"
|
|
|
|
sso.name = "Plato"
|
|
|
|
sso.email = "mail@mail.com"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
expect(user.username).to eq sso.name
|
|
|
|
end
|
|
|
|
|
2022-04-29 09:00:13 -04:00
|
|
|
it "stops using name as a source for username suggestions when disabled" do
|
|
|
|
SiteSetting.use_name_for_username_suggestions = false
|
|
|
|
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.external_id = "100"
|
|
|
|
|
|
|
|
sso.username = nil
|
|
|
|
sso.name = "John Smith"
|
|
|
|
sso.email = "mail@mail.com"
|
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.username).to eq "user"
|
|
|
|
end
|
|
|
|
|
2021-10-19 06:37:39 -04:00
|
|
|
it "doesn't use email as a source for username suggestions by default" do
|
2021-10-12 09:25:54 -04:00
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.external_id = "100"
|
|
|
|
|
|
|
|
# set username and name to nil, so they cannot be used as a source for suggestions
|
|
|
|
sso.username = nil
|
|
|
|
sso.name = nil
|
|
|
|
sso.email = "mail@mail.com"
|
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.username).to eq I18n.t("fallback_username")
|
|
|
|
end
|
|
|
|
|
2021-12-21 12:13:05 -05:00
|
|
|
it "uses email as a source for username suggestions if enabled" do
|
2021-10-19 06:37:39 -04:00
|
|
|
SiteSetting.use_email_for_username_and_name_suggestions = true
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.external_id = "100"
|
|
|
|
|
|
|
|
# set username and name to nil, so they cannot be used as a source for suggestions
|
|
|
|
sso.username = nil
|
|
|
|
sso.name = nil
|
|
|
|
sso.email = "mail@mail.com"
|
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.username).to eq "mail"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't use email as a source for name suggestions by default" do
|
2021-10-12 09:25:54 -04:00
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.external_id = "100"
|
|
|
|
|
|
|
|
# set username and name to nil, so they cannot be used as a source for suggestions
|
|
|
|
sso.username = nil
|
|
|
|
sso.name = nil
|
|
|
|
sso.email = "mail@mail.com"
|
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.name).to eq ""
|
|
|
|
end
|
|
|
|
|
2021-12-21 12:13:05 -05:00
|
|
|
it "uses email as a source for name suggestions if enabled" do
|
2021-10-19 06:37:39 -04:00
|
|
|
SiteSetting.use_email_for_username_and_name_suggestions = true
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.external_id = "100"
|
|
|
|
|
|
|
|
# set username and name to nil, so they cannot be used as a source for suggestions
|
|
|
|
sso.username = nil
|
|
|
|
sso.name = nil
|
|
|
|
sso.email = "mail@mail.com"
|
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.name).to eq "Mail"
|
|
|
|
end
|
|
|
|
|
2021-12-21 12:13:05 -05:00
|
|
|
it "uses email for username suggestions if username and name consist entirely of disallowed characters" do
|
|
|
|
SiteSetting.use_email_for_username_and_name_suggestions = true
|
|
|
|
SiteSetting.unicode_usernames = false
|
|
|
|
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.external_id = "100"
|
|
|
|
|
|
|
|
sso.username = "Πλάτων"
|
|
|
|
sso.name = "Πλάτων"
|
|
|
|
sso.email = "mail@mail.com"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
expect(user.username).to eq "mail"
|
|
|
|
end
|
|
|
|
|
2021-10-07 14:29:24 -04:00
|
|
|
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
|
|
|
|
|
2024-03-11 05:49:37 -04:00
|
|
|
it "stores registration ip address if it's present" do
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.external_id = "100"
|
|
|
|
|
|
|
|
sso.email = "mail@mail.com"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
expect(user.registration_ip_address).to eq ip_address
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not store registration ip address if it's not present" do
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.external_id = "100"
|
|
|
|
|
|
|
|
sso.email = "mail@mail.com"
|
|
|
|
user = sso.lookup_or_create_user(nil)
|
|
|
|
|
|
|
|
expect(user.registration_ip_address).to eq nil
|
|
|
|
end
|
|
|
|
|
2014-03-19 17:14:09 -04:00
|
|
|
it "can fill in data on way back" do
|
|
|
|
sso = make_sso
|
|
|
|
|
|
|
|
url, payload = sso.to_url.split("?")
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(url).to eq sso.sso_url
|
2022-01-06 07:28:46 -05:00
|
|
|
parsed = DiscourseConnectBase.parse(payload, "supersecret")
|
2014-03-19 17:14:09 -04:00
|
|
|
|
|
|
|
test_parsed(parsed, sso)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "handles sso_url with query params" do
|
|
|
|
sso = make_sso
|
|
|
|
sso.sso_url = "http://tcdev7.wpengine.com/?action=showlogin"
|
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(sso.to_url.split("?").size).to eq 2
|
2014-03-19 17:14:09 -04:00
|
|
|
|
|
|
|
url, payload = sso.to_url.split("?")
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(url).to eq "http://tcdev7.wpengine.com/"
|
2022-01-06 07:28:46 -05:00
|
|
|
parsed = DiscourseConnectBase.parse(payload, "supersecret")
|
2014-02-24 22:30:49 -05:00
|
|
|
|
2014-03-19 17:14:09 -04:00
|
|
|
test_parsed(parsed, sso)
|
2014-02-24 22:30:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "validates nonce" do
|
2022-01-06 07:28:46 -05:00
|
|
|
_, payload = DiscourseConnect.generate_url(secure_session: secure_session).split("?")
|
2014-02-24 22:30:49 -05:00
|
|
|
|
2022-01-06 07:28:46 -05:00
|
|
|
sso = DiscourseConnect.parse(payload, secure_session: secure_session)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(sso.nonce_valid?).to eq true
|
2014-02-24 22:30:49 -05:00
|
|
|
|
2022-01-06 07:28:46 -05:00
|
|
|
other_session_sso =
|
|
|
|
DiscourseConnect.parse(payload, secure_session: SecureSession.new("differentsession"))
|
2021-03-11 05:38:34 -05:00
|
|
|
expect(other_session_sso.nonce_valid?).to eq false
|
|
|
|
|
2014-02-24 22:30:49 -05:00
|
|
|
sso.expire_nonce!
|
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(sso.nonce_valid?).to eq false
|
2021-03-11 05:38:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "allows disabling CSRF protection" do
|
|
|
|
SiteSetting.discourse_connect_csrf_protection = false
|
2022-01-06 07:28:46 -05:00
|
|
|
_, payload = DiscourseConnect.generate_url(secure_session: secure_session).split("?")
|
2014-02-24 22:30:49 -05:00
|
|
|
|
2022-01-06 07:28:46 -05:00
|
|
|
sso = DiscourseConnect.parse(payload, secure_session: secure_session)
|
2021-03-11 05:38:34 -05:00
|
|
|
expect(sso.nonce_valid?).to eq true
|
|
|
|
|
2022-01-06 07:28:46 -05:00
|
|
|
other_session_sso =
|
|
|
|
DiscourseConnect.parse(payload, secure_session: SecureSession.new("differentsession"))
|
2021-03-11 05:38:34 -05:00
|
|
|
expect(other_session_sso.nonce_valid?).to eq true
|
|
|
|
|
|
|
|
sso.expire_nonce!
|
|
|
|
|
|
|
|
expect(sso.nonce_valid?).to eq false
|
2014-02-24 22:30:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a correct sso url" do
|
2022-01-06 07:28:46 -05:00
|
|
|
url, payload = DiscourseConnect.generate_url(secure_session: secure_session).split("?")
|
2021-02-08 05:04:33 -05:00
|
|
|
expect(url).to eq @discourse_connect_url
|
2014-02-24 22:30:49 -05:00
|
|
|
|
2022-01-06 07:28:46 -05:00
|
|
|
sso = DiscourseConnect.parse(payload, secure_session: secure_session)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(sso.nonce).to_not be_nil
|
2014-02-24 22:30:49 -05:00
|
|
|
end
|
2015-01-28 10:47:59 -05:00
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "nonce error" do
|
2021-08-18 09:14:12 -04:00
|
|
|
it "generates correct error message when nonce has already been used" do
|
2022-01-06 07:28:46 -05:00
|
|
|
_, payload = DiscourseConnect.generate_url(secure_session: secure_session).split("?")
|
2021-08-18 09:14:12 -04:00
|
|
|
|
2022-01-06 07:28:46 -05:00
|
|
|
sso = DiscourseConnect.parse(payload, secure_session: secure_session)
|
2021-08-18 09:14:12 -04:00
|
|
|
expect(sso.nonce_valid?).to eq true
|
|
|
|
|
|
|
|
sso.expire_nonce!
|
|
|
|
expect(sso.nonce_error).to eq("Nonce has already been used")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates correct error message when nonce is expired" do
|
2022-01-06 07:28:46 -05:00
|
|
|
_, payload = DiscourseConnect.generate_url(secure_session: secure_session).split("?")
|
2021-08-18 09:14:12 -04:00
|
|
|
|
2022-01-06 07:28:46 -05:00
|
|
|
sso = DiscourseConnect.parse(payload, secure_session: secure_session)
|
2021-08-18 09:14:12 -04:00
|
|
|
expect(sso.nonce_valid?).to eq true
|
|
|
|
|
|
|
|
Discourse.cache.delete(sso.used_nonce_key)
|
2021-11-09 12:39:05 -05:00
|
|
|
expect(sso.nonce_error).to eq(
|
|
|
|
"Nonce is incorrect, was generated in a different browser session, or has expired",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates correct error message when nonce is expired, and csrf protection disabled" do
|
|
|
|
SiteSetting.discourse_connect_csrf_protection = false
|
2022-01-06 07:28:46 -05:00
|
|
|
_, payload = DiscourseConnect.generate_url(secure_session: secure_session).split("?")
|
2021-11-09 12:39:05 -05:00
|
|
|
|
2022-01-06 07:28:46 -05:00
|
|
|
sso = DiscourseConnect.parse(payload, secure_session: secure_session)
|
2021-11-09 12:39:05 -05:00
|
|
|
expect(sso.nonce_valid?).to eq true
|
|
|
|
|
|
|
|
Discourse.cache.delete(sso.used_nonce_key)
|
|
|
|
expect(sso.nonce_error).to eq("Nonce is incorrect, or has expired")
|
2021-08-18 09:14:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "user locale" do
|
2018-08-29 19:57:53 -04:00
|
|
|
it "sets default user locale if specified" do
|
|
|
|
SiteSetting.allow_user_locale = true
|
|
|
|
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2018-08-29 19:57:53 -04:00
|
|
|
sso.username = "test"
|
|
|
|
sso.name = "test"
|
|
|
|
sso.email = "test@test.com"
|
|
|
|
sso.external_id = "123"
|
|
|
|
sso.locale = "es"
|
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
expect(user.locale).to eq("es")
|
|
|
|
|
|
|
|
user.update_column(:locale, "he")
|
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.locale).to eq("he")
|
|
|
|
|
|
|
|
sso.locale_force_update = true
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.locale).to eq("es")
|
|
|
|
|
|
|
|
sso.locale = "fake"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.locale).to eq("es")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "trusting emails" do
|
2017-06-21 22:23:31 -04:00
|
|
|
let(:sso) do
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2015-05-15 13:00:34 -04:00
|
|
|
sso.username = "test"
|
|
|
|
sso.name = "test"
|
|
|
|
sso.email = "test@example.com"
|
|
|
|
sso.external_id = "A"
|
2017-06-21 22:23:31 -04:00
|
|
|
sso.suppress_welcome_message = true
|
2015-05-15 13:00:34 -04:00
|
|
|
sso
|
2017-06-21 22:23:31 -04:00
|
|
|
end
|
2015-05-15 13:00:34 -04:00
|
|
|
|
|
|
|
it "activates users by default" do
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.active).to eq(true)
|
|
|
|
end
|
|
|
|
|
2015-05-19 12:16:02 -04:00
|
|
|
it "does not activate user when asked not to" do
|
|
|
|
sso.require_activation = true
|
2015-05-15 13:00:34 -04:00
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.active).to eq(false)
|
2018-09-10 18:24:02 -04:00
|
|
|
|
|
|
|
user.activate
|
|
|
|
|
|
|
|
sso.external_id = "B"
|
|
|
|
|
|
|
|
expect do sso.lookup_or_create_user(ip_address) end.to raise_error(
|
|
|
|
ActiveRecord::RecordInvalid,
|
|
|
|
)
|
2015-05-15 13:00:34 -04:00
|
|
|
end
|
|
|
|
|
2017-11-08 09:55:15 -05:00
|
|
|
it "does not deactivate user if email provided is capitalized" do
|
|
|
|
SiteSetting.email_editable = false
|
2021-02-08 05:04:33 -05:00
|
|
|
SiteSetting.auth_overrides_email = true
|
2017-11-08 09:55:15 -05:00
|
|
|
sso.require_activation = true
|
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.active).to eq(false)
|
|
|
|
|
|
|
|
user.update_columns(active: true)
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.active).to eq(true)
|
|
|
|
|
|
|
|
sso.email = "Test@example.com"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.active).to eq(true)
|
|
|
|
end
|
|
|
|
|
2017-05-16 16:18:18 -04:00
|
|
|
it "deactivates accounts that have updated email address" do
|
2017-07-09 22:12:21 -04:00
|
|
|
SiteSetting.email_editable = false
|
2021-02-08 05:04:33 -05:00
|
|
|
SiteSetting.auth_overrides_email = true
|
2017-05-16 16:18:18 -04:00
|
|
|
sso.require_activation = true
|
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.active).to eq(false)
|
|
|
|
|
|
|
|
old_email = user.email
|
|
|
|
|
|
|
|
user.update_columns(active: true)
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.active).to eq(true)
|
|
|
|
|
2017-04-26 14:47:36 -04:00
|
|
|
user.primary_email.update_columns(email: "xXx@themovie.com")
|
2017-05-16 16:18:18 -04:00
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.email).to eq(old_email)
|
|
|
|
expect(user.active).to eq(false)
|
|
|
|
end
|
2015-05-15 13:00:34 -04:00
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "welcome emails" do
|
2015-03-20 13:03:24 -04:00
|
|
|
let(:sso) do
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2015-03-20 13:03:24 -04:00
|
|
|
sso.username = "test"
|
|
|
|
sso.name = "test"
|
|
|
|
sso.email = "test@example.com"
|
|
|
|
sso.external_id = "A"
|
|
|
|
sso
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2015-03-20 13:03:24 -04:00
|
|
|
|
|
|
|
it "sends a welcome email by default" do
|
|
|
|
User.any_instance.expects(:enqueue_welcome_message).once
|
2017-05-16 16:18:18 -04:00
|
|
|
_user = sso.lookup_or_create_user(ip_address)
|
2015-03-20 13:03:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "suppresses the welcome email when asked to" do
|
|
|
|
User.any_instance.expects(:enqueue_welcome_message).never
|
|
|
|
sso.suppress_welcome_message = true
|
2017-05-16 16:18:18 -04:00
|
|
|
_user = sso.lookup_or_create_user(ip_address)
|
2015-03-20 13:03:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "setting title for a user" do
|
2017-01-31 19:42:27 -05:00
|
|
|
let(:sso) do
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2017-01-31 19:42:27 -05:00
|
|
|
sso.username = "test"
|
|
|
|
sso.name = "test"
|
|
|
|
sso.email = "test@test.com"
|
|
|
|
sso.external_id = "100"
|
|
|
|
sso.title = "The User's Title"
|
|
|
|
sso
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2017-01-31 19:42:27 -05:00
|
|
|
|
2017-02-07 10:41:27 -05:00
|
|
|
it "sets title correctly" do
|
2017-01-31 19:42:27 -05:00
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.title).to eq(sso.title)
|
|
|
|
|
2017-02-07 10:41:27 -05:00
|
|
|
sso.title = "farmer"
|
2017-01-31 19:42:27 -05:00
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
|
2017-02-07 10:41:27 -05:00
|
|
|
expect(user.title).to eq("farmer")
|
|
|
|
|
|
|
|
sso.title = nil
|
2017-01-31 19:42:27 -05:00
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
|
2017-02-07 10:41:27 -05:00
|
|
|
expect(user.title).to eq("farmer")
|
2017-01-31 19:42:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "setting bio for a user" do
|
2017-06-21 22:23:31 -04:00
|
|
|
let(:sso) do
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2016-08-01 01:29:28 -04:00
|
|
|
sso.username = "test"
|
|
|
|
sso.name = "test"
|
|
|
|
sso.email = "test@test.com"
|
|
|
|
sso.external_id = "100"
|
|
|
|
sso.bio = "This **is** the bio"
|
2017-06-21 22:23:31 -04:00
|
|
|
sso.suppress_welcome_message = true
|
2016-08-01 01:29:28 -04:00
|
|
|
sso
|
2017-06-21 22:23:31 -04:00
|
|
|
end
|
2016-08-01 01:29:28 -04:00
|
|
|
|
|
|
|
it "can set bio if supplied on new users or users with empty bio" do
|
|
|
|
# new account
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.user_profile.bio_cooked).to match_html("<p>This <strong>is</strong> the bio</p>")
|
|
|
|
|
|
|
|
# no override by default
|
|
|
|
sso.bio = "new profile"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
|
|
|
|
expect(user.user_profile.bio_cooked).to match_html("<p>This <strong>is</strong> the bio</p>")
|
|
|
|
|
|
|
|
# yes override for blank
|
2017-06-21 22:23:31 -04:00
|
|
|
user.user_profile.update!(bio_raw: "")
|
2016-08-01 01:29:28 -04:00
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
expect(user.user_profile.bio_cooked).to match_html("<p>new profile</p>")
|
|
|
|
|
|
|
|
# yes override if site setting
|
|
|
|
sso.bio = "new profile 2"
|
2021-02-08 05:04:33 -05:00
|
|
|
SiteSetting.discourse_connect_overrides_bio = true
|
2016-08-01 01:29:28 -04:00
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
2017-06-21 22:23:31 -04:00
|
|
|
expect(user.user_profile.bio_cooked).to match_html("<p>new profile 2</p")
|
2016-08-01 01:29:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-08 05:04:33 -05:00
|
|
|
context "when discourse_connect_overrides_avatar is not enabled" do
|
2016-09-01 22:04:22 -04:00
|
|
|
it "correctly handles provided avatar_urls" do
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2017-06-21 22:23:31 -04:00
|
|
|
sso.external_id = 666
|
|
|
|
sso.email = "sam@sam.com"
|
|
|
|
sso.name = "sam"
|
|
|
|
sso.username = "sam"
|
|
|
|
sso.avatar_url = "http://awesome.com/image.png"
|
|
|
|
sso.suppress_welcome_message = true
|
|
|
|
|
2019-04-08 10:58:21 -04:00
|
|
|
FileHelper.stubs(:download).returns(
|
|
|
|
file_from_fixtures("logo.png"),
|
|
|
|
file_from_fixtures("logo.png"),
|
|
|
|
)
|
2017-06-21 22:23:31 -04:00
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
user.reload
|
|
|
|
avatar_id = user.uploaded_avatar_id
|
|
|
|
|
|
|
|
# initial creation ...
|
|
|
|
expect(avatar_id).to_not eq(nil)
|
|
|
|
|
|
|
|
# junk avatar id should be updated
|
|
|
|
old_id = user.uploaded_avatar_id
|
|
|
|
Upload.destroy(old_id)
|
2019-04-08 10:58:21 -04:00
|
|
|
FileHelper.stubs(:download).returns(
|
|
|
|
file_from_fixtures("logo.png"),
|
|
|
|
file_from_fixtures("logo.png"),
|
|
|
|
)
|
2017-06-21 22:23:31 -04:00
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
user.reload
|
|
|
|
avatar_id = user.uploaded_avatar_id
|
|
|
|
|
|
|
|
expect(avatar_id).to_not eq(nil)
|
|
|
|
expect(old_id).to_not eq(avatar_id)
|
|
|
|
|
2018-03-28 04:20:08 -04:00
|
|
|
# FileHelper.stubs(:download) { raise "should not be called" }
|
|
|
|
# sso.avatar_url = "https://some.new/avatar.png"
|
|
|
|
# user = sso.lookup_or_create_user(ip_address)
|
|
|
|
# user.reload
|
|
|
|
#
|
|
|
|
# # avatar updated but no override specified ...
|
|
|
|
# expect(user.uploaded_avatar_id).to eq(avatar_id)
|
|
|
|
#
|
|
|
|
# sso.avatar_force_update = true
|
|
|
|
# FileHelper.stubs(:download).returns(file_from_fixtures("logo-dev.png"))
|
|
|
|
# user = sso.lookup_or_create_user(ip_address)
|
|
|
|
# user.reload
|
|
|
|
#
|
|
|
|
# # we better have a new avatar
|
|
|
|
# expect(user.uploaded_avatar_id).not_to eq(avatar_id)
|
|
|
|
# expect(user.uploaded_avatar_id).not_to eq(nil)
|
|
|
|
#
|
|
|
|
# avatar_id = user.uploaded_avatar_id
|
|
|
|
#
|
|
|
|
# sso.avatar_force_update = true
|
|
|
|
# FileHelper.stubs(:download) { raise "not found" }
|
|
|
|
# user = sso.lookup_or_create_user(ip_address)
|
|
|
|
# user.reload
|
|
|
|
#
|
|
|
|
# # we better have the same avatar
|
|
|
|
# expect(user.uploaded_avatar_id).to eq(avatar_id)
|
2016-09-01 22:04:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-08 05:04:33 -05:00
|
|
|
context "when discourse_connect_overrides_avatar is enabled" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:sso_record) do
|
|
|
|
Fabricate(:single_sign_on_record, external_avatar_url: "http://example.com/an_image.png")
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2016-10-24 13:55:30 -04:00
|
|
|
|
2015-01-28 11:52:07 -05:00
|
|
|
let!(:sso) do
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2015-01-28 11:52:07 -05:00
|
|
|
sso.username = "test"
|
|
|
|
sso.name = "test"
|
|
|
|
sso.email = sso_record.user.email
|
|
|
|
sso.external_id = sso_record.external_id
|
|
|
|
sso
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2016-10-24 13:55:30 -04:00
|
|
|
|
2015-01-28 11:52:07 -05:00
|
|
|
let(:logo) { file_from_fixtures("logo.png") }
|
2015-01-28 10:47:59 -05:00
|
|
|
|
2021-02-08 05:04:33 -05:00
|
|
|
before { SiteSetting.discourse_connect_overrides_avatar = true }
|
2015-01-28 10:47:59 -05:00
|
|
|
|
|
|
|
it "deal with no avatar url passed for an existing user with an avatar" do
|
2016-10-24 13:55:30 -04:00
|
|
|
Sidekiq::Testing.inline! do
|
|
|
|
# Deliberately not setting avatar_url so it should not update
|
|
|
|
sso_record.user.update_columns(uploaded_avatar_id: -1)
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(user).to_not be_nil
|
|
|
|
expect(user.uploaded_avatar_id).to eq(-1)
|
|
|
|
end
|
2015-01-28 10:47:59 -05:00
|
|
|
end
|
2015-01-28 11:52:07 -05:00
|
|
|
|
|
|
|
it "deal with no avatar_force_update passed as a boolean" do
|
2016-10-24 13:55:30 -04:00
|
|
|
Sidekiq::Testing.inline! do
|
|
|
|
FileHelper.stubs(:download).returns(logo)
|
2015-01-28 11:52:07 -05:00
|
|
|
|
2016-10-24 13:55:30 -04:00
|
|
|
sso_record.user.update_columns(uploaded_avatar_id: -1)
|
2016-09-01 22:04:22 -04:00
|
|
|
|
2016-10-24 13:55:30 -04:00
|
|
|
sso.avatar_url = "http://example.com/a_different_image.png"
|
|
|
|
sso.avatar_force_update = false
|
2015-01-28 11:52:07 -05:00
|
|
|
|
2016-10-24 13:55:30 -04:00
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
user.reload
|
2016-09-01 22:04:22 -04:00
|
|
|
|
2016-10-24 13:55:30 -04:00
|
|
|
expect(user).to_not be_nil
|
|
|
|
expect(user.uploaded_avatar_id).to_not eq(-1)
|
|
|
|
end
|
2015-01-28 11:52:07 -05:00
|
|
|
end
|
2015-01-28 10:47:59 -05:00
|
|
|
end
|
2018-05-07 04:03:26 -04:00
|
|
|
|
2021-02-08 05:04:33 -05:00
|
|
|
context "when discourse_connect_overrides_profile_background is not enabled" do
|
2018-05-07 04:03:26 -04:00
|
|
|
it "correctly handles provided profile_background_urls" do
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2018-05-07 04:03:26 -04:00
|
|
|
sso.external_id = 666
|
|
|
|
sso.email = "sam@sam.com"
|
|
|
|
sso.name = "sam"
|
|
|
|
sso.username = "sam"
|
|
|
|
sso.profile_background_url = "http://awesome.com/image.png"
|
|
|
|
sso.suppress_welcome_message = true
|
|
|
|
|
|
|
|
FileHelper.stubs(:download).returns(file_from_fixtures("logo.png"))
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
user.reload
|
|
|
|
user.user_profile.reload
|
2019-04-28 23:58:52 -04:00
|
|
|
profile_background_url = user.profile_background_upload.url
|
2018-05-07 04:03:26 -04:00
|
|
|
|
|
|
|
# initial creation ...
|
2019-04-28 23:58:52 -04:00
|
|
|
expect(profile_background_url).to_not eq(nil)
|
|
|
|
expect(profile_background_url).to_not eq("")
|
2018-05-07 04:03:26 -04:00
|
|
|
|
|
|
|
FileHelper.stubs(:download) { raise "should not be called" }
|
|
|
|
sso.profile_background_url = "https://some.new/avatar.png"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
user.reload
|
|
|
|
user.user_profile.reload
|
|
|
|
|
|
|
|
# profile_background updated but no override specified ...
|
2019-04-28 23:58:52 -04:00
|
|
|
expect(user.profile_background_upload.url).to eq(profile_background_url)
|
2018-05-07 04:03:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-08 05:04:33 -05:00
|
|
|
context "when discourse_connect_overrides_profile_background is enabled" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:sso_record) do
|
|
|
|
Fabricate(
|
|
|
|
:single_sign_on_record,
|
|
|
|
external_profile_background_url: "http://example.com/an_image.png",
|
|
|
|
)
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2018-05-07 04:03:26 -04:00
|
|
|
|
|
|
|
let!(:sso) do
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2018-05-07 04:03:26 -04:00
|
|
|
sso.username = "test"
|
|
|
|
sso.name = "test"
|
|
|
|
sso.email = sso_record.user.email
|
|
|
|
sso.external_id = sso_record.external_id
|
|
|
|
sso
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2018-05-07 04:03:26 -04:00
|
|
|
|
|
|
|
let(:logo) { file_from_fixtures("logo.png") }
|
|
|
|
|
2021-02-08 05:04:33 -05:00
|
|
|
before { SiteSetting.discourse_connect_overrides_profile_background = true }
|
2018-05-07 04:03:26 -04:00
|
|
|
|
|
|
|
it "deal with no profile_background_url passed for an existing user with a profile_background" do
|
2019-04-28 23:58:52 -04:00
|
|
|
# Deliberately not setting profile_background_url so it should not update
|
|
|
|
sso_record.user.user_profile.clear_profile_background
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
user.reload
|
2018-05-07 04:03:26 -04:00
|
|
|
|
2019-04-28 23:58:52 -04:00
|
|
|
expect(user.profile_background_upload).to eq(nil)
|
2018-05-07 04:03:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "deal with a profile_background_url passed for an existing user with a profile_background" do
|
2019-04-28 23:58:52 -04:00
|
|
|
url = "http://example.com/a_different_image.png"
|
|
|
|
stub_request(:get, url).to_return(body: logo)
|
2018-05-07 04:03:26 -04:00
|
|
|
|
2019-04-28 23:58:52 -04:00
|
|
|
sso_record.user.user_profile.clear_profile_background
|
|
|
|
sso.profile_background_url = "http://example.com/a_different_image.png"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
user.reload
|
2018-05-07 04:03:26 -04:00
|
|
|
|
2019-04-28 23:58:52 -04:00
|
|
|
expect(user.profile_background_upload).to_not eq(nil)
|
2018-05-07 04:03:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-08 05:04:33 -05:00
|
|
|
context "when discourse_connect_overrides_card_background is not enabled" do
|
2018-05-07 04:03:26 -04:00
|
|
|
it "correctly handles provided card_background_urls" do
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2018-05-07 04:03:26 -04:00
|
|
|
sso.external_id = 666
|
|
|
|
sso.email = "sam@sam.com"
|
|
|
|
sso.name = "sam"
|
|
|
|
sso.username = "sam"
|
|
|
|
sso.card_background_url = "http://awesome.com/image.png"
|
|
|
|
sso.suppress_welcome_message = true
|
|
|
|
FileHelper.stubs(:download).returns(file_from_fixtures("logo.png"))
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
user.reload
|
|
|
|
user.user_profile.reload
|
2019-04-28 23:58:52 -04:00
|
|
|
card_background_url = user.user_profile.card_background_upload.url
|
2018-05-07 04:03:26 -04:00
|
|
|
|
|
|
|
# initial creation ...
|
2019-04-28 23:58:52 -04:00
|
|
|
expect(card_background_url).to be_present
|
2018-05-07 04:03:26 -04:00
|
|
|
|
|
|
|
FileHelper.stubs(:download) { raise "should not be called" }
|
|
|
|
sso.card_background_url = "https://some.new/avatar.png"
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
user.reload
|
|
|
|
user.user_profile.reload
|
|
|
|
|
|
|
|
# card_background updated but no override specified ...
|
2019-04-28 23:58:52 -04:00
|
|
|
expect(user.user_profile.card_background_upload.url).to eq(card_background_url)
|
2018-05-07 04:03:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-08 05:04:33 -05:00
|
|
|
context "when discourse_connect_overrides_card_background is enabled" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:sso_record) do
|
|
|
|
Fabricate(
|
|
|
|
:single_sign_on_record,
|
|
|
|
external_card_background_url: "http://example.com/an_image.png",
|
|
|
|
)
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2018-05-07 04:03:26 -04:00
|
|
|
|
|
|
|
let!(:sso) do
|
2021-02-18 05:35:10 -05:00
|
|
|
sso = new_discourse_sso
|
2018-05-07 04:03:26 -04:00
|
|
|
sso.username = "test"
|
|
|
|
sso.name = "test"
|
|
|
|
sso.email = sso_record.user.email
|
|
|
|
sso.external_id = sso_record.external_id
|
|
|
|
sso
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2018-05-07 04:03:26 -04:00
|
|
|
|
|
|
|
let(:logo) { file_from_fixtures("logo.png") }
|
|
|
|
|
2021-02-08 05:04:33 -05:00
|
|
|
before { SiteSetting.discourse_connect_overrides_card_background = true }
|
2018-05-07 04:03:26 -04:00
|
|
|
|
|
|
|
it "deal with no card_background_url passed for an existing user with a card_background" do
|
2019-04-28 23:58:52 -04:00
|
|
|
# Deliberately not setting card_background_url so it should not update
|
|
|
|
sso_record.user.user_profile.clear_card_background
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
user.reload
|
2018-05-07 04:03:26 -04:00
|
|
|
|
2019-04-28 23:58:52 -04:00
|
|
|
expect(user.user_profile.card_background_upload).to eq(nil)
|
2018-05-07 04:03:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "deal with a card_background_url passed for an existing user with a card_background_url" do
|
2019-04-28 23:58:52 -04:00
|
|
|
url = "http://example.com/a_different_image.png"
|
|
|
|
stub_request(:get, url).to_return(body: logo)
|
2018-05-07 04:03:26 -04:00
|
|
|
|
2019-04-28 23:58:52 -04:00
|
|
|
sso_record.user.user_profile.clear_card_background
|
|
|
|
sso.card_background_url = url
|
2018-05-07 04:03:26 -04:00
|
|
|
|
2019-04-28 23:58:52 -04:00
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
user.reload
|
2018-05-07 04:03:26 -04:00
|
|
|
|
2019-04-28 23:58:52 -04:00
|
|
|
expect(user.user_profile.card_background_upload.url).to_not eq("")
|
2018-05-07 04:03:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-16 10:44:07 -05:00
|
|
|
context "when user is staged" do
|
|
|
|
it "uses username of the staged user if username is not present in payload" do
|
|
|
|
staged_username = "staged_user"
|
|
|
|
email = "staged@user.com"
|
|
|
|
Fabricate(:user, staged: true, username: staged_username, email: email)
|
|
|
|
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.email = email
|
|
|
|
sso.external_id = "B"
|
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(user.username).to eq(staged_username)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "uses username of the staged user if username in payload is the same" do
|
|
|
|
# it's important to check this, because we had regressions
|
|
|
|
# where usernames were changed to the same username with "1" added at the end
|
|
|
|
staged_username = "staged_user"
|
|
|
|
email = "staged@user.com"
|
|
|
|
Fabricate(:user, staged: true, username: staged_username, email: email)
|
|
|
|
|
|
|
|
sso = new_discourse_sso
|
|
|
|
sso.username = staged_username
|
|
|
|
sso.email = email
|
|
|
|
sso.external_id = "B"
|
|
|
|
|
|
|
|
user = sso.lookup_or_create_user(ip_address)
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(user.username).to eq(staged_username)
|
|
|
|
end
|
|
|
|
end
|
2014-02-24 22:30:49 -05:00
|
|
|
end
|