about summary refs log tree commit diff
path: root/spec/controllers/well_known/webfinger_controller_spec.rb
blob: 4d588bf4e3e9c3bb3a243789ccc49b4713057da7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'rails_helper'

describe WellKnown::WebfingerController, type: :controller do
  render_views

  describe 'GET #show' do
    let(:alice) { Fabricate(:account, username: 'alice') }

    around(:each) do |example|
      before = Rails.configuration.x.alternate_domains
      example.run
      Rails.configuration.x.alternate_domains = before
    end

    it 'returns http success when account can be found' do
      get :show, params: { resource: alice.to_webfinger_s }, format: :json

      expect(response).to have_http_status(:success)
    end

    it 'returns http not found when account cannot be found' do
      get :show, params: { resource: 'acct:not@existing.com' }, format: :json

      expect(response).to have_http_status(:not_found)
    end

    it 'returns http success when account can be found with alternate domains' do
      Rails.configuration.x.alternate_domains = ["foo.org"]
      username, domain = alice.to_webfinger_s.split("@")

      get :show, params: { resource: "#{username}@foo.org" }, format: :json

      expect(response).to have_http_status(:success)
    end

    it 'returns http not found when account can not be found with alternate domains' do
      Rails.configuration.x.alternate_domains = ["foo.org"]
      username, domain = alice.to_webfinger_s.split("@")

      get :show, params: { resource: "#{username}@bar.org" }, format: :json

      expect(response).to have_http_status(:not_found)
    end
  end
end