.circleci
.dependabot
.github
app
bin
config
db
dist
lib
log
nanobox
public
spec
controllers
fabricators
features
fixtures
helpers
lib
mailers
models
admin
concerns
form
web
account_alias_spec.rb
account_conversation_spec.rb
account_domain_block_spec.rb
account_filter_spec.rb
account_migration_spec.rb
account_moderation_note_spec.rb
account_spec.rb
account_stat_spec.rb
account_tag_stat_spec.rb
backup_spec.rb
block_spec.rb
conversation_mute_spec.rb
conversation_spec.rb
custom_emoji_category_spec.rb
custom_emoji_filter_spec.rb
custom_emoji_spec.rb
custom_filter_spec.rb
domain_allow_spec.rb
domain_block_spec.rb
email_domain_block_spec.rb
export_spec.rb
favourite_spec.rb
featured_tag_spec.rb
follow_request_spec.rb
follow_spec.rb
home_feed_spec.rb
identity_spec.rb
import_spec.rb
invite_spec.rb
list_account_spec.rb
list_spec.rb
marker_spec.rb
media_attachment_spec.rb
mention_spec.rb
mute_spec.rb
notification_spec.rb
poll_spec.rb
poll_vote_spec.rb
preview_card_spec.rb
relay_spec.rb
remote_follow_spec.rb
report_filter_spec.rb
report_spec.rb
scheduled_status_spec.rb
session_activation_spec.rb
setting_spec.rb
site_upload_spec.rb
status_pin_spec.rb
status_spec.rb
status_stat_spec.rb
tag_spec.rb
trending_tags_spec.rb
user_invite_request_spec.rb
user_spec.rb
policies
presenters
requests
routing
serializers
services
support
validators
views
workers
rails_helper.rb
spec_helper.rb
streaming
vendor
.buildpacks
.codeclimate.yml
.dockerignore
.editorconfig
.env.nanobox
.env.production.sample
.env.test
.env.vagrant
.eslintignore
.eslintrc.js
.foreman
.gitattributes
.gitignore
.haml-lint.yml
.nanoignore
.nvmrc
.profile
.rspec
.rubocop.yml
.ruby-version
.sass-lint.yml
.slugignore
.yarnclean
AUTHORS.md
Aptfile
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Capfile
Dockerfile
Gemfile
Gemfile.lock
LICENSE
Procfile
Procfile.dev
README.md
Rakefile
Vagrantfile
app.json
babel.config.js
boxfile.yml
config.ru
crowdin.yml
docker-compose.yml
package.json
postcss.config.js
priv-config
scalingo.json
yarn.lock
* Change domain blocks to automatically support subdomains If a more authoritative domain is blocked (example.com), then the same block will be applied to a subdomain (foo.example.com) * Match subdomains of existing accounts when blocking/unblocking domains * Improve code style
88 lines
3.4 KiB
Ruby
88 lines
3.4 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe DomainBlock, type: :model do
|
|
describe 'validations' do
|
|
it 'has a valid fabricator' do
|
|
domain_block = Fabricate.build(:domain_block)
|
|
expect(domain_block).to be_valid
|
|
end
|
|
|
|
it 'is invalid without a domain' do
|
|
domain_block = Fabricate.build(:domain_block, domain: nil)
|
|
domain_block.valid?
|
|
expect(domain_block).to model_have_error_on_field(:domain)
|
|
end
|
|
|
|
it 'is invalid if the same normalized domain already exists' do
|
|
domain_block_1 = Fabricate(:domain_block, domain: 'にゃん')
|
|
domain_block_2 = Fabricate.build(:domain_block, domain: 'xn--r9j5b5b')
|
|
domain_block_2.valid?
|
|
expect(domain_block_2).to model_have_error_on_field(:domain)
|
|
end
|
|
end
|
|
|
|
describe '.blocked?' do
|
|
it 'returns true if the domain is suspended' do
|
|
Fabricate(:domain_block, domain: 'example.com', severity: :suspend)
|
|
expect(DomainBlock.blocked?('example.com')).to eq true
|
|
end
|
|
|
|
it 'returns false even if the domain is silenced' do
|
|
Fabricate(:domain_block, domain: 'example.com', severity: :silence)
|
|
expect(DomainBlock.blocked?('example.com')).to eq false
|
|
end
|
|
|
|
it 'returns false if the domain is not suspended nor silenced' do
|
|
expect(DomainBlock.blocked?('example.com')).to eq false
|
|
end
|
|
end
|
|
|
|
describe '.rule_for' do
|
|
it 'returns rule matching a blocked domain' do
|
|
block = Fabricate(:domain_block, domain: 'example.com')
|
|
expect(DomainBlock.rule_for('example.com')).to eq block
|
|
end
|
|
|
|
it 'returns a rule matching a subdomain of a blocked domain' do
|
|
block = Fabricate(:domain_block, domain: 'example.com')
|
|
expect(DomainBlock.rule_for('sub.example.com')).to eq block
|
|
end
|
|
|
|
it 'returns a rule matching a blocked subdomain' do
|
|
block = Fabricate(:domain_block, domain: 'sub.example.com')
|
|
expect(DomainBlock.rule_for('sub.example.com')).to eq block
|
|
end
|
|
end
|
|
|
|
describe '#stricter_than?' do
|
|
it 'returns true if the new block has suspend severity while the old has lower severity' do
|
|
suspend = DomainBlock.new(domain: 'domain', severity: :suspend)
|
|
silence = DomainBlock.new(domain: 'domain', severity: :silence)
|
|
noop = DomainBlock.new(domain: 'domain', severity: :noop)
|
|
expect(suspend.stricter_than?(silence)).to be true
|
|
expect(suspend.stricter_than?(noop)).to be true
|
|
end
|
|
|
|
it 'returns false if the new block has lower severity than the old one' do
|
|
suspend = DomainBlock.new(domain: 'domain', severity: :suspend)
|
|
silence = DomainBlock.new(domain: 'domain', severity: :silence)
|
|
noop = DomainBlock.new(domain: 'domain', severity: :noop)
|
|
expect(silence.stricter_than?(suspend)).to be false
|
|
expect(noop.stricter_than?(suspend)).to be false
|
|
expect(noop.stricter_than?(silence)).to be false
|
|
end
|
|
|
|
it 'returns false if the new block does is less strict regarding reports' do
|
|
older = DomainBlock.new(domain: 'domain', severity: :silence, reject_reports: true)
|
|
newer = DomainBlock.new(domain: 'domain', severity: :silence, reject_reports: false)
|
|
expect(newer.stricter_than?(older)).to be false
|
|
end
|
|
|
|
it 'returns false if the new block does is less strict regarding media' do
|
|
older = DomainBlock.new(domain: 'domain', severity: :silence, reject_media: true)
|
|
newer = DomainBlock.new(domain: 'domain', severity: :silence, reject_media: false)
|
|
expect(newer.stricter_than?(older)).to be false
|
|
end
|
|
end
|
|
end
|