Merge commit '55e7c08a83547424024bac311d5459cb82cf6dae' into glitch-soc/merge-upstream
Conflicts: - `app/models/user_settings.rb`: Upstream added a constraint on a setting textually close to glitch-soc-only settings. Applied upstream's change. - `lib/sanitize_ext/sanitize_config.rb`: Upstream added support for the `translate` attribute on a few elements, where glitch-soc had a different set of allowed elements and attributes. Extended glitch-soc's allowed attributes with `translate` as upstream did. - `spec/validators/status_length_validator_spec.rb`: Upstream refactored to use RSpec's `instance_double` instead of `double`, but glitch-soc had changes to tests due to configurable max toot chars. Applied upstream's changes while keeping tests against configurable max toot chars.
This commit is contained in:
@@ -6,8 +6,8 @@ RSpec.describe BlacklistedEmailValidator, type: :validator do
|
||||
describe '#validate' do
|
||||
subject { described_class.new.validate(user); errors }
|
||||
|
||||
let(:user) { double(email: 'info@mail.com', sign_up_ip: '1.2.3.4', errors: errors) }
|
||||
let(:errors) { double(add: nil) }
|
||||
let(:user) { instance_double(User, email: 'info@mail.com', sign_up_ip: '1.2.3.4', errors: errors) }
|
||||
let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
|
||||
|
||||
before do
|
||||
allow(user).to receive(:valid_invitation?).and_return(false)
|
||||
|
@@ -11,8 +11,8 @@ RSpec.describe DisallowedHashtagsValidator, type: :validator do
|
||||
described_class.new.validate(status)
|
||||
end
|
||||
|
||||
let(:status) { double(errors: errors, local?: local, reblog?: reblog, text: disallowed_tags.map { |x| "##{x}" }.join(' ')) }
|
||||
let(:errors) { double(add: nil) }
|
||||
let(:status) { instance_double(Status, errors: errors, local?: local, reblog?: reblog, text: disallowed_tags.map { |x| "##{x}" }.join(' ')) }
|
||||
let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
|
||||
|
||||
context 'with a remote reblog' do
|
||||
let(:local) { false }
|
||||
|
@@ -4,7 +4,7 @@ require 'rails_helper'
|
||||
|
||||
describe EmailMxValidator do
|
||||
describe '#validate' do
|
||||
let(:user) { double(email: 'foo@example.com', sign_up_ip: '1.2.3.4', errors: double(add: nil)) }
|
||||
let(:user) { instance_double(User, email: 'foo@example.com', sign_up_ip: '1.2.3.4', errors: instance_double(ActiveModel::Errors, add: nil)) }
|
||||
|
||||
context 'with an e-mail domain that is explicitly allowed' do
|
||||
around do |block|
|
||||
@@ -15,7 +15,7 @@ describe EmailMxValidator do
|
||||
end
|
||||
|
||||
it 'does not add errors if there are no DNS records' do
|
||||
resolver = double
|
||||
resolver = instance_double(Resolv::DNS)
|
||||
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::MX).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::A).and_return([])
|
||||
@@ -29,7 +29,7 @@ describe EmailMxValidator do
|
||||
end
|
||||
|
||||
it 'adds no error if there are DNS records for the e-mail domain' do
|
||||
resolver = double
|
||||
resolver = instance_double(Resolv::DNS)
|
||||
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::MX).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::A).and_return([Resolv::DNS::Resource::IN::A.new('192.0.2.42')])
|
||||
@@ -46,19 +46,19 @@ describe EmailMxValidator do
|
||||
allow(TagManager).to receive(:instance).and_return(double)
|
||||
allow(double).to receive(:normalize_domain).with('example.com').and_raise(Addressable::URI::InvalidURIError)
|
||||
|
||||
user = double(email: 'foo@example.com', errors: double(add: nil))
|
||||
user = instance_double(User, email: 'foo@example.com', errors: instance_double(ActiveModel::Errors, add: nil))
|
||||
subject.validate(user)
|
||||
expect(user.errors).to have_received(:add)
|
||||
end
|
||||
|
||||
it 'adds an error if the domain email portion is blank' do
|
||||
user = double(email: 'foo@', errors: double(add: nil))
|
||||
user = instance_double(User, email: 'foo@', errors: instance_double(ActiveModel::Errors, add: nil))
|
||||
subject.validate(user)
|
||||
expect(user.errors).to have_received(:add)
|
||||
end
|
||||
|
||||
it 'adds an error if the email domain name contains empty labels' do
|
||||
resolver = double
|
||||
resolver = instance_double(Resolv::DNS)
|
||||
|
||||
allow(resolver).to receive(:getresources).with('example..com', Resolv::DNS::Resource::IN::MX).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('example..com', Resolv::DNS::Resource::IN::A).and_return([Resolv::DNS::Resource::IN::A.new('192.0.2.42')])
|
||||
@@ -66,13 +66,13 @@ describe EmailMxValidator do
|
||||
allow(resolver).to receive(:timeouts=).and_return(nil)
|
||||
allow(Resolv::DNS).to receive(:open).and_yield(resolver)
|
||||
|
||||
user = double(email: 'foo@example..com', sign_up_ip: '1.2.3.4', errors: double(add: nil))
|
||||
user = instance_double(User, email: 'foo@example..com', sign_up_ip: '1.2.3.4', errors: instance_double(ActiveModel::Errors, add: nil))
|
||||
subject.validate(user)
|
||||
expect(user.errors).to have_received(:add)
|
||||
end
|
||||
|
||||
it 'adds an error if there are no DNS records for the e-mail domain' do
|
||||
resolver = double
|
||||
resolver = instance_double(Resolv::DNS)
|
||||
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::MX).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::A).and_return([])
|
||||
@@ -85,9 +85,11 @@ describe EmailMxValidator do
|
||||
end
|
||||
|
||||
it 'adds an error if a MX record does not lead to an IP' do
|
||||
resolver = double
|
||||
resolver = instance_double(Resolv::DNS)
|
||||
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::MX).and_return([double(exchange: 'mail.example.com')])
|
||||
allow(resolver).to receive(:getresources)
|
||||
.with('example.com', Resolv::DNS::Resource::IN::MX)
|
||||
.and_return([instance_double(Resolv::DNS::Resource::MX, exchange: 'mail.example.com')])
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::A).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::AAAA).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('mail.example.com', Resolv::DNS::Resource::IN::A).and_return([])
|
||||
@@ -101,13 +103,15 @@ describe EmailMxValidator do
|
||||
|
||||
it 'adds an error if the MX record is blacklisted' do
|
||||
EmailDomainBlock.create!(domain: 'mail.example.com')
|
||||
resolver = double
|
||||
resolver = instance_double(Resolv::DNS)
|
||||
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::MX).and_return([double(exchange: 'mail.example.com')])
|
||||
allow(resolver).to receive(:getresources)
|
||||
.with('example.com', Resolv::DNS::Resource::IN::MX)
|
||||
.and_return([instance_double(Resolv::DNS::Resource::MX, exchange: 'mail.example.com')])
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::A).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::AAAA).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('mail.example.com', Resolv::DNS::Resource::IN::A).and_return([double(address: '2.3.4.5')])
|
||||
allow(resolver).to receive(:getresources).with('mail.example.com', Resolv::DNS::Resource::IN::AAAA).and_return([double(address: 'fd00::2')])
|
||||
allow(resolver).to receive(:getresources).with('mail.example.com', Resolv::DNS::Resource::IN::A).and_return([instance_double(Resolv::DNS::Resource::IN::A, address: '2.3.4.5')])
|
||||
allow(resolver).to receive(:getresources).with('mail.example.com', Resolv::DNS::Resource::IN::AAAA).and_return([instance_double(Resolv::DNS::Resource::IN::A, address: 'fd00::2')])
|
||||
allow(resolver).to receive(:timeouts=).and_return(nil)
|
||||
allow(Resolv::DNS).to receive(:open).and_yield(resolver)
|
||||
|
||||
|
@@ -12,9 +12,9 @@ RSpec.describe FollowLimitValidator, type: :validator do
|
||||
described_class.new.validate(follow)
|
||||
end
|
||||
|
||||
let(:follow) { double(account: account, errors: errors) }
|
||||
let(:errors) { double(add: nil) }
|
||||
let(:account) { double(nil?: _nil, local?: local, following_count: 0, followers_count: 0) }
|
||||
let(:follow) { instance_double(Follow, account: account, errors: errors) }
|
||||
let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
|
||||
let(:account) { instance_double(Account, nil?: _nil, local?: local, following_count: 0, followers_count: 0) }
|
||||
let(:_nil) { true }
|
||||
let(:local) { false }
|
||||
|
||||
|
@@ -8,7 +8,7 @@ describe NoteLengthValidator do
|
||||
describe '#validate' do
|
||||
it 'adds an error when text is over 500 characters' do
|
||||
text = 'a' * 520
|
||||
account = double(note: text, errors: double(add: nil))
|
||||
account = instance_double(Account, note: text, errors: activemodel_errors)
|
||||
|
||||
subject.validate_each(account, 'note', text)
|
||||
expect(account.errors).to have_received(:add)
|
||||
@@ -16,7 +16,7 @@ describe NoteLengthValidator do
|
||||
|
||||
it 'counts URLs as 23 characters flat' do
|
||||
text = ('a' * 476) + " http://#{'b' * 30}.com/example"
|
||||
account = double(note: text, errors: double(add: nil))
|
||||
account = instance_double(Account, note: text, errors: activemodel_errors)
|
||||
|
||||
subject.validate_each(account, 'note', text)
|
||||
expect(account.errors).to_not have_received(:add)
|
||||
@@ -24,10 +24,16 @@ describe NoteLengthValidator do
|
||||
|
||||
it 'does not count non-autolinkable URLs as 23 characters flat' do
|
||||
text = ('a' * 476) + "http://#{'b' * 30}.com/example"
|
||||
account = double(note: text, errors: double(add: nil))
|
||||
account = instance_double(Account, note: text, errors: activemodel_errors)
|
||||
|
||||
subject.validate_each(account, 'note', text)
|
||||
expect(account.errors).to have_received(:add)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def activemodel_errors
|
||||
instance_double(ActiveModel::Errors, add: nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -9,8 +9,8 @@ RSpec.describe PollValidator, type: :validator do
|
||||
end
|
||||
|
||||
let(:validator) { described_class.new }
|
||||
let(:poll) { double(options: options, expires_at: expires_at, errors: errors) }
|
||||
let(:errors) { double(add: nil) }
|
||||
let(:poll) { instance_double(Poll, options: options, expires_at: expires_at, errors: errors) }
|
||||
let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
|
||||
let(:options) { %w(foo bar) }
|
||||
let(:expires_at) { 1.day.from_now }
|
||||
|
||||
|
@@ -5,27 +5,27 @@ require 'rails_helper'
|
||||
describe StatusLengthValidator do
|
||||
describe '#validate' do
|
||||
it 'does not add errors onto remote statuses' do
|
||||
status = double(local?: false)
|
||||
status = instance_double(Status, local?: false)
|
||||
subject.validate(status)
|
||||
expect(status).to_not receive(:errors)
|
||||
end
|
||||
|
||||
it 'does not add errors onto local reblogs' do
|
||||
status = double(local?: false, reblog?: true)
|
||||
status = instance_double(Status, local?: false, reblog?: true)
|
||||
subject.validate(status)
|
||||
expect(status).to_not receive(:errors)
|
||||
end
|
||||
|
||||
it 'adds an error when content warning is over MAX_CHARS characters' do
|
||||
chars = StatusLengthValidator::MAX_CHARS + 1
|
||||
status = double(spoiler_text: 'a' * chars, text: '', errors: double(add: nil), local?: true, reblog?: false)
|
||||
status = instance_double(Status, spoiler_text: 'a' * chars, text: '', errors: activemodel_errors, local?: true, reblog?: false)
|
||||
subject.validate(status)
|
||||
expect(status.errors).to have_received(:add)
|
||||
end
|
||||
|
||||
it 'adds an error when text is over MAX_CHARS characters' do
|
||||
chars = StatusLengthValidator::MAX_CHARS + 1
|
||||
status = double(spoiler_text: '', text: 'a' * chars, errors: double(add: nil), local?: true, reblog?: false)
|
||||
status = instance_double(Status, spoiler_text: '', text: 'a' * chars, errors: activemodel_errors, local?: true, reblog?: false)
|
||||
subject.validate(status)
|
||||
expect(status.errors).to have_received(:add)
|
||||
end
|
||||
@@ -33,7 +33,7 @@ describe StatusLengthValidator do
|
||||
it 'adds an error when text and content warning are over MAX_CHARS characters total' do
|
||||
chars1 = 20
|
||||
chars2 = StatusLengthValidator::MAX_CHARS + 1 - chars1
|
||||
status = double(spoiler_text: 'a' * chars1, text: 'b' * chars2, errors: double(add: nil), local?: true, reblog?: false)
|
||||
status = instance_double(Status, spoiler_text: 'a' * chars1, text: 'b' * chars2, errors: activemodel_errors, local?: true, reblog?: false)
|
||||
subject.validate(status)
|
||||
expect(status.errors).to have_received(:add)
|
||||
end
|
||||
@@ -41,7 +41,7 @@ describe StatusLengthValidator do
|
||||
it 'counts URLs as 23 characters flat' do
|
||||
chars = StatusLengthValidator::MAX_CHARS - 1 - 23
|
||||
text = ('a' * chars) + " http://#{'b' * 30}.com/example"
|
||||
status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false)
|
||||
status = instance_double(Status, spoiler_text: '', text: text, errors: activemodel_errors, local?: true, reblog?: false)
|
||||
|
||||
subject.validate(status)
|
||||
expect(status.errors).to_not have_received(:add)
|
||||
@@ -49,7 +49,7 @@ describe StatusLengthValidator do
|
||||
|
||||
it 'does not count non-autolinkable URLs as 23 characters flat' do
|
||||
text = ('a' * 476) + "http://#{'b' * 30}.com/example"
|
||||
status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false)
|
||||
status = instance_double(Status, spoiler_text: '', text: text, errors: activemodel_errors, local?: true, reblog?: false)
|
||||
|
||||
subject.validate(status)
|
||||
expect(status.errors).to have_received(:add)
|
||||
@@ -57,7 +57,7 @@ describe StatusLengthValidator do
|
||||
|
||||
it 'does not count overly long URLs as 23 characters flat' do
|
||||
text = "http://example.com/valid?#{'#foo?' * 1000}"
|
||||
status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false)
|
||||
status = instance_double(Status, spoiler_text: '', text: text, errors: activemodel_errors, local?: true, reblog?: false)
|
||||
subject.validate(status)
|
||||
expect(status.errors).to have_received(:add)
|
||||
end
|
||||
@@ -66,7 +66,7 @@ describe StatusLengthValidator do
|
||||
username = '@alice'
|
||||
chars = StatusLengthValidator::MAX_CHARS - 1 - username.length
|
||||
text = ('a' * chars) + " #{username}@#{'b' * 30}.com"
|
||||
status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false)
|
||||
status = instance_double(Status, spoiler_text: '', text: text, errors: activemodel_errors, local?: true, reblog?: false)
|
||||
|
||||
subject.validate(status)
|
||||
expect(status.errors).to_not have_received(:add)
|
||||
@@ -74,10 +74,16 @@ describe StatusLengthValidator do
|
||||
|
||||
it 'does count both parts of remote usernames for overly long domains' do
|
||||
text = "@alice@#{'b' * 500}.com"
|
||||
status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false)
|
||||
status = instance_double(Status, spoiler_text: '', text: text, errors: activemodel_errors, local?: true, reblog?: false)
|
||||
|
||||
subject.validate(status)
|
||||
expect(status.errors).to have_received(:add)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def activemodel_errors
|
||||
instance_double(ActiveModel::Errors, add: nil)
|
||||
end
|
||||
end
|
||||
|
@@ -8,11 +8,11 @@ RSpec.describe StatusPinValidator, type: :validator do
|
||||
subject.validate(pin)
|
||||
end
|
||||
|
||||
let(:pin) { double(account: account, errors: errors, status: status, account_id: pin_account_id) }
|
||||
let(:status) { double(reblog?: reblog, account_id: status_account_id, visibility: visibility, direct_visibility?: visibility == 'direct') }
|
||||
let(:account) { double(status_pins: status_pins, local?: local) }
|
||||
let(:status_pins) { double(count: count) }
|
||||
let(:errors) { double(add: nil) }
|
||||
let(:pin) { instance_double(StatusPin, account: account, errors: errors, status: status, account_id: pin_account_id) }
|
||||
let(:status) { instance_double(Status, reblog?: reblog, account_id: status_account_id, visibility: visibility, direct_visibility?: visibility == 'direct') }
|
||||
let(:account) { instance_double(Account, status_pins: status_pins, local?: local) }
|
||||
let(:status_pins) { instance_double(Array, count: count) }
|
||||
let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
|
||||
let(:pin_account_id) { 1 }
|
||||
let(:status_account_id) { 1 }
|
||||
let(:visibility) { 'public' }
|
||||
|
@@ -6,7 +6,7 @@ describe UniqueUsernameValidator do
|
||||
describe '#validate' do
|
||||
context 'when local account' do
|
||||
it 'does not add errors if username is nil' do
|
||||
account = double(username: nil, domain: nil, persisted?: false, errors: double(add: nil))
|
||||
account = instance_double(Account, username: nil, domain: nil, persisted?: false, errors: activemodel_errors)
|
||||
subject.validate(account)
|
||||
expect(account.errors).to_not have_received(:add)
|
||||
end
|
||||
@@ -18,14 +18,14 @@ describe UniqueUsernameValidator do
|
||||
|
||||
it 'adds an error when the username is already used with ignoring cases' do
|
||||
Fabricate(:account, username: 'ABCdef')
|
||||
account = double(username: 'abcDEF', domain: nil, persisted?: false, errors: double(add: nil))
|
||||
account = instance_double(Account, username: 'abcDEF', domain: nil, persisted?: false, errors: activemodel_errors)
|
||||
subject.validate(account)
|
||||
expect(account.errors).to have_received(:add)
|
||||
end
|
||||
|
||||
it 'does not add errors when same username remote account exists' do
|
||||
Fabricate(:account, username: 'abcdef', domain: 'example.com')
|
||||
account = double(username: 'abcdef', domain: nil, persisted?: false, errors: double(add: nil))
|
||||
account = instance_double(Account, username: 'abcdef', domain: nil, persisted?: false, errors: activemodel_errors)
|
||||
subject.validate(account)
|
||||
expect(account.errors).to_not have_received(:add)
|
||||
end
|
||||
@@ -34,7 +34,7 @@ describe UniqueUsernameValidator do
|
||||
|
||||
context 'when remote account' do
|
||||
it 'does not add errors if username is nil' do
|
||||
account = double(username: nil, domain: 'example.com', persisted?: false, errors: double(add: nil))
|
||||
account = instance_double(Account, username: nil, domain: 'example.com', persisted?: false, errors: activemodel_errors)
|
||||
subject.validate(account)
|
||||
expect(account.errors).to_not have_received(:add)
|
||||
end
|
||||
@@ -46,23 +46,29 @@ describe UniqueUsernameValidator do
|
||||
|
||||
it 'adds an error when the username is already used with ignoring cases' do
|
||||
Fabricate(:account, username: 'ABCdef', domain: 'example.com')
|
||||
account = double(username: 'abcDEF', domain: 'example.com', persisted?: false, errors: double(add: nil))
|
||||
account = instance_double(Account, username: 'abcDEF', domain: 'example.com', persisted?: false, errors: activemodel_errors)
|
||||
subject.validate(account)
|
||||
expect(account.errors).to have_received(:add)
|
||||
end
|
||||
|
||||
it 'adds an error when the domain is already used with ignoring cases' do
|
||||
Fabricate(:account, username: 'ABCdef', domain: 'example.com')
|
||||
account = double(username: 'ABCdef', domain: 'EXAMPLE.COM', persisted?: false, errors: double(add: nil))
|
||||
account = instance_double(Account, username: 'ABCdef', domain: 'EXAMPLE.COM', persisted?: false, errors: activemodel_errors)
|
||||
subject.validate(account)
|
||||
expect(account.errors).to have_received(:add)
|
||||
end
|
||||
|
||||
it 'does not add errors when account with the same username and another domain exists' do
|
||||
Fabricate(:account, username: 'abcdef', domain: 'example.com')
|
||||
account = double(username: 'abcdef', domain: 'example2.com', persisted?: false, errors: double(add: nil))
|
||||
account = instance_double(Account, username: 'abcdef', domain: 'example2.com', persisted?: false, errors: activemodel_errors)
|
||||
subject.validate(account)
|
||||
expect(account.errors).to_not have_received(:add)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def activemodel_errors
|
||||
instance_double(ActiveModel::Errors, add: nil)
|
||||
end
|
||||
end
|
||||
|
@@ -10,8 +10,8 @@ RSpec.describe UnreservedUsernameValidator, type: :validator do
|
||||
end
|
||||
|
||||
let(:validator) { described_class.new }
|
||||
let(:account) { double(username: username, errors: errors) }
|
||||
let(:errors) { double(add: nil) }
|
||||
let(:account) { instance_double(Account, username: username, errors: errors) }
|
||||
let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
|
||||
|
||||
context 'when @username is blank?' do
|
||||
let(:username) { nil }
|
||||
|
@@ -10,8 +10,8 @@ RSpec.describe URLValidator, type: :validator do
|
||||
end
|
||||
|
||||
let(:validator) { described_class.new(attributes: [attribute]) }
|
||||
let(:record) { double(errors: errors) }
|
||||
let(:errors) { double(add: nil) }
|
||||
let(:record) { instance_double(Webhook, errors: errors) }
|
||||
let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
|
||||
let(:value) { '' }
|
||||
let(:attribute) { :foo }
|
||||
|
||||
|
Reference in New Issue
Block a user