participation not relayable anymore
receive only from author and no signature checking see #35
This commit is contained in:
parent
9927d7bea3
commit
7f869a5cdf
4 changed files with 59 additions and 4 deletions
|
|
@ -15,6 +15,22 @@ module DiasporaFederation
|
|||
# currently only "Post" is supported.
|
||||
# @return [String] parent type
|
||||
property :parent_type, xml_name: :target_type
|
||||
|
||||
# It is only valid to receive a {Participation} from the author itself.
|
||||
# @deprecated remove after {Participation} doesn't include {Relayable} anymore
|
||||
def sender_valid?(sender)
|
||||
sender == author
|
||||
end
|
||||
|
||||
# Default implementation, don't verify signatures for a {Participation}.
|
||||
# @see Entity.populate_entity
|
||||
# @deprecated remove after {Participation} doesn't include {Relayable} anymore
|
||||
# @param [Nokogiri::XML::Element] root_node xml nodes
|
||||
# @return [Entity] instance
|
||||
def self.populate_entity(root_node)
|
||||
new(entity_data(root_node).merge(parent: nil))
|
||||
end
|
||||
private_class_method :populate_entity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ module DiasporaFederation
|
|||
class ParticipationValidator < Validation::Validator
|
||||
include Validation
|
||||
|
||||
include RelayableValidator
|
||||
|
||||
rule :author, %i(not_empty diaspora_id)
|
||||
rule :guid, :guid
|
||||
rule :parent_guid, :guid
|
||||
rule :parent_type, [:not_empty, regular_expression: {regex: /\APost\z/}]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -28,8 +28,31 @@ XML
|
|||
|
||||
it_behaves_like "an Entity subclass"
|
||||
|
||||
it_behaves_like "an XML Entity"
|
||||
it_behaves_like "an XML Entity", [:parent]
|
||||
|
||||
it_behaves_like "a relayable Entity"
|
||||
|
||||
describe "#sender_valid?" do
|
||||
let(:entity) { Entities::Participation.new(data) }
|
||||
|
||||
it "allows the author" do
|
||||
expect(entity.sender_valid?(alice.diaspora_id)).to be_truthy
|
||||
end
|
||||
|
||||
it "does not allow the parent author" do
|
||||
expect(entity.sender_valid?(bob.diaspora_id)).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
context "relayable signature verification" do
|
||||
it "does not verify the signature" do
|
||||
data.merge!(author_signature: "aa", parent_author_signature: "bb")
|
||||
xml = Entities::Participation.new(data).to_xml
|
||||
|
||||
expect {
|
||||
Entities::Participation.from_xml(xml)
|
||||
}.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,22 @@ module DiasporaFederation
|
|||
|
||||
it_behaves_like "a common validator"
|
||||
|
||||
it_behaves_like "a relayable validator"
|
||||
it_behaves_like "a diaspora id validator" do
|
||||
let(:property) { :author }
|
||||
let(:mandatory) { true }
|
||||
end
|
||||
|
||||
describe "#guid" do
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { :guid }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#parent_guid" do
|
||||
it_behaves_like "a guid validator" do
|
||||
let(:property) { :parent_guid }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#parent_type" do
|
||||
it_behaves_like "a property with a value validation/restriction" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue