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.

82 lines
2.1 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(:head, 'https://redirect.me/abc').to_return(status: 301, headers: { 'Location' => ActivityPub::TagManager.instance.url_for(account) })
  8. stub_request(:get, 'http://example.com').to_return(status: 200, body: html)
  9. subject.call(field)
  10. end
  11. context 'when a link contains an <a> back' do
  12. let(:html) do
  13. <<-HTML
  14. <!doctype html>
  15. <body>
  16. <a href="#{ActivityPub::TagManager.instance.url_for(account)}" rel="me">Follow me on Mastodon</a>
  17. </body>
  18. HTML
  19. end
  20. it 'marks the field as verified' do
  21. expect(field.verified?).to be true
  22. end
  23. end
  24. context 'when a link contains an <a rel="noopener"> back' do
  25. let(:html) do
  26. <<-HTML
  27. <!doctype html>
  28. <body>
  29. <a href="#{ActivityPub::TagManager.instance.url_for(account)}" rel="noopener me" target="_blank">Follow me on Mastodon</a>
  30. </body>
  31. HTML
  32. end
  33. it 'marks the field as verified' do
  34. expect(field.verified?).to be true
  35. end
  36. end
  37. context 'when a link contains a <link> back' do
  38. let(:html) do
  39. <<-HTML
  40. <!doctype html>
  41. <head>
  42. <link type="text/html" href="#{ActivityPub::TagManager.instance.url_for(account)}" rel="me" />
  43. </head>
  44. HTML
  45. end
  46. it 'marks the field as verified' do
  47. expect(field.verified?).to be true
  48. end
  49. end
  50. context 'when a link goes through a redirect back' do
  51. let(:html) do
  52. <<-HTML
  53. <!doctype html>
  54. <head>
  55. <link type="text/html" href="https://redirect.me/abc" rel="me" />
  56. </head>
  57. HTML
  58. end
  59. it 'marks the field as verified' do
  60. expect(field.verified?).to be true
  61. end
  62. end
  63. context 'when a link does not contain a link back' do
  64. let(:html) { '' }
  65. it 'marks the field as verified' do
  66. expect(field.verified?).to be false
  67. end
  68. end
  69. end