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:
Claire
2023-06-25 12:02:52 +02:00
117 changed files with 1235 additions and 862 deletions

View File

@ -26,7 +26,7 @@ RSpec.describe ActivityPub::Activity::Add do
end
context 'when status was not known before' do
let(:service_stub) { double }
let(:service_stub) { instance_double(ActivityPub::FetchRemoteStatusService) }
let(:json) do
{

View File

@ -26,7 +26,7 @@ RSpec.describe ActivityPub::Activity::Move do
stub_request(:post, old_account.inbox_url).to_return(status: 200)
stub_request(:post, new_account.inbox_url).to_return(status: 200)
service_stub = double
service_stub = instance_double(ActivityPub::FetchRemoteAccountService)
allow(ActivityPub::FetchRemoteAccountService).to receive(:new).and_return(service_stub)
allow(service_stub).to receive(:call).and_return(returned_account)
end

View File

@ -48,16 +48,25 @@ describe RequestPool do
expect(subject.size).to be > 1
end
it 'closes idle connections' do
stub_request(:get, 'http://example.com/').to_return(status: 200, body: 'Hello!')
subject.with('http://example.com') do |http_client|
http_client.get('/').flush
context 'with an idle connection' do
before do
stub_const('RequestPool::MAX_IDLE_TIME', 1) # Lower idle time limit to 1 seconds
stub_const('RequestPool::REAPER_FREQUENCY', 0.1) # Run reaper every 0.1 seconds
stub_request(:get, 'http://example.com/').to_return(status: 200, body: 'Hello!')
end
expect(subject.size).to eq 1
sleep RequestPool::MAX_IDLE_TIME + 30 + 1
expect(subject.size).to eq 0
it 'closes the connections' do
subject.with('http://example.com') do |http_client|
http_client.get('/').flush
end
expect { reaper_observes_idle_timeout }.to change(subject, :size).from(1).to(0)
end
def reaper_observes_idle_timeout
# One full idle period and 2 reaper cycles more
sleep RequestPool::MAX_IDLE_TIME + (RequestPool::REAPER_FREQUENCY * 2)
end
end
end
end

View File

@ -48,7 +48,7 @@ describe Request do
end
it 'executes a HTTP request when the first address is private' do
resolver = double
resolver = instance_double(Resolv::DNS)
allow(resolver).to receive(:getaddresses).with('example.com').and_return(%w(0.0.0.0 2001:4860:4860::8844))
allow(resolver).to receive(:timeouts=).and_return(nil)
@ -83,7 +83,7 @@ describe Request do
end
it 'raises Mastodon::ValidationError' do
resolver = double
resolver = instance_double(Resolv::DNS)
allow(resolver).to receive(:getaddresses).with('example.com').and_return(%w(0.0.0.0 2001:db8::face))
allow(resolver).to receive(:timeouts=).and_return(nil)

View File

@ -36,6 +36,14 @@ describe Sanitize::Config do
expect(Sanitize.fragment('<a href="http://example.com">Test</a>', subject)).to eq '<a href="http://example.com" rel="nofollow noopener noreferrer" target="_blank">Test</a>'
end
it 'keeps a with translate="no"' do
expect(Sanitize.fragment('<a href="http://example.com" translate="no">Test</a>', subject)).to eq '<a href="http://example.com" translate="no" rel="nofollow noopener noreferrer" target="_blank">Test</a>'
end
it 'removes "translate" attribute with invalid value' do
expect(Sanitize.fragment('<a href="http://example.com" translate="foo">Test</a>', subject)).to eq '<a href="http://example.com" rel="nofollow noopener noreferrer" target="_blank">Test</a>'
end
it 'removes a with unparsable href' do
expect(Sanitize.fragment('<a href=" https://google.fr">Test</a>', subject)).to eq 'Test'
end

View File

@ -7,7 +7,7 @@ RSpec.describe SuspiciousSignInDetector do
subject { described_class.new(user).suspicious?(request) }
let(:user) { Fabricate(:user, current_sign_in_at: 1.day.ago) }
let(:request) { double(remote_ip: remote_ip) }
let(:request) { instance_double(ActionDispatch::Request, remote_ip: remote_ip) }
let(:remote_ip) { nil }
context 'when user has 2FA enabled' do