SECURITY: Any group can be invited into a PM.

This commit is contained in:
Guo Xiang Tan
2017-12-14 10:53:21 +08:00
parent 14cfce2827
commit f2565f6c7e
8 changed files with 97 additions and 9 deletions

View File

@@ -211,12 +211,30 @@ describe Guardian do
it "returns true if target is a staff group" do
Group::STAFF_GROUPS.each do |name|
g = Group[name]
g.messageable_level = Group::ALIAS_LEVELS[:everyone]
g.update!(messageable_level: Group::ALIAS_LEVELS[:everyone])
expect(Guardian.new(user).can_send_private_message?(g)).to be_truthy
end
end
end
it "respects the group's messageable_level" do
group = Fabricate(:group)
Group::ALIAS_LEVELS.each do |level, _|
group.update!(messageable_level: Group::ALIAS_LEVELS[level])
output = level == :everyone ? true : false
expect(Guardian.new(user).can_send_private_message?(group)).to eq(output)
end
admin = Fabricate(:admin)
Group::ALIAS_LEVELS.each do |level, _|
group.update!(messageable_level: Group::ALIAS_LEVELS[level])
expect(Guardian.new(admin).can_send_private_message?(group)).to eq(true)
end
end
context 'target user has private message disabled' do
before do
another_user.user_option.update!(allow_private_messages: false)

View File

@@ -765,7 +765,7 @@ describe PostCreator do
let(:target_user1) { Fabricate(:coding_horror) }
let(:target_user2) { Fabricate(:moderator) }
let(:group) do
g = Fabricate.build(:group)
g = Fabricate.build(:group, messageable_level: Group::ALIAS_LEVELS[:everyone])
g.add(target_user1)
g.add(target_user2)
g.save
@@ -773,10 +773,12 @@ describe PostCreator do
end
let(:unrelated) { Fabricate(:user) }
let(:post) do
PostCreator.create(user, title: 'hi there welcome to my topic',
raw: "this is my awesome message @#{unrelated.username_lower}",
archetype: Archetype.private_message,
target_group_names: group.name)
PostCreator.create!(user,
title: 'hi there welcome to my topic',
raw: "this is my awesome message @#{unrelated.username_lower}",
archetype: Archetype.private_message,
target_group_names: group.name
)
end
it 'can post to a group correctly' do