Files
mastodon/spec/lib/webfinger_resource_spec.rb
jcoffey-dev 319ed76dbd
Crowdin / Upload translations / upload-translations (push) Skipped
Historical data migration test / test (14-alpine) (push) Canceled after 0s
Historical data migration test / test (15-alpine) (push) Canceled after 0s
Historical data migration test / test (16-alpine) (push) Canceled after 0s
Historical data migration test / test (17-alpine) (push) Canceled after 0s
Bundler Audit / security (push) Canceled after 0s
Haml Linting / lint (push) Canceled after 0s
JavaScript Linting / lint (push) Canceled after 0s
Ruby Linting / lint (push) Canceled after 0s
JavaScript Testing / test (push) Canceled after 0s
Ruby Testing / build (production) (push) Canceled after 0s
Ruby Testing / test (.ruby-version) (push) Canceled after 0s
Ruby Testing / test (3.3) (push) Canceled after 0s
Ruby Testing / test (3.4) (push) Canceled after 0s
Ruby Testing / End to End testing (.ruby-version) (push) Canceled after 0s
Ruby Testing / End to End testing (3.3) (push) Canceled after 0s
Ruby Testing / End to End testing (3.4) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check i18n / check-i18n (push) Canceled after 0s
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (javascript) (push) Canceled after 0s
CodeQL / Analyze (ruby) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check formatting / lint (push) Canceled after 0s
CSS Linting / lint (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Canceled after 0s
Chromatic / Check for relevant changes (push) Canceled after 0s
Chromatic / Run Chromatic (push) Canceled after 0s
Import Mastodon v4.7.3
Snapshot of upstream tag v4.7.3 (commit 8ff11c2bb7b9f0714e947b10fa3629c6542c7121) from
https://github.com/mastodon/mastodon, unmodified.
2026-10-05 22:03:13 -07:00

139 lines
4.3 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe WebfingerResource do
around do |example|
before_local = Rails.configuration.x.local_domain
before_web = Rails.configuration.x.web_domain
example.run
Rails.configuration.x.local_domain = before_local
Rails.configuration.x.web_domain = before_web
end
describe '#account' do
subject { described_class.new(resource).account }
describe 'with a URL value' do
context 'with a route whose controller is not AccountsController' do
let(:resource) { 'https://example.com/users/alice/other' }
it 'raises an error' do
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'with a string that does not start with an URL' do
let(:resource) { 'website for http://example.com/users/alice.other' }
it 'raises an error' do
expect { subject }.to raise_error(described_class::InvalidRequest)
end
end
context 'with a valid HTTPS route to an existing user' do
let(:account) { Fabricate(:account) }
let(:resource) { "https://example.com/users/#{account.username}" }
it { is_expected.to eq(account) }
end
context 'with a valid HTTPS route to an existing user using the new API scheme' do
let(:account) { Fabricate(:account) }
let(:resource) { "https://example.com/ap/users/#{account.id}" }
it { is_expected.to eq(account) }
end
context 'with a valid HTTPS route to a non-existing user' do
let(:account) { Fabricate(:account) }
let(:resource) { 'https://example.com/users/alice' }
it 'raises an error' do
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'with a mixed case HTTP but valid route to an existing user' do
let(:account) { Fabricate(:account) }
let(:resource) { "HTTp://example.com/users/#{account.username}" }
it { is_expected.to eq(account) }
end
context 'with a valid HTTP route to an existing user' do
let(:account) { Fabricate(:account) }
let(:resource) { "http://example.com/users/#{account.username}" }
it { is_expected.to eq(account) }
end
end
describe 'with a username and hostname value' do
context 'with a non-local domain' do
let(:account) { Fabricate(:account) }
let(:resource) { "#{account.username}@remote-host.com" }
it 'raises an error' do
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'with a valid handle for a local user with local domain' do
let(:account) { Fabricate(:account) }
let(:resource) { "#{account.username}@example.com" }
before { Rails.configuration.x.local_domain = 'example.com' }
it { is_expected.to eq(account) }
end
context 'with a valid handle for a local user with web domain' do
let(:account) { Fabricate(:account) }
let(:resource) { "#{account.username}@example.com" }
before { Rails.configuration.x.web_domain = 'example.com' }
it { is_expected.to eq(account) }
end
end
describe 'with an acct value' do
context 'with a non-local domain' do
let(:account) { Fabricate(:account) }
let(:resource) { "acct:#{account.username}@remote-host.com" }
it 'raises an error' do
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'with a valid handle for a local user with local domain' do
let(:account) { Fabricate(:account) }
let(:resource) { "acct:#{account.username}@example.com" }
before { Rails.configuration.x.local_domain = 'example.com' }
it { is_expected.to eq(account) }
end
context 'with a valid handle for a local user with web domain' do
let(:account) { Fabricate(:account) }
let(:resource) { "acct:#{account.username}@example.com" }
before { Rails.configuration.x.web_domain = 'example.com' }
it { is_expected.to eq(account) }
end
end
describe 'with a nonsense resource' do
let(:resource) { 'df/:dfkj' }
it 'raises an error' do
expect { subject }.to raise_error(described_class::InvalidRequest)
end
end
end
end