You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.6 KiB

  1. require 'rails_helper'
  2. RSpec.describe FetchRemoteAccountService, type: :service do
  3. let(:url) { 'https://example.com' }
  4. let(:prefetched_body) { nil }
  5. let(:protocol) { :ostatus }
  6. subject { FetchRemoteAccountService.new.call(url, prefetched_body, protocol) }
  7. let(:actor) do
  8. {
  9. '@context': 'https://www.w3.org/ns/activitystreams',
  10. id: 'https://example.com/alice',
  11. type: 'Person',
  12. preferredUsername: 'alice',
  13. name: 'Alice',
  14. summary: 'Foo bar',
  15. inbox: 'http://example.com/alice/inbox',
  16. }
  17. end
  18. let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } }
  19. let(:xml) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'xml', 'mastodon.atom')) }
  20. shared_examples 'return Account' do
  21. it { is_expected.to be_an Account }
  22. end
  23. context 'protocol is :activitypub' do
  24. let(:prefetched_body) { Oj.dump(actor) }
  25. let(:protocol) { :activitypub }
  26. before do
  27. 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' })
  28. end
  29. include_examples 'return Account'
  30. end
  31. context 'protocol is :ostatus' do
  32. let(:prefetched_body) { xml }
  33. let(:protocol) { :ostatus }
  34. before do
  35. stub_request(:get, "https://kickass.zone/.well-known/webfinger?resource=acct:localhost@kickass.zone").to_return(request_fixture('webfinger-hacker3.txt'))
  36. stub_request(:get, "https://kickass.zone/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt'))
  37. end
  38. include_examples 'return Account'
  39. end
  40. context 'when prefetched_body is nil' do
  41. context 'protocol is :activitypub' do
  42. before do
  43. stub_request(:get, url).to_return(status: 200, body: Oj.dump(actor), headers: { 'Content-Type' => 'application/activity+json' })
  44. 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' })
  45. end
  46. include_examples 'return Account'
  47. end
  48. context 'protocol is :ostatus' do
  49. before do
  50. stub_request(:get, url).to_return(status: 200, body: xml, headers: { 'Content-Type' => 'application/atom+xml' })
  51. stub_request(:get, "https://kickass.zone/.well-known/webfinger?resource=acct:localhost@kickass.zone").to_return(request_fixture('webfinger-hacker3.txt'))
  52. stub_request(:get, "https://kickass.zone/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt'))
  53. end
  54. include_examples 'return Account'
  55. end
  56. end
  57. end