mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-13 07:49:29 +00:00
Merge commit 'c644413f8a068490ddb8038441e5b59112e8294e' into glitch-soc/merge-upstream
This commit is contained in:
@@ -29,3 +29,15 @@ Fabricator(:debug_fasp, from: :fasp_provider) do
|
||||
def fasp.update_remote_capabilities = true
|
||||
end
|
||||
end
|
||||
|
||||
Fabricator(:follow_recommendation_fasp, from: :fasp_provider) do
|
||||
confirmed true
|
||||
capabilities [
|
||||
{ id: 'follow_recommendation', version: '0.1', enabled: true },
|
||||
]
|
||||
|
||||
after_build do |fasp|
|
||||
# Prevent fabrication from attempting an HTTP call to the provider
|
||||
def fasp.update_remote_capabilities = true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -101,7 +101,7 @@ RSpec.describe HomeHelper do
|
||||
allow(helper).to receive(:closed_registrations?).and_return(true)
|
||||
result = helper.sign_up_message
|
||||
|
||||
expect(result).to eq t('auth.registration_closed', instance: Rails.configuration.x.local_domain)
|
||||
expect(result).to eq t('auth.registration_closed', instance: local_domain_uri.host)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -326,7 +326,7 @@ RSpec.describe UserMailer do
|
||||
expect(mail)
|
||||
.to be_present
|
||||
.and(have_subject(I18n.t('user_mailer.announcement_published.subject')))
|
||||
.and(have_body_text(I18n.t('user_mailer.announcement_published.description', domain: Rails.configuration.x.local_domain)))
|
||||
.and(have_body_text(I18n.t('user_mailer.announcement_published.description', domain: local_domain_uri.host)))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -61,7 +61,16 @@ RSpec.describe RemoteFollow do
|
||||
let(:account) { Fabricate(:account, username: 'alice') }
|
||||
|
||||
it 'returns subscribe address' do
|
||||
expect(subject).to eq "https://quitter.no/main/ostatussub?profile=https%3A%2F%2F#{Rails.configuration.x.local_domain}%2Fusers%2Falice"
|
||||
expect(subject).to eq(expected_subscribe_url)
|
||||
end
|
||||
|
||||
def expected_subscribe_url
|
||||
Addressable::URI.new(
|
||||
host: 'quitter.no',
|
||||
path: '/main/ostatussub',
|
||||
query_values: { profile: "https://#{Rails.configuration.x.local_domain}/users/alice" },
|
||||
scheme: 'https'
|
||||
).to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,5 +34,14 @@ RSpec.describe 'Suggestions API' do
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
context 'when `follow_recommendation` FASP is enabled', feature: :fasp do
|
||||
it 'enqueues a retrieval job and adds a header to inform the client' do
|
||||
get '/api/v2/suggestions', headers: headers
|
||||
|
||||
expect(Fasp::FollowRecommendationWorker).to have_enqueued_sidekiq_job
|
||||
expect(response.headers['Mastodon-Async-Refresh']).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -472,12 +472,12 @@ RSpec.describe 'Caching behavior' do
|
||||
context 'when enabling LIMITED_FEDERATION_MODE mode' do
|
||||
around do |example|
|
||||
ClimateControl.modify LIMITED_FEDERATION_MODE: 'true' do
|
||||
old_limited_federation_mode = Rails.configuration.x.limited_federation_mode
|
||||
Rails.configuration.x.limited_federation_mode = true
|
||||
old_limited_federation_mode = Rails.configuration.x.mastodon.limited_federation_mode
|
||||
Rails.configuration.x.mastodon.limited_federation_mode = true
|
||||
|
||||
example.run
|
||||
|
||||
Rails.configuration.x.limited_federation_mode = old_limited_federation_mode
|
||||
Rails.configuration.x.mastodon.limited_federation_mode = old_limited_federation_mode
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Instance actor endpoint' do
|
||||
describe 'GET /actor' do
|
||||
let!(:original_federation_mode) { Rails.configuration.x.limited_federation_mode }
|
||||
let!(:original_federation_mode) { Rails.configuration.x.mastodon.limited_federation_mode }
|
||||
|
||||
shared_examples 'instance actor endpoint' do
|
||||
before { get instance_actor_path(format: :json) }
|
||||
@@ -31,8 +31,8 @@ RSpec.describe 'Instance actor endpoint' do
|
||||
end
|
||||
|
||||
context 'with limited federation mode disabled' do
|
||||
before { Rails.configuration.x.limited_federation_mode = false }
|
||||
after { Rails.configuration.x.limited_federation_mode = original_federation_mode }
|
||||
before { Rails.configuration.x.mastodon.limited_federation_mode = false }
|
||||
after { Rails.configuration.x.mastodon.limited_federation_mode = original_federation_mode }
|
||||
|
||||
it_behaves_like 'instance actor endpoint'
|
||||
|
||||
@@ -44,8 +44,8 @@ RSpec.describe 'Instance actor endpoint' do
|
||||
end
|
||||
|
||||
context 'with limited federation mode enabled' do
|
||||
before { Rails.configuration.x.limited_federation_mode = true }
|
||||
after { Rails.configuration.x.limited_federation_mode = original_federation_mode }
|
||||
before { Rails.configuration.x.mastodon.limited_federation_mode = true }
|
||||
after { Rails.configuration.x.mastodon.limited_federation_mode = original_federation_mode }
|
||||
|
||||
it_behaves_like 'instance actor endpoint'
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ RSpec.describe 'Statuses' do
|
||||
include AccountsHelper
|
||||
|
||||
def site_hostname
|
||||
Rails.configuration.x.web_domain || Rails.configuration.x.local_domain
|
||||
local_domain_uri.host
|
||||
end
|
||||
|
||||
it 'has valid opengraph tags' do
|
||||
|
||||
@@ -176,7 +176,7 @@ RSpec.describe 'The /.well-known/webfinger endpoint' do
|
||||
|
||||
context 'with limited federation mode' do
|
||||
before do
|
||||
allow(Rails.configuration.x).to receive(:limited_federation_mode).and_return(true)
|
||||
allow(Rails.configuration.x.mastodon).to receive(:limited_federation_mode).and_return(true)
|
||||
end
|
||||
|
||||
it 'does not return avatar in response' do
|
||||
|
||||
@@ -15,7 +15,7 @@ RSpec.describe UnallowDomainService do
|
||||
|
||||
context 'with limited federation mode', :inline_jobs do
|
||||
before do
|
||||
allow(Rails.configuration.x).to receive(:limited_federation_mode).and_return(true)
|
||||
allow(Rails.configuration.x.mastodon).to receive(:limited_federation_mode).and_return(true)
|
||||
end
|
||||
|
||||
describe '#call' do
|
||||
@@ -34,7 +34,7 @@ RSpec.describe UnallowDomainService do
|
||||
|
||||
context 'without limited federation mode' do
|
||||
before do
|
||||
allow(Rails.configuration.x).to receive(:limited_federation_mode).and_return(false)
|
||||
allow(Rails.configuration.x.mastodon).to receive(:limited_federation_mode).and_return(false)
|
||||
end
|
||||
|
||||
describe '#call' do
|
||||
|
||||
@@ -47,6 +47,10 @@ module DomainHelpers
|
||||
.and_yield(resolver)
|
||||
end
|
||||
|
||||
def local_domain_uri
|
||||
Addressable::URI.parse("//#{Rails.configuration.x.local_domain}")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def double_mx(exchange)
|
||||
|
||||
@@ -13,12 +13,12 @@ RSpec.describe 'Admin::DomainAllows' do
|
||||
end
|
||||
|
||||
around do |example|
|
||||
original = Rails.configuration.x.limited_federation_mode
|
||||
Rails.configuration.x.limited_federation_mode = true
|
||||
original = Rails.configuration.x.mastodon.limited_federation_mode
|
||||
Rails.configuration.x.mastodon.limited_federation_mode = true
|
||||
|
||||
example.run
|
||||
|
||||
Rails.configuration.x.limited_federation_mode = original
|
||||
Rails.configuration.x.mastodon.limited_federation_mode = original
|
||||
end
|
||||
|
||||
describe 'Managing domain allows' do
|
||||
|
||||
@@ -31,7 +31,7 @@ RSpec.describe 'email confirmation flow when captcha is enabled' do
|
||||
|
||||
# It presents a page with a link to the app callback
|
||||
expect(page)
|
||||
.to have_content(I18n.t('auth.confirmations.registration_complete', domain: Rails.configuration.x.local_domain))
|
||||
.to have_content(I18n.t('auth.confirmations.registration_complete', domain: local_domain_uri.host))
|
||||
.and have_link(I18n.t('auth.confirmations.clicking_this_link'), href: client_app.confirmation_redirect_uri)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,8 +5,6 @@ require 'rails_helper'
|
||||
RSpec.describe 'Profile' do
|
||||
include ProfileStories
|
||||
|
||||
let(:local_domain) { Rails.configuration.x.local_domain }
|
||||
|
||||
before do
|
||||
as_a_logged_in_user
|
||||
Fabricate(:user, account: Fabricate(:account, username: 'alice'))
|
||||
@@ -16,7 +14,7 @@ RSpec.describe 'Profile' do
|
||||
visit account_path('alice')
|
||||
|
||||
expect(page)
|
||||
.to have_title("alice (@alice@#{local_domain})")
|
||||
.to have_title("alice (@alice@#{local_domain_uri.host})")
|
||||
end
|
||||
|
||||
it 'I can change my account' do
|
||||
|
||||
@@ -31,6 +31,6 @@ RSpec.describe 'redirection confirmations' do
|
||||
end
|
||||
|
||||
def redirect_title
|
||||
I18n.t('redirects.title', instance: Rails.configuration.x.local_domain)
|
||||
I18n.t('redirects.title', instance: local_domain_uri.host)
|
||||
end
|
||||
end
|
||||
|
||||
51
spec/workers/fasp/follow_recommendation_worker_spec.rb
Normal file
51
spec/workers/fasp/follow_recommendation_worker_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Fasp::FollowRecommendationWorker, feature: :fasp do
|
||||
include ProviderRequestHelper
|
||||
|
||||
let(:provider) { Fabricate(:follow_recommendation_fasp) }
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:fetch_service) { instance_double(ActivityPub::FetchRemoteActorService, call: true) }
|
||||
|
||||
let!(:stubbed_request) do
|
||||
account_uri = ActivityPub::TagManager.instance.uri_for(account)
|
||||
path = "/follow_recommendation/v0/accounts?accountUri=#{URI.encode_uri_component(account_uri)}"
|
||||
stub_provider_request(provider,
|
||||
method: :get,
|
||||
path:,
|
||||
response_body: [
|
||||
'https://fedi.example.com/accounts/1',
|
||||
'https://fedi.example.com/accounts/7',
|
||||
])
|
||||
end
|
||||
|
||||
before do
|
||||
allow(ActivityPub::FetchRemoteActorService).to receive(:new).and_return(fetch_service)
|
||||
end
|
||||
|
||||
it "sends the requesting account's uri to provider and fetches received account uris" do
|
||||
described_class.new.perform(account.id)
|
||||
|
||||
expect(stubbed_request).to have_been_made
|
||||
expect(fetch_service).to have_received(:call).with('https://fedi.example.com/accounts/1')
|
||||
expect(fetch_service).to have_received(:call).with('https://fedi.example.com/accounts/7')
|
||||
end
|
||||
|
||||
it 'marks a running async refresh as finished' do
|
||||
async_refresh = AsyncRefresh.create("fasp:follow_recommendation:#{account.id}", count_results: true)
|
||||
|
||||
described_class.new.perform(account.id)
|
||||
|
||||
expect(async_refresh.reload).to be_finished
|
||||
end
|
||||
|
||||
it 'tracks the number of fetched accounts in the async refresh' do
|
||||
async_refresh = AsyncRefresh.create("fasp:follow_recommendation:#{account.id}", count_results: true)
|
||||
|
||||
described_class.new.perform(account.id)
|
||||
|
||||
expect(async_refresh.reload.result_count).to eq 2
|
||||
end
|
||||
end
|
||||
@@ -5,6 +5,14 @@ require 'rails_helper'
|
||||
RSpec.describe PublishScheduledAnnouncementWorker do
|
||||
subject { described_class.new }
|
||||
|
||||
around do |example|
|
||||
original_web_domain = Rails.configuration.x.web_domain
|
||||
original_default_host = Rails.configuration.action_mailer.default_url_options[:host]
|
||||
example.run
|
||||
Rails.configuration.x.web_domain = original_web_domain
|
||||
Rails.configuration.action_mailer.default_url_options[:host] = original_default_host
|
||||
end
|
||||
|
||||
let!(:remote_account) { Fabricate(:account, domain: 'domain.com', username: 'foo', uri: 'https://domain.com/users/foo') }
|
||||
let!(:remote_status) { Fabricate(:status, uri: 'https://domain.com/users/foo/12345', account: remote_account) }
|
||||
let!(:local_status) { Fabricate(:status) }
|
||||
@@ -12,15 +20,16 @@ RSpec.describe PublishScheduledAnnouncementWorker do
|
||||
|
||||
describe 'perform' do
|
||||
before do
|
||||
Rails.configuration.x.web_domain = 'mastodon.social' # The TwitterText Regex needs a real/plausible link target
|
||||
Rails.configuration.action_mailer.default_url_options[:host] = Rails.configuration.x.web_domain
|
||||
service = instance_double(FetchRemoteStatusService)
|
||||
allow(FetchRemoteStatusService).to receive(:new).and_return(service)
|
||||
allow(service).to receive(:call).with('https://domain.com/users/foo/12345') { remote_status.reload }
|
||||
|
||||
subject.perform(scheduled_announcement.id)
|
||||
end
|
||||
|
||||
it 'updates the linked statuses' do
|
||||
expect(scheduled_announcement.reload.status_ids).to eq [remote_status.id, local_status.id]
|
||||
expect { subject.perform(scheduled_announcement.id) }
|
||||
.to change { scheduled_announcement.reload.status_ids }.from(nil).to([remote_status.id, local_status.id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user