Be more strict about strings.

This commit is contained in:
Netscape Navigator 2020-04-01 08:07:39 -05:00
parent e79e0aedf3
commit 94009bc725
3 changed files with 21 additions and 12 deletions

View File

@ -39,13 +39,10 @@ module Pigeon
when BLOB_SIGIL, MESSAGE_SIGIL, IDENTITY_SIGIL, STRING_SIGIL
self.body[key] = value
else
# JSON.stringify calls were done in the name of time
# and as a convinience for values like
# bools and ints
if value.is_a?(String)
self.body[key] = value.inspect
else
self.body[key] = value.to_json
raise "Unexpected value! Did you wrap it in quotes?: #{value}"
end
end
self.save

View File

@ -8,7 +8,7 @@ module Pigeon
MESG_VALUE = /%.{40,90}.sha256/
BLOB_VALUE = /&.{40,90}.sha256/
NULL_VALUE = /NONE/
STRG_VALUE = /".{1,64}"/
STRG_VALUE = /\".{1,64}\"/
ALPHANUMERICISH = /[a-zA-Z\d\._]{1,64}/
ALL_VALUES = [
FEED_VALUE,

View File

@ -2,6 +2,8 @@ require "spec_helper"
RSpec.describe Pigeon::Message do
before(:each) do
p = Pigeon::DEFAULT_BUNDLE_PATH
File.delete(p) if File.file?(p)
Pigeon::Storage.reset
Pigeon::LocalIdentity.reset
end
@ -12,17 +14,27 @@ RSpec.describe Pigeon::Message do
Pigeon::Message.publish(draft)
end
it "creates a bundle" do
p = Pigeon::DEFAULT_BUNDLE_PATH
File.delete(p) if File.file?(p)
expected_bundle = (1..10)
def create_fake_messages
(1..10)
.to_a
.map do |n| { "foo" => ["bar", 123, SecureRandom.uuid].sample } end
.map do |n| { "foo" => ["bar", "123", SecureRandom.uuid].sample } end
.map do |d| create_message(d) end
.map(&:render)
.join("\n\n") + "\n"
end
it "creates a bundle" do
expected_bundle = create_fake_messages.map(&:render).join("\n\n") + "\n"
Pigeon::Bundle.create
actual_bundle = File.read(Pigeon::DEFAULT_BUNDLE_PATH)
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)
create_fake_messages
Pigeon::Bundle.create
actual_bundle = File.read(Pigeon::DEFAULT_BUNDLE_PATH)
binding.pry
end
end