Skip to content

Commit

Permalink
Replace legacy webfinger with new route from .well-known
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperTux88 committed May 28, 2017
1 parent 12cd5b0 commit 6e51ae5
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 83 deletions.
32 changes: 2 additions & 30 deletions app/controllers/diaspora_federation/webfinger_controller.rb
Expand Up @@ -8,7 +8,8 @@ class WebfingerController < ApplicationController
# example:
# <?xml version="1.0" encoding="UTF-8"?>
# <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
# <Link rel="lrdd" type="application/xrd+xml" template="https://server.example/webfinger?q={uri}"/>
# <Link rel="lrdd" type="application/xrd+xml"
# template="https://server.example/.well-known/webfinger.xml?resource={uri}"/>
# </XRD>
#
# GET /.well-known/host-meta
Expand Down Expand Up @@ -91,35 +92,6 @@ def webfinger
end
end

# @deprecated This is the pre RFC 7033 webfinger.
#
# example:
# <?xml version="1.0" encoding="UTF-8"?>
# <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
# <Subject>acct:alice@localhost:3000</Subject>
# <Alias>http://localhost:3000/people/c8e87290f6a20132963908fbffceb188</Alias>
# <Link rel="http://microformats.org/profile/hcard" type="text/html"
# href="http://localhost:3000/hcard/users/c8e87290f6a20132963908fbffceb188"/>
# <Link rel="http://joindiaspora.com/seed_location" type="text/html" href="http://localhost:3000/"/>
# <Link rel="http://joindiaspora.com/guid" type="text/html" href="c8e87290f6a20132963908fbffceb188"/>
# <Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="http://localhost:3000/u/alice"/>
# <Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml"
# href="http://localhost:3000/public/alice.atom"/>
# <Link rel="salmon" href="http://localhost:3000/receive/users/c8e87290f6a20132963908fbffceb188"/>
# <Link rel="diaspora-public-key" type="RSA" href="LS0tLS1CRU......"/>
# </XRD>
# GET /webfinger?q=<uri>
def legacy_webfinger
person_wf = find_person_webfinger(params[:q]) if params[:q]

if person_wf.nil?
head :not_found
else
logger.info "webfinger profile request for: #{person_wf.acct_uri}"
render xml: person_wf.to_xml, content_type: "application/xrd+xml"
end
end

# Creates the host-meta xml with the configured server_uri and caches it
# @return [String] XML string
def self.host_meta_xml
Expand Down
5 changes: 2 additions & 3 deletions config/routes.rb
Expand Up @@ -9,9 +9,8 @@
end

controller :webfinger do
get ".well-known/host-meta" => :host_meta, :as => "host_meta"
get ".well-known/webfinger" => :webfinger, :as => "webfinger"
get "webfinger" => :legacy_webfinger, :as => "legacy_webfinger"
get ".well-known/host-meta" => :host_meta, :as => "host_meta"
get ".well-known/webfinger" => :webfinger, :as => "webfinger"
end

controller :h_card do
Expand Down
7 changes: 4 additions & 3 deletions docs/discovery/webfinger.md
Expand Up @@ -6,7 +6,7 @@ diaspora\* uses an old draft of [WebFinger][webfinger-draft] to discover users f

{% include warning_box.html
title="Old WebFinger"
content="<p>diaspora* doesn't yet support the RFC 7033 WebFinger!</p>"
content="<p>diaspora* doesn't yet fully support the RFC 7033 WebFinger!</p>"
%}

## WebFinger endpoint discovery
Expand Down Expand Up @@ -54,7 +54,7 @@ Content-Type: application/xrd+xml; charset=utf-8
~~~xml
<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Link rel="lrdd" type="application/xrd+xml" template="https://example.org/webfinger?q={uri}"/>
<Link rel="lrdd" type="application/xrd+xml" template="https://example.org/.well-known/webfinger.xml?resource={uri}"/>
</XRD>
~~~

Expand All @@ -70,7 +70,7 @@ of the searched person.
#### Example

~~~
GET /webfinger?q=acct:alice@example.org
GET /.well-known/webfinger.xml?resource=acct:alice@example.org
Host: example.org
~~~

Expand Down Expand Up @@ -117,6 +117,7 @@ Content-Type: application/xrd+xml; charset=utf-8
* [RFC 6415: Web Host Metadata][host-meta]
* [WebFinger draft][webfinger-draft]
* [Extensible Resource Descriptor (XRD) Version 1.0][xrd]
* [RFC 7033: WebFinger][webfinger-rfc]

[host-meta]: https://tools.ietf.org/html/rfc6415
[webfinger-draft]: https://tools.ietf.org/html/draft-jones-appsawg-webfinger-06
Expand Down
2 changes: 1 addition & 1 deletion lib/diaspora_federation/discovery/host_meta.rb
Expand Up @@ -26,7 +26,7 @@ def initialize(webfinger_url)
end

# URL fragment to append to the base URL
WEBFINGER_SUFFIX = "/webfinger?q={uri}".freeze
WEBFINGER_SUFFIX = "/.well-known/webfinger.xml?resource={uri}".freeze

# Returns the WebFinger URL that was used to build this instance (either from
# xml or by giving a base URL).
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/diaspora_federation/rails4_spec.rb
Expand Up @@ -17,13 +17,13 @@ module DiasporaFederation
public_key: alice.serialized_public_key
).to_xml

get :legacy_webfinger, q: alice.diaspora_id
get :webfinger, format: :xml, resource: alice.diaspora_id
expect(response).to be_success
expect(response.body).to eq(webfinger_xrd)
end

it "404s when the person does not exist" do
get :legacy_webfinger, q: "me@mydiaspora.pod.com"
get :webfinger, format: :xml, resource: "me@mydiaspora.pod.com"
expect(response).to be_not_found
end
end
Expand Down
Expand Up @@ -15,7 +15,7 @@ module DiasporaFederation

it "contains the webfinger-template" do
get :host_meta
expect(response.body).to include "template=\"http://localhost:3000/webfinger?q={uri}\""
expect(response.body).to include "template=\"http://localhost:3000/.well-known/webfinger.xml?resource={uri}\""
end

it "returns a application/xrd+xml" do
Expand Down Expand Up @@ -119,33 +119,5 @@ module DiasporaFederation
end
end
end

describe "GET #legacy_webfinger", rails: 5 do
it "succeeds when the person exists" do
get :legacy_webfinger, params: {q: alice.diaspora_id}
expect(response).to be_success
end

it "succeeds with 'acct:' in the query when the person exists" do
get :legacy_webfinger, params: {q: "acct:#{alice.diaspora_id}"}
expect(response).to be_success
end

it "contains the diaspora* ID" do
get :legacy_webfinger, params: {q: "acct:#{alice.diaspora_id}"}
expect(response.body).to include "<Subject>acct:alice@localhost:3000</Subject>"
end

it "404s when the person does not exist" do
get :legacy_webfinger, params: {q: "me@mydiaspora.pod.com"}
expect(response).to be_not_found
end

it "calls the fetch_person_for_webfinger callback" do
expect_callback(:fetch_person_for_webfinger, "alice@localhost:3000").and_call_original

get :legacy_webfinger, params: {q: "acct:alice@localhost:3000"}
end
end
end
end
12 changes: 6 additions & 6 deletions spec/lib/diaspora_federation/discovery/discovery_spec.rb
Expand Up @@ -49,7 +49,7 @@ module DiasporaFederation
it "fetches the userdata and returns a person object" do
stub_request(:get, "https://localhost:3000/.well-known/host-meta")
.to_return(status: 200, body: host_meta_xrd)
stub_request(:get, "http://localhost:3000/webfinger?q=acct:#{account}")
stub_request(:get, "http://localhost:3000/.well-known/webfinger.xml?resource=acct:#{account}")
.to_return(status: 200, body: webfinger_xrd)
stub_request(:get, "http://localhost:3000/hcard/users/#{alice.guid}")
.to_return(status: 200, body: hcard_html)
Expand All @@ -76,7 +76,7 @@ module DiasporaFederation
it "fetches the userdata and saves the person object via callback" do
stub_request(:get, "https://localhost:3000/.well-known/host-meta")
.to_return(status: 200, body: host_meta_xrd)
stub_request(:get, "http://localhost:3000/webfinger?q=acct:#{account}")
stub_request(:get, "http://localhost:3000/.well-known/webfinger.xml?resource=acct:#{account}")
.to_return(status: 200, body: webfinger_xrd)
stub_request(:get, "http://localhost:3000/hcard/users/#{alice.guid}")
.to_return(status: 200, body: hcard_html)
Expand All @@ -96,7 +96,7 @@ module DiasporaFederation
.to_return(status: 404)
stub_request(:get, "http://localhost:3000/.well-known/host-meta")
.to_return(status: 200, body: host_meta_xrd)
stub_request(:get, "http://localhost:3000/webfinger?q=acct:#{account}")
stub_request(:get, "http://localhost:3000/.well-known/webfinger.xml?resource=acct:#{account}")
.to_return(status: 200, body: webfinger_xrd)
stub_request(:get, "http://localhost:3000/hcard/users/#{alice.guid}")
.to_return(status: 200, body: hcard_html)
Expand All @@ -113,7 +113,7 @@ module DiasporaFederation
.to_raise(OpenSSL::SSL::SSLError)
stub_request(:get, "http://localhost:3000/.well-known/host-meta")
.to_return(status: 200, body: host_meta_xrd)
stub_request(:get, "http://localhost:3000/webfinger?q=acct:#{account}")
stub_request(:get, "http://localhost:3000/.well-known/webfinger.xml?resource=acct:#{account}")
.to_return(status: 200, body: webfinger_xrd)
stub_request(:get, "http://localhost:3000/hcard/users/#{alice.guid}")
.to_return(status: 200, body: hcard_html)
Expand All @@ -130,7 +130,7 @@ module DiasporaFederation

stub_request(:get, "https://localhost:3000/.well-known/host-meta")
.to_return(status: 200, body: host_meta_xrd)
stub_request(:get, "http://localhost:3000/webfinger?q=acct:#{account}")
stub_request(:get, "http://localhost:3000/.well-known/webfinger.xml?resource=acct:#{account}")
.to_return(status: 200, body: modified_webfinger)

expect { Discovery::Discovery.new(account).fetch_and_save }.to raise_error Discovery::DiscoveryError
Expand All @@ -139,7 +139,7 @@ module DiasporaFederation
it "fails if the diaspora* ID was not found" do
stub_request(:get, "https://localhost:3000/.well-known/host-meta")
.to_return(status: 200, body: host_meta_xrd)
stub_request(:get, "http://localhost:3000/webfinger?q=acct:#{account}")
stub_request(:get, "http://localhost:3000/.well-known/webfinger.xml?resource=acct:#{account}")
.to_return(status: 404)

expect { Discovery::Discovery.new(account).fetch_and_save }.to raise_error Discovery::DiscoveryError
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/diaspora_federation/discovery/host_meta_spec.rb
Expand Up @@ -4,7 +4,7 @@ module DiasporaFederation
let(:xml) { <<-XML }
<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Link rel="lrdd" type="application/xrd+xml" template="#{base_url}webfinger?q={uri}"/>
<Link rel="lrdd" type="application/xrd+xml" template="#{base_url}.well-known/webfinger.xml?resource={uri}"/>
</XRD>
XML

Expand Down Expand Up @@ -36,7 +36,7 @@ module DiasporaFederation
context "parsing" do
it "parses its own output" do
hm = Discovery::HostMeta.from_xml(xml)
expect(hm.webfinger_template_url).to eq("#{base_url}webfinger?q={uri}")
expect(hm.webfinger_template_url).to eq("#{base_url}.well-known/webfinger.xml?resource={uri}")
end

it "also reads old-style XML" do
Expand Down
7 changes: 0 additions & 7 deletions spec/routing/webfinger_routing_spec.rb
Expand Up @@ -15,12 +15,5 @@ module DiasporaFederation
action: "webfinger"
)
end

it "routes GET legacy webfinger" do
expect(get: "/webfinger").to route_to(
controller: "diaspora_federation/webfinger",
action: "legacy_webfinger"
)
end
end
end

0 comments on commit 6e51ae5

Please sign in to comment.