Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `app/controllers/home_controller.rb`: Upstream made it so `/web` is available to non-logged-in users and `/` redirects to `/web` instead of `/about`. Kept our version since glitch-soc's WebUI doesn't have what's needed yet and I think /about is still a much better landing page anyway. - `app/models/form/admin_settings.rb`: Upstream added new settings, and glitch-soc had an extra setting. Not really a conflict. Added upstream's new settings. - `app/serializers/initial_state_serializer.rb`: Upstream added a new `server` initial state object. Not really a conflict. Merged upstream's changes. - `app/views/admin/settings/edit.html.haml`: Upstream added new settings. Not really a conflict. Merged upstream's changes. - `app/workers/scheduler/feed_cleanup_scheduler.rb`: Upstream refactored that part and removed the file. Ported our relevant changes into `app/lib/vacuum/feeds_vacuum.rb` - `config/settings.yml`: Upstream added new settings. Not a real conflict. Added upstream's new settings.
This commit is contained in:
@@ -31,16 +31,6 @@ RSpec.describe AboutController, type: :controller do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #terms' do
|
||||
before do
|
||||
get :terms
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'helper_method :new_user' do
|
||||
it 'returns a new User' do
|
||||
user = @controller.view_context.new_user
|
||||
|
@@ -420,7 +420,7 @@ RSpec.describe AccountsController, type: :controller do
|
||||
let(:remote_account) { Fabricate(:account, domain: 'example.com') }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:signed_request_account).and_return(remote_account)
|
||||
allow(controller).to receive(:signed_request_actor).and_return(remote_account)
|
||||
get :show, params: { username: account.username, format: format }
|
||||
end
|
||||
|
||||
|
@@ -24,7 +24,7 @@ RSpec.describe ActivityPub::CollectionsController, type: :controller do
|
||||
end
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:signed_request_account).and_return(remote_account)
|
||||
allow(controller).to receive(:signed_request_actor).and_return(remote_account)
|
||||
|
||||
Fabricate(:status_pin, account: account)
|
||||
Fabricate(:status_pin, account: account)
|
||||
|
@@ -15,7 +15,7 @@ RSpec.describe ActivityPub::FollowersSynchronizationsController, type: :controll
|
||||
end
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:signed_request_account).and_return(remote_account)
|
||||
allow(controller).to receive(:signed_request_actor).and_return(remote_account)
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
|
@@ -6,7 +6,7 @@ RSpec.describe ActivityPub::InboxesController, type: :controller do
|
||||
let(:remote_account) { nil }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:signed_request_account).and_return(remote_account)
|
||||
allow(controller).to receive(:signed_request_actor).and_return(remote_account)
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
|
@@ -28,7 +28,7 @@ RSpec.describe ActivityPub::OutboxesController, type: :controller do
|
||||
end
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:signed_request_account).and_return(remote_account)
|
||||
allow(controller).to receive(:signed_request_actor).and_return(remote_account)
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
|
@@ -168,7 +168,7 @@ RSpec.describe ActivityPub::RepliesController, type: :controller do
|
||||
|
||||
before do
|
||||
stub_const 'ActivityPub::RepliesController::DESCENDANTS_LIMIT', 5
|
||||
allow(controller).to receive(:signed_request_account).and_return(remote_querier)
|
||||
allow(controller).to receive(:signed_request_actor).and_return(remote_querier)
|
||||
|
||||
Fabricate(:status, thread: status, visibility: :public)
|
||||
Fabricate(:status, thread: status, visibility: :public)
|
||||
|
@@ -145,6 +145,17 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
|
||||
expect(json[:showing_reblogs]).to be false
|
||||
expect(json[:notifying]).to be true
|
||||
end
|
||||
|
||||
it 'changes languages option' do
|
||||
post :follow, params: { id: other_account.id, languages: %w(en es) }
|
||||
|
||||
json = body_as_json
|
||||
|
||||
expect(json[:following]).to be true
|
||||
expect(json[:showing_reblogs]).to be false
|
||||
expect(json[:notifying]).to be false
|
||||
expect(json[:languages]).to match_array %w(en es)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -3,6 +3,16 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ApplicationController, type: :controller do
|
||||
class WrappedActor
|
||||
attr_reader :wrapped_account
|
||||
|
||||
def initialize(wrapped_account)
|
||||
@wrapped_account = wrapped_account
|
||||
end
|
||||
|
||||
delegate :uri, :keypair, to: :wrapped_account
|
||||
end
|
||||
|
||||
controller do
|
||||
include SignatureVerification
|
||||
|
||||
@@ -73,6 +83,41 @@ describe ApplicationController, type: :controller do
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a valid actor that is not an Account' do
|
||||
let(:actor) { WrappedActor.new(author) }
|
||||
|
||||
before do
|
||||
get :success
|
||||
|
||||
fake_request = Request.new(:get, request.url)
|
||||
fake_request.on_behalf_of(author)
|
||||
|
||||
request.headers.merge!(fake_request.headers)
|
||||
|
||||
allow(ActivityPub::TagManager.instance).to receive(:uri_to_actor).with(anything) do
|
||||
actor
|
||||
end
|
||||
end
|
||||
|
||||
describe '#signed_request?' do
|
||||
it 'returns true' do
|
||||
expect(controller.signed_request?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#signed_request_account' do
|
||||
it 'returns nil' do
|
||||
expect(controller.signed_request_account).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '#signed_request_actor' do
|
||||
it 'returns the expected actor' do
|
||||
expect(controller.signed_request_actor).to eq actor
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with request older than a day' do
|
||||
before do
|
||||
get :success
|
||||
|
@@ -11,7 +11,7 @@ describe Settings::Exports::FollowingAccountsController do
|
||||
sign_in user, scope: :user
|
||||
get :index, format: :csv
|
||||
|
||||
expect(response.body).to eq "Account address,Show boosts\nusername@domain,true\n"
|
||||
expect(response.body).to eq "Account address,Show boosts,Notify on new posts,Languages\nusername@domain,true,false,\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -426,7 +426,7 @@ describe StatusesController do
|
||||
let(:remote_account) { Fabricate(:account, domain: 'example.com') }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:signed_request_account).and_return(remote_account)
|
||||
allow(controller).to receive(:signed_request_actor).and_return(remote_account)
|
||||
end
|
||||
|
||||
context 'when account blocks account' do
|
||||
|
6
spec/fabricators/access_grant_fabricator.rb
Normal file
6
spec/fabricators/access_grant_fabricator.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
Fabricator :access_grant, from: 'Doorkeeper::AccessGrant' do
|
||||
application
|
||||
resource_owner_id { Fabricate(:user).id }
|
||||
expires_in 3_600
|
||||
redirect_uri { Doorkeeper.configuration.native_redirect_uri }
|
||||
end
|
@@ -3,4 +3,5 @@ Fabricator(:preview_card) do
|
||||
title { Faker::Lorem.sentence }
|
||||
description { Faker::Lorem.paragraph }
|
||||
type 'link'
|
||||
image { attachment_fixture('attachment.jpg') }
|
||||
end
|
||||
|
@@ -115,7 +115,7 @@ RSpec.describe ActivityPub::Activity::Announce do
|
||||
|
||||
let(:object_json) { 'https://example.com/actor/hello-world' }
|
||||
|
||||
subject { described_class.new(json, sender, relayed_through_account: relay_account) }
|
||||
subject { described_class.new(json, sender, relayed_through_actor: relay_account) }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: Oj.dump(unknown_object_json))
|
||||
|
@@ -4,10 +4,10 @@ RSpec.describe ActivityPub::Dereferencer do
|
||||
describe '#object' do
|
||||
let(:object) { { '@context': 'https://www.w3.org/ns/activitystreams', id: 'https://example.com/foo', type: 'Note', content: 'Hoge' } }
|
||||
let(:permitted_origin) { 'https://example.com' }
|
||||
let(:signature_account) { nil }
|
||||
let(:signature_actor) { nil }
|
||||
let(:uri) { nil }
|
||||
|
||||
subject { described_class.new(uri, permitted_origin: permitted_origin, signature_account: signature_account).object }
|
||||
subject { described_class.new(uri, permitted_origin: permitted_origin, signature_actor: signature_actor).object }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/foo').to_return(body: Oj.dump(object), headers: { 'Content-Type' => 'application/activity+json' })
|
||||
@@ -21,7 +21,7 @@ RSpec.describe ActivityPub::Dereferencer do
|
||||
end
|
||||
|
||||
context 'with signature account' do
|
||||
let(:signature_account) { Fabricate(:account) }
|
||||
let(:signature_actor) { Fabricate(:account) }
|
||||
|
||||
it 'makes signed request' do
|
||||
subject
|
||||
@@ -52,7 +52,7 @@ RSpec.describe ActivityPub::Dereferencer do
|
||||
end
|
||||
|
||||
context 'with signature account' do
|
||||
let(:signature_account) { Fabricate(:account) }
|
||||
let(:signature_actor) { Fabricate(:account) }
|
||||
|
||||
it 'makes signed request' do
|
||||
subject
|
||||
|
@@ -20,7 +20,7 @@ RSpec.describe ActivityPub::LinkedDataSignature do
|
||||
stub_jsonld_contexts!
|
||||
end
|
||||
|
||||
describe '#verify_account!' do
|
||||
describe '#verify_actor!' do
|
||||
context 'when signature matches' do
|
||||
let(:raw_signature) do
|
||||
{
|
||||
@@ -32,7 +32,7 @@ RSpec.describe ActivityPub::LinkedDataSignature do
|
||||
let(:signature) { raw_signature.merge('type' => 'RsaSignature2017', 'signatureValue' => sign(sender, raw_signature, raw_json)) }
|
||||
|
||||
it 'returns creator' do
|
||||
expect(subject.verify_account!).to eq sender
|
||||
expect(subject.verify_actor!).to eq sender
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,7 +40,7 @@ RSpec.describe ActivityPub::LinkedDataSignature do
|
||||
let(:signature) { nil }
|
||||
|
||||
it 'returns nil' do
|
||||
expect(subject.verify_account!).to be_nil
|
||||
expect(subject.verify_actor!).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -55,7 +55,7 @@ RSpec.describe ActivityPub::LinkedDataSignature do
|
||||
let(:signature) { raw_signature.merge('type' => 'RsaSignature2017', 'signatureValue' => 's69F3mfddd99dGjmvjdjjs81e12jn121Gkm1') }
|
||||
|
||||
it 'returns nil' do
|
||||
expect(subject.verify_account!).to be_nil
|
||||
expect(subject.verify_actor!).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -73,14 +73,14 @@ RSpec.describe ActivityPub::LinkedDataSignature do
|
||||
end
|
||||
|
||||
it 'can be verified again' do
|
||||
expect(described_class.new(subject).verify_account!).to eq sender
|
||||
expect(described_class.new(subject).verify_actor!).to eq sender
|
||||
end
|
||||
end
|
||||
|
||||
def sign(from_account, options, document)
|
||||
def sign(from_actor, options, document)
|
||||
options_hash = Digest::SHA256.hexdigest(canonicalize(options.merge('@context' => ActivityPub::LinkedDataSignature::CONTEXT)))
|
||||
document_hash = Digest::SHA256.hexdigest(canonicalize(document))
|
||||
to_be_verified = options_hash + document_hash
|
||||
Base64.strict_encode64(from_account.keypair.sign(OpenSSL::Digest.new('SHA256'), to_be_verified))
|
||||
Base64.strict_encode64(from_actor.keypair.sign(OpenSSL::Digest.new('SHA256'), to_be_verified))
|
||||
end
|
||||
end
|
||||
|
@@ -134,6 +134,18 @@ RSpec.describe FeedManager do
|
||||
reblog = Fabricate(:status, reblog: status, account: jeff)
|
||||
expect(FeedManager.instance.filter?(:home, reblog, alice)).to be true
|
||||
end
|
||||
|
||||
it 'returns true for German post when follow is set to English only' do
|
||||
alice.follow!(bob, languages: %w(en))
|
||||
status = Fabricate(:status, text: 'Hallo Welt', account: bob, language: 'de')
|
||||
expect(FeedManager.instance.filter?(:home, status, alice)).to be true
|
||||
end
|
||||
|
||||
it 'returns false for German post when follow is set to German' do
|
||||
alice.follow!(bob, languages: %w(de))
|
||||
status = Fabricate(:status, text: 'Hallo Welt', account: bob, language: 'de')
|
||||
expect(FeedManager.instance.filter?(:home, status, alice)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'for mentions feed' do
|
||||
|
@@ -21,7 +21,7 @@ describe PermalinkRedirector do
|
||||
|
||||
it 'returns path for legacy tag links' do
|
||||
redirector = described_class.new('web/timelines/tag/hoge')
|
||||
expect(redirector.redirect_path).to eq '/tags/hoge'
|
||||
expect(redirector.redirect_path).to be_nil
|
||||
end
|
||||
|
||||
it 'returns path for pretty account links' do
|
||||
@@ -36,7 +36,7 @@ describe PermalinkRedirector do
|
||||
|
||||
it 'returns path for pretty tag links' do
|
||||
redirector = described_class.new('web/tags/hoge')
|
||||
expect(redirector.redirect_path).to eq '/tags/hoge'
|
||||
expect(redirector.redirect_path).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -63,7 +63,7 @@ describe Request do
|
||||
expect(a_request(:get, 'http://example.com').with(headers: subject.headers)).to have_been_made
|
||||
end
|
||||
|
||||
it 'closes underlaying connection' do
|
||||
it 'closes underlying connection' do
|
||||
expect_any_instance_of(HTTP::Client).to receive(:close)
|
||||
expect { |block| subject.perform &block }.to yield_control
|
||||
end
|
||||
|
33
spec/lib/vacuum/access_tokens_vacuum_spec.rb
Normal file
33
spec/lib/vacuum/access_tokens_vacuum_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vacuum::AccessTokensVacuum do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:revoked_access_token) { Fabricate(:access_token, revoked_at: 1.minute.ago) }
|
||||
let!(:active_access_token) { Fabricate(:access_token) }
|
||||
|
||||
let!(:revoked_access_grant) { Fabricate(:access_grant, revoked_at: 1.minute.ago) }
|
||||
let!(:active_access_grant) { Fabricate(:access_grant) }
|
||||
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'deletes revoked access tokens' do
|
||||
expect { revoked_access_token.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
it 'deletes revoked access grants' do
|
||||
expect { revoked_access_grant.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
it 'does not delete active access tokens' do
|
||||
expect { active_access_token.reload }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'does not delete active access grants' do
|
||||
expect { active_access_grant.reload }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
24
spec/lib/vacuum/backups_vacuum_spec.rb
Normal file
24
spec/lib/vacuum/backups_vacuum_spec.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vacuum::BackupsVacuum do
|
||||
let(:retention_period) { 7.days }
|
||||
|
||||
subject { described_class.new(retention_period) }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:expired_backup) { Fabricate(:backup, created_at: (retention_period + 1.day).ago) }
|
||||
let!(:current_backup) { Fabricate(:backup) }
|
||||
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'deletes backups past the retention period' do
|
||||
expect { expired_backup.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
it 'does not delete backups within the retention period' do
|
||||
expect { current_backup.reload }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
30
spec/lib/vacuum/feeds_vacuum_spec.rb
Normal file
30
spec/lib/vacuum/feeds_vacuum_spec.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vacuum::FeedsVacuum do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:active_user) { Fabricate(:user, current_sign_in_at: 2.days.ago) }
|
||||
let!(:inactive_user) { Fabricate(:user, current_sign_in_at: 22.days.ago) }
|
||||
|
||||
before do
|
||||
redis.zadd(feed_key_for(inactive_user), 1, 1)
|
||||
redis.zadd(feed_key_for(active_user), 1, 1)
|
||||
redis.zadd(feed_key_for(inactive_user, 'reblogs'), 2, 2)
|
||||
redis.sadd(feed_key_for(inactive_user, 'reblogs:2'), 3)
|
||||
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'clears feeds of inactive users and lists' do
|
||||
expect(redis.zcard(feed_key_for(inactive_user))).to eq 0
|
||||
expect(redis.zcard(feed_key_for(active_user))).to eq 1
|
||||
expect(redis.exists?(feed_key_for(inactive_user, 'reblogs'))).to be false
|
||||
expect(redis.exists?(feed_key_for(inactive_user, 'reblogs:2'))).to be false
|
||||
end
|
||||
end
|
||||
|
||||
def feed_key_for(user, subtype = nil)
|
||||
FeedManager.instance.key(:home, user.account_id, subtype)
|
||||
end
|
||||
end
|
47
spec/lib/vacuum/media_attachments_vacuum_spec.rb
Normal file
47
spec/lib/vacuum/media_attachments_vacuum_spec.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vacuum::MediaAttachmentsVacuum do
|
||||
let(:retention_period) { 7.days }
|
||||
|
||||
subject { described_class.new(retention_period) }
|
||||
|
||||
let(:remote_status) { Fabricate(:status, account: Fabricate(:account, domain: 'example.com')) }
|
||||
let(:local_status) { Fabricate(:status) }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:old_remote_media) { Fabricate(:media_attachment, remote_url: 'https://example.com/foo.png', status: remote_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) }
|
||||
let!(:old_local_media) { Fabricate(:media_attachment, status: local_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) }
|
||||
let!(:new_remote_media) { Fabricate(:media_attachment, remote_url: 'https://example.com/foo.png', status: remote_status) }
|
||||
let!(:new_local_media) { Fabricate(:media_attachment, status: local_status) }
|
||||
let!(:old_unattached_media) { Fabricate(:media_attachment, account_id: nil, created_at: 10.days.ago) }
|
||||
let!(:new_unattached_media) { Fabricate(:media_attachment, account_id: nil, created_at: 1.hour.ago) }
|
||||
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'deletes cache of remote media attachments past the retention period' do
|
||||
expect(old_remote_media.reload.file).to be_blank
|
||||
end
|
||||
|
||||
it 'does not touch local media attachments past the retention period' do
|
||||
expect(old_local_media.reload.file).to_not be_blank
|
||||
end
|
||||
|
||||
it 'does not delete cache of remote media attachments within the retention period' do
|
||||
expect(new_remote_media.reload.file).to_not be_blank
|
||||
end
|
||||
|
||||
it 'does not touch local media attachments within the retention period' do
|
||||
expect(new_local_media.reload.file).to_not be_blank
|
||||
end
|
||||
|
||||
it 'deletes unattached media attachments past TTL' do
|
||||
expect { old_unattached_media.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it 'does not delete unattached media attachments within TTL' do
|
||||
expect(new_unattached_media.reload).to be_persisted
|
||||
end
|
||||
end
|
||||
end
|
36
spec/lib/vacuum/preview_cards_vacuum_spec.rb
Normal file
36
spec/lib/vacuum/preview_cards_vacuum_spec.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vacuum::PreviewCardsVacuum do
|
||||
let(:retention_period) { 7.days }
|
||||
|
||||
subject { described_class.new(retention_period) }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:orphaned_preview_card) { Fabricate(:preview_card, created_at: 2.days.ago) }
|
||||
let!(:old_preview_card) { Fabricate(:preview_card, updated_at: (retention_period + 1.day).ago) }
|
||||
let!(:new_preview_card) { Fabricate(:preview_card) }
|
||||
|
||||
before do
|
||||
old_preview_card.statuses << Fabricate(:status)
|
||||
new_preview_card.statuses << Fabricate(:status)
|
||||
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'deletes cache of preview cards last updated before the retention period' do
|
||||
expect(old_preview_card.reload.image).to be_blank
|
||||
end
|
||||
|
||||
it 'does not delete cache of preview cards last updated within the retention period' do
|
||||
expect(new_preview_card.reload.image).to_not be_blank
|
||||
end
|
||||
|
||||
it 'does not delete attached preview cards' do
|
||||
expect(new_preview_card.reload).to be_persisted
|
||||
end
|
||||
|
||||
it 'deletes preview cards not attached to any status' do
|
||||
expect { orphaned_preview_card.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
end
|
||||
end
|
36
spec/lib/vacuum/statuses_vacuum_spec.rb
Normal file
36
spec/lib/vacuum/statuses_vacuum_spec.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vacuum::StatusesVacuum do
|
||||
let(:retention_period) { 7.days }
|
||||
|
||||
let(:remote_account) { Fabricate(:account, domain: 'example.com') }
|
||||
|
||||
subject { described_class.new(retention_period) }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:remote_status_old) { Fabricate(:status, account: remote_account, created_at: (retention_period + 2.days).ago) }
|
||||
let!(:remote_status_recent) { Fabricate(:status, account: remote_account, created_at: (retention_period - 2.days).ago) }
|
||||
let!(:local_status_old) { Fabricate(:status, created_at: (retention_period + 2.days).ago) }
|
||||
let!(:local_status_recent) { Fabricate(:status, created_at: (retention_period - 2.days).ago) }
|
||||
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'deletes remote statuses past the retention period' do
|
||||
expect { remote_status_old.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
it 'does not delete local statuses past the retention period' do
|
||||
expect { local_status_old.reload }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'does not delete remote statuses within the retention period' do
|
||||
expect { remote_status_recent.reload }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'does not delete local statuses within the retention period' do
|
||||
expect { local_status_recent.reload }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
22
spec/lib/vacuum/system_keys_vacuum_spec.rb
Normal file
22
spec/lib/vacuum/system_keys_vacuum_spec.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vacuum::SystemKeysVacuum do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:expired_system_key) { Fabricate(:system_key, created_at: (SystemKey::ROTATION_PERIOD * 4).ago) }
|
||||
let!(:current_system_key) { Fabricate(:system_key) }
|
||||
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'deletes the expired key' do
|
||||
expect { expired_system_key.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
it 'does not delete the current key' do
|
||||
expect { current_system_key.reload }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
@@ -14,14 +14,14 @@ describe AccountInteractions do
|
||||
context 'account with Follow' do
|
||||
it 'returns { target_account_id => { reblogs: true } }' do
|
||||
Fabricate(:follow, account: account, target_account: target_account)
|
||||
is_expected.to eq(target_account_id => { reblogs: true, notify: false })
|
||||
is_expected.to eq(target_account_id => { reblogs: true, notify: false, languages: nil })
|
||||
end
|
||||
end
|
||||
|
||||
context 'account with Follow but with reblogs disabled' do
|
||||
it 'returns { target_account_id => { reblogs: false } }' do
|
||||
Fabricate(:follow, account: account, target_account: target_account, show_reblogs: false)
|
||||
is_expected.to eq(target_account_id => { reblogs: false, notify: false })
|
||||
is_expected.to eq(target_account_id => { reblogs: false, notify: false, languages: nil })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -647,7 +647,7 @@ describe AccountInteractions do
|
||||
end
|
||||
|
||||
it 'does mute notifications' do
|
||||
expect(me.muting_notifications?(you)).to be true
|
||||
expect(me.muting_notifications?(you)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -35,8 +35,8 @@ describe Export do
|
||||
results = export.strip.split("\n")
|
||||
|
||||
expect(results.size).to eq 3
|
||||
expect(results.first).to eq 'Account address,Show boosts'
|
||||
expect(results.second).to eq 'one@local.host,true'
|
||||
expect(results.first).to eq 'Account address,Show boosts,Notify on new posts,Languages'
|
||||
expect(results.second).to eq 'one@local.host,true,false,'
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -7,7 +7,7 @@ RSpec.describe FollowRequest, type: :model do
|
||||
let(:target_account) { Fabricate(:account) }
|
||||
|
||||
it 'calls Account#follow!, MergeWorker.perform_async, and #destroy!' do
|
||||
expect(account).to receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, bypass_limit: true)
|
||||
expect(account).to receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, languages: nil, bypass_limit: true)
|
||||
expect(MergeWorker).to receive(:perform_async).with(target_account.id, account.id)
|
||||
expect(follow_request).to receive(:destroy!)
|
||||
follow_request.authorize!
|
||||
|
@@ -119,6 +119,58 @@ RSpec.describe ActivityPub::FetchRemoteAccountService, type: :service do
|
||||
include_examples 'sets profile data'
|
||||
end
|
||||
|
||||
context 'when WebFinger returns a different URI' do
|
||||
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/bob' }] } }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor))
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'does not create account' do
|
||||
expect(account).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when WebFinger returns a different URI after a redirection' do
|
||||
let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/bob' }] } }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor))
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up "redirected" webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'does not create account' do
|
||||
expect(account).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with wrong id' do
|
||||
it 'does not create account' do
|
||||
expect(subject.call('https://fake.address/@foo', prefetched_body: Oj.dump(actor))).to be_nil
|
||||
|
180
spec/services/activitypub/fetch_remote_actor_service_spec.rb
Normal file
180
spec/services/activitypub/fetch_remote_actor_service_spec.rb
Normal file
@@ -0,0 +1,180 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::FetchRemoteActorService, type: :service do
|
||||
subject { ActivityPub::FetchRemoteActorService.new }
|
||||
|
||||
let!(:actor) do
|
||||
{
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: 'https://example.com/alice',
|
||||
type: 'Person',
|
||||
preferredUsername: 'alice',
|
||||
name: 'Alice',
|
||||
summary: 'Foo bar',
|
||||
inbox: 'http://example.com/alice/inbox',
|
||||
}
|
||||
end
|
||||
|
||||
describe '#call' do
|
||||
let(:account) { subject.call('https://example.com/alice', id: true) }
|
||||
|
||||
shared_examples 'sets profile data' do
|
||||
it 'returns an account' do
|
||||
expect(account).to be_an Account
|
||||
end
|
||||
|
||||
it 'sets display name' do
|
||||
expect(account.display_name).to eq 'Alice'
|
||||
end
|
||||
|
||||
it 'sets note' do
|
||||
expect(account.note).to eq 'Foo bar'
|
||||
end
|
||||
|
||||
it 'sets URL' do
|
||||
expect(account.url).to eq 'https://example.com/alice'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the account does not have a inbox' do
|
||||
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } }
|
||||
|
||||
before do
|
||||
actor[:inbox] = nil
|
||||
|
||||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor))
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'returns nil' do
|
||||
expect(account).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when URI and WebFinger share the same host' do
|
||||
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor))
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'sets username and domain from webfinger' do
|
||||
expect(account.username).to eq 'alice'
|
||||
expect(account.domain).to eq 'example.com'
|
||||
end
|
||||
|
||||
include_examples 'sets profile data'
|
||||
end
|
||||
|
||||
context 'when WebFinger presents different domain than URI' do
|
||||
let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/alice' }] } }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor))
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up "redirected" webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'sets username and domain from final webfinger' do
|
||||
expect(account.username).to eq 'alice'
|
||||
expect(account.domain).to eq 'iscool.af'
|
||||
end
|
||||
|
||||
include_examples 'sets profile data'
|
||||
end
|
||||
|
||||
context 'when WebFinger returns a different URI' do
|
||||
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/bob' }] } }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor))
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'does not create account' do
|
||||
expect(account).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when WebFinger returns a different URI after a redirection' do
|
||||
let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/bob' }] } }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor))
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up "redirected" webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'does not create account' do
|
||||
expect(account).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with wrong id' do
|
||||
it 'does not create account' do
|
||||
expect(subject.call('https://fake.address/@foo', prefetched_body: Oj.dump(actor))).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
83
spec/services/activitypub/fetch_remote_key_service_spec.rb
Normal file
83
spec/services/activitypub/fetch_remote_key_service_spec.rb
Normal file
@@ -0,0 +1,83 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::FetchRemoteKeyService, type: :service do
|
||||
subject { ActivityPub::FetchRemoteKeyService.new }
|
||||
|
||||
let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } }
|
||||
|
||||
let(:public_key_pem) do
|
||||
"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu3L4vnpNLzVH31MeWI39\n4F0wKeJFsLDAsNXGeOu0QF2x+h1zLWZw/agqD2R3JPU9/kaDJGPIV2Sn5zLyUA9S\n6swCCMOtn7BBR9g9sucgXJmUFB0tACH2QSgHywMAybGfmSb3LsEMNKsGJ9VsvYoh\n8lDET6X4Pyw+ZJU0/OLo/41q9w+OrGtlsTm/PuPIeXnxa6BLqnDaxC+4IcjG/FiP\nahNCTINl/1F/TgSSDZ4Taf4U9XFEIFw8wmgploELozzIzKq+t8nhQYkgAkt64euW\npva3qL5KD1mTIZQEP+LZvh3s2WHrLi3fhbdRuwQ2c0KkJA2oSTFPDpqqbPGZ3Qvu\nHQIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||
end
|
||||
|
||||
let(:public_key_id) { 'https://example.com/alice#main-key' }
|
||||
|
||||
let(:key_json) do
|
||||
{
|
||||
id: public_key_id,
|
||||
owner: 'https://example.com/alice',
|
||||
publicKeyPem: public_key_pem,
|
||||
}
|
||||
end
|
||||
|
||||
let(:actor_public_key) { key_json }
|
||||
|
||||
let(:actor) do
|
||||
{
|
||||
'@context': [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://w3id.org/security/v1',
|
||||
],
|
||||
id: 'https://example.com/alice',
|
||||
type: 'Person',
|
||||
preferredUsername: 'alice',
|
||||
name: 'Alice',
|
||||
summary: 'Foo bar',
|
||||
inbox: 'http://example.com/alice/inbox',
|
||||
publicKey: actor_public_key,
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor))
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
describe '#call' do
|
||||
let(:account) { subject.call(public_key_id, id: false) }
|
||||
|
||||
context 'when the key is a sub-object from the actor' do
|
||||
before do
|
||||
stub_request(:get, public_key_id).to_return(body: Oj.dump(actor))
|
||||
end
|
||||
|
||||
it 'returns the expected account' do
|
||||
expect(account.uri).to eq 'https://example.com/alice'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the key is a separate document' do
|
||||
let(:public_key_id) { 'https://example.com/alice-public-key.json' }
|
||||
|
||||
before do
|
||||
stub_request(:get, public_key_id).to_return(body: Oj.dump(key_json.merge({ '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'] })))
|
||||
end
|
||||
|
||||
it 'returns the expected account' do
|
||||
expect(account.uri).to eq 'https://example.com/alice'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the key and owner do not match' do
|
||||
let(:public_key_id) { 'https://example.com/fake-public-key.json' }
|
||||
let(:actor_public_key) { 'https://example.com/alice-public-key.json' }
|
||||
|
||||
before do
|
||||
stub_request(:get, public_key_id).to_return(body: Oj.dump(key_json.merge({ '@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'] })))
|
||||
end
|
||||
|
||||
it 'returns the nil' do
|
||||
expect(account).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -68,7 +68,7 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
|
||||
let(:forwarder) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/other_account') }
|
||||
|
||||
it 'does not process payload if no signature exists' do
|
||||
expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_account!).and_return(nil)
|
||||
expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(nil)
|
||||
expect(ActivityPub::Activity).not_to receive(:factory)
|
||||
|
||||
subject.call(json, forwarder)
|
||||
@@ -77,7 +77,7 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
|
||||
it 'processes payload with actor if valid signature exists' do
|
||||
payload['signature'] = { 'type' => 'RsaSignature2017' }
|
||||
|
||||
expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_account!).and_return(actor)
|
||||
expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(actor)
|
||||
expect(ActivityPub::Activity).to receive(:factory).with(instance_of(Hash), actor, instance_of(Hash))
|
||||
|
||||
subject.call(json, forwarder)
|
||||
@@ -86,7 +86,7 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
|
||||
it 'does not process payload if invalid signature exists' do
|
||||
payload['signature'] = { 'type' => 'RsaSignature2017' }
|
||||
|
||||
expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_account!).and_return(nil)
|
||||
expect_any_instance_of(ActivityPub::LinkedDataSignature).to receive(:verify_actor!).and_return(nil)
|
||||
expect(ActivityPub::Activity).not_to receive(:factory)
|
||||
|
||||
subject.call(json, forwarder)
|
||||
|
@@ -66,7 +66,7 @@ RSpec.describe FetchResourceService, type: :service do
|
||||
|
||||
it 'signs request' do
|
||||
subject
|
||||
expect(a_request(:get, url).with(headers: { 'Signature' => /keyId="#{Regexp.escape(ActivityPub::TagManager.instance.uri_for(Account.representative) + '#main-key')}"/ })).to have_been_made
|
||||
expect(a_request(:get, url).with(headers: { 'Signature' => /keyId="#{Regexp.escape(ActivityPub::TagManager.instance.key_uri_for(Account.representative))}"/ })).to have_been_made
|
||||
end
|
||||
|
||||
context 'when content type is application/atom+xml' do
|
||||
|
@@ -121,6 +121,19 @@ RSpec.describe FollowService, type: :service do
|
||||
expect(sender.muting_reblogs?(bob)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'already followed account, changing languages' do
|
||||
let(:bob) { Fabricate(:account, username: 'bob') }
|
||||
|
||||
before do
|
||||
sender.follow!(bob)
|
||||
subject.call(sender, bob, languages: %w(en es))
|
||||
end
|
||||
|
||||
it 'changes languages' do
|
||||
expect(Follow.find_by(account: sender, target_account: bob)&.languages).to match_array %w(en es)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'remote ActivityPub account' do
|
||||
|
@@ -42,13 +42,44 @@ RSpec.describe ReportService, type: :service do
|
||||
end
|
||||
|
||||
it 'creates a report' do
|
||||
is_expected.to change { target_account.targeted_reports.count }.from(0).to(1)
|
||||
expect { subject.call }.to change { target_account.targeted_reports.count }.from(0).to(1)
|
||||
end
|
||||
|
||||
it 'attaches the DM to the report' do
|
||||
subject.call
|
||||
expect(target_account.targeted_reports.pluck(:status_ids)).to eq [[status.id]]
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is not addressed to the reporter' do
|
||||
it 'errors out' do
|
||||
is_expected.to raise_error
|
||||
expect { subject.call }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the reporter is remote' do
|
||||
let(:source_account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/users/1') }
|
||||
|
||||
context 'when it is addressed to the reporter' do
|
||||
before do
|
||||
status.mentions.create(account: source_account)
|
||||
end
|
||||
|
||||
it 'creates a report' do
|
||||
expect { subject.call }.to change { target_account.targeted_reports.count }.from(0).to(1)
|
||||
end
|
||||
|
||||
it 'attaches the DM to the report' do
|
||||
subject.call
|
||||
expect(target_account.targeted_reports.pluck(:status_ids)).to eq [[status.id]]
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is not addressed to the reporter' do
|
||||
it 'does not add the DM to the report' do
|
||||
subject.call
|
||||
expect(target_account.targeted_reports.pluck(:status_ids)).to eq [[]]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -67,7 +98,7 @@ RSpec.describe ReportService, type: :service do
|
||||
end
|
||||
|
||||
it 'does not send an e-mail' do
|
||||
is_expected.to_not change(ActionMailer::Base.deliveries, :count).from(0)
|
||||
expect { subject.call }.to_not change(ActionMailer::Base.deliveries, :count).from(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -137,8 +137,8 @@ RSpec.describe ResolveAccountService, type: :service do
|
||||
stub_request(:get, 'https://evil.example.com/.well-known/webfinger?resource=acct:foo@evil.example.com').to_return(body: Oj.dump(webfinger2), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'returns new remote account' do
|
||||
expect { subject.call('Foo@redirected.example.com') }.to raise_error Webfinger::RedirectError
|
||||
it 'does not return a new remote account' do
|
||||
expect(subject.call('Foo@redirected.example.com')).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -23,8 +23,8 @@ describe RefollowWorker do
|
||||
result = subject.perform(account.id)
|
||||
|
||||
expect(result).to be_nil
|
||||
expect(service).to have_received(:call).with(alice, account, reblogs: true, notify: false, bypass_limit: true)
|
||||
expect(service).to have_received(:call).with(bob, account, reblogs: false, notify: false, bypass_limit: true)
|
||||
expect(service).to have_received(:call).with(alice, account, reblogs: true, notify: false, languages: nil, bypass_limit: true)
|
||||
expect(service).to have_received(:call).with(bob, account, reblogs: false, notify: false, languages: nil, bypass_limit: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -1,26 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Scheduler::FeedCleanupScheduler do
|
||||
subject { described_class.new }
|
||||
|
||||
let!(:active_user) { Fabricate(:user, current_sign_in_at: 2.days.ago) }
|
||||
let!(:inactive_user) { Fabricate(:user, current_sign_in_at: 22.days.ago) }
|
||||
|
||||
it 'clears feeds of inactives' do
|
||||
redis.zadd(feed_key_for(inactive_user), 1, 1)
|
||||
redis.zadd(feed_key_for(active_user), 1, 1)
|
||||
redis.zadd(feed_key_for(inactive_user, 'reblogs'), 2, 2)
|
||||
redis.sadd(feed_key_for(inactive_user, 'reblogs:2'), 3)
|
||||
|
||||
subject.perform
|
||||
|
||||
expect(redis.zcard(feed_key_for(inactive_user))).to eq 0
|
||||
expect(redis.zcard(feed_key_for(active_user))).to eq 1
|
||||
expect(redis.exists?(feed_key_for(inactive_user, 'reblogs'))).to be false
|
||||
expect(redis.exists?(feed_key_for(inactive_user, 'reblogs:2'))).to be false
|
||||
end
|
||||
|
||||
def feed_key_for(user, subtype = nil)
|
||||
FeedManager.instance.key(:home, user.account_id, subtype)
|
||||
end
|
||||
end
|
@@ -1,15 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Scheduler::MediaCleanupScheduler do
|
||||
subject { described_class.new }
|
||||
|
||||
let!(:old_media) { Fabricate(:media_attachment, account_id: nil, created_at: 10.days.ago) }
|
||||
let!(:new_media) { Fabricate(:media_attachment, account_id: nil, created_at: 1.hour.ago) }
|
||||
|
||||
it 'removes old media records' do
|
||||
subject.perform
|
||||
|
||||
expect { old_media.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect(new_media.reload).to be_persisted
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user