Select correct self link when parsing Webfinger response (#31110)
This commit is contained in:
		@@ -33,7 +33,7 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do
 | 
			
		||||
    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' }] } }
 | 
			
		||||
      let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
 | 
			
		||||
 | 
			
		||||
      before do
 | 
			
		||||
        actor[:inbox] = nil
 | 
			
		||||
@@ -51,7 +51,7 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do
 | 
			
		||||
    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' }] } }
 | 
			
		||||
      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: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
 | 
			
		||||
@@ -72,7 +72,7 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do
 | 
			
		||||
    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' }] } }
 | 
			
		||||
      let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
 | 
			
		||||
 | 
			
		||||
      before do
 | 
			
		||||
        stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
 | 
			
		||||
@@ -95,7 +95,7 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context 'when WebFinger returns a different URI' do
 | 
			
		||||
      let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/bob' }] } }
 | 
			
		||||
      let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } }
 | 
			
		||||
 | 
			
		||||
      before do
 | 
			
		||||
        stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
 | 
			
		||||
@@ -111,7 +111,7 @@ RSpec.describe ActivityPub::FetchRemoteAccountService do
 | 
			
		||||
    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' }] } }
 | 
			
		||||
      let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } }
 | 
			
		||||
 | 
			
		||||
      before do
 | 
			
		||||
        stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,7 @@ RSpec.describe ActivityPub::FetchRemoteActorService do
 | 
			
		||||
    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' }] } }
 | 
			
		||||
      let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
 | 
			
		||||
 | 
			
		||||
      before do
 | 
			
		||||
        actor[:inbox] = nil
 | 
			
		||||
@@ -51,7 +51,7 @@ RSpec.describe ActivityPub::FetchRemoteActorService do
 | 
			
		||||
    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' }] } }
 | 
			
		||||
      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: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
 | 
			
		||||
@@ -72,7 +72,7 @@ RSpec.describe ActivityPub::FetchRemoteActorService do
 | 
			
		||||
    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' }] } }
 | 
			
		||||
      let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
 | 
			
		||||
 | 
			
		||||
      before do
 | 
			
		||||
        stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
 | 
			
		||||
@@ -95,7 +95,7 @@ RSpec.describe ActivityPub::FetchRemoteActorService do
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context 'when WebFinger returns a different URI' do
 | 
			
		||||
      let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/bob' }] } }
 | 
			
		||||
      let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } }
 | 
			
		||||
 | 
			
		||||
      before do
 | 
			
		||||
        stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
 | 
			
		||||
@@ -111,7 +111,7 @@ RSpec.describe ActivityPub::FetchRemoteActorService do
 | 
			
		||||
    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' }] } }
 | 
			
		||||
      let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } }
 | 
			
		||||
 | 
			
		||||
      before do
 | 
			
		||||
        stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' })
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@ require 'rails_helper'
 | 
			
		||||
RSpec.describe ActivityPub::FetchRemoteKeyService do
 | 
			
		||||
  subject { described_class.new }
 | 
			
		||||
 | 
			
		||||
  let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } }
 | 
			
		||||
  let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
 | 
			
		||||
 | 
			
		||||
  let(:public_key_pem) do
 | 
			
		||||
    <<~TEXT
 | 
			
		||||
 
 | 
			
		||||
@@ -215,7 +215,7 @@ RSpec.describe ActivityPub::ProcessAccountService do
 | 
			
		||||
        }.with_indifferent_access
 | 
			
		||||
        webfinger = {
 | 
			
		||||
          subject: "acct:user#{i}@foo.test",
 | 
			
		||||
          links: [{ rel: 'self', href: "https://foo.test/users/#{i}" }],
 | 
			
		||||
          links: [{ rel: 'self', href: "https://foo.test/users/#{i}", type: 'application/activity+json' }],
 | 
			
		||||
        }.with_indifferent_access
 | 
			
		||||
        stub_request(:get, "https://foo.test/users/#{i}").to_return(status: 200, body: actor_json.to_json, headers: { 'Content-Type': 'application/activity+json' })
 | 
			
		||||
        stub_request(:get, "https://foo.test/users/#{i}/featured").to_return(status: 200, body: featured_json.to_json, headers: { 'Content-Type': 'application/activity+json' })
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user