logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

fetch_remote_account_service_spec.rb (4357B)


  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::FetchRemoteAccountService do
  3. subject { ActivityPub::FetchRemoteAccountService.new }
  4. let!(:actor) do
  5. {
  6. '@context': 'https://www.w3.org/ns/activitystreams',
  7. id: 'https://example.com/alice',
  8. type: 'Person',
  9. preferredUsername: 'alice',
  10. name: 'Alice',
  11. summary: 'Foo bar',
  12. inbox: 'http://example.com/alice/inbox',
  13. }
  14. end
  15. describe '#call' do
  16. let(:account) { subject.call('https://example.com/alice', id: true) }
  17. shared_examples 'sets profile data' do
  18. it 'returns an account' do
  19. expect(account).to be_an Account
  20. end
  21. it 'sets display name' do
  22. expect(account.display_name).to eq 'Alice'
  23. end
  24. it 'sets note' do
  25. expect(account.note).to eq 'Foo bar'
  26. end
  27. it 'sets URL' do
  28. expect(account.url).to eq 'https://example.com/alice'
  29. end
  30. end
  31. context 'when the account does not have a inbox' do
  32. let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } }
  33. before do
  34. actor[:inbox] = nil
  35. stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor))
  36. 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' })
  37. end
  38. it 'fetches resource' do
  39. account
  40. expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
  41. end
  42. it 'looks up webfinger' do
  43. account
  44. expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
  45. end
  46. it 'returns nil' do
  47. expect(account).to be_nil
  48. end
  49. end
  50. context 'when URI and WebFinger share the same host' do
  51. let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } }
  52. before do
  53. stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor))
  54. 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' })
  55. end
  56. it 'fetches resource' do
  57. account
  58. expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
  59. end
  60. it 'looks up webfinger' do
  61. account
  62. expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
  63. end
  64. it 'sets username and domain from webfinger' do
  65. expect(account.username).to eq 'alice'
  66. expect(account.domain).to eq 'example.com'
  67. end
  68. include_examples 'sets profile data'
  69. end
  70. context 'when WebFinger presents different domain than URI' do
  71. let!(:webfinger) { { subject: 'acct:alice@iscool.af', links: [{ rel: 'self', href: 'https://example.com/alice' }] } }
  72. before do
  73. stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor))
  74. 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' })
  75. 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' })
  76. end
  77. it 'fetches resource' do
  78. account
  79. expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
  80. end
  81. it 'looks up webfinger' do
  82. account
  83. expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
  84. end
  85. it 'looks up "redirected" webfinger' do
  86. account
  87. expect(a_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af')).to have_been_made.once
  88. end
  89. it 'sets username and domain from final webfinger' do
  90. expect(account.username).to eq 'alice'
  91. expect(account.domain).to eq 'iscool.af'
  92. end
  93. include_examples 'sets profile data'
  94. end
  95. end
  96. end