diff --git a/app/models/account/field.rb b/app/models/account/field.rb index 4b3ccea9c43..acc073b49c8 100644 --- a/app/models/account/field.rb +++ b/app/models/account/field.rb @@ -44,7 +44,7 @@ class Account::Field < ActiveModelSerializers::Model parsed_url.user.nil? && parsed_url.password.nil? && parsed_url.host.present? && - parsed_url.normalized_host == parsed_url.host && + parsed_url.normalized_host == parsed_url.host.downcase && (parsed_url.path.empty? || parsed_url.path == parsed_url.normalized_path) rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError false diff --git a/app/services/verify_link_service.rb b/app/services/verify_link_service.rb index fc3c4cbc282..406ba033e25 100644 --- a/app/services/verify_link_service.rb +++ b/app/services/verify_link_service.rb @@ -44,6 +44,6 @@ class VerifyLinkService < BaseService res.headers['Location'] end - redirect_to_url == @link_back + redirect_to_url&.downcase == @link_back.downcase end end diff --git a/spec/services/verify_link_service_spec.rb b/spec/services/verify_link_service_spec.rb index 7e2f9607cfa..138f0aacdb7 100644 --- a/spec/services/verify_link_service_spec.rb +++ b/spec/services/verify_link_service_spec.rb @@ -211,4 +211,68 @@ RSpec.describe VerifyLinkService do end end end -end + + context 'when given a local account with an uppercase URL' do + let(:account) { Fabricate(:account, username: 'alice') } + let(:field) { Account::Field.new(account, 'name' => 'Website', 'value' => 'http://EXAMPLE.COM/Path') } + + before do + stub_request(:get, 'http://EXAMPLE.COM/Path').to_return(status: 200, body: html) + subject.call(field) + end + + context 'when a link contains an back' do + let(:html) do + <<~HTML + + + Follow me on Mastodon + + HTML + end + + it 'marks the field as verified' do + expect(field.verified?).to be true + end + end + + context 'when a link contains an uppercase back' do + let(:html) do + <<~HTML + + + Follow me on Mastodon + + HTML + end + + it 'marks the field as verified' do + expect(field.verified?).to be true + end + end + end + + context 'when link goes through a redirect with different case' do + let(:account) { Fabricate(:account, username: 'alice') } + let(:field) { Account::Field.new(account, 'name' => 'Website', 'value' => 'http://example.com') } + + before do + stub_request(:get, 'http://example.com').to_return(status: 200, body: html) + stub_request(:head, 'https://redirect.me/abc').to_return(status: 301, headers: { 'Location' => ActivityPub::TagManager.instance.url_for(account).upcase }) + subject.call(field) + end + + let(:html) do + <<~HTML + + + + + HTML + end + + it 'marks the field as verified' do + expect(field.verified?).to be true + end + end +end \ No newline at end of file