FIX - limit number of embedded media items in a post (#10391)

* FIX - limit number of embedded media items in a post

* Add renamed settings to DeprecatedSettings
This commit is contained in:
jbrw
2020-08-07 12:08:59 -04:00
committed by GitHub
parent abebc4e05e
commit 3593e582a3
13 changed files with 108 additions and 71 deletions

View File

@ -137,45 +137,45 @@ describe PostValidator do
end
end
context "too_many_images" do
context "too_many_embedded_media" do
before do
SiteSetting.min_trust_to_post_images = 0
SiteSetting.newuser_max_images = 2
SiteSetting.min_trust_to_post_embedded_media = 0
SiteSetting.newuser_max_embedded_media = 2
end
it "should be invalid when new user exceeds max mentions limit" do
post.acting_user = build(:newuser)
post.expects(:image_count).returns(3)
validator.max_images_validator(post)
post.expects(:embedded_media_count).returns(3)
validator.max_embedded_media_validator(post)
expect(post.errors.count).to be > 0
end
it "should be valid when new user does not exceed max mentions limit" do
post.acting_user = build(:newuser)
post.expects(:image_count).returns(2)
validator.max_images_validator(post)
post.expects(:embedded_media_count).returns(2)
validator.max_embedded_media_validator(post)
expect(post.errors.count).to be(0)
end
it "should be invalid when user trust level is not sufficient" do
SiteSetting.min_trust_to_post_images = 4
SiteSetting.min_trust_to_post_embedded_media = 4
post.acting_user = build(:leader)
post.expects(:image_count).returns(2)
validator.max_images_validator(post)
post.expects(:embedded_media_count).returns(2)
validator.max_embedded_media_validator(post)
expect(post.errors.count).to be > 0
end
it "should be valid for moderator in all cases" do
post.acting_user = build(:moderator)
post.expects(:image_count).never
validator.max_images_validator(post)
post.expects(:embedded_media_count).never
validator.max_embedded_media_validator(post)
expect(post.errors.count).to be(0)
end
it "should be valid for admin in all cases" do
post.acting_user = build(:admin)
post.expects(:image_count).never
validator.max_images_validator(post)
post.expects(:embedded_media_count).never
validator.max_embedded_media_validator(post)
expect(post.errors.count).to be(0)
end
end
@ -290,7 +290,7 @@ describe PostValidator do
validator.expects(:raw_quality).never
validator.expects(:max_posts_validator).never
validator.expects(:max_mention_validator).never
validator.expects(:max_images_validator).never
validator.expects(:max_embedded_media_validator).never
validator.expects(:max_attachments_validator).never
validator.expects(:newuser_links_validator).never
validator.expects(:unique_post_validator).never