rename target_type to parent_type in relayables
this is equivalent to parent_guid and parent_author_signature also added a validator for parent_type
This commit is contained in:
parent
8bd9c28ce0
commit
08ecfca5d3
18 changed files with 53 additions and 41 deletions
|
|
@ -23,8 +23,8 @@ module DiasporaFederation
|
||||||
property :diaspora_id, xml_name: :diaspora_handle
|
property :diaspora_id, xml_name: :diaspora_handle
|
||||||
|
|
||||||
# The {Comment} parent is a Post
|
# The {Comment} parent is a Post
|
||||||
# @return [String] target type
|
# @return [String] parent type
|
||||||
def target_type
|
def parent_type
|
||||||
"Post"
|
"Post"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,12 @@ module DiasporaFederation
|
||||||
# @return [String] like guid
|
# @return [String] like guid
|
||||||
property :guid
|
property :guid
|
||||||
|
|
||||||
# @!attribute [r] target_type
|
# @!attribute [r] parent_type
|
||||||
# A string describing the type of the target.
|
# A string describing the type of the parent.
|
||||||
# Can be "Post" or "Comment" (Comments are currently not implemented in the
|
# Can be "Post" or "Comment" (Comments are currently not implemented in the
|
||||||
# Diaspora Frontend).
|
# Diaspora Frontend).
|
||||||
# @return [String] target type
|
# @return [String] parent type
|
||||||
property :target_type
|
property :parent_type, xml_name: :target_type
|
||||||
|
|
||||||
include Relayable
|
include Relayable
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ module DiasporaFederation
|
||||||
property :conversation_guid
|
property :conversation_guid
|
||||||
|
|
||||||
# The {Message} parent is a {Conversation}
|
# The {Message} parent is a {Conversation}
|
||||||
# @return [String] target type
|
# @return [String] parent type
|
||||||
def target_type
|
def parent_type
|
||||||
"Conversation"
|
"Conversation"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@ module DiasporaFederation
|
||||||
# @return [String] participation guid
|
# @return [String] participation guid
|
||||||
property :guid
|
property :guid
|
||||||
|
|
||||||
# @!attribute [r] target_type
|
# @!attribute [r] parent_type
|
||||||
# a string describing a type of the target to subscribe on.
|
# a string describing a type of the target to subscribe on.
|
||||||
# currently only "Post" is supported.
|
# currently only "Post" is supported.
|
||||||
# @return [String] target type
|
# @return [String] parent type
|
||||||
property :target_type
|
property :parent_type, xml_name: :target_type
|
||||||
|
|
||||||
include Relayable
|
include Relayable
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ module DiasporaFederation
|
||||||
property :poll_answer_guid
|
property :poll_answer_guid
|
||||||
|
|
||||||
# The {PollParticipation} parent is a {Poll}
|
# The {PollParticipation} parent is a {Poll}
|
||||||
# @return [String] target type
|
# @return [String] parent type
|
||||||
def target_type
|
def parent_type
|
||||||
"Poll"
|
"Poll"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
if parent_author_signature.nil?
|
if parent_author_signature.nil?
|
||||||
privkey = DiasporaFederation.callbacks.trigger(
|
privkey = DiasporaFederation.callbacks.trigger(
|
||||||
:fetch_author_private_key_by_entity_guid, target_type, parent_guid
|
:fetch_author_private_key_by_entity_guid, parent_type, parent_guid
|
||||||
)
|
)
|
||||||
hash[:parent_author_signature] = Signing.sign_with_key(hash, privkey) unless privkey.nil?
|
hash[:parent_author_signature] = Signing.sign_with_key(hash, privkey) unless privkey.nil?
|
||||||
end
|
end
|
||||||
|
|
@ -79,7 +79,7 @@ module DiasporaFederation
|
||||||
data, author_signature, pubkey
|
data, author_signature, pubkey
|
||||||
)
|
)
|
||||||
|
|
||||||
author_is_local = DiasporaFederation.callbacks.trigger(:entity_author_is_local?, target_type, parent_guid)
|
author_is_local = DiasporaFederation.callbacks.trigger(:entity_author_is_local?, parent_type, parent_guid)
|
||||||
verify_parent_signature unless author_is_local
|
verify_parent_signature unless author_is_local
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -87,7 +87,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
# this happens only on downstream federation
|
# this happens only on downstream federation
|
||||||
def verify_parent_signature
|
def verify_parent_signature
|
||||||
pubkey = DiasporaFederation.callbacks.trigger(:fetch_author_public_key_by_entity_guid, target_type, parent_guid)
|
pubkey = DiasporaFederation.callbacks.trigger(:fetch_author_public_key_by_entity_guid, parent_type, parent_guid)
|
||||||
|
|
||||||
raise SignatureVerificationFailed, "failed to fetch public key for author of #{parent_guid}" if pubkey.nil?
|
raise SignatureVerificationFailed, "failed to fetch public key for author of #{parent_guid}" if pubkey.nil?
|
||||||
raise SignatureVerificationFailed, "wrong parent_author_signature" unless Signing.verify_signature(
|
raise SignatureVerificationFailed, "wrong parent_author_signature" unless Signing.verify_signature(
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ module DiasporaFederation
|
||||||
factory :participation_entity,
|
factory :participation_entity,
|
||||||
class: DiasporaFederation::Entities::Participation, parent: :relayable_entity do
|
class: DiasporaFederation::Entities::Participation, parent: :relayable_entity do
|
||||||
guid
|
guid
|
||||||
target_type "Post"
|
parent_type "Post"
|
||||||
diaspora_id
|
diaspora_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -118,7 +118,7 @@ module DiasporaFederation
|
||||||
factory :like_entity, class: DiasporaFederation::Entities::Like, parent: :relayable_entity do
|
factory :like_entity, class: DiasporaFederation::Entities::Like, parent: :relayable_entity do
|
||||||
positive true
|
positive true
|
||||||
guid
|
guid
|
||||||
target_type "Post"
|
parent_type "Post"
|
||||||
diaspora_id
|
diaspora_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ module DiasporaFederation
|
||||||
|
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
|
|
||||||
|
rule :parent_type, [:not_empty, regular_expression: {regex: /\A(Post|Comment)\z/}]
|
||||||
|
|
||||||
include RelayableValidator
|
include RelayableValidator
|
||||||
|
|
||||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
rule :guid, :guid
|
rule :guid, :guid
|
||||||
|
|
||||||
rule :target_type, :not_empty
|
rule :parent_type, [:not_empty, regular_expression: {regex: /\APost\z/}]
|
||||||
|
|
||||||
include RelayableValidator
|
include RelayableValidator
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@ XML
|
||||||
|
|
||||||
it_behaves_like "a relayable Entity"
|
it_behaves_like "a relayable Entity"
|
||||||
|
|
||||||
describe "#target_type" do
|
describe "#parent_type" do
|
||||||
it "returns \"Post\" as target type" do
|
it "returns \"Post\" as parent type" do
|
||||||
expect(described_class.new(data).target_type).to eq("Post")
|
expect(described_class.new(data).parent_type).to eq("Post")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ module DiasporaFederation
|
||||||
<like>
|
<like>
|
||||||
<positive>#{data[:positive]}</positive>
|
<positive>#{data[:positive]}</positive>
|
||||||
<guid>#{data[:guid]}</guid>
|
<guid>#{data[:guid]}</guid>
|
||||||
<target_type>#{data[:target_type]}</target_type>
|
<target_type>#{data[:parent_type]}</target_type>
|
||||||
<parent_guid>#{data[:parent_guid]}</parent_guid>
|
<parent_guid>#{data[:parent_guid]}</parent_guid>
|
||||||
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
||||||
<author_signature>#{data[:author_signature]}</author_signature>
|
<author_signature>#{data[:author_signature]}</author_signature>
|
||||||
|
|
@ -22,9 +22,9 @@ XML
|
||||||
|
|
||||||
it_behaves_like "a relayable Entity"
|
it_behaves_like "a relayable Entity"
|
||||||
|
|
||||||
describe "#target_type" do
|
describe "#parent_type" do
|
||||||
it "returns data[:target_type] as target type" do
|
it "returns data[:parent_type] as parent type" do
|
||||||
expect(described_class.new(data).target_type).to eq(data[:target_type])
|
expect(described_class.new(data).parent_type).to eq(data[:parent_type])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,9 @@ XML
|
||||||
|
|
||||||
it_behaves_like "a relayable Entity"
|
it_behaves_like "a relayable Entity"
|
||||||
|
|
||||||
describe "#target_type" do
|
describe "#parent_type" do
|
||||||
it "returns \"Conversation\" as target type" do
|
it "returns \"Conversation\" as parent type" do
|
||||||
expect(described_class.new(data).target_type).to eq("Conversation")
|
expect(described_class.new(data).parent_type).to eq("Conversation")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ module DiasporaFederation
|
||||||
<<-XML
|
<<-XML
|
||||||
<participation>
|
<participation>
|
||||||
<guid>#{data[:guid]}</guid>
|
<guid>#{data[:guid]}</guid>
|
||||||
<target_type>#{data[:target_type]}</target_type>
|
<target_type>#{data[:parent_type]}</target_type>
|
||||||
<parent_guid>#{data[:parent_guid]}</parent_guid>
|
<parent_guid>#{data[:parent_guid]}</parent_guid>
|
||||||
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
<parent_author_signature>#{data[:parent_author_signature]}</parent_author_signature>
|
||||||
<author_signature>#{data[:author_signature]}</author_signature>
|
<author_signature>#{data[:author_signature]}</author_signature>
|
||||||
|
|
@ -21,9 +21,9 @@ XML
|
||||||
|
|
||||||
it_behaves_like "a relayable Entity"
|
it_behaves_like "a relayable Entity"
|
||||||
|
|
||||||
describe "#target_type" do
|
describe "#parent_type" do
|
||||||
it "returns data[:target_type] as target type" do
|
it "returns data[:parent_type] as parent type" do
|
||||||
expect(described_class.new(data).target_type).to eq(data[:target_type])
|
expect(described_class.new(data).parent_type).to eq(data[:parent_type])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@ XML
|
||||||
|
|
||||||
it_behaves_like "a relayable Entity"
|
it_behaves_like "a relayable Entity"
|
||||||
|
|
||||||
describe "#target_type" do
|
describe "#parent_type" do
|
||||||
it "returns \"Poll\" as target type" do
|
it "returns \"Poll\" as parent type" do
|
||||||
expect(described_class.new(data).target_type).to eq("Poll")
|
expect(described_class.new(data).parent_type).to eq("Poll")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
property :diaspora_id, xml_name: :diaspora_handle
|
property :diaspora_id, xml_name: :diaspora_handle
|
||||||
|
|
||||||
def target_type
|
def parent_type
|
||||||
"Target"
|
"Target"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,5 +15,13 @@ module DiasporaFederation
|
||||||
let(:property) { :diaspora_id }
|
let(:property) { :diaspora_id }
|
||||||
let(:mandatory) { true }
|
let(:mandatory) { true }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#parent_type" do
|
||||||
|
it_behaves_like "a property with a value validation/restriction" do
|
||||||
|
let(:property) { :parent_type }
|
||||||
|
let(:wrong_values) { [nil, "", "any", "Postxxx", "post"] }
|
||||||
|
let(:correct_values) { %w(Post Comment) }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,11 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#target_type" do
|
describe "#parent_type" do
|
||||||
it_behaves_like "a property that mustn't be empty" do
|
it_behaves_like "a property with a value validation/restriction" do
|
||||||
let(:property) { :target_type }
|
let(:property) { :parent_type }
|
||||||
|
let(:wrong_values) { [nil, "", "any", "Postxxx", "post"] }
|
||||||
|
let(:correct_values) { ["Post"] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ module DiasporaFederation
|
||||||
let(:mandatory) { true }
|
let(:mandatory) { true }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#type" do
|
describe "#target_type" do
|
||||||
it_behaves_like "a property that mustn't be empty" do
|
it_behaves_like "a property that mustn't be empty" do
|
||||||
let(:property) { :target_type }
|
let(:property) { :target_type }
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue