mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
SECURITY: Restrict unlisted topic creation (#19259)
This commit is contained in:
@@ -518,5 +518,27 @@ RSpec.describe TopicCreator do
|
||||
expect(topic.external_id).to eq('external_id')
|
||||
end
|
||||
end
|
||||
|
||||
context "when invisible/unlisted" do
|
||||
let(:unlisted_attrs) { valid_attrs.merge(visible: false) }
|
||||
|
||||
it "throws an exception for a non-staff user" do
|
||||
expect do
|
||||
TopicCreator.create(user, Guardian.new(user), unlisted_attrs)
|
||||
end.to raise_error(ActiveRecord::Rollback)
|
||||
end
|
||||
|
||||
it "is invalid for a non-staff user" do
|
||||
expect(TopicCreator.new(user, Guardian.new(user), unlisted_attrs).valid?).to eq(false)
|
||||
end
|
||||
|
||||
it "creates unlisted topic for an admin" do
|
||||
expect(TopicCreator.create(admin, Guardian.new(admin), unlisted_attrs)).to be_valid
|
||||
end
|
||||
|
||||
it "is valid for an admin" do
|
||||
expect(TopicCreator.new(admin, Guardian.new(admin), unlisted_attrs).valid?).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user