webfinger_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Webfinger do
  4. describe 'self link' do
  5. context 'when self link is specified with type application/activity+json' do
  6. let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
  7. it 'correctly parses the response' do
  8. 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' })
  9. response = described_class.new('acct:alice@example.com').perform
  10. expect(response.self_link_href).to eq 'https://example.com/alice'
  11. end
  12. end
  13. context 'when self link is specified with type application/ld+json' do
  14. let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' }] } }
  15. it 'correctly parses the response' do
  16. 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' })
  17. response = described_class.new('acct:alice@example.com').perform
  18. expect(response.self_link_href).to eq 'https://example.com/alice'
  19. end
  20. end
  21. context 'when self link is specified with incorrect type' do
  22. let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/json"' }] } }
  23. it 'raises an error' do
  24. 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' })
  25. expect { described_class.new('acct:alice@example.com').perform }.to raise_error(Webfinger::Error)
  26. end
  27. end
  28. end
  29. end