summaryrefslogtreecommitdiff
path: root/users
diff options
context:
space:
mode:
Diffstat (limited to 'users')
-rw-r--r--users/app/views/webfinger/host_meta.xml.erb10
-rw-r--r--users/lib/webfinger/host_meta_presenter.rb22
-rw-r--r--users/test/unit/webfinger/.user_presenter_test.rb.swpbin12288 -> 0 bytes
-rw-r--r--users/test/unit/webfinger/host_meta_presenter_test.rb24
4 files changed, 42 insertions, 14 deletions
diff --git a/users/app/views/webfinger/host_meta.xml.erb b/users/app/views/webfinger/host_meta.xml.erb
index 37c9d1e..cfcbcc0 100644
--- a/users/app/views/webfinger/host_meta.xml.erb
+++ b/users/app/views/webfinger/host_meta.xml.erb
@@ -3,9 +3,9 @@
<Subject><%= @host_meta.subject %></Subject>
-
- <Link rel='lrdd'
- type='application/xrd+xml'
- template='<%= @host_meta.webfinger_template %>' />
-
+ <%- @host_meta.links.each do |rel, link| %>
+ <Link rel='<%= rel %>'
+ type='<%= link[:type] %>'
+ template='<%= link[:template] %>' />
+ <%- end %>
</XRD>
diff --git a/users/lib/webfinger/host_meta_presenter.rb b/users/lib/webfinger/host_meta_presenter.rb
index 6a6235f..84ab7a9 100644
--- a/users/lib/webfinger/host_meta_presenter.rb
+++ b/users/lib/webfinger/host_meta_presenter.rb
@@ -5,22 +5,26 @@ class Webfinger::HostMetaPresenter
@request = request
end
+ def to_json(options = {})
+ {
+ subject: subject,
+ links: links
+ }.to_json(options)
+ end
+
def subject
url = URI.parse(@request.url)
url.path = ''
url.to_s
end
- def webfinger_template(path = 'webfinger', query_param='q')
- "#{subject}/#{path}?#{query_param}={uri}"
+ def links
+ { lrdd: { type: 'application/xrd+xml', template: webfinger_template } }
end
- def to_json(options = {})
- {
- subject: subject,
- links: {
- lrdd: { type: 'application/xrd+xml', template: webfinger_template }
- }
- }.to_json(options)
+ protected
+
+ def webfinger_template(path = 'webfinger', query_param='q')
+ "#{subject}/#{path}?#{query_param}={uri}"
end
end
diff --git a/users/test/unit/webfinger/.user_presenter_test.rb.swp b/users/test/unit/webfinger/.user_presenter_test.rb.swp
deleted file mode 100644
index 5b92867..0000000
--- a/users/test/unit/webfinger/.user_presenter_test.rb.swp
+++ /dev/null
Binary files differ
diff --git a/users/test/unit/webfinger/host_meta_presenter_test.rb b/users/test/unit/webfinger/host_meta_presenter_test.rb
new file mode 100644
index 0000000..af86404
--- /dev/null
+++ b/users/test/unit/webfinger/host_meta_presenter_test.rb
@@ -0,0 +1,24 @@
+require 'test_helper'
+require 'webfinger'
+require 'json'
+
+class Webfinger::HostMetaPresenterTest < ActiveSupport::TestCase
+
+ setup do
+ @request = stub(
+ url: "https://#{APP_CONFIG[:domain]}/.well-known/host-meta"
+ )
+ @meta = Webfinger::HostMetaPresenter.new(@request)
+ end
+
+ test "creates proper json" do
+ hash = JSON.parse @meta.to_json
+ assert_equal ["subject", "links"].sort, hash.keys.sort
+ hash.each do |key, value|
+ assert_equal @meta.send(key.to_sym).to_json, value.to_json
+ end
+ end
+
+end
+
+