add more info to errors for better logging
This commit is contained in:
parent
117ee79c8c
commit
4b0e77b25a
9 changed files with 28 additions and 24 deletions
|
|
@ -38,7 +38,7 @@ module DiasporaFederation
|
||||||
def validate
|
def validate
|
||||||
super
|
super
|
||||||
messages.each do |message|
|
messages.each do |message|
|
||||||
raise ValidationError, "nested message has different author" if message.author != author
|
raise ValidationError, "nested #{message} has different author: author=#{author}" if message.author != author
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -38,15 +38,15 @@ module DiasporaFederation
|
||||||
# @deprecated remove after {Message} doesn't include {Relayable} anymore
|
# @deprecated remove after {Message} doesn't include {Relayable} anymore
|
||||||
def verify_author_signature
|
def verify_author_signature
|
||||||
pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key, author)
|
pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key, author)
|
||||||
raise PublicKeyNotFound, "author_signature author=#{author} guid=#{guid}" if pubkey.nil?
|
raise PublicKeyNotFound, "author_signature author=#{author} obj=#{self}" if pubkey.nil?
|
||||||
raise SignatureVerificationFailed, "wrong author_signature" unless verify_signature(pubkey, author_signature)
|
raise SignatureVerificationFailed, "obj=#{self}" unless verify_signature(pubkey, author_signature)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# @deprecated remove after {Message} doesn't include {Relayable} anymore
|
# @deprecated remove after {Message} doesn't include {Relayable} anymore
|
||||||
def parent_author
|
def parent_author
|
||||||
parent = DiasporaFederation.callbacks.trigger(:fetch_related_entity, "Conversation", conversation_guid)
|
parent = DiasporaFederation.callbacks.trigger(:fetch_related_entity, "Conversation", conversation_guid)
|
||||||
raise Federation::Fetcher::NotFetchable, "Conversation:#{conversation_guid} not found" unless parent
|
raise Federation::Fetcher::NotFetchable, "parent of #{self} not found" unless parent
|
||||||
parent.author
|
parent.author
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ module DiasporaFederation
|
||||||
# validates that the parent exists and the parent author is local
|
# validates that the parent exists and the parent author is local
|
||||||
def validate_parent
|
def validate_parent
|
||||||
parent = DiasporaFederation.callbacks.trigger(:fetch_related_entity, parent_type, parent_guid)
|
parent = DiasporaFederation.callbacks.trigger(:fetch_related_entity, parent_type, parent_guid)
|
||||||
raise ParentNotLocal, "parent: #{parent_type}:#{parent_guid}" unless parent && parent.local
|
raise ParentNotLocal, "obj=#{self}" unless parent && parent.local
|
||||||
end
|
end
|
||||||
|
|
||||||
# Don't verify signatures for a {Participation}. Validate that the parent is local.
|
# Don't verify signatures for a {Participation}. Validate that the parent is local.
|
||||||
|
|
|
||||||
|
|
@ -82,8 +82,10 @@ module DiasporaFederation
|
||||||
# @raise [SignatureVerificationFailed] if the signature is not valid or no public key is found
|
# @raise [SignatureVerificationFailed] if the signature is not valid or no public key is found
|
||||||
def verify_signatures
|
def verify_signatures
|
||||||
pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key, author)
|
pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key, author)
|
||||||
raise PublicKeyNotFound, "author_signature author=#{author} guid=#{guid}" if pubkey.nil?
|
raise PublicKeyNotFound, "author_signature author=#{author} obj=#{self}" if pubkey.nil?
|
||||||
raise SignatureVerificationFailed, "wrong author_signature" unless verify_signature(pubkey, author_signature)
|
unless verify_signature(pubkey, author_signature)
|
||||||
|
raise SignatureVerificationFailed, "wrong author_signature for #{self}"
|
||||||
|
end
|
||||||
|
|
||||||
verify_parent_author_signature unless parent.local
|
verify_parent_author_signature unless parent.local
|
||||||
end
|
end
|
||||||
|
|
@ -102,9 +104,9 @@ module DiasporaFederation
|
||||||
# this happens only on downstream federation
|
# this happens only on downstream federation
|
||||||
def verify_parent_author_signature
|
def verify_parent_author_signature
|
||||||
pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key, parent.author)
|
pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key, parent.author)
|
||||||
raise PublicKeyNotFound, "parent_author_signature parent_author=#{parent.author} guid=#{guid}" if pubkey.nil?
|
raise PublicKeyNotFound, "parent_author_signature parent_author=#{parent.author} obj=#{self}" if pubkey.nil?
|
||||||
unless verify_signature(pubkey, parent_author_signature)
|
unless verify_signature(pubkey, parent_author_signature)
|
||||||
raise SignatureVerificationFailed, "wrong parent_author_signature parent_guid=#{parent_guid}"
|
raise SignatureVerificationFailed, "wrong parent_author_signature for #{self}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -120,7 +122,7 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
|
|
||||||
pubkey.verify(DIGEST, Base64.decode64(signature), signature_data).tap do |valid|
|
pubkey.verify(DIGEST, Base64.decode64(signature), signature_data).tap do |valid|
|
||||||
logger.info "event=verify_signature status=complete guid=#{guid} valid=#{valid}"
|
logger.info "event=verify_signature status=complete obj=#{self} valid=#{valid}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -129,9 +131,9 @@ module DiasporaFederation
|
||||||
# @return [String] A Base64 encoded signature of #signature_data with key
|
# @return [String] A Base64 encoded signature of #signature_data with key
|
||||||
def sign_with_author
|
def sign_with_author
|
||||||
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, author)
|
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, author)
|
||||||
raise AuthorPrivateKeyNotFound, "author=#{author} guid=#{guid}" if privkey.nil?
|
raise AuthorPrivateKeyNotFound, "author=#{author} obj=#{self}" if privkey.nil?
|
||||||
sign_with_key(privkey).tap do
|
sign_with_key(privkey).tap do
|
||||||
logger.info "event=sign status=complete signature=author_signature author=#{author} guid=#{guid}"
|
logger.info "event=sign status=complete signature=author_signature author=#{author} obj=#{self}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -141,7 +143,7 @@ module DiasporaFederation
|
||||||
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, parent.author)
|
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, parent.author)
|
||||||
if privkey
|
if privkey
|
||||||
sign_with_key(privkey).tap do
|
sign_with_key(privkey).tap do
|
||||||
logger.info "event=sign status=complete signature=parent_author_signature guid=#{guid}"
|
logger.info "event=sign status=complete signature=parent_author_signature obj=#{self}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,9 @@ module DiasporaFederation
|
||||||
def validate
|
def validate
|
||||||
super
|
super
|
||||||
photos.each do |photo|
|
photos.each do |photo|
|
||||||
raise ValidationError, "nested photo has different author" if photo.author != author
|
if photo.author != author
|
||||||
|
raise ValidationError, "nested #{photo} has different author: author=#{author} obj=#{self}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ XML
|
||||||
invalid_data = data.merge(author: alice.diaspora_id)
|
invalid_data = data.merge(author: alice.diaspora_id)
|
||||||
expect {
|
expect {
|
||||||
Entities::Conversation.new(invalid_data)
|
Entities::Conversation.new(invalid_data)
|
||||||
}.to raise_error Entity::ValidationError, "nested message has different author"
|
}.to raise_error Entity::ValidationError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ XML
|
||||||
invalid_entity = Entities::Message.new(data.merge(author_signature: "aa"))
|
invalid_entity = Entities::Message.new(data.merge(author_signature: "aa"))
|
||||||
expect {
|
expect {
|
||||||
invalid_entity.sender_valid?(bob.diaspora_id)
|
invalid_entity.sender_valid?(bob.diaspora_id)
|
||||||
}.to raise_error Entities::Relayable::SignatureVerificationFailed, "wrong author_signature"
|
}.to raise_error Entities::Relayable::SignatureVerificationFailed, "obj=#{invalid_entity}"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises NotFetchable if the parent Conversation can not be found" do
|
it "raises NotFetchable if the parent Conversation can not be found" do
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,9 @@ XML
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#validate_parent" do
|
describe "#validate_parent" do
|
||||||
let(:xml) {
|
let(:participation) {
|
||||||
allow(DiasporaFederation.callbacks).to receive(:trigger).and_call_original
|
allow(DiasporaFederation.callbacks).to receive(:trigger).and_call_original
|
||||||
Entities::Participation.new(data).to_xml
|
Entities::Participation.new(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
it "succeeds when the parent is local" do
|
it "succeeds when the parent is local" do
|
||||||
|
|
@ -65,7 +65,7 @@ XML
|
||||||
expect_callback(:fetch_related_entity, parent.entity_type, parent.guid).and_return(local_parent)
|
expect_callback(:fetch_related_entity, parent.entity_type, parent.guid).and_return(local_parent)
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
Entities::Participation.from_xml(xml)
|
Entities::Participation.from_xml(participation.to_xml)
|
||||||
}.not_to raise_error
|
}.not_to raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -73,8 +73,8 @@ XML
|
||||||
expect_callback(:fetch_related_entity, parent.entity_type, parent.guid).and_return(nil)
|
expect_callback(:fetch_related_entity, parent.entity_type, parent.guid).and_return(nil)
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
Entities::Participation.from_xml(xml)
|
Entities::Participation.from_xml(participation.to_xml)
|
||||||
}.to raise_error Entities::Participation::ParentNotLocal, "parent: #{parent.entity_type}:#{parent.guid}"
|
}.to raise_error Entities::Participation::ParentNotLocal, "obj=#{participation}"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises ParentNotLocal when the parent is not local" do
|
it "raises ParentNotLocal when the parent is not local" do
|
||||||
|
|
@ -82,8 +82,8 @@ XML
|
||||||
expect_callback(:fetch_related_entity, parent.entity_type, parent.guid).and_return(remote_parent)
|
expect_callback(:fetch_related_entity, parent.entity_type, parent.guid).and_return(remote_parent)
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
Entities::Participation.from_xml(xml)
|
Entities::Participation.from_xml(participation.to_xml)
|
||||||
}.to raise_error Entities::Participation::ParentNotLocal, "parent: #{parent.entity_type}:#{parent.guid}"
|
}.to raise_error Entities::Participation::ParentNotLocal, "obj=#{participation}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ module DiasporaFederation
|
||||||
invalid_data = data.merge(author: FactoryGirl.generate(:diaspora_id))
|
invalid_data = data.merge(author: FactoryGirl.generate(:diaspora_id))
|
||||||
expect {
|
expect {
|
||||||
Entities::StatusMessage.new(invalid_data)
|
Entities::StatusMessage.new(invalid_data)
|
||||||
}.to raise_error Entity::ValidationError, "nested photo has different author"
|
}.to raise_error Entity::ValidationError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue