Commit 90ad681b authored by georg's avatar georg

Merge branch 'paz/handle-more-keywords-without-argument' into 'master'

Handle more keywords without argument

See merge request schleuder/schleuder!196
parents f70d1e49 7bae9f52
......@@ -7,7 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
* Handle X-SET-FINGERPRINT without an argument and reply with a helpful error-message.
* Handle missing arguments for several keywords and reply with a helpful error-message.
### Changed
......
......@@ -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
......@@ -84,6 +90,12 @@ module Schleuder
end
def self.fetch_key(arguments, list, mail)
if arguments.blank?
return I18n.t(
"plugins.key_management.fetch_key_requires_arguments"
)
end
arguments.map do |argument|
list.fetch_keys(argument)
end
......
module Schleuder
module RequestPlugins
def self.subscribe(arguments, list, mail)
if arguments.blank?
return I18n.t(
"plugins.subscription_management.subscribe_requires_arguments"
)
end
email = arguments.shift
if arguments.present?
......
......@@ -98,6 +98,28 @@ 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.
fetch_key_requires_arguments: |
Fehler: Du hast zu dem Schlüsselwort 'FETCH-KEY' keinen Wert angegeben.
Ein Wert ist nötig, weitere sind optional. Jeder Wert kann eine URL sein, die via HTTP geladen wird, oder ein Text, mit dem auf den OpenPGP-Schlüsselserver gesucht wird.
Bspw., um einen Schlüssel per fingerprint vom Schlüsselserver zu holen:
X-FETCH-KEY: 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3
Oder, um zwei Schlüssel per Email-Adresse vom Schlüsselserver zu holen:
X-FETCH-KEY: a-subscription@hostname anotherone@example.org
Oder, um einen Schlüssel per HTTP von einem Server zu laden:
X-FETCH-KEY: https://example.org/keys/mykey.asc
resend:
not_resent_no_keys: Resending an <%{email}> fehlgeschlagen (%{num_keys} Schlüssel gefunden und unverschlüsseltes Senden verboten).
encrypted_to: Verschlüsselt an
......@@ -134,6 +156,22 @@ de:
oder (als admin):
X-SET-FINGERPRINT: subscription2@hostname 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3
subscribe_requires_arguments: |
Fehler: Du hast zu dem Schlüsselwort 'SUBSCRIBE' keinen Wert angegeben.
Mindestens ein Wert ist nötig, drei weitere sind optional. Bspw.:
X-SUBSCRIBE: new-subscription@hostname
Oder, um den Schlüssel für das neue Abo zuzuweisen:
X-SUBSCRIBE: new-subscription@hostname 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3
Oder, um den Schlüssel zuzuweisen, und das Abo zum admin zu machen:
X-SUBSCRIBE: new-subscription@hostname 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3 true
Oder, um den Schlüssel zuzuweisen, das Abo zum admin zu machen, und die Zustellung von Listen-Emails für dieses Abo abzuschalten:
X-SUBSCRIBE: new-subscription@hostname 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3 true false
Wenn du die optionalen Werte weglässt hat das Abo keinen Schlüssel zugewiesen, ist nicht admin, und hat die Zustellung von Listen-Email aktiviert.
signatures_attached: Die Signaturen hängen an.
list_management:
no_logfile: Keine Log-Datei für %{listname} gefunden. (Das kann an einem hohem Log-Level und der Abwesenheit von Fehlern liegen.)
......
......@@ -102,6 +102,28 @@ 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.
fetch_key_requires_arguments: |
Error: You did not send any arguments for the keyword 'FETCH-KEY'.
One is required, more are optional. Each argument can be an URL to fetch via HTTP, or a string to look up at the OpenPGP-keyservers.
E.g., to fetch a key by fingerprint from the keyserver:
X-FETCH-KEY: 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3
Or, to fetch two keys by email-address from the keyserver:
X-FETCH-KEY: a-subscription@hostname anotherone@example.org
Or, to fetch a key keys by URL:
X-FETCH-KEY: https://example.org/keys/mykey.asc
resend:
not_resent_no_keys: Resending to <%{email}> failed (%{num_keys} keys found and unencrypted sending disallowed).
encrypted_to: Encrypted to
......@@ -138,6 +160,22 @@ en:
or (as an admin):
X-SET-FINGERPRINT: subscription2@hostname 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3
subscribe_requires_arguments: |
Error: You did not send any arguments for the keyword 'SUBSCRIBE'.
At least one argument is required, three more are optional. E.g.:
X-SUBSCRIBE: new-subscription@hostname
Or, defining the key to use for the new subscription:
X-SUBSCRIBE: new-subscription@hostname 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3
Or, defining the key to use, and setting this subscription to be an admin:
X-SUBSCRIBE: new-subscription@hostname 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3 true
Or, defining the key to use, setting this subscription as admin, and disabling the delivery of list-emails to this subscription:
X-SUBSCRIBE: new-subscription@hostname 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3 true false
If you omit the optional arguments, the subscription has no key assigned, is not an admin, and has the delivery of list-emails enabled.
signatures_attached: Find the signatures attached.
list_management:
no_logfile: No logfile could be found for %{listname}. (This might be caused by a high log-level and the absence of errors.)
......
......@@ -298,6 +298,44 @@ describe "user sends keyword" do
teardown_list_and_mailer(list)
end
it "x-subscribe without arguments" do
list = create(:list)
list.subscribe("schleuder@example.org", '59C71FB38AEE22E091C78259D06350440F759BD3', true)
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-SUBSCRIBE:"
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
subscription = list.subscriptions.where(email: 'test@example.org').first
puts message
expect(message.to).to eql(['schleuder@example.org'])
expect(message.to_s).not_to include("translation missing")
expect(message.first_plaintext_part.body.to_s).to eql(I18n.t("plugins.subscription_management.subscribe_requires_arguments"))
expect(subscription).to be_blank
teardown_list_and_mailer(list)
end
it "x-unsubscribe without argument" do
list = create(:list)
list.subscribe("schleuder@example.org", '59C71FB38AEE22E091C78259D06350440F759BD3', true)
......@@ -1276,6 +1314,43 @@ describe "user sends keyword" do
teardown_list_and_mailer(list)
end
it "x-fetch-key without arguments" do
list = create(:list)
list.subscribe("schleuder@example.org", '59C71FB38AEE22E091C78259D06350440F759BD3', true)
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-fetch-KEY: "
mail.deliver
encrypted_mail = Mail::TestMailer.deliveries.first
Mail::TestMailer.deliveries.clear
with_sks_mock do
begin
Schleuder::Runner.new().run(encrypted_mail.to_s, list.request_address)
rescue SystemExit
end
end
raw = Mail::TestMailer.deliveries.first
message = Mail.create_message_to_list(raw.to_s, list.request_address, list).setup
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.fetch_key_requires_arguments"))
teardown_list_and_mailer(list)
end
it "x-resend" do
list = create(:list, public_footer: "-- \nblablabla")
list.subscribe("schleuder@example.org", '59C71FB38AEE22E091C78259D06350440F759BD3', true)
......@@ -2095,6 +2170,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