summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-12-19 00:26:53 +0100
committerGitHub <noreply@github.com>2020-12-19 00:26:53 +0100
commit36b9b8deaa252b458d2fa6a3c9b31cb82b8dfedb (patch)
tree56aa7e4a1a43abfaa81106703c123a967fff32f4
parent406adfca275909111153dfde91626a849fed5a1f (diff)
Fix ResolveAccountService accepting mismatching acct: URI (#15368)
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
-rw-r--r--app/services/resolve_account_service.rb10
-rw-r--r--spec/services/resolve_account_service_spec.rb21
2 files changed, 21 insertions, 10 deletions
diff --git a/app/services/resolve_account_service.rb b/app/services/resolve_account_service.rb
index eee1de51a1b..f8d61611f2e 100644
--- a/app/services/resolve_account_service.rb
+++ b/app/services/resolve_account_service.rb
@@ -46,7 +46,7 @@ class ResolveAccountService < BaseService
# Now it is certain, it is definitely a remote account, and it
# either needs to be created, or updated from fresh data
- process_account!
+ fetch_account!
rescue Webfinger::Error, WebfingerRedirectError, Oj::ParseError => e
Rails.logger.debug "Webfinger query for #{@uri} failed: #{e}"
nil
@@ -99,16 +99,12 @@ class ResolveAccountService < BaseService
acct.gsub(/\Aacct:/, '').split('@')
end
- def process_account!
+ def fetch_account!
return unless activitypub_ready?
RedisLock.acquire(lock_options) do |lock|
if lock.acquired?
- @account = Account.find_remote(@username, @domain)
-
- next if actor_json.nil?
-
- @account = ActivityPub::ProcessAccountService.new.call(@username, @domain, actor_json)
+ @account = ActivityPub::FetchRemoteAccountService.new.call(actor_url)
else
raise Mastodon::RaceConditionError
end
diff --git a/spec/services/resolve_account_service_spec.rb b/spec/services/resolve_account_service_spec.rb
index 6e4a0d9fe04..92c837050ec 100644
--- a/spec/services/resolve_account_service_spec.rb
+++ b/spec/services/resolve_account_service_spec.rb
@@ -35,7 +35,22 @@ RSpec.describe ResolveAccountService, type: :service do
context 'with a legitimate webfinger redirection' do
before do
- webfinger = { subject: 'acct:foo@ap.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo' }] }
+ webfinger = { subject: 'acct:foo@ap.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] }
+ stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
+ end
+
+ it 'returns new remote account' do
+ account = subject.call('Foo@redirected.example.com')
+
+ expect(account.activitypub?).to eq true
+ expect(account.acct).to eq 'foo@ap.example.com'
+ expect(account.inbox_url).to eq 'https://ap.example.com/users/foo/inbox'
+ end
+ end
+
+ context 'with a misconfigured redirection' do
+ before do
+ webfinger = { subject: 'acct:Foo@redirected.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] }
stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
end
@@ -50,9 +65,9 @@ RSpec.describe ResolveAccountService, type: :service do
context 'with too many webfinger redirections' do
before do
- webfinger = { subject: 'acct:foo@evil.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo' }] }
+ webfinger = { subject: 'acct:foo@evil.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] }
stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
- webfinger2 = { subject: 'acct:foo@ap.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo' }] }
+ webfinger2 = { subject: 'acct:foo@ap.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] }
stub_request(:get, 'https://evil.example.com/.well-known/webfinger?resource=acct:foo@evil.example.com').to_return(body: Oj.dump(webfinger2), headers: { 'Content-Type': 'application/jrd+json' })
end