Verified Commit 30f77e1c authored by paz's avatar paz
Browse files

Handle x-delete-key without argument.

parent d2d69e92
......@@ -31,6 +31,12 @@ module Schleuder
end
def self.delete_key(arguments, list, mail)
if arguments.blank?
return I18n.t(
"plugins.key_management.delete_key_requires_arguments"
)
end
arguments.map do |argument|
keys = list.keys(argument)
case keys.size
......
......@@ -98,6 +98,16 @@ de:
Der Schlüssel mit diesem Fingerabdruck konnte aus unbekanntem Grund nicht hinzugefügt werden:
%{fingerprint}
matching_keys_intro: Alle Schlüssel aus dem Schlüsselring der Liste, die '%{input}' enthalten, sind an diese Email angehängt.
delete_key_requires_arguments: |
Fehler: Du hast zu dem Schlüsselwort 'DELETE-KEY' keinen Wert angegeben.
Ein Wert ist nötig, weitere sind optional. Bspw.:
X-DELETE-KEY: 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3
Oder, um mehrere Schlüssel auf einmal zu löschen:
X-DELETE-KEY: 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3 a-subscription@hostname
Die Schlüssel werden nur gelöscht, wenn sie der einzige Treffer für den jeweiligen Wert sind.
resend:
not_resent_no_keys: Resending an <%{email}> fehlgeschlagen (%{num_keys} Schlüssel gefunden und unverschlüsseltes Senden verboten).
encrypted_to: Verschlüsselt an
......
......@@ -102,6 +102,16 @@ en:
The key with this fingerprint could not be added due to an unknown error:
%{fingerprint}
matching_keys_intro: All keys from the list's keyring matching '%{input}' are attached to this message.
delete_key_requires_arguments: |
Error: You did not send any arguments for the keyword 'DELETE-KEY'.
One is required, more are optional, e.g.:
X-DELETE-KEY: 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3
Or, to delete multiple keys at once:
X-DELETE-KEY: 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3 a-subscription@hostname
The matching keys will be deleted only if the argument matches them distinctly.
resend:
not_resent_no_keys: Resending to <%{email}> failed (%{num_keys} keys found and unencrypted sending disallowed).
encrypted_to: Encrypted to
......
......@@ -2133,6 +2133,43 @@ describe "user sends keyword" do
teardown_list_and_mailer(list)
end
it "x-delete-key without argument" do
list = create(:list)
list.subscribe("schleuder@example.org", '59C71FB38AEE22E091C78259D06350440F759BD3', true)
list.import_key(File.read('spec/fixtures/example_key.txt'))
list_keys_num = list.keys.size
ENV['GNUPGHOME'] = list.listdir
mail = Mail.new
mail.to = list.request_address
mail.from = list.admins.first.email
gpg_opts = {
encrypt: true,
keys: {list.request_address => list.fingerprint},
sign: true,
sign_as: list.admins.first.fingerprint
}
mail.gpg(gpg_opts)
mail.body = "x-list-name: #{list.email}\nX-delete-KEY:"
mail.deliver
encrypted_mail = Mail::TestMailer.deliveries.first
Mail::TestMailer.deliveries.clear
begin
Schleuder::Runner.new().run(encrypted_mail.to_s, list.request_address)
rescue SystemExit
end
raw = Mail::TestMailer.deliveries.first
message = Mail.create_message_to_list(raw.to_s, list.request_address, list).setup
puts message
expect(list.keys.size).to eql(list_keys_num)
expect(message.to_s).not_to include("translation missing")
expect(message.first_plaintext_part.body.to_s).to eql(I18n.t("plugins.key_management.delete_key_requires_arguments"))
teardown_list_and_mailer(list)
end
it "x-get-logfile with debug level sends non-empty logfile" do
list = create(:list)
list.update_attribute(:log_level, 'debug')
......
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