Add support for FEP-2c59 (#38239)

This commit is contained in:
Claire
2026-03-26 14:33:16 +01:00
committed by GitHub
parent abd29109c5
commit e81a4e258c
5 changed files with 128 additions and 5 deletions

View File

@@ -133,5 +133,97 @@ RSpec.describe ActivityPub::FetchRemoteActorService do
expect(subject.call('https://fake.address/@foo', prefetched_body: actor.to_json)).to be_nil
end
end
context 'when the actor uses the webfinger propery from FEP-2c59' do
before do
actor[:webfinger] = acct
end
context 'when URI and WebFinger share the same host' do
let(:acct) { 'alice@example.com' }
let!(:webfinger) { { subject: "acct:#{acct}", links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
before do
stub_request(:get, 'https://example.com/alice').to_return(body: actor.to_json, headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, "https://example.com/.well-known/webfinger?resource=acct:#{acct}").to_return(body: webfinger.to_json, headers: { 'Content-Type': 'application/jrd+json' })
end
it 'fetches resource and looks up webfinger and sets values' do
account
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
expect(a_request(:get, "https://example.com/.well-known/webfinger?resource=acct:#{acct}")).to have_been_made.once
expect(account.username).to eq 'alice'
expect(account.domain).to eq 'example.com'
end
it_behaves_like 'sets profile data'
end
context 'when WebFinger returns a different URI' do
let(:acct) { 'alice@example.com' }
let!(:webfinger) { { subject: "acct:#{acct}", links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } }
before do
stub_request(:get, 'https://example.com/alice').to_return(body: actor.to_json, headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, "https://example.com/.well-known/webfinger?resource=acct:#{acct}").to_return(body: webfinger.to_json, headers: { 'Content-Type': 'application/jrd+json' })
end
it 'fetches resource and looks up webfinger and does not create account' do
expect(account).to be_nil
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
expect(a_request(:get, "https://example.com/.well-known/webfinger?resource=acct:#{acct}")).to have_been_made.once
end
end
context 'when WebFinger is at another domain' do
let(:acct) { 'alice@iscool.af' }
let!(:webfinger) { { subject: "acct:#{acct}", links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
before do
stub_request(:get, 'https://example.com/alice').to_return(body: actor.to_json, headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, "https://iscool.af/.well-known/webfinger?resource=acct:#{acct}").to_return(body: webfinger.to_json, headers: { 'Content-Type': 'application/jrd+json' })
end
it 'fetches resource and looks up webfinger and follows redirect and sets values' do
account
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to_not have_been_made
expect(a_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af')).to have_been_made.once
expect(account.username).to eq 'alice'
expect(account.domain).to eq 'iscool.af'
end
it_behaves_like 'sets profile data'
end
context 'when WebFinger is at another domain and redirects back' do
let(:acct) { 'alice@iscool.af' }
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
before do
stub_request(:get, 'https://example.com/alice').to_return(body: actor.to_json, headers: { 'Content-Type': 'application/activity+json' })
stub_request(:get, "https://iscool.af/.well-known/webfinger?resource=acct:#{acct}").to_return(body: webfinger.to_json, headers: { 'Content-Type': 'application/jrd+json' })
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: webfinger.to_json, headers: { 'Content-Type': 'application/jrd+json' })
end
it 'fetches resource and looks up webfinger and follows redirect and sets values' do
account
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
expect(a_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af')).to have_been_made.once
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made
expect(account.username).to eq 'alice'
expect(account.domain).to eq 'example.com'
end
it_behaves_like 'sets profile data'
end
end
end
end