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.

66 lines
1.7 KiB

  1. require 'rails_helper'
  2. RSpec.describe VerifyLinkService, type: :service do
  3. subject { described_class.new }
  4. let(:account) { Fabricate(:account, username: 'alice') }
  5. let(:field) { Account::Field.new(account, 'name' => 'Website', 'value' => 'http://example.com') }
  6. before do
  7. stub_request(:get, 'http://example.com').to_return(status: 200, body: html)
  8. subject.call(field)
  9. end
  10. context 'when a link contains an <a> back' do
  11. let(:html) do
  12. <<-HTML
  13. <!doctype html>
  14. <body>
  15. <a href="#{ActivityPub::TagManager.instance.url_for(account)}" rel="me">Follow me on Mastodon</a>
  16. </body>
  17. HTML
  18. end
  19. it 'marks the field as verified' do
  20. expect(field.verified?).to be true
  21. end
  22. end
  23. context 'when a link contains an <a rel="noopener"> back' do
  24. let(:html) do
  25. <<-HTML
  26. <!doctype html>
  27. <body>
  28. <a href="#{ActivityPub::TagManager.instance.url_for(account)}" rel="noopener me" target="_blank">Follow me on Mastodon</a>
  29. </body>
  30. HTML
  31. end
  32. it 'marks the field as verified' do
  33. expect(field.verified?).to be true
  34. end
  35. end
  36. context 'when a link contains a <link> back' do
  37. let(:html) do
  38. <<-HTML
  39. <!doctype html>
  40. <head>
  41. <link type="text/html" href="#{ActivityPub::TagManager.instance.url_for(account)}" rel="me" />
  42. </head>
  43. HTML
  44. end
  45. it 'marks the field as verified' do
  46. expect(field.verified?).to be true
  47. end
  48. end
  49. context 'when a link does not contain a link back' do
  50. let(:html) { '' }
  51. it 'marks the field as verified' do
  52. expect(field.verified?).to be false
  53. end
  54. end
  55. end