Commit 29a7628e authored by paz's avatar paz

Tolerate spaces in fingerprint as keyword-arguments.

parent 5b026931
Pipeline #3306 failed with stage
in 22 seconds
......@@ -17,6 +17,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
* Don't write errors of list-plugins into the list of pseudo-headers. List-plugins must handle errors on their own.
* Fix x-get-key for multiple keys per match, and attach the resulting keys.
* Tolerate 0x-prefix on input for fingerprints of subscriptions.
* Tolerate spaces on input for fingerprints in keywords.
* `X-GET-KEY` returns keys as attachments now.
### Fixed
......
......@@ -2,12 +2,16 @@ module Schleuder
module RequestPlugins
def self.subscribe(arguments, list, mail)
email = arguments.shift
fingerprint = arguments.shift
# Pop the last two in order to be tolerant about spaces in the
# fingerprint.
deliveryflag = arguments.pop
adminflag = arguments.pop
# Use the remainders as fingerprint. This enables tolerating spaces.
fingerprint = arguments.join
if fingerprint.present?
fingerprint.sub!(/^0x/, '')
end
adminflag = arguments.shift
deliveryflag = arguments.shift
sub = list.subscribe(email, fingerprint, adminflag, deliveryflag)
......@@ -95,7 +99,7 @@ module Schleuder
def self.set_fingerprint(arguments, list, mail)
if arguments.first.match(/@/)
if arguments.first == mail.signer.email || list.from_admin?(mail)
email = arguments.first
email = arguments.shift
else
return I18n.t(
"plugins.subscription_management.set_fingerprint_only_self"
......@@ -113,7 +117,7 @@ module Schleuder
)
end
sub.fingerprint = arguments.last
sub.fingerprint = arguments.join
if sub.save
I18n.t(
......
......@@ -86,6 +86,48 @@ describe "user sends keyword" do
teardown_list_and_mailer(list)
end
it "x-subscribe with attributes and spaces-separated fingerprint" 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-listname: #{list.email}\nX-SUBSCRIBE: test@example.org 0x#{list.fingerprint.dup.insert(4, ' ')} true false"
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 = raw.setup(list.request_address, list)
subscription = list.subscriptions.where(email: 'test@example.org').first
expect(message.to).to eql(['schleuder@example.org'])
expect(message.to_s).to include("test@example.org has been subscribed")
expect(message.to_s).to match(/Fingerprint:\s+#{list.fingerprint.downcase}/)
expect(message.to_s).to include("Admin? true")
expect(message.to_s).to include("Email-delivery enabled? false")
expect(subscription).to be_present
expect(subscription.fingerprint).to eql(list.fingerprint.downcase)
expect(subscription.admin).to eql(true)
expect(subscription.delivery_enabled).to eql(false)
teardown_list_and_mailer(list)
end
it "x-unsubscribe without argument" do
list = create(:list)
list.subscribe("schleuder@example.org", '59C71FB38AEE22E091C78259D06350440F759BD3', true)
......@@ -233,6 +275,45 @@ describe "user sends keyword" do
end
it "x-set-fingerprint with own email-address and valid, spaces-separated fingerprint" do
list = create(:list)
list.subscribe("schleuder@example.org", '59C71FB38AEE22E091C78259D06350440F759BD3', true)
list.import_key(File.read('spec/fixtures/example_key.txt'))
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-listname: #{list.email}\nX-set-fingerprint: schleuder@example.org C4D6 0F88 3378 9C7C AA44 496F D3FF A661 3AB1 0ECE"
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 = raw.setup(list.request_address, list)
subscription = list.subscriptions.where(email: 'schleuder@example.org').first
expect(message.to).to eql(['schleuder@example.org'])
expect(message.to_s).to include("Fingerprint for schleuder@example.org set to c4d60f8833789c7caa44496fd3ffa6613ab10ece")
expect(subscription).to be_present
expect(subscription.fingerprint).to eql('c4d60f8833789c7caa44496fd3ffa6613ab10ece')
teardown_list_and_mailer(list)
end
it "x-set-fingerprint without email-address and with valid fingerprint" do
list = create(:list)
list.subscribe("schleuder@example.org", '59C71FB38AEE22E091C78259D06350440F759BD3', true)
......
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