Skip to content

Commit

Permalink
Combine repeated subject in ap fetch remote actor service spec (masto…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored Jan 26, 2024
1 parent 239244e commit 44f6d28
Showing 1 changed file with 21 additions and 66 deletions.
87 changes: 21 additions & 66 deletions spec/services/activitypub/fetch_remote_actor_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,14 @@
let(:account) { subject.call('https://example.com/alice', id: true) }

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'
it 'returns an account and sets attributes' do
expect(account)
.to be_an(Account)
.and have_attributes(
display_name: eq('Alice'),
note: eq('Foo bar'),
url: eq('https://example.com/alice')
)
end
end

Expand All @@ -48,19 +42,12 @@
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:[email protected]').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 'fetches resource and looks up webfinger and returns nil' do
expect(account).to be_nil

it 'looks up webfinger' 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:[email protected]')).to have_been_made.once
end

it 'returns nil' do
expect(account).to be_nil
end
end

context 'when URI and WebFinger share the same host' do
Expand All @@ -71,17 +58,12 @@
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:[email protected]').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end

it 'fetches resource' do
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
end

it 'looks up webfinger' 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:[email protected]')).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
Expand All @@ -98,22 +80,13 @@
stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:[email protected]').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end

it 'fetches resource' do
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
end

it 'looks up webfinger' 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:[email protected]')).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:[email protected]')).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
Expand All @@ -129,19 +102,12 @@
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:[email protected]').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 'fetches resource and looks up webfinger and does not create account' do
expect(account).to be_nil

it 'looks up webfinger' 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:[email protected]')).to have_been_made.once
end

it 'does not create account' do
expect(account).to be_nil
end
end

context 'when WebFinger returns a different URI after a redirection' do
Expand All @@ -153,24 +119,13 @@
stub_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:[email protected]').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 'fetches resource and looks up webfinger and follows redirect and does not create account' do
expect(account).to be_nil

it 'looks up webfinger' 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:[email protected]')).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:[email protected]')).to have_been_made.once
end

it 'does not create account' do
expect(account).to be_nil
end
end

context 'with wrong id' do
Expand Down

0 comments on commit 44f6d28

Please sign in to comment.