[DRE-commits] [schleuder] 01/02: New upstream version 3.0.0~beta15

Georg Faerber georg-alioth-guest at moszumanska.debian.org
Tue Jan 10 23:12:59 UTC 2017


This is an automated email from the git hooks/post-receive script.

georg-alioth-guest pushed a commit to branch master
in repository schleuder.

commit 882a9374fcd6d184d4d35166a0918c546a62204b
Author: Georg Faerber <georg at riseup.net>
Date:   Wed Jan 11 00:11:35 2017 +0100

    New upstream version 3.0.0~beta15
---
 .travis.yml                                      |  2 +-
 CHANGELOG.md                                     | 29 +++++++++++++
 Gemfile.lock                                     |  2 +-
 README.md                                        |  8 ++--
 bin/schleuder                                    |  2 +-
 bin/schleuder-api-daemon                         |  5 +--
 etc/init.d/schleuder-api-daemon                  |  2 +-
 etc/schleuder.cron.weekly                        |  8 ++++
 etc/schleuder.yml                                |  7 +--
 lib/schleuder.rb                                 |  1 +
 lib/schleuder/cli.rb                             | 27 ++++++------
 lib/schleuder/conf.rb                            |  7 +--
 lib/schleuder/gpgme/ctx.rb                       | 51 ++++++++++++++++++++--
 lib/schleuder/gpgme/key.rb                       | 36 ++++++++++++----
 lib/schleuder/list.rb                            |  2 +-
 lib/schleuder/list_builder.rb                    | 43 ++++++++----------
 lib/schleuder/plugins/subscription_management.rb |  6 ++-
 lib/schleuder/runner.rb                          | 13 +++---
 lib/schleuder/version.rb                         |  2 +-
 spec/schleuder/unit/list_builder_spec.rb         | 55 ++++++++++++++++++++++++
 spec/spec_helper.rb                              |  1 +
 21 files changed, 233 insertions(+), 76 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 872b3f4..e7dd7fa 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,7 +6,7 @@ rvm:
 before_install:
   - gem install bundler
   - sudo apt-get -qq update
-  - sudo apt-get install -y gnupg2 libgpgme11-dev libsqlite3-dev
+  - sudo apt-get install -y gnupg2 libgpgme11-dev libsqlite3-dev haveged
 before_script:
   - SCHLEUDER_ENV=test SCHLEUDER_CONFIG=spec/schleuder.yml bundle exec rake db:create db:schema:load
 script:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b38955e..3b36f94 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,35 @@ This project adheres to [Semantic Versioning](http://semver.org/).
 
 The format of this file is based on [Keep a Changelog](http://keepachangelog.com/).
 
+
+## [3.0.0.beta15]
+
+### Changed
+
+* Default `lists_dir` and `listlogs_dir` to `/var/lib/schleuder`.
+* Use '/usr/local/bin' as daemon PATH in schleuder-api-daemon sysvinit
+  script.
+
+### Fixed
+
+* Fix running for fresh lists if `lists_dir` is different from `listlogs_dir`
+  (by creating logfile-basedir, closes Debian bug #850545).
+* Fix error-message from ListBuilder if given email is invalid.
+* Fix checking for sufficient gpg-version (previously '2.1' didn't suffice if
+  '2.1.0' was required).
+
+### Added
+
+* Cron job file to check keys.
+* Show when delivery is disabled for a subscription (in reply to
+  'list-subscriptions'-keyword).
+* Add timeout to default sqlite-config (avoids errors in the case that the
+  DB-file is locked on first attempt).
+* Provide method to call gpg-executable.
+* Also add additional UIDs to generated PGP-keys when using gpg 2.0.
+* Specs for ListBuilder.
+
+
 ## [3.0.0.beta14] / 2016-12-29
 
 ### Fixed
diff --git a/Gemfile.lock b/Gemfile.lock
index 1f8a77f..3cd4226 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,7 +1,7 @@
 PATH
   remote: .
   specs:
-    schleuder (3.0.0.beta14)
+    schleuder (3.0.0.beta15)
       activerecord (~> 4.1)
       mail-gpg (~> 0.3.0)
       rake (~> 10)
diff --git a/README.md b/README.md
index e5d642c..4fa5345 100644
--- a/README.md
+++ b/README.md
@@ -42,15 +42,15 @@ Additionally these **rubygems** are required (will be installed automatically un
 Installing Schleuder
 ------------
 
-1. Download [the gem](https://git.codecoop.org/schleuder/schleuder3/raw/master/gems/schleuder-3.0.0.beta14.gem) and [the OpenPGP-signature](https://git.codecoop.org/schleuder/schleuder3/raw/master/gems/schleuder-3.0.0.beta14.gem.sig) and verify:
+1. Download [the gem](https://git.codecoop.org/schleuder/schleuder3/raw/master/gems/schleuder-3.0.0.beta15.gem) and [the OpenPGP-signature](https://git.codecoop.org/schleuder/schleuder3/raw/master/gems/schleuder-3.0.0.beta15.gem.sig) and verify:
    ```
    gpg --recv-key 0xB3D190D5235C74E1907EACFE898F2C91E2E6E1F3
-   gpg --verify schleuder-3.0.0.beta14.gem.sig
+   gpg --verify schleuder-3.0.0.beta15.gem.sig
    ```
 
 2. If all went well install the gem:
    ```
-   gem install schleuder-3.0.0.beta14.gem
+   gem install schleuder-3.0.0.beta15.gem
    ```
 
 3. Set up schleuder:
@@ -124,4 +124,4 @@ GNU GPL 3.0. Please see [LICENSE.txt](LICENSE.txt).
 Alternative Download
 --------------------
 
-Alternatively to the gem-files you can download the latest release as [a tarball](https://git.codecoop.org/schleuder/schleuder3/raw/master/gems/schleuder-3.0.0.beta14.tar.gz) and [its OpenPGP-signature](https://git.codecoop.org/schleuder/schleuder3/raw/master/gems/schleuder-3.0.0.beta14.tar.gz.sig).
+Alternatively to the gem-files you can download the latest release as [a tarball](https://git.codecoop.org/schleuder/schleuder3/raw/master/gems/schleuder-3.0.0.beta15.tar.gz) and [its OpenPGP-signature](https://git.codecoop.org/schleuder/schleuder3/raw/master/gems/schleuder-3.0.0.beta15.tar.gz.sig).
diff --git a/bin/schleuder b/bin/schleuder
index 342dd2e..9cfaaed 100755
--- a/bin/schleuder
+++ b/bin/schleuder
@@ -7,6 +7,6 @@ begin
   require_relative '../lib/schleuder/cli'
   Schleuder::Cli.start
 rescue => exc
-  $stderr.puts exc.to_s
+  $stderr.puts "Technical Error: #{exc}\n#{exc.backtrace.first}"
   exit 1
 end
diff --git a/bin/schleuder-api-daemon b/bin/schleuder-api-daemon
index 150722c..4044c6d 100755
--- a/bin/schleuder-api-daemon
+++ b/bin/schleuder-api-daemon
@@ -135,8 +135,6 @@ class SchleuderApiDaemon < Sinatra::Base
       text = case obj_or_msg
              when String, Symbol
                obj_or_msg.to_s
-             when Array
-               obj_or_msg.join("\n")
              when ActiveRecord::Base
                obj_or_msg.errors.full_messages
              else
@@ -178,9 +176,10 @@ class SchleuderApiDaemon < Sinatra::Base
 
     post '.json' do
       listname = parsed_body['email']
+      fingerprint = parsed_body['fingerprint']
       adminaddress = parsed_body['adminaddress']
       adminkey = parsed_body['adminkey']
-      list, messages = ListBuilder.new({email: listname}, adminaddress, adminkey).run
+      list, messages = ListBuilder.new({email: listname, fingerprint: fingerprint}, adminaddress, adminkey).run
       if list.nil?
         client_error(messages, 422)
       elsif ! list.valid?
diff --git a/etc/init.d/schleuder-api-daemon b/etc/init.d/schleuder-api-daemon
index 8918bc2..33bc47b 100755
--- a/etc/init.d/schleuder-api-daemon
+++ b/etc/init.d/schleuder-api-daemon
@@ -17,7 +17,7 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin
 . /lib/lsb/init-functions
 
 NAME=schleuder-api-daemon
-DAEMON=/usr/bin/schleuder-api-daemon
+DAEMON=/usr/local/bin/schleuder-api-daemon
 PIDFILE=/var/run/$NAME.pid
 USER=schleuder
 GROUP=schleuder
diff --git a/etc/schleuder.cron.weekly b/etc/schleuder.cron.weekly
new file mode 100644
index 0000000..2e0b3a1
--- /dev/null
+++ b/etc/schleuder.cron.weekly
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+set -e
+test -x /usr/local/bin/schleuder || exit 0
+
+su -s /bin/sh schleuder -c "/usr/local/bin/schleuder check_keys"
+
+exit 0
diff --git a/etc/schleuder.yml b/etc/schleuder.yml
index d2cad54..9b152d2 100644
--- a/etc/schleuder.yml
+++ b/etc/schleuder.yml
@@ -1,8 +1,8 @@
 # Where are the list-directories stored (contain log-files and GnuPG-keyrings).
-lists_dir: /var/schleuder/lists
+lists_dir: /var/lib/schleuder/lists
 
 # Where to write list-logs. The actual log-file will be <lists_logs_base_dir>/<hostname>/<listname>/list.log.
-listlogs_dir: /var/schleuder/lists
+listlogs_dir: /var/lib/schleuder/lists
 
 # Schleuder reads plugins also from this directory.
 plugins_dir: /etc/schleuder/plugins
@@ -25,7 +25,8 @@ smtp_settings:
 database:
   production:
     adapter:  'sqlite3'
-    database: /var/schleuder/db.sqlite
+    database: /var/lib/schleuder/db.sqlite
+    timeout: 5000
 
 # Note: The API-daemon will bind only to localhost if no TLS-cert+keys are available.
 api:
diff --git a/lib/schleuder.rb b/lib/schleuder.rb
index ebec025..d33c271 100644
--- a/lib/schleuder.rb
+++ b/lib/schleuder.rb
@@ -59,6 +59,7 @@ ENV["SCHLEUDER_LIST_DEFAULTS"] ||= '/etc/schleuder/list-defaults.yml'
 ENV["SCHLEUDER_ENV"] ||= 'production'
 ENV["SCHLEUDER_ROOT"] = rootdir.to_s
 
+GPGME::Ctx.set_gpg_path_from_env
 GPGME::Ctx.check_gpg_version
 
 # Require lib for database specified in config.
diff --git a/lib/schleuder/cli.rb b/lib/schleuder/cli.rb
index b172603..26f8f8a 100644
--- a/lib/schleuder/cli.rb
+++ b/lib/schleuder/cli.rb
@@ -74,7 +74,7 @@ module Schleuder
         fatal msg, 2
       end
 
-      [Conf.lists_dir, config_dir].each do |dir|
+      [Conf.lists_dir, Conf.listlogs_dir, config_dir].each do |dir|
         dir = Pathname.new(dir)
         if ! dir.exist?
           begin
@@ -136,19 +136,22 @@ module Schleuder
 
       # Identify list-fingerprint.
       ENV['GNUPGHOME'] = dir.to_s
-      # Save all the keys for later import, we shouldn't change ENV['GNUPGHOME'] later.
-      #allkeys = GPGME::Key.find(:public, '')
-      listkey = GPGME::Key.find(:public, "<#{listname}>")
-      if listkey.size == 1
-        fingerprint = listkey.first.fingerprint
-      else
-        fingerprint = nil
-        error 'Failed to identify fingerprint of GnuPG key for list, you must set it manually to make the list operational!'
+      listkey = GPGME::Key.find(:public, "<#{listname}>").first
+      if listkey.nil?
+        fatal "Failed to identify the list's OpenPGP-key!"
       end
 
       # Create list.
-      # TODO: Check for errors!
-      list, messages = Schleuder::ListBuilder.new({email: listname, fingerprint: fingerprint}).run
+      begin
+        list, messages = Schleuder::ListBuilder.new({email: listname, fingerprint: fingerprint}).run
+      rescue => exc
+        fatal exc
+      end
+      if messages
+        fatal messages.values.join(" - ")
+      elsif list.errors.any?
+        fatal list.errors.full_messages.join(" - ")
+      end
 
       # Set list-options.
       List.configurable_attributes.each do |option|
@@ -223,7 +226,7 @@ Please notify the users and admins of this list of these changes.
         say messages.gsub(' // ', "\n")
       end
     rescue => exc
-      fatal [exc, exc.backtrace.slice(0,2)].join("\n")
+      fatal "#{exc}\n#{exc.backtrace.first}"
     end
 
     no_commands do
diff --git a/lib/schleuder/conf.rb b/lib/schleuder/conf.rb
index 7675ff7..461dd11 100644
--- a/lib/schleuder/conf.rb
+++ b/lib/schleuder/conf.rb
@@ -5,8 +5,8 @@ module Schleuder
     EMAIL_REGEXP = /\A.+ at .+\z/i
 
     DEFAULTS = {
-      'lists_dir' => '/var/schleuder/lists',
-      'listlogs_dir' => '/var/schleuder/lists',
+      'lists_dir' => '/var/lib/schleuder/lists',
+      'listlogs_dir' => '/var/lib/schleuder/lists',
       'plugins_dir' => '/etc/schleuder/plugins',
       'log_level' => 'warn',
       'smtp_settings' => {
@@ -24,7 +24,8 @@ module Schleuder
       'database' => {
         'production' => {
           'adapter' =>  'sqlite3',
-          'database' => '/var/schleuder/db.sqlite'
+          'database' => '/var/lib/schleuder/db.sqlite',
+          'timeout' => 5000
         }
       },
       'api' => {
diff --git a/lib/schleuder/gpgme/ctx.rb b/lib/schleuder/gpgme/ctx.rb
index 234c90a..b86d5ee 100644
--- a/lib/schleuder/gpgme/ctx.rb
+++ b/lib/schleuder/gpgme/ctx.rb
@@ -11,7 +11,7 @@ module GPGME
     def self.set_gpg_path_from_env
       path = ENV['GPGBIN'].to_s
       if ! path.empty?
-        puts "setting gpg to use #{path}"
+        Schleuder.logger.debug "setting gpg to use #{path}"
         GPGME::Engine.set_info(GPGME::PROTOCOL_OpenPGP, path, ENV['GNUPGHOME'])
         if gpg_engine.version.nil?
           $stderr.puts "Error: The binary you specified doesn't provide a gpg-version."
@@ -21,11 +21,10 @@ module GPGME
     end
 
     def self.sufficient_gpg_version?(required)
-      Gem::Version.new(required) < Gem::Version.new(gpg_engine.version)
+      Gem::Version.new(required) <= Gem::Version.new(gpg_engine.version)
     end
 
     def self.check_gpg_version
-      set_gpg_path_from_env
       if ! sufficient_gpg_version?('2.0')
         $stderr.puts "Error: GnuPG version >= 2.0 required.\nPlease install it and/or provide the path to the binary via the environment-variable GPGBIN.\nExample: GPGBIN=/opt/gpg2/bin/gpg ..."
         exit 1
@@ -35,5 +34,51 @@ module GPGME
     def self.gpg_engine
       GPGME::Engine.info.find {|e| e.protocol == GPGME::PROTOCOL_OpenPGP }
     end
+
+    def self.gpgcli(args)
+      exitcode = -1
+      errors = ''
+      output = ''
+      base_cmd = gpg_engine.file_name
+      base_args = "--armor --trust-model always --quiet --no-tty --command-fd 0 --status-fd 1"
+      cmd = [base_cmd, base_args, args].flatten.join(' ')
+      Open3.popen3(cmd) do |stdin, stdout, stderr, thread|
+        if block_given?
+          output = yield(stdin, stdout, stderr)
+        end
+        stdin.close
+        errors = stderr.readlines
+        exitcode = thread.value.exitstatus
+      end
+
+      if output.present?
+        output
+      elsif exitcode > 0
+        errors.join("\n")
+      else
+        nil
+      end
+    rescue Errno::ENOENT
+      raise 'Need gpg in $PATH or in $GPGBIN'
+    end
+
+    def self.gpgcli_expect(args)
+      gpgcli(args) do |stdin, stdout, stderr|
+        counter = 0
+        while line = stdout.gets rescue nil
+          counter += 1
+          if counter > 1042
+            return "Too many input-lines from gpg, something went wrong"
+          end
+          output, error = yield(line.chomp)
+          if output == false
+            return error
+          elsif output
+            stdin.puts output
+          end
+        end
+      end
+      nil
+    end
   end
 end
diff --git a/lib/schleuder/gpgme/key.rb b/lib/schleuder/gpgme/key.rb
index 4bb06d9..39ca979 100644
--- a/lib/schleuder/gpgme/key.rb
+++ b/lib/schleuder/gpgme/key.rb
@@ -28,17 +28,35 @@ module GPGME
       orig_fingerprint.encode(Encoding::US_ASCII)
     end
 
-    def adduid(uid, newuid, homedir)
-      output = ''
-      exitcode = -1
-      # Specifying the key via fingerprint apparently doesn't work.
-      cmd = "gpg --homedir '#{homedir}' --quick-adduid #{uid} '#{uid} <#{newuid}>'"
-      Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
-        output = stdout_err.readlines.join
-        exitcode = wait_thr.value
+    def adduid(uid, email)
+      # This block can be deleted once we cease to support gnupg 2.0.
+      if ! GPGME::Ctx.sufficient_gpg_version?('2.1.4')
+        return adduid_expect(uid, email)
       end
 
-      [exitcode.to_i, output.to_s]
+      # Specifying the key via fingerprint apparently doesn't work.
+      GPGME::Ctx.gpgcli("--quick-adduid #{uid} '#{uid} <#{email}>'")
+    end
+
+    # This method can be deleted once we cease to support gnupg 2.0.
+    def adduid_expect(uid, email)
+      GPGME::Ctx.gpgcli_expect("--allow-freeform-uid --edit-key '#{self.fingerprint}' adduid") do |line|
+        case line.chomp
+        when /keygen.name/
+          uid
+        when /keygen.email/
+          email
+        when /keygen.comment/
+          ''
+        when /keyedit.prompt/
+          "save"
+        when /USERID_HINT|GOT_IT|GOOD_PASSPHRASE/
+          nil
+        else
+          [false, "Unexpected line: #{line}"]
+        end
+      end
     end
+
   end
 end
diff --git a/lib/schleuder/list.rb b/lib/schleuder/list.rb
index 4c9fffa..c254d02 100644
--- a/lib/schleuder/list.rb
+++ b/lib/schleuder/list.rb
@@ -291,7 +291,7 @@ module Schleuder
         Schleuder.logger.info "Deleted listdir"
       else
         # Don't use list-logger here — if the list-dir isn't present we can't log to it!
-        Schleuder.logger.info "Couldn't delete listdir, directly not present"
+        Schleuder.logger.info "Couldn't delete listdir, directory not present"
       end
       true
     rescue => exc
diff --git a/lib/schleuder/list_builder.rb b/lib/schleuder/list_builder.rb
index 6850475..f9599ce 100644
--- a/lib/schleuder/list_builder.rb
+++ b/lib/schleuder/list_builder.rb
@@ -6,7 +6,6 @@ module Schleuder
       @fingerprint = list_attributes[:fingerprint]
       @adminemail = adminemail
       @adminkey = adminkey
-      @messages = []
     end
 
     def read_default_settings
@@ -23,14 +22,17 @@ module Schleuder
       Schleuder.logger.info "Building new list"
 
       if @listname.blank? || ! @listname.match(Conf::EMAIL_REGEXP)
-        return [nil, "Given 'listname' is not a valid email address."]
+        return [nil, {'email' => ["'#{@listname}' is not a valid email address"]}]
       end
 
       settings = read_default_settings.merge(@list_attributes)
       list = List.new(settings)
 
       @list_dir = list.listdir
-      create_or_test_list_dir
+      create_or_test_dir(@list_dir)
+      # In case listlogs_dir != lists_dir we have to create the basedir of the
+      # list's log-file.
+      create_or_test_dir(File.dirname(list.logfile))
 
       if list.fingerprint.blank?
         list_key = gpg.keys("<#{list.email}>").first
@@ -70,7 +72,7 @@ module Schleuder
         end
       end
 
-      [list, @messages]
+      list
     end
 
     def gpg
@@ -99,23 +101,14 @@ module Schleuder
 
     def adduids(list, key)
       # Add UIDs for -owner and -request.
-      gpg_version = `gpg --version`.lines.first.split.last
-      # Gem::Version knows that e.g. ".10" is higher than ".4", String doesn't.
-      if Gem::Version.new(gpg_version) < Gem::Version.new("2.1.4")
-        string = "Couldn't add additional UIDs to the list's key automatically (GnuPG version >= 2.1.4 is required for that, using 'gpg' in PATH).\nPlease add these UIDs to the list's key manually: #{list.request_address}, #{list.owner_address}."
-        # Don't add to errors because then the list isn't saved.
-        @messages << Errors::KeyAdduidFailed.new(string).message
-        return false
-      end
-
       [list.request_address, list.owner_address].each do |address|
-        err, string = key.adduid(list.email, address, list.listdir)
-        if err > 0
-          raise Errors::KeyAdduidFailed.new(string)
+        err = key.adduid(list.email, address)
+        if err.present?
+          raise err
         end
       end
-    rescue Errno::ENOENT
-      raise Errors::KeyAdduidFailed.new('Need gpg in $PATH')
+    rescue => exc
+      raise Errors::KeyAdduidFailed.new(exc.to_s)
     end
 
     def key_params(list)
@@ -134,17 +127,17 @@ module Schleuder
       "
     end
 
-    def create_or_test_list_dir
-      if File.exists?(@list_dir)
-        if ! File.directory?(@list_dir)
-          raise Errors::ListdirProblem.new(@list_dir, :not_a_directory)
+    def create_or_test_dir(dir)
+      if File.exists?(dir)
+        if ! File.directory?(dir)
+          raise Errors::ListdirProblem.new(dir, :not_a_directory)
         end
 
-        if ! File.writable?(@list_dir)
-          raise Errors::ListdirProblem.new(@list_dir, :not_writable)
+        if ! File.writable?(dir)
+          raise Errors::ListdirProblem.new(dir, :not_writable)
         end
       else
-        FileUtils.mkdir_p(@list_dir)
+        FileUtils.mkdir_p(dir)
       end
     end
 
diff --git a/lib/schleuder/plugins/subscription_management.rb b/lib/schleuder/plugins/subscription_management.rb
index 7740b7a..5f9359e 100644
--- a/lib/schleuder/plugins/subscription_management.rb
+++ b/lib/schleuder/plugins/subscription_management.rb
@@ -70,7 +70,11 @@ module Schleuder
       out << subs.map do |subscription|
         # Fingerprints are at most 40 characters long, and lines shouldn't
         # exceed 80 characters if possible.
-        "#{subscription.email.rjust(37)} 0x#{subscription.fingerprint}"
+        s = "#{subscription.email}\t0x#{subscription.fingerprint}"
+        if ! subscription.delivery_enabled?
+          s << "\tDelivery disabled!"
+        end
+        s
       end
     end
 
diff --git a/lib/schleuder/runner.rb b/lib/schleuder/runner.rb
index 530ceb2..089e86a 100644
--- a/lib/schleuder/runner.rb
+++ b/lib/schleuder/runner.rb
@@ -94,13 +94,6 @@ module Schleuder
         return log_and_return(Errors::ListNotFound.new(recipient))
       end
 
-      # Check basic sanity of list.
-      %w[fingerprint key secret_key admins].each do |attrib|
-        if @list.send(attrib).blank?
-          return log_and_return(Errors::ListPropertyMissing.new(attrib))
-        end
-      end
-
       # Check neccessary permissions of crucial files.
       if ! File.exist?(@list.listdir)
         return log_and_return(Errors::ListdirProblem.new(@list.listdir, :not_existing))
@@ -116,6 +109,12 @@ module Schleuder
         end
       end
 
+      # Check basic sanity of list.
+      %w[fingerprint key secret_key admins].each do |attrib|
+        if @list.send(attrib).blank?
+          return log_and_return(Errors::ListPropertyMissing.new(attrib))
+        end
+      end
 
       # Set locale
       if I18n.available_locales.include?(@list.language.to_sym)
diff --git a/lib/schleuder/version.rb b/lib/schleuder/version.rb
index 4b62400..f6be2f2 100644
--- a/lib/schleuder/version.rb
+++ b/lib/schleuder/version.rb
@@ -1,3 +1,3 @@
 module Schleuder
-  VERSION = '3.0.0.beta14'
+  VERSION = '3.0.0.beta15'
 end
diff --git a/spec/schleuder/unit/list_builder_spec.rb b/spec/schleuder/unit/list_builder_spec.rb
new file mode 100644
index 0000000..40d7040
--- /dev/null
+++ b/spec/schleuder/unit/list_builder_spec.rb
@@ -0,0 +1,55 @@
+require "spec_helper"
+
+describe Schleuder::ListBuilder do
+
+  it "creates a new, valid list" do
+    listname = "list-#{rand}@example.org"
+    adminaddress = 'schleuder2 at example.org'
+    adminkey = File.read('spec/fixtures/example_key.txt')
+    list, messages = ListBuilder.new({email: listname, fingerprint: nil}, adminaddress, adminkey).run
+    expect(list).to be_an_instance_of Schleuder::List
+    expect(list).to be_valid
+    expect(messages).to be_blank
+  end
+
+  it "returns an error-message if given an invalid email-address" do
+    listname = "list-#{rand}"
+    adminaddress = 'schleuder2 at example.org'
+    adminkey = File.read('spec/fixtures/example_key.txt')
+    list, messages = ListBuilder.new({email: listname, fingerprint: nil}, adminaddress, adminkey).run
+    expect(list).to be_nil
+    expect(messages).to be_an_instance_of Hash
+    expect(messages.keys).to eq ['email']
+    expect(messages.values).to be_present
+  end
+
+  it "creates a listdir for the list" do
+    listname = "list-#{rand}@example.org"
+    adminaddress = 'schleuder2 at example.org'
+    adminkey = File.read('spec/fixtures/example_key.txt')
+    list, _ = ListBuilder.new({email: listname, fingerprint: nil}, adminaddress, adminkey).run
+    expect(File.directory?(list.listdir)).to be true
+  end
+
+  it "creates a list-key with all required UIDs" do
+    listname = "list-#{rand}@example.org"
+    adminaddress = 'schleuder2 at example.org'
+    adminkey = File.read('spec/fixtures/example_key.txt')
+    list, _ = ListBuilder.new({email: listname, fingerprint: nil}, adminaddress, adminkey).run
+    uids = list.key.uids.map(&:email)
+    expect(uids).to include(list.email)
+    expect(uids).to include(list.request_address)
+    expect(uids).to include(list.owner_address)
+  end
+
+  it "subscribes the adminaddress and imports the adminkey" do
+    listname = "list-#{rand}@example.org"
+    adminaddress = 'schleuder2 at example.org'
+    adminkey = File.read('spec/fixtures/example_key.txt')
+    list, _ = ListBuilder.new({email: listname, fingerprint: nil}, adminaddress, adminkey).run
+    subscription_emails = list.subscriptions.map(&:email)
+    keys_emails = list.keys.map(&:uids).flatten.map(&:email)
+    expect(subscription_emails).to eq [adminaddress]
+    expect(keys_emails).to include(adminaddress)
+  end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 067938f..e415cd8 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,5 +1,6 @@
 ENV['SCHLEUDER_ENV'] ||= 'test'
 ENV['SCHLEUDER_CONFIG'] = 'spec/schleuder.yml'
+ENV["SCHLEUDER_LIST_DEFAULTS"] = "etc/list-defaults.yml"
 require 'bundler/setup'
 Bundler.setup
 require 'schleuder'

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/schleuder.git



More information about the Pkg-ruby-extras-commits mailing list