refactor: rename diaspora_handle to diaspora_id
diaspora uses the new wording "diaspora ID" instead of "diaspora handle"
This commit is contained in:
parent
03c94bc344
commit
0deb74c103
21 changed files with 83 additions and 75 deletions
|
|
@ -43,8 +43,8 @@ DiasporaFederation.configure do |config|
|
||||||
config.server_uri = AppConfig.pod_uri
|
config.server_uri = AppConfig.pod_uri
|
||||||
|
|
||||||
config.define_callbacks do
|
config.define_callbacks do
|
||||||
on :person_webfinger_fetch do |handle|
|
on :person_webfinger_fetch do |diaspora_id|
|
||||||
person = Person.find_local_by_diaspora_handle(handle)
|
person = Person.find_local_by_diaspora_id(diaspora_id)
|
||||||
if person
|
if person
|
||||||
DiasporaFederation::Discovery::WebFinger.new(
|
DiasporaFederation::Discovery::WebFinger.new(
|
||||||
# ...
|
# ...
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,25 @@
|
||||||
module DiasporaFederation
|
module DiasporaFederation
|
||||||
module Discovery
|
module Discovery
|
||||||
# This class contains the logic to fetch all data for the given handle
|
# This class contains the logic to fetch all data for the given diaspora ID
|
||||||
class Discovery
|
class Discovery
|
||||||
include DiasporaFederation::Logging
|
include DiasporaFederation::Logging
|
||||||
|
|
||||||
# @return [String] the handle of the account
|
# @return [String] the diaspora ID of the account
|
||||||
attr_reader :handle
|
attr_reader :diaspora_id
|
||||||
|
|
||||||
# @param [String] account the diaspora handle to discover
|
# @param [String] diaspora_id the diaspora id to discover
|
||||||
def initialize(account)
|
def initialize(diaspora_id)
|
||||||
@handle = clean_handle(account)
|
@diaspora_id = clean_diaspora_id(diaspora_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
# fetch all metadata for the account
|
# fetch all metadata for the account
|
||||||
# @return [Person]
|
# @return [Person]
|
||||||
def fetch
|
def fetch
|
||||||
logger.info "Fetch data for #{handle}"
|
logger.info "Fetch data for #{diaspora_id}"
|
||||||
|
|
||||||
unless handle == clean_handle(webfinger.acct_uri)
|
unless diaspora_id == clean_diaspora_id(webfinger.acct_uri)
|
||||||
raise DiscoveryError, "Handle does not match: Wanted #{handle} but got #{clean_handle(webfinger.acct_uri)}"
|
raise DiscoveryError, "Diaspora ID does not match: Wanted #{diaspora_id} but got" \
|
||||||
|
" #{clean_diaspora_id(webfinger.acct_uri)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
person
|
person
|
||||||
|
|
@ -26,34 +27,34 @@ module DiasporaFederation
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def clean_handle(account)
|
def clean_diaspora_id(diaspora_id)
|
||||||
account.strip.sub("acct:", "").to_s.downcase
|
diaspora_id.strip.sub("acct:", "").to_s.downcase
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(url, http_fallback=false)
|
def get(url, http_fallback=false)
|
||||||
logger.info "Fetching #{url} for #{handle}"
|
logger.info "Fetching #{url} for #{diaspora_id}"
|
||||||
response = Fetcher.get(url)
|
response = Fetcher.get(url)
|
||||||
raise "Failed to fetch #{url}: #{response.status}" unless response.success?
|
raise "Failed to fetch #{url}: #{response.status}" unless response.success?
|
||||||
response.body
|
response.body
|
||||||
rescue => e
|
rescue => e
|
||||||
if http_fallback && url.start_with?("https://")
|
if http_fallback && url.start_with?("https://")
|
||||||
logger.warn "Retry with http: #{url} for #{handle}: #{e.class}: #{e.message}"
|
logger.warn "Retry with http: #{url} for #{diaspora_id}: #{e.class}: #{e.message}"
|
||||||
url.sub!("https://", "http://")
|
url.sub!("https://", "http://")
|
||||||
retry
|
retry
|
||||||
else
|
else
|
||||||
raise DiscoveryError, "Failed to fetch #{url} for #{handle}: #{e.class}: #{e.message}"
|
raise DiscoveryError, "Failed to fetch #{url} for #{diaspora_id}: #{e.class}: #{e.message}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def host_meta_url
|
def host_meta_url
|
||||||
domain = handle.split("@")[1]
|
domain = diaspora_id.split("@")[1]
|
||||||
"https://#{domain}/.well-known/host-meta"
|
"https://#{domain}/.well-known/host-meta"
|
||||||
end
|
end
|
||||||
|
|
||||||
def legacy_webfinger_url_from_host_meta
|
def legacy_webfinger_url_from_host_meta
|
||||||
# this tries the xrd url with https first, then falls back to http
|
# this tries the xrd url with https first, then falls back to http
|
||||||
host_meta = HostMeta.from_xml get(host_meta_url, true)
|
host_meta = HostMeta.from_xml get(host_meta_url, true)
|
||||||
host_meta.webfinger_template_url.gsub("{uri}", "acct:#{handle}")
|
host_meta.webfinger_template_url.gsub("{uri}", "acct:#{diaspora_id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def webfinger
|
def webfinger
|
||||||
|
|
@ -66,17 +67,17 @@ module DiasporaFederation
|
||||||
|
|
||||||
def person
|
def person
|
||||||
Entities::Person.new(
|
Entities::Person.new(
|
||||||
guid: hcard.guid || webfinger.guid,
|
guid: hcard.guid || webfinger.guid,
|
||||||
diaspora_handle: handle,
|
diaspora_id: diaspora_id,
|
||||||
url: webfinger.seed_url,
|
url: webfinger.seed_url,
|
||||||
exported_key: hcard.public_key || webfinger.public_key,
|
exported_key: hcard.public_key || webfinger.public_key,
|
||||||
profile: profile
|
profile: profile
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def profile
|
def profile
|
||||||
Entities::Profile.new(
|
Entities::Profile.new(
|
||||||
diaspora_handle: handle,
|
diaspora_id: diaspora_id,
|
||||||
first_name: hcard.first_name,
|
first_name: hcard.first_name,
|
||||||
last_name: hcard.last_name,
|
last_name: hcard.last_name,
|
||||||
image_url: hcard.photo_large_url,
|
image_url: hcard.photo_large_url,
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ module DiasporaFederation
|
||||||
property :guid
|
property :guid
|
||||||
|
|
||||||
# @!attribute [r] nickname
|
# @!attribute [r] nickname
|
||||||
# the first part of the diaspora handle
|
# the first part of the diaspora ID
|
||||||
# @return [String] nickname
|
# @return [String] nickname
|
||||||
property :nickname
|
property :nickname
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,11 @@ module DiasporaFederation
|
||||||
# @return [String] guid
|
# @return [String] guid
|
||||||
property :guid
|
property :guid
|
||||||
|
|
||||||
# @!attribute [r] diaspora_handle
|
# @!attribute [r] diaspora_id
|
||||||
# The diaspora handle of the person
|
# @todo refactoring with properties_dsl, xml name should be diaspora_handle
|
||||||
# @return [String] diaspora handle
|
# The diaspora ID of the person
|
||||||
property :diaspora_handle
|
# @return [String] diaspora ID
|
||||||
|
property :diaspora_id
|
||||||
|
|
||||||
# @!attribute [r] url
|
# @!attribute [r] url
|
||||||
# @see WebFinger#seed_url
|
# @see WebFinger#seed_url
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,12 @@ module DiasporaFederation
|
||||||
module Entities
|
module Entities
|
||||||
# this entity contains all the profile data of a person
|
# this entity contains all the profile data of a person
|
||||||
class Profile < Entity
|
class Profile < Entity
|
||||||
# @!attribute [r] diaspora_handle
|
# @!attribute [r] diaspora_id
|
||||||
# The diaspora handle of the person
|
# @todo refactoring with properties_dsl, xml name should be diaspora_handle
|
||||||
# @see Person#diaspora_handle
|
# The diaspora ID of the person
|
||||||
# @return [String] diaspora handle
|
# @see Person#diaspora_id
|
||||||
property :diaspora_handle
|
# @return [String] diaspora ID
|
||||||
|
property :diaspora_id
|
||||||
|
|
||||||
# @!attribute [r] first_name
|
# @!attribute [r] first_name
|
||||||
# @deprecated
|
# @deprecated
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
|
|
||||||
rule :diaspora_handle, :diaspora_id
|
rule :diaspora_id, :diaspora_id
|
||||||
|
|
||||||
rule :url, :URI
|
rule :url, :URI
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ module DiasporaFederation
|
||||||
class ProfileValidator < Validation::Validator
|
class ProfileValidator < Validation::Validator
|
||||||
include Validation
|
include Validation
|
||||||
|
|
||||||
rule :diaspora_handle, :diaspora_id
|
rule :diaspora_id, :diaspora_id
|
||||||
|
|
||||||
# the name must not contain a semicolon because of mentions
|
# the name must not contain a semicolon because of mentions
|
||||||
# @{<name> ; <handle>}
|
# @{<full_name> ; <diaspora_id>}
|
||||||
rule :first_name, regular_expression: {regex: /\A[^;]{,32}\z/}
|
rule :first_name, regular_expression: {regex: /\A[^;]{,32}\z/}
|
||||||
rule :last_name, regular_expression: {regex: /\A[^;]{,32}\z/}
|
rule :last_name, regular_expression: {regex: /\A[^;]{,32}\z/}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ module Validation
|
||||||
# This rule is based on https://github.com/zombor/Validator/blob/master/lib/validation/rule/email.rb
|
# This rule is based on https://github.com/zombor/Validator/blob/master/lib/validation/rule/email.rb
|
||||||
# which was adapted from https://github.com/emmanuel/aequitas/blob/master/lib/aequitas/rule/format/email_address.rb
|
# which was adapted from https://github.com/emmanuel/aequitas/blob/master/lib/aequitas/rule/format/email_address.rb
|
||||||
class DiasporaId
|
class DiasporaId
|
||||||
DIASPORA_HANDLE = begin
|
DIASPORA_ID = begin
|
||||||
letter = "a-zA-Z"
|
letter = "a-zA-Z"
|
||||||
digit = "0-9"
|
digit = "0-9"
|
||||||
username = "[#{letter}#{digit}\-\_\.]+"
|
username = "[#{letter}#{digit}\-\_\.]+"
|
||||||
|
|
@ -31,7 +31,7 @@ module Validation
|
||||||
|
|
||||||
# Determines if value is a valid email
|
# Determines if value is a valid email
|
||||||
def valid_value?(value)
|
def valid_value?(value)
|
||||||
!DIASPORA_HANDLE.match(value).nil?
|
!DIASPORA_ID.match(value).nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
# This rule has no params
|
# This rule has no params
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ module DiasporaFederation
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it "contains the diaspora handle" do
|
it "contains the diaspora id" do
|
||||||
get :legacy_webfinger, "q" => "acct:alice@localhost:3000"
|
get :legacy_webfinger, "q" => "acct:alice@localhost:3000"
|
||||||
expect(response.body).to include "<Subject>acct:alice@localhost:3000</Subject>"
|
expect(response.body).to include "<Subject>acct:alice@localhost:3000</Subject>"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ def r_str
|
||||||
end
|
end
|
||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
sequence(:diaspora_handle) {|n| "person-#{n}-#{r_str}@localhost:3000" }
|
sequence(:diaspora_id) {|n| "person-#{n}-#{r_str}@localhost:3000" }
|
||||||
sequence(:public_key) { OpenSSL::PKey::RSA.generate(1024).public_key.export }
|
sequence(:public_key) { OpenSSL::PKey::RSA.generate(1024).public_key.export }
|
||||||
|
|
||||||
factory :person do
|
factory :person do
|
||||||
diaspora_handle
|
diaspora_id
|
||||||
url "http://localhost:3000/"
|
url "http://localhost:3000/"
|
||||||
serialized_public_key { generate(:public_key) }
|
serialized_public_key { generate(:public_key) }
|
||||||
after(:create) do |u|
|
after(:create) do |u|
|
||||||
|
|
@ -19,17 +19,17 @@ FactoryGirl.define do
|
||||||
|
|
||||||
factory :person_entity, class: DiasporaFederation::Entities::Person do
|
factory :person_entity, class: DiasporaFederation::Entities::Person do
|
||||||
guid UUID.generate :compact
|
guid UUID.generate :compact
|
||||||
diaspora_handle
|
diaspora_id
|
||||||
url "http://localhost:3000/"
|
url "http://localhost:3000/"
|
||||||
exported_key { generate(:public_key) }
|
exported_key { generate(:public_key) }
|
||||||
profile {
|
profile {
|
||||||
DiasporaFederation::Entities::Profile.new(
|
DiasporaFederation::Entities::Profile.new(
|
||||||
FactoryGirl.attributes_for(:profile_entity, diaspora_handle: diaspora_handle))
|
FactoryGirl.attributes_for(:profile_entity, diaspora_id: diaspora_id))
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :profile_entity, class: DiasporaFederation::Entities::Profile do
|
factory :profile_entity, class: DiasporaFederation::Entities::Profile do
|
||||||
diaspora_handle
|
diaspora_id
|
||||||
first_name "my_name"
|
first_name "my_name"
|
||||||
last_name nil
|
last_name nil
|
||||||
tag_string "#i #love #tags"
|
tag_string "#i #love #tags"
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,18 @@ module DiasporaFederation
|
||||||
let(:host_meta_xrd) { FixtureGeneration.load_fixture("host-meta") }
|
let(:host_meta_xrd) { FixtureGeneration.load_fixture("host-meta") }
|
||||||
let(:webfinger_xrd) { FixtureGeneration.load_fixture("legacy-webfinger") }
|
let(:webfinger_xrd) { FixtureGeneration.load_fixture("legacy-webfinger") }
|
||||||
let(:hcard_html) { FixtureGeneration.load_fixture("hcard") }
|
let(:hcard_html) { FixtureGeneration.load_fixture("hcard") }
|
||||||
let(:account) { alice.diaspora_handle }
|
let(:account) { alice.diaspora_id }
|
||||||
let(:default_image) { "http://localhost:3000/assets/user/default.png" }
|
let(:default_image) { "http://localhost:3000/assets/user/default.png" }
|
||||||
|
|
||||||
describe "#intialize" do
|
describe "#intialize" do
|
||||||
it "sets handle" do
|
it "sets diaspora id" do
|
||||||
discovery = Discovery::Discovery.new("some_user@example.com")
|
discovery = Discovery::Discovery.new("some_user@example.com")
|
||||||
expect(discovery.handle).to eq("some_user@example.com")
|
expect(discovery.diaspora_id).to eq("some_user@example.com")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "downcases account and strips whitespace, and sub 'acct:'" do
|
it "downcases account and strips whitespace, and sub 'acct:'" do
|
||||||
discovery = Discovery::Discovery.new("acct:BIGBOY@Example.Com ")
|
discovery = Discovery::Discovery.new("acct:BIGBOY@Example.Com ")
|
||||||
expect(discovery.handle).to eq("bigboy@example.com")
|
expect(discovery.diaspora_id).to eq("bigboy@example.com")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -30,13 +30,13 @@ module DiasporaFederation
|
||||||
person = Discovery::Discovery.new(account).fetch
|
person = Discovery::Discovery.new(account).fetch
|
||||||
|
|
||||||
expect(person.guid).to eq(alice.guid)
|
expect(person.guid).to eq(alice.guid)
|
||||||
expect(person.diaspora_handle).to eq(account)
|
expect(person.diaspora_id).to eq(account)
|
||||||
expect(person.url).to eq(alice.url)
|
expect(person.url).to eq(alice.url)
|
||||||
expect(person.exported_key).to eq(alice.serialized_public_key)
|
expect(person.exported_key).to eq(alice.serialized_public_key)
|
||||||
|
|
||||||
profile = person.profile
|
profile = person.profile
|
||||||
|
|
||||||
expect(profile.diaspora_handle).to eq(alice.diaspora_handle)
|
expect(profile.diaspora_id).to eq(alice.diaspora_id)
|
||||||
expect(profile.first_name).to eq("Dummy")
|
expect(profile.first_name).to eq("Dummy")
|
||||||
expect(profile.last_name).to eq("User")
|
expect(profile.last_name).to eq("User")
|
||||||
|
|
||||||
|
|
@ -58,7 +58,7 @@ module DiasporaFederation
|
||||||
person = Discovery::Discovery.new(account).fetch
|
person = Discovery::Discovery.new(account).fetch
|
||||||
|
|
||||||
expect(person.guid).to eq(alice.guid)
|
expect(person.guid).to eq(alice.guid)
|
||||||
expect(person.diaspora_handle).to eq(account)
|
expect(person.diaspora_id).to eq(account)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "falls back to http if https fails with ssl error" do
|
it "falls back to http if https fails with ssl error" do
|
||||||
|
|
@ -74,10 +74,10 @@ module DiasporaFederation
|
||||||
person = Discovery::Discovery.new(account).fetch
|
person = Discovery::Discovery.new(account).fetch
|
||||||
|
|
||||||
expect(person.guid).to eq(alice.guid)
|
expect(person.guid).to eq(alice.guid)
|
||||||
expect(person.diaspora_handle).to eq(account)
|
expect(person.diaspora_id).to eq(account)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if the handle does not match" do
|
it "fails if the diaspora id does not match" do
|
||||||
modified_webfinger = webfinger_xrd.gsub(account, "anonther_user@example.com")
|
modified_webfinger = webfinger_xrd.gsub(account, "anonther_user@example.com")
|
||||||
|
|
||||||
stub_request(:get, "https://localhost:3000/.well-known/host-meta")
|
stub_request(:get, "https://localhost:3000/.well-known/host-meta")
|
||||||
|
|
@ -88,7 +88,7 @@ module DiasporaFederation
|
||||||
expect { Discovery::Discovery.new(account).fetch }.to raise_error Discovery::DiscoveryError
|
expect { Discovery::Discovery.new(account).fetch }.to raise_error Discovery::DiscoveryError
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if the handle was not found" do
|
it "fails if the diaspora id was not found" do
|
||||||
stub_request(:get, "https://localhost:3000/.well-known/host-meta")
|
stub_request(:get, "https://localhost:3000/.well-known/host-meta")
|
||||||
.to_return(status: 200, body: host_meta_xrd)
|
.to_return(status: 200, body: host_meta_xrd)
|
||||||
stub_request(:get, "http://localhost:3000/webfinger?q=acct:#{account}")
|
stub_request(:get, "http://localhost:3000/webfinger?q=acct:#{account}")
|
||||||
|
|
@ -173,13 +173,13 @@ module DiasporaFederation
|
||||||
person = Discovery::Discovery.new(account).fetch
|
person = Discovery::Discovery.new(account).fetch
|
||||||
|
|
||||||
expect(person.guid).to eq(alice.guid)
|
expect(person.guid).to eq(alice.guid)
|
||||||
expect(person.diaspora_handle).to eq(account)
|
expect(person.diaspora_id).to eq(account)
|
||||||
expect(person.url).to eq(alice.url)
|
expect(person.url).to eq(alice.url)
|
||||||
expect(person.exported_key).to eq(alice.serialized_public_key)
|
expect(person.exported_key).to eq(alice.serialized_public_key)
|
||||||
|
|
||||||
profile = person.profile
|
profile = person.profile
|
||||||
|
|
||||||
expect(profile.diaspora_handle).to eq(alice.diaspora_handle)
|
expect(profile.diaspora_id).to eq(alice.diaspora_id)
|
||||||
expect(profile.first_name).to be_nil
|
expect(profile.first_name).to be_nil
|
||||||
expect(profile.last_name).to be_nil
|
expect(profile.last_name).to be_nil
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
module DiasporaFederation
|
module DiasporaFederation
|
||||||
describe Discovery::WebFinger do
|
describe Discovery::WebFinger do
|
||||||
let(:person) { FactoryGirl.create(:person) }
|
let(:person) { FactoryGirl.create(:person) }
|
||||||
let(:acct) { "acct:#{person.diaspora_handle}" }
|
let(:acct) { "acct:#{person.diaspora_id}" }
|
||||||
let(:public_key_base64) { Base64.strict_encode64(person.serialized_public_key) }
|
let(:public_key_base64) { Base64.strict_encode64(person.serialized_public_key) }
|
||||||
|
|
||||||
let(:xml) {
|
let(:xml) {
|
||||||
|
|
@ -28,7 +28,7 @@ XML
|
||||||
context "generation" do
|
context "generation" do
|
||||||
it "creates a nice XML document" do
|
it "creates a nice XML document" do
|
||||||
wf = Discovery::WebFinger.new(
|
wf = Discovery::WebFinger.new(
|
||||||
acct_uri: "acct:#{person.diaspora_handle}",
|
acct_uri: "acct:#{person.diaspora_id}",
|
||||||
alias_url: person.alias_url,
|
alias_url: person.alias_url,
|
||||||
hcard_url: person.hcard_url,
|
hcard_url: person.hcard_url,
|
||||||
seed_url: person.url,
|
seed_url: person.url,
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ module DiasporaFederation
|
||||||
expect(validator.errors).to be_empty
|
expect(validator.errors).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like "a diaspora_handle validator" do
|
it_behaves_like "a diaspora_id validator" do
|
||||||
let(:entity) { :person_entity }
|
let(:entity) { :person_entity }
|
||||||
let(:validator_class) { Validators::PersonValidator }
|
let(:validator_class) { Validators::PersonValidator }
|
||||||
let(:property) { :diaspora_handle }
|
let(:property) { :diaspora_id }
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like "a guid validator" do
|
it_behaves_like "a guid validator" do
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ module DiasporaFederation
|
||||||
expect(validator.errors).to be_empty
|
expect(validator.errors).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like "a diaspora_handle validator" do
|
it_behaves_like "a diaspora_id validator" do
|
||||||
let(:entity) { :profile_entity }
|
let(:entity) { :profile_entity }
|
||||||
let(:validator_class) { Validators::ProfileValidator }
|
let(:validator_class) { Validators::ProfileValidator }
|
||||||
let(:property) { :diaspora_handle }
|
let(:property) { :diaspora_id }
|
||||||
end
|
end
|
||||||
|
|
||||||
%i(first_name last_name).each do |prop|
|
%i(first_name last_name).each do |prop|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ require "entities"
|
||||||
# some helper methods
|
# some helper methods
|
||||||
|
|
||||||
def alice
|
def alice
|
||||||
@alice ||= Person.find_by(diaspora_handle: "alice@localhost:3000")
|
@alice ||= Person.find_by(diaspora_id: "alice@localhost:3000")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Requires supporting files with custom matchers and macros, etc,
|
# Requires supporting files with custom matchers and macros, etc,
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,6 @@ FixtureBuilder.configure do |fbuilder|
|
||||||
|
|
||||||
# now declare objects
|
# now declare objects
|
||||||
fbuilder.factory do
|
fbuilder.factory do
|
||||||
FactoryGirl.create(:person, diaspora_handle: "alice@localhost:3000")
|
FactoryGirl.create(:person, diaspora_id: "alice@localhost:3000")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ def entity_stub(entity, property, val=nil)
|
||||||
instance
|
instance
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples "a diaspora_handle validator" do
|
shared_examples "a diaspora_id validator" do
|
||||||
it "validates a well-formed diaspora_handle" do
|
it "validates a well-formed diaspora_id" do
|
||||||
validator = validator_class.new(entity_stub(entity, property))
|
validator = validator_class.new(entity_stub(entity, property))
|
||||||
|
|
||||||
expect(validator).to be_valid
|
expect(validator).to be_valid
|
||||||
|
|
@ -19,8 +19,8 @@ shared_examples "a diaspora_handle validator" do
|
||||||
expect(validator.errors).to include(property)
|
expect(validator.errors).to include(property)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "must resemble an email address" do
|
it "must be a valid diaspora id" do
|
||||||
validator = validator_class.new(entity_stub(entity, property, "i am a weird handle @@@ ### 12345"))
|
validator = validator_class.new(entity_stub(entity, property, "i am a weird diaspora id @@@ ### 12345"))
|
||||||
|
|
||||||
expect(validator).not_to be_valid
|
expect(validator).not_to be_valid
|
||||||
expect(validator.errors).to include(property)
|
expect(validator.errors).to include(property)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ class Person < ActiveRecord::Base
|
||||||
def atom_url; "#{url}public/#{nickname}.atom" end
|
def atom_url; "#{url}public/#{nickname}.atom" end
|
||||||
def salmon_url; "#{url}receive/users/#{guid}" end
|
def salmon_url; "#{url}receive/users/#{guid}" end
|
||||||
|
|
||||||
def nickname; diaspora_handle.split("@")[0] end
|
def nickname; diaspora_id.split("@")[0] end
|
||||||
|
|
||||||
def photo_default_url; "#{url}assets/user/default.png" end
|
def photo_default_url; "#{url}assets/user/default.png" end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@ DiasporaFederation.configure do |config|
|
||||||
config.certificate_authorities = ca_file
|
config.certificate_authorities = ca_file
|
||||||
|
|
||||||
config.define_callbacks do
|
config.define_callbacks do
|
||||||
on :person_webfinger_fetch do |handle|
|
on :person_webfinger_fetch do |diaspora_id|
|
||||||
person = Person.find_by(diaspora_handle: handle)
|
person = Person.find_by(diaspora_id: diaspora_id)
|
||||||
if person
|
if person
|
||||||
DiasporaFederation::Discovery::WebFinger.new(
|
DiasporaFederation::Discovery::WebFinger.new(
|
||||||
acct_uri: "acct:#{person.diaspora_handle}",
|
acct_uri: "acct:#{person.diaspora_id}",
|
||||||
alias_url: person.alias_url,
|
alias_url: person.alias_url,
|
||||||
hcard_url: person.hcard_url,
|
hcard_url: person.hcard_url,
|
||||||
seed_url: person.url,
|
seed_url: person.url,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
class RenameDiasporaHandleToDiasporaId < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
rename_column :people, :diaspora_handle, :diaspora_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -11,12 +11,12 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150614014411) do
|
ActiveRecord::Schema.define(version: 20150722224751) do
|
||||||
|
|
||||||
create_table "people", force: :cascade do |t|
|
create_table "people", force: :cascade do |t|
|
||||||
t.string "guid", null: false
|
t.string "guid", null: false
|
||||||
t.text "url", null: false
|
t.text "url", null: false
|
||||||
t.string "diaspora_handle", null: false
|
t.string "diaspora_id", null: false
|
||||||
t.text "serialized_public_key", null: false
|
t.text "serialized_public_key", null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue