2020-03-15 16:51:13 +00:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
RSpec.describe Pigeon::Message do
|
|
|
|
before(:each) do
|
2020-05-14 13:32:57 +00:00
|
|
|
`rm -rf #{Pigeon::DEFAULT_BLOB_DIR}`
|
2020-04-01 13:07:39 +00:00
|
|
|
p = Pigeon::DEFAULT_BUNDLE_PATH
|
|
|
|
File.delete(p) if File.file?(p)
|
2020-03-15 16:51:13 +00:00
|
|
|
end
|
|
|
|
|
2020-04-17 13:55:18 +00:00
|
|
|
let(:db) do
|
|
|
|
db = Pigeon::Database.new
|
2020-04-19 14:25:42 +00:00
|
|
|
db.reset_database
|
2020-04-17 13:55:18 +00:00
|
|
|
db
|
|
|
|
end
|
2020-04-15 13:00:11 +00:00
|
|
|
|
2020-04-01 13:07:39 +00:00
|
|
|
def create_fake_messages
|
2020-04-23 12:21:00 +00:00
|
|
|
blobs = [db.add_message(db.add_blob("one"), { "a" => "b" }),
|
|
|
|
db.add_message("a", { db.add_blob("two") => "b" }),
|
|
|
|
db.add_message("a", { "b" => db.add_blob("three") })]
|
2020-04-21 12:31:34 +00:00
|
|
|
normal = (1..10)
|
2020-03-15 16:51:13 +00:00
|
|
|
.to_a
|
2020-04-25 15:11:25 +00:00
|
|
|
.map { |_n| { "foo" => ["bar", "123", SecureRandom.uuid].sample } }
|
|
|
|
.map { |d| db.add_message(SecureRandom.uuid, d) }
|
2020-04-21 12:31:34 +00:00
|
|
|
|
|
|
|
blobs + normal
|
2020-04-01 13:07:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a bundle" do
|
|
|
|
expected_bundle = create_fake_messages.map(&:render).join("\n\n") + "\n"
|
2020-04-24 11:20:02 +00:00
|
|
|
db.export_bundle
|
2020-05-14 13:25:02 +00:00
|
|
|
actual_bundle = File.read(File.join(Pigeon::DEFAULT_BUNDLE_PATH, Pigeon::MESSAGE_FILE))
|
2020-03-15 16:51:13 +00:00
|
|
|
expect(expected_bundle).to eq(actual_bundle)
|
|
|
|
end
|
2020-04-01 13:07:39 +00:00
|
|
|
|
2020-04-03 10:29:19 +00:00
|
|
|
it "does not crash when ingesting old messages" do
|
2020-04-01 13:07:39 +00:00
|
|
|
create_fake_messages
|
2020-04-24 11:20:02 +00:00
|
|
|
db.export_bundle
|
|
|
|
db.import_bundle
|
2020-04-01 13:07:39 +00:00
|
|
|
end
|
2020-04-20 02:32:37 +00:00
|
|
|
|
|
|
|
it "does not ingest messages from blocked peers" do
|
|
|
|
db.reset_database
|
2020-05-22 13:36:02 +00:00
|
|
|
antagonist = "TEXT.YDVX7JWTVNRFEVYC8E8DS9MVWW9KB66F1XQYMNB2FQ6QBPXKAQX0.ed25519"
|
2020-04-20 02:32:37 +00:00
|
|
|
db.block_peer(antagonist)
|
2020-05-21 12:50:02 +00:00
|
|
|
db.import_bundle(BLOCKED_PEER_FIXTURE_PATH)
|
2020-04-23 12:21:00 +00:00
|
|
|
expect(db.all_messages.count).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ingests a bundle's blobs" do
|
|
|
|
db.reset_database
|
2020-05-07 12:01:58 +00:00
|
|
|
blobs = [
|
2020-05-22 13:36:02 +00:00
|
|
|
"FILE.622PRNJ7C0S05XR2AHDPKWMG051B1QW5SXMN2RQHF2AND6J8VGPG",
|
|
|
|
"FILE.FV0FJ0YZADY7C5JTTFYPKDBHTZJ5JVVP5TCKP0605WWXYJG4VMRG",
|
|
|
|
"FILE.YPF11E5N9JFVB6KB1N1WDVVT9DXMCHE0XJWBZHT2CQ29S5SEPCSG",
|
2020-05-07 12:01:58 +00:00
|
|
|
]
|
2020-05-21 12:50:02 +00:00
|
|
|
db.import_bundle(HAS_BLOB_PATH)
|
2020-05-07 12:30:32 +00:00
|
|
|
expect(db.all_messages.count).to eq(3)
|
2020-05-07 12:01:58 +00:00
|
|
|
blobs.map do |h|
|
2020-05-07 11:50:07 +00:00
|
|
|
expect(db.have_blob?(h)).to be true
|
2020-04-25 15:36:26 +00:00
|
|
|
expect(db.get_blob(h)).to be_kind_of(String)
|
|
|
|
end
|
2020-04-20 02:32:37 +00:00
|
|
|
end
|
2020-03-15 16:51:13 +00:00
|
|
|
end
|