diff --git a/dist/pigeon/message.rb b/dist/pigeon/message.rb index 6f705ae..3c74bf4 100644 --- a/dist/pigeon/message.rb +++ b/dist/pigeon/message.rb @@ -67,7 +67,7 @@ module Pigeon def verify_depth_prev_and_depth count = store.get_message_count_for(author.public_key) expected_prev = store.get_message_by_depth(author.public_key, count - 1) || Pigeon::EMPTY_MESSAGE - assert("depth", depth, count) + assert("depth", count, depth) assert("prev", prev, expected_prev) end diff --git a/spec/pigeon/bundle_spec.rb b/spec/pigeon/bundle_spec.rb index c136a83..e98a50f 100644 --- a/spec/pigeon/bundle_spec.rb +++ b/spec/pigeon/bundle_spec.rb @@ -22,12 +22,7 @@ RSpec.describe Pigeon::Message do expect(expected_bundle).to eq(actual_bundle) end - it "debugs a problem" do - seed = "\xA3@\x12\xA6\x8Cl\x83\xF5)\x97\xED\xE67\x91\xAD\xFD\xCFf\xF4(\xEF\x81P\xBBD\xF7\x8C\xF7\x8D\xC0\xA9\f" - ident = Pigeon::LocalIdentity.new(seed) - Pigeon::LocalIdentity.instance_variable_set(:@current, ident) - public_key = "@NYTrqYYN2ffTqFyPCUULjhhUkfbY9LorpWYMoMpsOO4=.ed25519" - expect(Pigeon::LocalIdentity.current.public_key).to eq(public_key) + it "does not crash when ingesting old messages" do create_fake_messages Pigeon::Bundle.create Pigeon::Bundle.ingest diff --git a/spec/pigeon/message_spec.rb b/spec/pigeon/message_spec.rb index 00d3776..b9e898e 100644 --- a/spec/pigeon/message_spec.rb +++ b/spec/pigeon/message_spec.rb @@ -118,4 +118,19 @@ RSpec.describe Pigeon::Message do expect(message.signature).to eq(sig1_b64) expect(message.signature).to eq(sig2_b64) end + + it "crashes on forged fields" do + msg = Pigeon::Parser.parse([ + [:AUTHOR, "@DYdgK1KUInVtG3lS45hA1HZ-jTuvfLKsxDpXPFCve04=.ed25519"], + [:KIND, "invalid"], + [:PREV, "NONE"], + [:DEPTH, 10], + [:HEADER_END], + [:BODY_ENTRY, "duplicate", "This key is a duplicate."], + [:SIGNATURE, "DN7yPTE-m433ND3jBL4oM23XGxBKafjq0Dp9ArBQa_TIGU7DmCxTumieuPBN-NKxlx_0N7-c5zjLb5XXVHYPCQ==.sig.ed25519"], + [:MESSAGE_END], + ]) + m = "Expected field `depth` to equal 0, got: 10" + expect { msg.first.save! }.to raise_error(Pigeon::Message::VerificationError, m) + end end