Commit 13c9e364 authored by paz's avatar paz

More tests around un/usable keys.

parent d9260cf3
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBExlilkBCACb2AQyclf7latAIE1kCTfKQ9jmcKyf959ymyhzoeNmBDpKjILC
7MOXtICo/V/xAzhWBK/vT9+56brGUBTugnW3yK+zllQprI3kIYaRS1SrbmKVwVse
9qLVUL1BssohFaEeQqT4MNh62ziJymqCguGEGXpYlEqzEDTmmhTANiPKRBZDrdfq
3FU3OJUMTGzuG34mKmXMRr0azprF228LUujMMKyWhG1hxh3El04C4jPuMSbaVcwN
E2rgIg8jaNAQuSyXkaprPZ8/nRG8UFGRtCMEIEh6Ou6KybF1NI9LQKCwcsGcLHKU
2u/8vOCExxdwl9Jjlqmof4FQV7bT++6SC0n3ABEBAAG0EWV4cGlyZWQgPGJsYUBm
b28+iQE+BBMBAgAoBQJMZYpZAhsDBQkAAVGABgsJCAcDAgYVCAIJCgsEFgIDAQIe
AQIXgAAKCRD3Gj+EEtg4iV6yB/4uDLoN1+TswtGjpUlu2CyjHe7pb05dAU4sWfTV
I+fxBuyEo+cf/23nOeoGyltBDR0heSg3TIfXQrbWD4WoVsOXPaT0fq6UEzeadkmn
A5NN3PGkv46o3ZSF1ltkY9ybMgnmRLHYCojSu5bSBMRVyurr0ozwNRPtFUTka8Lj
wxiwDJ394D5y6PjL56FPkUdKydzFGV2ptSKsqyAJvMBeGlQ4I6TpiBx0Lz2A1Qn+
4uXgTVPqgalC5YKTTTjOfQcieOOeqtI0LHqDpS/DIPLnwTUCN8OL2TQIeDudm3YI
P8FCKvImh840vTbpgFSgQeaJzJFv9UrloNyyvbVtaeoxnxoBiQFPBBMBCgA5AhsD
BgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgBYhBJh2nooQkfNr2IQD7PcaP4QS2DiJ
BQJZ6HpOAAoJEPcaP4QS2DiJfQwH/2+mSIWXyc8hJyFyPiKFsiwb1JDsAV4DSSUh
x+KYZsX0biBx6DRBf0IXt2Qdrbow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xAyq
-----END PGP PUBLIC KEY BLOCK-----
......@@ -595,4 +595,117 @@ describe Schleuder::List do
expect(list.keys.map(&:fingerprint)).to eql(["59C71FB38AEE22E091C78259D06350440F759BD3"])
end
end
describe "#send_to_subscriptions" do
it "sends the message to all subscribers" do
list = create(:list, send_encrypted_only: false)
sub, msgs = list.subscribe("admin@example.org", nil, true)
sub, msgs = list.subscribe("user1@example.org")
sub, msgs = list.subscribe("user2@example.org")
mail = Mail.new
mail.to = list.email
mail.from = 'something@localhost'
mail.subject = 'Something'
mail.body = "Some content"
Schleuder::Runner.new().run(mail, list.email)
messages = Mail::TestMailer.deliveries
recipients = messages.map { |m| m.to.first }.sort
expect(messages.size).to be(3)
expect(recipients).to eql(['admin@example.org', 'user1@example.org', 'user2@example.org'])
expect(messages[0].parts.first.parts.last.body.to_s).to eql("Some content")
expect(messages[0].subject).to eql("Something")
expect(messages[1].parts.first.parts.last.body.to_s).to eql("Some content")
expect(messages[1].subject).to eql("Something")
expect(messages[2].parts.first.parts.last.body.to_s).to eql("Some content")
expect(messages[2].subject).to eql("Something")
teardown_list_and_mailer(list)
end
it "sends the message to all subscribers, in the clear if one's key is unusable, if send_encrypted_only is false" do
list = create(:list, send_encrypted_only: false)
sub, msgs = list.subscribe("admin@example.org", nil, true)
key_material = File.read("spec/fixtures/expired_key.txt")
sub, msgs = list.subscribe("user1@example.org", nil, false, true, key_material)
sub, msgs = list.subscribe("user2@example.org")
mail = Mail.new
mail.to = list.email
mail.from = 'something@localhost'
mail.subject = 'Something'
mail.body = "Some content"
Schleuder::Runner.new().run(mail, list.email)
messages = Mail::TestMailer.deliveries
recipients = messages.map { |m| m.to.first }.sort
expect(messages.size).to be(3)
expect(recipients).to eql(['admin@example.org', 'user1@example.org', 'user2@example.org'])
expect(messages[0].parts.first.parts.last.body.to_s).to eql("Some content")
expect(messages[0].subject).to eql("Something")
expect(messages[1].parts.first.parts.last.body.to_s).to eql("Some content")
expect(messages[1].subject).to eql("Something")
expect(messages[2].parts.first.parts.last.body.to_s).to eql("Some content")
expect(messages[2].subject).to eql("Something")
teardown_list_and_mailer(list)
end
it "sends the message only to subscribers with available keys if send_encrypted_only is true, and a notification to the other subscribers" do
list = create(:list, send_encrypted_only: true)
sub, msgs = list.subscribe("admin@example.org", '59C71FB38AEE22E091C78259D06350440F759BD3', true)
sub, msgs = list.subscribe("user1@example.org")
sub, msgs = list.subscribe("user2@example.org", '59C71FB38AEE22E091C78259D06350440F759BD3')
mail = Mail.new
mail.to = list.email
mail.from = 'something@localhost'
mail.subject = 'Something'
mail.body = "Some content"
Schleuder::Runner.new().run(mail, list.email)
messages = Mail::TestMailer.deliveries
recipients = messages.map { |m| m.to.first }.sort
expect(messages.size).to be(3)
expect(recipients).to eql(['admin@example.org', 'user1@example.org', 'user2@example.org'])
expect(messages[0].parts.last.body.to_s).to include("-----BEGIN PGP MESSAGE-----")
expect(messages[0].subject).to eql("Something")
expect(messages[1].parts.first.body.to_s).to include("You missed an email")
expect(messages[1].subject).to eql("Notice")
expect(messages[2].parts.last.body.to_s).to include("-----BEGIN PGP MESSAGE-----")
expect(messages[2].subject).to eql("Something")
teardown_list_and_mailer(list)
end
it "sends the message only to subscribers with usable keys if send_encrypted_only is true, and a notification to the other subscribers" do
list = create(:list, send_encrypted_only: true)
key_material = File.read("spec/fixtures/partially_expired_key.txt")
sub, msgs = list.subscribe("admin@example.org", nil, true, true, key_material)
key_material = File.read("spec/fixtures/expired_key.txt")
sub, msgs = list.subscribe("user1@example.org", nil, false, true, key_material)
sub, msgs = list.subscribe("user2@example.org", '59C71FB38AEE22E091C78259D06350440F759BD3')
mail = Mail.new
mail.to = list.email
mail.from = 'something@localhost'
mail.subject = 'Something'
mail.body = "Some content"
Schleuder::Runner.new().run(mail, list.email)
messages = Mail::TestMailer.deliveries
recipients = messages.map { |m| m.to.first }.sort
expect(messages.size).to be(3)
expect(recipients).to eql(['admin@example.org', 'user1@example.org', 'user2@example.org'])
expect(messages[0].parts.first.body.to_s).to include("You missed an email")
expect(messages[0].subject).to eql("Notice")
expect(messages[1].parts.first.body.to_s).to include("You missed an email")
expect(messages[1].subject).to eql("Notice")
expect(messages[2].parts.last.body.to_s).to include("-----BEGIN PGP MESSAGE-----")
expect(messages[2].subject).to eql("Something")
teardown_list_and_mailer(list)
end
end
end
......@@ -81,4 +81,33 @@ describe Schleuder::LoggerNotifications do
expect(message.parts.first.parts[2].body.to_s).to include("Subject: A subject")
expect(message.parts.first.parts[2][:content_type].content_type).to eql("message/rfc822")
end
it "notifies admins encryptedly if their key is usable" do
list = create(:list, send_encrypted_only: false)
list.subscribe("schleuder@example.org", '59C71FB38AEE22E091C78259D06350440F759BD3', true)
mail = Mail.new
mail.subject = "A subject"
list.logger.notify_admin(["Something", "anotherthing"], mail.to_s, I18n.t('notice'))
message = Mail::TestMailer.deliveries.first
expect(message.subject).to eql('Notice')
expect(message.parts.size).to be(2)
expect(message.parts.last.body.to_s).to include('-----BEGIN PGP MESSAGE-----')
end
it "notifies admins in the clear if their key is unusable" do
list = create(:list, send_encrypted_only: false)
key_material = File.read("spec/fixtures/partially_expired_key.txt")
list.subscribe("schleuder@example.org", nil, true, true, key_material)
mail = Mail.new
mail.subject = "A subject"
list.logger.notify_admin("Something", mail.to_s, I18n.t('notice'))
message = Mail::TestMailer.deliveries.first
expect(message.subject).to eql('Notice')
expect(message.parts.size).to be(2)
expect(message.parts.first.parts.first.body.to_s).to eql('Something')
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment