add basic webfinger stuf (WIP)
and: - add configure method to set some configs - write rdoc
This commit is contained in:
parent
069f114eb7
commit
f0591a745b
16 changed files with 205 additions and 1 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,5 +1,4 @@
|
|||
.bundle/
|
||||
log/*.log
|
||||
pkg/
|
||||
|
||||
# IDE files
|
||||
|
|
@ -8,6 +7,9 @@ pkg/
|
|||
# coverage reports
|
||||
coverage
|
||||
|
||||
# documentation
|
||||
rdoc
|
||||
|
||||
# Temporary files
|
||||
.DS_Store
|
||||
*.swp
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ AllCops:
|
|||
Exclude:
|
||||
- "bin/**/*"
|
||||
- "test/dummy/bin/**/*"
|
||||
- "test/dummy/db/**/*"
|
||||
|
||||
# Commonly used screens these days easily fit more than 80 characters.
|
||||
Metrics/LineLength:
|
||||
|
|
|
|||
20
app/controllers/diaspora_federation/webfinger_controller.rb
Normal file
20
app/controllers/diaspora_federation/webfinger_controller.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
require_dependency "diaspora_federation/application_controller"
|
||||
|
||||
module DiasporaFederation
|
||||
class WebfingerController < ApplicationController
|
||||
def host_meta
|
||||
render "host_meta", content_type: "application/xrd+xml"
|
||||
end
|
||||
|
||||
##
|
||||
# this is the pre RFC 7033 webfinger
|
||||
def legacy_webfinger
|
||||
@person = Person.find_local_by_diaspora_handle(params[:q].strip.downcase.gsub("acct:", "")) if params[:q]
|
||||
|
||||
return render nothing: true, status: 404 if @person.nil?
|
||||
|
||||
logger.info "webfinger profile request for: #{@person.diaspora_handle}"
|
||||
render "webfinger", content_type: "application/xrd+xml"
|
||||
end
|
||||
end
|
||||
end
|
||||
10
app/views/diaspora_federation/webfinger/host_meta.erb
Normal file
10
app/views/diaspora_federation/webfinger/host_meta.erb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
|
||||
<!-- Resource-specific Information -->
|
||||
|
||||
<Link rel="lrdd"
|
||||
type="application/xrd+xml"
|
||||
template="<%= DiasporaFederation.server_uri.to_s %>webfinger?q={uri}" />
|
||||
|
||||
</XRD>
|
||||
14
app/views/diaspora_federation/webfinger/webfinger.erb
Normal file
14
app/views/diaspora_federation/webfinger/webfinger.erb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
<Subject>acct:<%=@person.diaspora_handle%></Subject>
|
||||
<Alias>"<%= @person.url %>"</Alias>
|
||||
<Link rel="http://microformats.org/profile/hcard" type="text/html" href="<%=@person.hcard_url%>"/>
|
||||
<Link rel="http://joindiaspora.com/seed_location" type="text/html" href="<%=@person.url%>"/>
|
||||
<Link rel="http://joindiaspora.com/guid" type="text/html" href="<%=@person.guid%>"/>
|
||||
|
||||
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="<%=@person.profile_url%>"/>
|
||||
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="<%=@person.atom_url%>"/>
|
||||
<Link rel="salmon" href="<%=@person.salmon_url%>"/>
|
||||
|
||||
<Link rel="diaspora-public-key" type="RSA" href="<%=Base64.strict_encode64(@person.serialized_public_key)%>"/>
|
||||
</XRD>
|
||||
|
|
@ -3,4 +3,9 @@ DiasporaFederation::Engine.routes.draw do
|
|||
post "receive/public" => :public, :as => "receive_public"
|
||||
post "receive/users/:guid" => :private, :as => "receive_private"
|
||||
end
|
||||
|
||||
controller :webfinger do
|
||||
get ".well-known/host-meta" => :host_meta, :as => "host_meta"
|
||||
get "webfinger" => :legacy_webfinger, :as => "legacy_webfinger"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,36 @@
|
|||
require "diaspora_federation/engine"
|
||||
|
||||
##
|
||||
# diaspora* federation rails engine
|
||||
module DiasporaFederation
|
||||
class << self
|
||||
##
|
||||
# the pod url
|
||||
#
|
||||
# Example:
|
||||
# config.server_uri = URI("http://localhost:3000/")
|
||||
# or
|
||||
# config.server_uri = AppConfig.pod_uri
|
||||
attr_accessor :server_uri
|
||||
|
||||
##
|
||||
# the class to use as person.
|
||||
#
|
||||
# Example:
|
||||
# config.person_class = Person.class.to_s
|
||||
attr_accessor :person_class
|
||||
def person_class
|
||||
const_get(@person_class)
|
||||
end
|
||||
|
||||
##
|
||||
# configure the federation engine
|
||||
#
|
||||
# DiasporaFederation.configure do |config|
|
||||
# config.server_uri = "http://localhost:3000/"
|
||||
# end
|
||||
def configure
|
||||
yield self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
module DiasporaFederation
|
||||
##
|
||||
# diaspora* federation rails engine
|
||||
class Engine < ::Rails::Engine
|
||||
isolate_namespace DiasporaFederation
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
module DiasporaFederation
|
||||
##
|
||||
# the gem version
|
||||
VERSION = "0.0.1"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
module DiasporaFederation
|
||||
describe WebfingerController, type: :controller do
|
||||
routes { DiasporaFederation::Engine.routes }
|
||||
|
||||
describe "#host_meta" do
|
||||
it "succeeds" do
|
||||
get :host_meta
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it "contains the webfinger-template" do
|
||||
DiasporaFederation.server_uri = "http://localhost:3000/"
|
||||
get :host_meta
|
||||
expect(response.body).to include "template=\"http://localhost:3000/webfinger?q={uri}\""
|
||||
end
|
||||
|
||||
it "renders the host_meta template" do
|
||||
get :host_meta
|
||||
expect(response).to render_template("host_meta")
|
||||
expect(response.header["Content-Type"]).to include "application/xrd+xml"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#legacy_webfinger" do
|
||||
it "succeeds when the person exists" do
|
||||
skip
|
||||
post :legacy_webfinger, "q" => "bob@diaspora.pod"
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it "succeeds with 'acct:' in the query when the person exists" do
|
||||
skip
|
||||
post :legacy_webfinger, "q" => "acct:bob@diaspora.pod"
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it "404s when the person does not exist" do
|
||||
post :legacy_webfinger, "q" => "me@mydiaspora.pod.com"
|
||||
expect(response).to be_not_found
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -14,6 +14,8 @@ CodeClimate::TestReporter.start
|
|||
RSpec.configure do |config|
|
||||
config.infer_spec_type_from_file_location!
|
||||
|
||||
config.render_views
|
||||
|
||||
config.expect_with :rspec do |expect_config|
|
||||
expect_config.syntax = :expect
|
||||
end
|
||||
|
|
|
|||
26
test/dummy/app/models/person.rb
Normal file
26
test/dummy/app/models/person.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
class Person < ActiveRecord::Base
|
||||
def salmon_url
|
||||
"#{url}receive/users/#{guid}"
|
||||
end
|
||||
|
||||
def atom_url
|
||||
"#{url}public/#{diaspora_handle.split('@')[0]}.atom"
|
||||
end
|
||||
|
||||
def profile_url
|
||||
"#{url}u/#{diaspora_handle.split('@')[0]}"
|
||||
end
|
||||
|
||||
def hcard_url
|
||||
"#{url}hcard/users/#{guid}"
|
||||
end
|
||||
|
||||
def self.find_by_diaspora_handle(identifier)
|
||||
find_by(diaspora_handle: identifier)
|
||||
end
|
||||
|
||||
def self.find_local_by_diaspora_handle(identifier)
|
||||
# no remote? check ... this class is only for testing
|
||||
find_by_diaspora_handle(identifier)
|
||||
end
|
||||
end
|
||||
8
test/dummy/config/initializers/diaspora_federation.rb
Normal file
8
test/dummy/config/initializers/diaspora_federation.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# configure the federation engine
|
||||
DiasporaFederation.configure do |config|
|
||||
# the pod url
|
||||
config.server_uri = URI("http://localhost:3000/")
|
||||
|
||||
# the class to be used for a person
|
||||
config.person_class = Person.class.to_s
|
||||
end
|
||||
12
test/dummy/db/migrate/20150614014411_create_people.rb
Normal file
12
test/dummy/db/migrate/20150614014411_create_people.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
class CreatePeople < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :people do |t|
|
||||
t.string "guid", null: false
|
||||
t.text "url", null: false
|
||||
t.string "diaspora_handle", null: false
|
||||
t.text "serialized_public_key", null: false
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
25
test/dummy/db/schema.rb
Normal file
25
test/dummy/db/schema.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# encoding: UTF-8
|
||||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# Note that this schema.rb definition is the authoritative source for your
|
||||
# database schema. If you need to create the application database on another
|
||||
# system, you should be using db:schema:load, not running all the migrations
|
||||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150614014411) do
|
||||
|
||||
create_table "people", force: :cascade do |t|
|
||||
t.string "guid", null: false
|
||||
t.text "url", null: false
|
||||
t.string "diaspora_handle", null: false
|
||||
t.text "serialized_public_key", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Reference in a new issue