mirror of
https://github.com/mastodon/mastodon.git
synced 2024-10-21 17:16:09 +00:00
dd7ef0dc41
* Add ActivityPub inbox * Handle ActivityPub deletes * Handle ActivityPub creates * Handle ActivityPub announces * Stubs for handling all activities that need to be handled * Add ActivityPub actor resolving * Handle conversation URI passing in ActivityPub * Handle content language in ActivityPub * Send accept header when fetching actor, handle JSON parse errors * Test for ActivityPub::FetchRemoteAccountService * Handle public key and icon/image when embedded/as array/as resolvable URI * Implement ActivityPub::FetchRemoteStatusService * Add stubs for more interactions * Undo activities implemented * Handle out of order activities * Hook up ActivityPub to ResolveRemoteAccountService, handle Update Account activities * Add fragment IDs to all transient activity serializers * Add tests and fixes * Add stubs for missing tests * Add more tests * Add more tests
97 lines
3.3 KiB
Ruby
97 lines
3.3 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe ActivityPub::FetchRemoteAccountService do
|
|
subject { ActivityPub::FetchRemoteAccountService.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',
|
|
}
|
|
end
|
|
|
|
describe '#call' do
|
|
let(:account) { subject.call('https://example.com/alice') }
|
|
|
|
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 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
|
|
end
|
|
end
|