Remove parent_author_signature from json

This commit is contained in:
Benjamin Neff 2017-05-23 03:20:58 +02:00
parent 57edc8baab
commit a05c6fe6d1
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
8 changed files with 14 additions and 22 deletions

View file

@ -134,7 +134,7 @@ module DiasporaFederation
def enriched_properties
super.merge(additional_data).tap do |hash|
hash[:author_signature] = author_signature || sign_with_author
hash[:parent_author_signature] = parent_author_signature || sign_with_parent_author_if_available.to_s
hash.delete(:parent_author_signature)
end
end
@ -142,7 +142,9 @@ module DiasporaFederation
#
# @return [Hash] sorted xml elements
def xml_elements
data = super
data = super.tap do |hash|
hash[:parent_author_signature] = parent_author_signature || sign_with_parent_author_if_available.to_s
end
order = signature_order + %i(author_signature parent_author_signature)
order.map {|element| [element, data[element] || ""] }.to_h
end

View file

@ -46,8 +46,7 @@
"author": { "type": "string" },
"guid": { "$ref": "#/definitions/guid" },
"parent_guid": { "$ref": "#/definitions/guid" },
"author_signature": { "$ref": "#/definitions/signature" },
"parent_author_signature": { "$ref": "#/definitions/signature" }
"author_signature": { "$ref": "#/definitions/signature" }
},
"required": [
"author", "guid", "parent_guid"

View file

@ -32,7 +32,6 @@ XML
"guid": "#{data[:guid]}",
"parent_guid": "#{parent.guid}",
"author_signature": "#{data[:author_signature]}",
"parent_author_signature": "#{data[:parent_author_signature]}",
"text": "#{data[:text]}",
"created_at": "#{data[:created_at].iso8601}"
},

View file

@ -32,7 +32,6 @@ XML
"guid": "#{data[:guid]}",
"parent_guid": "#{parent.guid}",
"author_signature": "#{data[:author_signature]}",
"parent_author_signature": "#{data[:parent_author_signature]}",
"parent_type": "#{parent.entity_type}",
"positive": #{data[:positive]}
},

View file

@ -30,7 +30,6 @@ XML
"guid": "#{data[:guid]}",
"parent_guid": "#{parent.guid}",
"author_signature": "#{data[:author_signature]}",
"parent_author_signature": "#{data[:parent_author_signature]}",
"poll_answer_guid": "#{data[:poll_answer_guid]}"
},
"property_order": [

View file

@ -307,25 +307,21 @@ XML
)
end
it "computes correct signatures for the entity with new unknown elements" do
it "computes correct author_signature for the entity with new unknown elements" do
expect_callback(:fetch_private_key, author).and_return(author_pkey)
expect_callback(:fetch_private_key, local_parent.author).and_return(parent_pkey)
property_order = [:author, :guid, :parent_guid, "new_property", :property]
signature_data_with_new_property = "#{author};#{guid};#{parent_guid};#{new_property};#{property}"
json_hash = Entities::SomeRelayable.new(hash, property_order, "new_property" => new_property).to_json
author_signature = json_hash[:entity_data][:author_signature]
parent_author_signature = json_hash[:entity_data][:parent_author_signature]
expect(verify_signature(author_pkey, author_signature, signature_data_with_new_property)).to be_truthy
expect(verify_signature(parent_pkey, parent_author_signature, signature_data_with_new_property)).to be_truthy
end
it "doesn't change signatures if they are already set" do
it "doesn't change author_signature if it is already set" do
json = Entities::SomeRelayable.new(hash_with_fake_signatures).to_json.to_json
expect(json).to include_json(entity_data: {author_signature: "aa"})
expect(json).to include_json(entity_data: {parent_author_signature: "bb"})
end
it "raises when author_signature not set and key isn't supplied" do
@ -336,12 +332,11 @@ XML
}.to raise_error Entities::Relayable::AuthorPrivateKeyNotFound
end
it "doesn't set parent_author_signature if key isn't supplied" do
it "doesn't contain the parent_author_signature" do
expect_callback(:fetch_private_key, author).and_return(author_pkey)
expect_callback(:fetch_private_key, local_parent.author).and_return(nil)
json = Entities::SomeRelayable.new(hash).to_json.to_json
expect(json).to include_json(entity_data: {parent_author_signature: ""})
json = Entities::SomeRelayable.new(hash).to_json
expect(json[:entity_data]).not_to include(:parent_author_signature)
end
end
@ -453,7 +448,6 @@ XML
before do
expect_callback(:fetch_public_key, author).and_return(author_pkey.public_key)
expect_callback(:fetch_private_key, author).and_return(author_pkey)
expect_callback(:fetch_private_key, remote_parent.author).and_return(parent_pkey)
end
let(:entity) { Entities::SomeRelayable.new(hash) }

View file

@ -14,7 +14,7 @@ end
# signature methods
def add_signatures(hash, klass=described_class)
properties = klass.new(hash).send(:enriched_properties)
properties = klass.new(hash).send(:xml_elements)
hash[:author_signature] = properties[:author_signature]
hash[:parent_author_signature] = properties[:parent_author_signature]
end

View file

@ -1,4 +1,5 @@
def entity_hash_from(hash)
hash.delete(:parent_author_signature)
hash.map {|key, value|
if [String, TrueClass, FalseClass, Integer, NilClass].any? {|c| value.is_a? c }
[key, value]
@ -136,10 +137,9 @@ shared_examples "a JSON Entity" do
it "contains JSON properties for each of the entity properties with the entity_data property" do
entity_data = entity_hash_from(data)
entity_data.delete(:parent)
nested_elements = entity_data.select {|_key, value| value.is_a?(Array) || value.is_a?(Hash) }
entity_data.reject! {|_key, value| value.is_a?(Array) || value.is_a?(Hash) }
nested_elements, simple_props = entity_data.partition {|_key, value| value.is_a?(Array) || value.is_a?(Hash) }
expect(to_json_output).to include_json(entity_data: entity_data)
expect(to_json_output).to include_json(entity_data: simple_props.to_h)
nested_elements.each {|key, value|
type = described_class.class_props[key]
if value.is_a?(Array)