forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Select correct self link when parsing Webfinger response (mastodon#31110
- Loading branch information
1 parent
a8330be
commit cd0ca4b
Showing
10 changed files
with
73 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ Content-Type: application/jrd+json; charset=utf-8 | |
X-Content-Type-Options: nosniff | ||
Date: Sun, 17 Sep 2017 06:22:50 GMT | ||
|
||
{"subject":"acct:[email protected]","aliases":["https://ap.example.com/@foo","https://ap.example.com/users/foo"],"links":[{"rel":"http://webfinger.net/rel/profile-page","type":"text/html","href":"https://ap.example.com/@foo"},{"rel":"http://schemas.google.com/g/2010#updates-from","type":"application/atom+xml","href":"https://ap.example.com/users/foo.atom"},{"rel":"self","type":"application/activity+json","href":"https://ap.example.com/users/foo"},{"rel":"salmon","href":"https://ap.example.com/api/salmon/1"},{"rel":"magic-public-key","href":"data:application/magic-public-key,RSA.u3L4vnpNLzVH31MeWI394F0wKeJFsLDAsNXGeOu0QF2x-h1zLWZw_agqD2R3JPU9_kaDJGPIV2Sn5zLyUA9S6swCCMOtn7BBR9g9sucgXJmUFB0tACH2QSgHywMAybGfmSb3LsEMNKsGJ9VsvYoh8lDET6X4Pyw-ZJU0_OLo_41q9w-OrGtlsTm_PuPIeXnxa6BLqnDaxC-4IcjG_FiPahNCTINl_1F_TgSSDZ4Taf4U9XFEIFw8wmgploELozzIzKq-t8nhQYkgAkt64euWpva3qL5KD1mTIZQEP-LZvh3s2WHrLi3fhbdRuwQ2c0KkJA2oSTFPDpqqbPGZ3QvuHQ==.AQAB"},{"rel":"http://ostatus.org/schema/1.0/subscribe","template":"https://ap.example.com/authorize_follow?acct={uri}"}]} | ||
{"subject":"acct:[email protected]","aliases":["https://ap.example.com/@foo","https://ap.example.com/users/foo"],"links":[{"rel":"http://webfinger.net/rel/profile-page","type":"text/html","href":"https://ap.example.com/@foo"},{"rel":"http://schemas.google.com/g/2010#updates-from","type":"application/atom+xml","href":"https://ap.example.com/users/foo.atom"},{"rel":"self","type":"application/html","href":"https://ap.example.com/users/foo.html"},{"rel":"self","type":"application/activity+json","href":"https://ap.example.com/users/foo"},{"rel":"self","type":"application/json","href":"https://ap.example.com/users/foo.json"},{"rel":"salmon","href":"https://ap.example.com/api/salmon/1"},{"rel":"magic-public-key","href":"data:application/magic-public-key,RSA.u3L4vnpNLzVH31MeWI394F0wKeJFsLDAsNXGeOu0QF2x-h1zLWZw_agqD2R3JPU9_kaDJGPIV2Sn5zLyUA9S6swCCMOtn7BBR9g9sucgXJmUFB0tACH2QSgHywMAybGfmSb3LsEMNKsGJ9VsvYoh8lDET6X4Pyw-ZJU0_OLo_41q9w-OrGtlsTm_PuPIeXnxa6BLqnDaxC-4IcjG_FiPahNCTINl_1F_TgSSDZ4Taf4U9XFEIFw8wmgploELozzIzKq-t8nhQYkgAkt64euWpva3qL5KD1mTIZQEP-LZvh3s2WHrLi3fhbdRuwQ2c0KkJA2oSTFPDpqqbPGZ3QvuHQ==.AQAB"},{"rel":"http://ostatus.org/schema/1.0/subscribe","template":"https://ap.example.com/authorize_follow?acct={uri}"}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ Access-Control-Allow-Origin: * | |
Vary: Accept-Encoding,Cookie | ||
Strict-Transport-Security: max-age=31536000; includeSubdomains; | ||
|
||
{"subject":"acct:[email protected]","aliases":["https:\/\/quitter.no\/user\/7477","https:\/\/quitter.no\/gargron","https:\/\/quitter.no\/index.php\/user\/7477","https:\/\/quitter.no\/index.php\/gargron"],"links":[{"rel":"http:\/\/webfinger.net\/rel\/profile-page","type":"text\/html","href":"https:\/\/quitter.no\/gargron"},{"rel":"http:\/\/gmpg.org\/xfn\/11","type":"text\/html","href":"https:\/\/quitter.no\/gargron"},{"rel":"describedby","type":"application\/rdf+xml","href":"https:\/\/quitter.no\/gargron\/foaf"},{"rel":"http:\/\/apinamespace.org\/atom","type":"application\/atomsvc+xml","href":"https:\/\/quitter.no\/api\/statusnet\/app\/service\/gargron.xml"},{"rel":"http:\/\/apinamespace.org\/twitter","href":"https:\/\/quitter.no\/api\/"},{"rel":"http:\/\/specs.openid.net\/auth\/2.0\/provider","href":"https:\/\/quitter.no\/gargron"},{"rel":"http:\/\/schemas.google.com\/g\/2010#updates-from","type":"application\/atom+xml","href":"https:\/\/quitter.no\/api\/statuses\/user_timeline\/7477.atom"},{"rel":"magic-public-key","href":"data:application\/magic-public-key,RSA.1ZBkHTavLvxH3FzlKv4O6WtlILKRFfNami3_Rcu8EuogtXSYiS-bB6hElZfUCSHbC4uLemOA34PEhz__CDMozax1iI_t8dzjDnh1x0iFSup7pSfW9iXk_WU3Dm74yWWW2jildY41vWgrEstuQ1dJ8vVFfSJ9T_tO4c-T9y8vDI8=.AQAB"},{"rel":"salmon","href":"https:\/\/quitter.no\/main\/salmon\/user\/7477"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-replies","href":"https:\/\/quitter.no\/main\/salmon\/user\/7477"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-mention","href":"https:\/\/quitter.no\/main\/salmon\/user\/7477"},{"rel":"http:\/\/ostatus.org\/schema\/1.0\/subscribe","template":"https:\/\/quitter.no\/main\/ostatussub?profile={uri}"}]} | ||
{"subject":"acct:[email protected]","aliases":["https:\/\/quitter.no\/user\/7477","https:\/\/quitter.no\/gargron","https:\/\/quitter.no\/index.php\/user\/7477","https:\/\/quitter.no\/index.php\/gargron"],"links":[{"rel":"http:\/\/webfinger.net\/rel\/profile-page","type":"text\/html","href":"https:\/\/quitter.no\/gargron"},{"rel":"http:\/\/gmpg.org\/xfn\/11","type":"text\/html","href":"https:\/\/quitter.no\/gargron"},{"rel":"describedby","type":"application\/rdf+xml","href":"https:\/\/quitter.no\/gargron\/foaf"},{"rel":"self","type":"application/activity+json","href":"https://ap.example.com/users/foo"},{"rel":"http:\/\/apinamespace.org\/atom","type":"application\/atomsvc+xml","href":"https:\/\/quitter.no\/api\/statusnet\/app\/service\/gargron.xml"},{"rel":"http:\/\/apinamespace.org\/twitter","href":"https:\/\/quitter.no\/api\/"},{"rel":"http:\/\/specs.openid.net\/auth\/2.0\/provider","href":"https:\/\/quitter.no\/gargron"},{"rel":"http:\/\/schemas.google.com\/g\/2010#updates-from","type":"application\/atom+xml","href":"https:\/\/quitter.no\/api\/statuses\/user_timeline\/7477.atom"},{"rel":"magic-public-key","href":"data:application\/magic-public-key,RSA.1ZBkHTavLvxH3FzlKv4O6WtlILKRFfNami3_Rcu8EuogtXSYiS-bB6hElZfUCSHbC4uLemOA34PEhz__CDMozax1iI_t8dzjDnh1x0iFSup7pSfW9iXk_WU3Dm74yWWW2jildY41vWgrEstuQ1dJ8vVFfSJ9T_tO4c-T9y8vDI8=.AQAB"},{"rel":"salmon","href":"https:\/\/quitter.no\/main\/salmon\/user\/7477"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-replies","href":"https:\/\/quitter.no\/main\/salmon\/user\/7477"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-mention","href":"https:\/\/quitter.no\/main\/salmon\/user\/7477"},{"rel":"http:\/\/ostatus.org\/schema\/1.0\/subscribe","template":"https:\/\/quitter.no\/main\/ostatussub?profile={uri}"}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Webfinger do | ||
describe 'self link' do | ||
context 'when self link is specified with type application/activity+json' do | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } | ||
|
||
it 'correctly parses the response' do | ||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:[email protected]').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) | ||
|
||
response = described_class.new('acct:[email protected]').perform | ||
|
||
expect(response.self_link_href).to eq 'https://example.com/alice' | ||
end | ||
end | ||
|
||
context 'when self link is specified with type application/ld+json' do | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' }] } } | ||
|
||
it 'correctly parses the response' do | ||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:[email protected]').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) | ||
|
||
response = described_class.new('acct:[email protected]').perform | ||
|
||
expect(response.self_link_href).to eq 'https://example.com/alice' | ||
end | ||
end | ||
|
||
context 'when self link is specified with incorrect type' do | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/json"' }] } } | ||
|
||
it 'raises an error' do | ||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:[email protected]').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) | ||
|
||
expect { described_class.new('acct:[email protected]').perform }.to raise_error(Webfinger::Error) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ | |
end | ||
|
||
context 'when the account does not have a inbox' do | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice' }] } } | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } | ||
|
||
before do | ||
actor[:inbox] = nil | ||
|
@@ -51,7 +51,7 @@ | |
end | ||
|
||
context 'when URI and WebFinger share the same host' do | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice' }] } } | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } | ||
|
||
before do | ||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) | ||
|
@@ -72,7 +72,7 @@ | |
end | ||
|
||
context 'when WebFinger presents different domain than URI' do | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice' }] } } | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } | ||
|
||
before do | ||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) | ||
|
@@ -95,7 +95,7 @@ | |
end | ||
|
||
context 'when WebFinger returns a different URI' do | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/bob' }] } } | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } } | ||
|
||
before do | ||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) | ||
|
@@ -111,7 +111,7 @@ | |
end | ||
|
||
context 'when WebFinger returns a different URI after a redirection' do | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/bob' }] } } | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } } | ||
|
||
before do | ||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ | |
end | ||
|
||
context 'when the account does not have a inbox' do | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice' }] } } | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } | ||
|
||
before do | ||
actor[:inbox] = nil | ||
|
@@ -51,7 +51,7 @@ | |
end | ||
|
||
context 'when URI and WebFinger share the same host' do | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice' }] } } | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } | ||
|
||
before do | ||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) | ||
|
@@ -72,7 +72,7 @@ | |
end | ||
|
||
context 'when WebFinger presents different domain than URI' do | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice' }] } } | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } | ||
|
||
before do | ||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) | ||
|
@@ -95,7 +95,7 @@ | |
end | ||
|
||
context 'when WebFinger returns a different URI' do | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/bob' }] } } | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } } | ||
|
||
before do | ||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) | ||
|
@@ -111,7 +111,7 @@ | |
end | ||
|
||
context 'when WebFinger returns a different URI after a redirection' do | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/bob' }] } } | ||
let!(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/bob', type: 'application/activity+json' }] } } | ||
|
||
before do | ||
stub_request(:get, 'https://example.com/alice').to_return(body: Oj.dump(actor), headers: { 'Content-Type': 'application/activity+json' }) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
RSpec.describe ActivityPub::FetchRemoteKeyService do | ||
subject { described_class.new } | ||
|
||
let(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice' }] } } | ||
let(:webfinger) { { subject: 'acct:[email protected]', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } } | ||
|
||
let(:public_key_pem) do | ||
<<~TEXT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters