mirror of
https://github.com/mastodon/mastodon.git
synced 2026-09-11 09:56:17 -05:00
Merge fdd024630d into 20c105c194
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 <a> back' do
|
||||
let(:html) do
|
||||
<<~HTML
|
||||
<!doctype html>
|
||||
<body>
|
||||
<a href="#{ActivityPub::TagManager.instance.url_for(account)}" rel="me">Follow me on Mastodon</a>
|
||||
</body>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'marks the field as verified' do
|
||||
expect(field.verified?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a link contains an uppercase <a> back' do
|
||||
let(:html) do
|
||||
<<~HTML
|
||||
<!doctype html>
|
||||
<body>
|
||||
<a href="#{ActivityPub::TagManager.instance.url_for(account).upcase}" rel="me">Follow me on Mastodon</a>
|
||||
</body>
|
||||
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
|
||||
<!doctype html>
|
||||
<head>
|
||||
<link type="text/html" href="https://redirect.me/abc" rel="me" />
|
||||
</head>
|
||||
HTML
|
||||
end
|
||||
|
||||
it 'marks the field as verified' do
|
||||
expect(field.verified?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user