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
|
||||
super
|
||||
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
|
||||
|
|
|
|||
|
|
@ -38,15 +38,15 @@ module DiasporaFederation
|
|||
# @deprecated remove after {Message} doesn't include {Relayable} anymore
|
||||
def verify_author_signature
|
||||
pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key, author)
|
||||
raise PublicKeyNotFound, "author_signature author=#{author} guid=#{guid}" if pubkey.nil?
|
||||
raise SignatureVerificationFailed, "wrong author_signature" unless verify_signature(pubkey, author_signature)
|
||||
raise PublicKeyNotFound, "author_signature author=#{author} obj=#{self}" if pubkey.nil?
|
||||
raise SignatureVerificationFailed, "obj=#{self}" unless verify_signature(pubkey, author_signature)
|
||||
true
|
||||
end
|
||||
|
||||
# @deprecated remove after {Message} doesn't include {Relayable} anymore
|
||||
def parent_author
|
||||
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
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ module DiasporaFederation
|
|||
# validates that the parent exists and the parent author is local
|
||||
def validate_parent
|
||||
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
|
||||
|
||||
# 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
|
||||
def verify_signatures
|
||||
pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key, author)
|
||||
raise PublicKeyNotFound, "author_signature author=#{author} guid=#{guid}" if pubkey.nil?
|
||||
raise SignatureVerificationFailed, "wrong author_signature" unless verify_signature(pubkey, author_signature)
|
||||
raise PublicKeyNotFound, "author_signature author=#{author} obj=#{self}" if pubkey.nil?
|
||||
unless verify_signature(pubkey, author_signature)
|
||||
raise SignatureVerificationFailed, "wrong author_signature for #{self}"
|
||||
end
|
||||
|
||||
verify_parent_author_signature unless parent.local
|
||||
end
|
||||
|
|
@ -102,9 +104,9 @@ module DiasporaFederation
|
|||
# this happens only on downstream federation
|
||||
def verify_parent_author_signature
|
||||
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)
|
||||
raise SignatureVerificationFailed, "wrong parent_author_signature parent_guid=#{parent_guid}"
|
||||
raise SignatureVerificationFailed, "wrong parent_author_signature for #{self}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -120,7 +122,7 @@ module DiasporaFederation
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -129,9 +131,9 @@ module DiasporaFederation
|
|||
# @return [String] A Base64 encoded signature of #signature_data with key
|
||||
def sign_with_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
|
||||
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
|
||||
|
||||
|
|
@ -141,7 +143,7 @@ module DiasporaFederation
|
|||
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, parent.author)
|
||||
if privkey
|
||||
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
|
||||
|
|
|
|||
|
|
@ -36,7 +36,9 @@ module DiasporaFederation
|
|||
def validate
|
||||
super
|
||||
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
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ XML
|
|||
invalid_data = data.merge(author: alice.diaspora_id)
|
||||
expect {
|
||||
Entities::Conversation.new(invalid_data)
|
||||
}.to raise_error Entity::ValidationError, "nested message has different author"
|
||||
}.to raise_error Entity::ValidationError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ XML
|
|||
invalid_entity = Entities::Message.new(data.merge(author_signature: "aa"))
|
||||
expect {
|
||||
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
|
||||
|
||||
it "raises NotFetchable if the parent Conversation can not be found" do
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ XML
|
|||
end
|
||||
|
||||
describe "#validate_parent" do
|
||||
let(:xml) {
|
||||
let(:participation) {
|
||||
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
|
||||
|
|
@ -65,7 +65,7 @@ XML
|
|||
expect_callback(:fetch_related_entity, parent.entity_type, parent.guid).and_return(local_parent)
|
||||
|
||||
expect {
|
||||
Entities::Participation.from_xml(xml)
|
||||
Entities::Participation.from_xml(participation.to_xml)
|
||||
}.not_to raise_error
|
||||
end
|
||||
|
||||
|
|
@ -73,8 +73,8 @@ XML
|
|||
expect_callback(:fetch_related_entity, parent.entity_type, parent.guid).and_return(nil)
|
||||
|
||||
expect {
|
||||
Entities::Participation.from_xml(xml)
|
||||
}.to raise_error Entities::Participation::ParentNotLocal, "parent: #{parent.entity_type}:#{parent.guid}"
|
||||
Entities::Participation.from_xml(participation.to_xml)
|
||||
}.to raise_error Entities::Participation::ParentNotLocal, "obj=#{participation}"
|
||||
end
|
||||
|
||||
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 {
|
||||
Entities::Participation.from_xml(xml)
|
||||
}.to raise_error Entities::Participation::ParentNotLocal, "parent: #{parent.entity_type}:#{parent.guid}"
|
||||
Entities::Participation.from_xml(participation.to_xml)
|
||||
}.to raise_error Entities::Participation::ParentNotLocal, "obj=#{participation}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ module DiasporaFederation
|
|||
invalid_data = data.merge(author: FactoryGirl.generate(:diaspora_id))
|
||||
expect {
|
||||
Entities::StatusMessage.new(invalid_data)
|
||||
}.to raise_error Entity::ValidationError, "nested photo has different author"
|
||||
}.to raise_error Entity::ValidationError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue