summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2024-02-23 09:53:09 +0100
committerGitHub <noreply@github.com>2024-02-23 09:53:09 +0100
commitd3c4441af8d82f2135a0453d1cf6fd08e944cb31 (patch)
tree583b10366b7bb03028ab2ee3b24c3545ec27f92b
parentf0541adbd44bc031fb8b070e24a605e0a0e853e4 (diff)
Fix processing of `Link` objects in `Image` objects (#29364)
-rw-r--r--app/services/activitypub/process_account_service.rb11
-rw-r--r--spec/services/activitypub/process_account_service_spec.rb51
2 files changed, 49 insertions, 13 deletions
diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb
index fef3781e1aa..d2223938dc3 100644
--- a/app/services/activitypub/process_account_service.rb
+++ b/app/services/activitypub/process_account_service.rb
@@ -199,10 +199,15 @@ class ActivityPub::ProcessAccountService < BaseService
value = first_of_value(@json[key])
return if value.nil?
- return value['url'] if value.is_a?(Hash)
- image = fetch_resource_without_id_validation(value)
- image['url'] if image
+ if value.is_a?(String)
+ value = fetch_resource_without_id_validation(value)
+ return if value.nil?
+ end
+
+ value = first_of_value(value['url']) if value.is_a?(Hash) && value['type'] == 'Image'
+ value = value['href'] if value.is_a?(Hash)
+ value if value.is_a?(String)
end
def public_key
diff --git a/spec/services/activitypub/process_account_service_spec.rb b/spec/services/activitypub/process_account_service_spec.rb
index 2b20d17b1bc..fbb5d58978b 100644
--- a/spec/services/activitypub/process_account_service_spec.rb
+++ b/spec/services/activitypub/process_account_service_spec.rb
@@ -3,7 +3,7 @@ require 'rails_helper'
RSpec.describe ActivityPub::ProcessAccountService, type: :service do
subject { described_class.new }
- context 'property values' do
+ context 'with property values, an avatar, and a profile header' do
let(:payload) do
{
id: 'https://foo.test',
@@ -14,19 +14,50 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
{ type: 'PropertyValue', name: 'Occupation', value: 'Unit test' },
{ type: 'PropertyValue', name: 'non-string', value: ['foo', 'bar'] },
],
+ image: {
+ type: 'Image',
+ mediaType: 'image/png',
+ url: 'https://foo.test/image.png',
+ },
+ icon: {
+ type: 'Image',
+ url: [
+ {
+ mediaType: 'image/png',
+ href: 'https://foo.test/icon.png',
+ },
+ ],
+ },
}.with_indifferent_access
end
- it 'parses out of attachment' do
+ before do
+ stub_request(:get, 'https://foo.test/image.png').to_return(request_fixture('avatar.txt'))
+ stub_request(:get, 'https://foo.test/icon.png').to_return(request_fixture('avatar.txt'))
+ end
+
+ it 'parses property values, avatar and profile header as expected' do
account = subject.call('alice', 'example.com', payload)
- expect(account.fields).to be_a Array
- expect(account.fields.size).to eq 2
- expect(account.fields[0]).to be_a Account::Field
- expect(account.fields[0].name).to eq 'Pronouns'
- expect(account.fields[0].value).to eq 'They/them'
- expect(account.fields[1]).to be_a Account::Field
- expect(account.fields[1].name).to eq 'Occupation'
- expect(account.fields[1].value).to eq 'Unit test'
+
+ expect(account.fields)
+ .to be_an(Array)
+ .and have_attributes(size: 2)
+ expect(account.fields.first)
+ .to be_an(Account::Field)
+ .and have_attributes(
+ name: eq('Pronouns'),
+ value: eq('They/them')
+ )
+ expect(account.fields.last)
+ .to be_an(Account::Field)
+ .and have_attributes(
+ name: eq('Occupation'),
+ value: eq('Unit test')
+ )
+ expect(account).to have_attributes(
+ avatar_remote_url: 'https://foo.test/icon.png',
+ header_remote_url: 'https://foo.test/image.png'
+ )
end
end