merge sync IOSAD-111
authorDirk Zimmermann <dz@pep.security>
Tue, 30 Apr 2019 07:49:02 +0200
branchIOSAD-111
changeset 3582f7ecbde8ba3a
parent 3579 de4c1305ff46
parent 3580 7c757957849b
child 3613 f330f7da89c5
merge sync
default.conf
     1.1 --- a/Makefile.conf	Mon Apr 29 16:21:38 2019 +0200
     1.2 +++ b/Makefile.conf	Tue Apr 30 07:49:02 2019 +0200
     1.3 @@ -273,6 +273,10 @@
     1.4  
     1.5  
     1.6  ######### Misc #########
     1.7 +# FIXME Maybe include these variables here.
     1.8 +# Check how they are used throughout the project before setting them here
     1.9 +#LLDB_BIN
    1.10 +
    1.11  # Add this for running tests in debugger
    1.12  #TEST_DEBUGGER=lldb --batch -o r
    1.13  
     2.1 --- a/default.conf	Mon Apr 29 16:21:38 2019 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,280 +0,0 @@
     2.4 -# Copyright 2017, pEp Foundation
     2.5 -# This file is part of pEpEngine
     2.6 -# This file may be used under the terms of the GNU General Public License version 3
     2.7 -# see LICENSE.txt
     2.8 -
     2.9 -# See `doc/build-<your platform>.md` for documentation on how to build, and customize your build.
    2.10 -
    2.11 -# This file sets all the make variables that allow you to customize a build.
    2.12 -# There are 4 ways in which you can customize your build:
    2.13 -# 1) Edit the variable assignments in this file (this is a tracked file, so your repository will be dirty)
    2.14 -# 2) Edit the variable assignments in `Makefile.conf` (which is a tracked file, so your repository will be dirty)
    2.15 -# 3) Create `local.conf` and fill it with variable assignments.
    2.16 -# 4) Set the environment variable `BUILD_CONFIG` to an absolute path.
    2.17 -#    The variable assignments found in the make file at the path indicated by `BUILD_CONFIG` will be evaluated.
    2.18 -# Customization options are applied in the order given above. Later variable assignments take precedence over earlier ones.
    2.19 -# It is possible to use multiple variants simultaniously.
    2.20 -# If nothing is changed according to these 4 methods, a default configuration for your platform (specified below) will be used for the build.
    2.21 -
    2.22 -
    2.23 -######### Header #########
    2.24 -HERE:=$(dir $(lastword $(MAKEFILE_LIST)))
    2.25 -
    2.26 -
    2.27 -######### General #########
    2.28 -# To use (only) system libraries, set all the *_INC and *_LIB variables to the empty string.
    2.29 -# All the *_INC and *_LIB variables are command line flags, not paths.
    2.30 -# Thus, all *_INC variables' values must start with "-I", and all *_LIB variables' values must start with "-L".
    2.31 -
    2.32 -BUILD_ON:=$(shell uname)
    2.33 -
    2.34 -# This variable specifies the platform that the engine should be cross-compiled for.
    2.35 -BUILD_FOR=$(BUILD_ON)
    2.36 -
    2.37 -# Cross-compiling is currently not supported.
    2.38 -# Maybe you can hack something with `local.conf`.
    2.39 -ifneq ($(BUILD_ON),$(BUILD_FOR))
    2.40 -    $(error I don't know how to build for $(BUILD_FOR) on $(BUILD_ON).)
    2.41 -endif
    2.42 -
    2.43 -# Installation path prefix for libraries and binaries, except for system.db
    2.44 -PREFIX=$(HOME)
    2.45 -
    2.46 -# Installation path for system.db
    2.47 -SYSTEM_DB=/usr/local/share/pEp/system.db
    2.48 -
    2.49 -# Filename of the pEpEngine library
    2.50 -ifeq ($(BUILD_FOR),Linux)
    2.51 -    TARGET=libpEpEngine.so
    2.52 -else ifeq ($(BUILD_FOR),Darwin)
    2.53 -    TARGET=libpEpEngine.dylib
    2.54 -endif
    2.55 -
    2.56 -# If empty, create a release build.
    2.57 -# Otherwise, create a debug build.
    2.58 -# This variable is ineffective in your local.conf file.
    2.59 -DEBUG=placeholder
    2.60 -
    2.61 -# If empty, suppress compiler warnings.
    2.62 -# Otherwise, print warnings.
    2.63 -# This variable is ineffective in your local.conf file.
    2.64 -WARN=placeholder
    2.65 -
    2.66 -
    2.67 -######### C and C++ #########
    2.68 -TARGET_ARCH=
    2.69 -# The following two variables will be appended to.
    2.70 -# You can thus not set them to a fixed value here.
    2.71 -ifeq ($(BUILD_FOR),Linux)
    2.72 -    LDFLAGS=
    2.73 -else ifeq ($(BUILD_FOR),Darwin)
    2.74 -    # "-bind_at_load" helps find symbol resolution errors faster
    2.75 -    LDFLAGS=-bind_at_load
    2.76 -endif
    2.77 -
    2.78 -LDLIBS=
    2.79 -
    2.80 -
    2.81 -######### C #########
    2.82 -ifeq ($(BUILD_FOR),Linux)
    2.83 -    CC=gcc -std=c99 -pthread
    2.84 -else ifeq ($(BUILD_FOR),Darwin)
    2.85 -    # clang issues a warning when "-pthread" is used for linking.
    2.86 -    # So, include it in CFLAGS, and not in CC
    2.87 -    CC=clang -std=c99
    2.88 -endif
    2.89 -
    2.90 -ifeq ($(BUILD_FOR),Linux)
    2.91 -    CFLAGS=-fPIC -fstrict-aliasing -fdiagnostics-color=always
    2.92 -else ifeq ($(BUILD_FOR),Darwin)
    2.93 -    CFLAGS=-pthread -fPIC -fstrict-aliasing -fcolor-diagnostics
    2.94 -endif
    2.95 -
    2.96 -CPPFLAGS=
    2.97 -
    2.98 -# The flag -DNDEBUG will always be removed from CFLAGS for compiling tests.
    2.99 -# The tests do not work properly, if compiled with -DNDEBUG
   2.100 -ifeq ($(BUILD_FOR),Linux)
   2.101 -    ifdef WARN
   2.102 -        CFLAGS+= -Wall -pedantic -Wstrict-aliasing=3
   2.103 -    else
   2.104 -        CFLAGS+= -w
   2.105 -    endif
   2.106 -    ifdef DEBUG
   2.107 -        CFLAGS+= -g -ggdb -DDEBUG_ERRORSTACK
   2.108 -    else
   2.109 -        CFLAGS+= -O3 -DNDEBUG
   2.110 -    endif
   2.111 -else ifeq ($(BUILD_FOR),Darwin)
   2.112 -    ifdef WARN
   2.113 -        # FIXME Remove 'no-extended-offsetof' after ENGINE-236 is closed.
   2.114 -        CFLAGS+= -Wall -pedantic -Wno-extended-offsetof
   2.115 -    else
   2.116 -        CFLAGS+= -w
   2.117 -    endif
   2.118 -    ifdef DEBUG
   2.119 -        CFLAGS+= -O0 -g -DDEBUG_ERRORSTACK
   2.120 -    else
   2.121 -        CFLAGS+= -O3 -DNDEBUG
   2.122 -    endif
   2.123 -endif
   2.124 -
   2.125 -# Additional CFLAGS used for compiling ASN1C-generated code
   2.126 -ifeq ($(BUILD_FOR),Linux)
   2.127 -    # The '_DEFAULT_SOURCE' feature test macro is required to suppress the warning
   2.128 -    #   _BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE
   2.129 -    # otherwise printed during the compilation of every asn1c-generated C file.
   2.130 -    # It's a glibc specific warning, only present in few versions around ~2.19.
   2.131 -    # See https://lwn.net/Articles/590381/ for a discussion.
   2.132 -    CFLAGS_GENERATED=-D_DEFAULT_SOURCE
   2.133 -else ifeq ($(BUILD_FOR),Darwin)
   2.134 -    CFLAGS_GENERATED=
   2.135 -endif
   2.136 -
   2.137 -
   2.138 -######### C++ #########
   2.139 -ifeq ($(BUILD_FOR),Linux)
   2.140 -    CXX=g++ -std=gnu++11 -pthread
   2.141 -else ifeq ($(BUILD_FOR),Darwin)
   2.142 -    # clang issues a warning when "-pthread" is used for linking. So, include it in CXXFLAGS, and not in CXX
   2.143 -    CXX=clang -std=c++11
   2.144 -endif
   2.145 -
   2.146 -# The flag -DNDEBUG will always be removed from CXXFLAGS for compiling tests.
   2.147 -# The tests do not work properly, if compiled with -DNDEBUG
   2.148 -ifeq ($(BUILD_FOR),Linux)
   2.149 -    CXXFLAGS=-fdiagnostics-color=always -I../src -I../asn.1 $(ETPAN_INC)
   2.150 -    ifdef WARN
   2.151 -        CXXFLAGS+=
   2.152 -    else
   2.153 -        CXXFLAGS+= -w
   2.154 -    endif
   2.155 -    ifdef DEBUG
   2.156 -        CXXFLAGS+= -g -ggdb
   2.157 -    else
   2.158 -        CXXFLAGS+= -O3 -DNDEBUG
   2.159 -    endif
   2.160 -else ifeq ($(BUILD_FOR),Darwin)
   2.161 -    CXXFLAGS=-pthread -fcolor-diagnostics -I../src -I../asn.1 $(ETPAN_INC)
   2.162 -    ifdef WARN
   2.163 -        CXXFLAGS+=
   2.164 -    else
   2.165 -        CXXFLAGS+= -w
   2.166 -    endif
   2.167 -    ifdef DEBUG
   2.168 -        CXXFLAGS+= -O0 -g
   2.169 -    else
   2.170 -        CXXFLAGS+= -O3 -DNDEBUG
   2.171 -    endif
   2.172 -endif
   2.173 -
   2.174 -
   2.175 -######### YML2 #########
   2.176 -YML2_PATH=$(HOME)/yml2
   2.177 -
   2.178 -YML2_PROC=$(YML2_PATH)/yml2proc
   2.179 -
   2.180 -YML2_OPTS=--encoding=utf8
   2.181 -
   2.182 -
   2.183 -######### asn1c #########
   2.184 -# asn1c binary
   2.185 -ASN1C=asn1c
   2.186 -
   2.187 -# asn1c include search flag
   2.188 -ASN1C_INC=-I$(PREFIX)/include
   2.189 -
   2.190 -
   2.191 -######### libetpan #########
   2.192 -# libetpan library search flag
   2.193 -ETPAN_LIB=-L$(PREFIX)/lib
   2.194 -
   2.195 -# libetpan include search flag
   2.196 -ETPAN_INC=-I$(PREFIX)/include
   2.197 -
   2.198 -
   2.199 -######### sqlite3 #########
   2.200 -# If empty (or undefined), compile sqlite3 from the sources shipped with the pEp distribution.
   2.201 -# Otherwise, use an sqlite3 implementation found in the OS's include/library paths.
   2.202 -SQLITE3_FROM_OS=placeholder
   2.203 -
   2.204 -
   2.205 -######### OpenPGP #########
   2.206 -# Path of GPG binary
   2.207 -# gpgconf is not available for old version of GPG, for example GPG 2.0.30. Override this variable, if you compile the engine for such an old version.
   2.208 -GPG_CMD:=$(shell gpgconf --list-components | awk -F: '/^gpg:/ { print $$3; exit 0; }')
   2.209 -
   2.210 -# Selects OpenPGP implementation. must be either `GPG` or `NETPGP` or `SEQUOIA`
   2.211 -OPENPGP=GPG
   2.212 -
   2.213 -# Path of libGPGME binary
   2.214 -ifeq ($(BUILD_FOR),Linux)
   2.215 -    LIBGPGME=libgpgme.so.11
   2.216 -else ifeq ($(BUILD_FOR),Darwin)
   2.217 -    LIBGPGME=libgpgme.11.dylib
   2.218 -endif
   2.219 -
   2.220 -# libGPGME library search flag
   2.221 -ifeq ($(BUILD_FOR),Linux)
   2.222 -    GPGME_LIB=
   2.223 -else ifeq ($(BUILD_FOR),Darwin)
   2.224 -    GPGME_LIB=-L$(HOME)/lib
   2.225 -endif
   2.226 -
   2.227 -# libGPGME include search flag
   2.228 -ifeq ($(BUILD_FOR),Linux)
   2.229 -    GPGME_INC=
   2.230 -else ifeq ($(BUILD_FOR),Darwin)
   2.231 -    GPGME_INC=-I$(HOME)/include
   2.232 -endif
   2.233 -
   2.234 -# NETPGP library search flag
   2.235 -NETPGP_LIB=
   2.236 -#NETPGP_LIB=-L$(PREFIX)/lib
   2.237 -
   2.238 -# libGPGME include search flag
   2.239 -NETPGP_INC=
   2.240 -#NETPGP_INC=-I$(PREFIX)/include
   2.241 -
   2.242 -SEQUOIA_CFLAGS=$(shell pkg-config --cflags-only-other sequoia-openpgp)
   2.243 -SEQUOIA_LDFLAGS=$(shell pkg-config --libs-only-l --libs-only-other sequoia-openpgp)
   2.244 -SEQUOIA_LIB=$(shell pkg-config --libs-only-L sequoia-openpgp)
   2.245 -SEQUOIA_INC=$(shell pkg-config --cflags-only-I sequoia-openpgp)
   2.246 -
   2.247 -
   2.248 -######### OpenPGP #########
   2.249 -# CppUnit library search flag
   2.250 -CPPUNIT_LIB=
   2.251 -#CPPUNIT_LIB=-L$(HOME)/local/lib
   2.252 -
   2.253 -# CppUnit include search flag
   2.254 -CPPUNIT_INC=
   2.255 -#CPPUNIT_INC=-I$(HOME)/local/inc
   2.256 -
   2.257 -
   2.258 -######### Engine internals #########
   2.259 -# C macros (not environment variables) that can be overridden:
   2.260 -# DEFAULT_KEYSERVER - string with default keyserver
   2.261 -# CRASHDUMP_DEFAULT_LINES - number of log lines to deliver for crashdumps
   2.262 -# Example:
   2.263 -#    EXTRA_MACROS=-DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23
   2.264 -EXTRA_MACROS=
   2.265 -
   2.266 -
   2.267 -######### Misc #########
   2.268 -# FIXME Maybe include these variables here.
   2.269 -# Check how they are used throughout the project before setting them here
   2.270 -#LLDB_BIN
   2.271 -
   2.272 -
   2.273 -######### Footer #########
   2.274 -include $(HERE)/Makefile.conf
   2.275 -
   2.276 --include $(HERE)/local.conf
   2.277 -
   2.278 -ifdef BUILD_CONFIG
   2.279 -    include $(BUILD_CONFIG)
   2.280 -endif
   2.281 -
   2.282 -# YML_PATH is needed in the environment of every call to a program of the YML2 distribution
   2.283 -export YML_PATH=$(YML2_PATH)
     3.1 --- a/doc/build-debian.md	Mon Apr 29 16:21:38 2019 +0200
     3.2 +++ b/doc/build-debian.md	Tue Apr 30 07:49:02 2019 +0200
     3.3 @@ -64,11 +64,11 @@
     3.4  mkdir ~/code/pep-engine/build
     3.5  ~~~
     3.6  
     3.7 -Edit the build configuration to your needs in `Makefile.conf`, or create a `local.conf` that sets any of the make variables documented in `Makefile.conf`. All the default values for the build configuration variables on each platform are documented in `default.conf`.
     3.8 +Edit the build configuration to your needs in `Makefile.conf`, or create a `local.conf` that sets any of the make variables documented in `Makefile.conf`. All the default values for the build configuration variables on each platform are documented in `Makefile.conf`.
     3.9  
    3.10  If a dependency is not found in your system's default include or library paths, you will have to specify the according paths in a make variable. Typically, this has to be done at least for YML2, libetpan and asn1c.
    3.11  
    3.12 -For a more detailed explanation of the mechanics of these build configuration files, and overriding defaults, see the comments in `default.conf`.
    3.13 +For a more detailed explanation of the mechanics of these build configuration files, and overriding defaults, see the comments in `Makefile.conf`.
    3.14  
    3.15  Below is a sample `./local.conf` file, for orientation.
    3.16  
     4.1 --- a/doc/build-macos.md	Mon Apr 29 16:21:38 2019 +0200
     4.2 +++ b/doc/build-macos.md	Tue Apr 30 07:49:02 2019 +0200
     4.3 @@ -105,11 +105,11 @@
     4.4  mkdir ~/code/pep-engine/build
     4.5  ~~~
     4.6  
     4.7 -Edit the build configuration to your needs in `Makefile.conf`, or create a `local.conf` that sets any of the make variables documented in `Makefile.conf`. All the default values for the build configuration variables on each platform are documented in `default.conf`.
     4.8 +Edit the build configuration to your needs in `Makefile.conf`, or create a `local.conf` that sets any of the make variables documented in `Makefile.conf`. All the default values for the build configuration variables on each platform are documented in `Makefile.conf`.
     4.9  
    4.10  If a dependency is not found in your system's default include or library paths, you will have to specify the according paths in a make variable. Typically, this has to be done at least for YML2, and libetpan.
    4.11  
    4.12 -For a more detailed explanation of the mechanics of these build configuration files, and overriding defaults, see the comments in `default.conf`.
    4.13 +For a more detailed explanation of the mechanics of these build configuration files, and overriding defaults, see the comments in `Makefile.conf`.
    4.14  
    4.15  Below is a sample `./local.conf` file, for orientation.
    4.16  
     5.1 --- a/src/pgp_sequoia.c	Mon Apr 29 16:21:38 2019 +0200
     5.2 +++ b/src/pgp_sequoia.c	Tue Apr 30 07:49:02 2019 +0200
     5.3 @@ -1587,6 +1587,11 @@
     5.4      if (sqlite_result != SQLITE_OK)
     5.5          return PEP_CANNOT_DELETE_KEY;
     5.6  
     5.7 +    sqlite_result = sqlite3_changes(session->key_db);
     5.8 +    assert(sqlite_result >= 0 && sqlite_result < 2);
     5.9 +    if (sqlite_result < 1)
    5.10 +        return PEP_KEY_NOT_FOUND;
    5.11 +
    5.12      return PEP_STATUS_OK;
    5.13  }
    5.14  
     6.1 --- a/sync/sync.fsm	Mon Apr 29 16:21:38 2019 +0200
     6.2 +++ b/sync/sync.fsm	Tue Apr 30 07:49:02 2019 +0200
     6.3 @@ -225,6 +225,7 @@
     6.4  
     6.5          state NewGroupFirst {
     6.6              on Init {
     6.7 +                do closeTransaction;
     6.8                  do prepareOwnKeys;
     6.9                  send OwnKeysFirst; // we're not grouped yet, this is our own keys
    6.10              }
    6.11 @@ -243,6 +244,7 @@
    6.12  
    6.13          state NewGroupSecond {
    6.14              on Init {
    6.15 +                do closeTransaction;
    6.16                  do prepareOwnKeys;
    6.17                  send OwnKeysSecond; // we're not grouped yet, this is our own keys
    6.18              }
    6.19 @@ -360,11 +362,12 @@
    6.20  
    6.21          state JoinGroup {
    6.22              on Init {
    6.23 +                do closeTransaction;
    6.24                  do prepareOwnKeys;
    6.25 -                send GroupKeys;
    6.26 +                send OwnKeys;
    6.27              }
    6.28  
    6.29 -            on GroupKeys if sameTransaction {
    6.30 +            on GroupKeys {
    6.31                  do saveGroupKeys;
    6.32                  do receivedKeysAreGroupKeys;
    6.33                  do showDeviceAdded;
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/include/DeleteKeyTests.h	Tue Apr 30 07:49:02 2019 +0200
     7.3 @@ -0,0 +1,41 @@
     7.4 +// This file is under GNU General Public License 3.0
     7.5 +// see LICENSE.txt
     7.6 +
     7.7 +#ifndef DELETE_KEY_H
     7.8 +#define DELETE_KEY_H
     7.9 +
    7.10 +#include <string>
    7.11 +#include "EngineTestIndividualSuite.h"
    7.12 +
    7.13 +using namespace std;
    7.14 +
    7.15 +class DeleteKeyTests : public EngineTestIndividualSuite {
    7.16 +    public:
    7.17 +        DeleteKeyTests(string test_suite, string test_home_dir);
    7.18 +
    7.19 +        static constexpr const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
    7.20 +        static constexpr const char* bob_fpr = "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39";
    7.21 +        static constexpr const char* carol_fpr = "8DD4F5827B45839E9ACCA94687BDDFFB42A85A42";
    7.22 +        static constexpr const char* dave_fpr = "E8AC9779A2D13A15D8D55C84B049F489BB5BCCF6";
    7.23 +        static constexpr const char* erin_fpr = "1B0E197E8AE66277B8A024B9AEA69F509F8D7CBA";
    7.24 +        static constexpr const char* fenris_fpr = "0969FA229DF21C832A64A04711B1B9804F3D2900";
    7.25 +
    7.26 +        static const string alice_user_id;
    7.27 +        static const string bob_user_id;    
    7.28 +        static const string carol_user_id;
    7.29 +        static const string dave_user_id;
    7.30 +        static const string erin_user_id;
    7.31 +        static const string fenris_user_id;
    7.32 +
    7.33 +    private:
    7.34 +        void import_test_keys();
    7.35 +        
    7.36 +        void check_delete_single_pubkey();
    7.37 +        void check_delete_pub_priv_keypair();
    7.38 +        void check_delete_multiple_keys();
    7.39 +        void check_delete_all_keys();
    7.40 +        void check_delete_key_not_found();
    7.41 +        void check_delete_empty_keyring();        
    7.42 +};
    7.43 +
    7.44 +#endif
     8.1 --- a/test/src/SuiteMaker.cc	Mon Apr 29 16:21:38 2019 +0200
     8.2 +++ b/test/src/SuiteMaker.cc	Tue Apr 30 07:49:02 2019 +0200
     8.3 @@ -59,6 +59,7 @@
     8.4  #include "StringpairListTests.h"
     8.5  #include "EncryptForIdentityTests.h"
     8.6  #include "KeyResetMessageTests.h"
     8.7 +#include "DeleteKeyTests.h"
     8.8  #include "KeyAttachmentTests.h"
     8.9  #include "TrustManipulationTests.h"
    8.10  #include "SyncTests.h"
    8.11 @@ -113,6 +114,7 @@
    8.12      "StringpairListTests",
    8.13      "EncryptForIdentityTests",
    8.14      "KeyResetMessageTests",
    8.15 +    "DeleteKeyTests",
    8.16      "KeyAttachmentTests",
    8.17      "TrustManipulationTests",
    8.18      "SyncTests",
    8.19 @@ -120,7 +122,7 @@
    8.20  };
    8.21  
    8.22  // This file is generated, so magic constants are ok.
    8.23 -int SuiteMaker::num_suites = 51;
    8.24 +int SuiteMaker::num_suites = 52;
    8.25  
    8.26  void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
    8.27      if (strcmp(test_class_name, "MimeTests") == 0)
    8.28 @@ -217,6 +219,8 @@
    8.29          *test_suite = new EncryptForIdentityTests(test_class_name, test_home);
    8.30      else if (strcmp(test_class_name, "KeyResetMessageTests") == 0)
    8.31          *test_suite = new KeyResetMessageTests(test_class_name, test_home);
    8.32 +    else if (strcmp(test_class_name, "DeleteKeyTests") == 0)
    8.33 +        *test_suite = new DeleteKeyTests(test_class_name, test_home);
    8.34      else if (strcmp(test_class_name, "KeyAttachmentTests") == 0)
    8.35          *test_suite = new KeyAttachmentTests(test_class_name, test_home);
    8.36      else if (strcmp(test_class_name, "TrustManipulationTests") == 0)
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/src/engine_tests/DeleteKeyTests.cc	Tue Apr 30 07:49:02 2019 +0200
     9.3 @@ -0,0 +1,340 @@
     9.4 +// This file is under GNU General Public License 3.0
     9.5 +// see LICENSE.txt
     9.6 +
     9.7 +#include <stdlib.h>
     9.8 +#include <string>
     9.9 +#include <cpptest.h>
    9.10 +
    9.11 +#include "pEpEngine.h"
    9.12 +#include "test_util.h"
    9.13 +
    9.14 +#include "EngineTestIndividualSuite.h"
    9.15 +#include "DeleteKeyTests.h"
    9.16 +
    9.17 +using namespace std;
    9.18 +
    9.19 +const string DeleteKeyTests::alice_user_id = PEP_OWN_USERID;
    9.20 +const string DeleteKeyTests::bob_user_id = "BobId";    
    9.21 +const string DeleteKeyTests::carol_user_id = "carolId";
    9.22 +const string DeleteKeyTests::dave_user_id = "DaveId";
    9.23 +const string DeleteKeyTests::erin_user_id = "ErinErinErin";
    9.24 +const string DeleteKeyTests::fenris_user_id = "BadWolf";
    9.25 +
    9.26 +
    9.27 +DeleteKeyTests::DeleteKeyTests(string suitename, string test_home_dir) :
    9.28 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
    9.29 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeleteKeyTests::check_delete_single_pubkey"),
    9.30 +                                                                      static_cast<Func>(&DeleteKeyTests::check_delete_single_pubkey)));
    9.31 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeleteKeyTests::check_delete_pub_priv_keypair"),
    9.32 +                                                                      static_cast<Func>(&DeleteKeyTests::check_delete_pub_priv_keypair)));
    9.33 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeleteKeyTests::check_delete_multiple_keys"),
    9.34 +                                                                      static_cast<Func>(&DeleteKeyTests::check_delete_multiple_keys)));
    9.35 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeleteKeyTests::check_delete_all_keys"),
    9.36 +                                                                      static_cast<Func>(&DeleteKeyTests::check_delete_all_keys)));
    9.37 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeleteKeyTests::check_delete_key_not_found"),
    9.38 +                                                                      static_cast<Func>(&DeleteKeyTests::check_delete_key_not_found)));
    9.39 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeleteKeyTests::check_delete_empty_keyring"),
    9.40 +                                                                      static_cast<Func>(&DeleteKeyTests::check_delete_empty_keyring)));
    9.41 +}
    9.42 +
    9.43 +void DeleteKeyTests::import_test_keys() {
    9.44 +    PEP_STATUS status = read_file_and_import_key(session,
    9.45 +                "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    9.46 +    assert(status == PEP_KEY_IMPORTED);
    9.47 +    status = set_up_ident_from_scratch(session,
    9.48 +                "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
    9.49 +                "pep.test.alice@pep-project.org", alice_fpr, 
    9.50 +                alice_user_id.c_str(), "Alice in Wonderland", NULL, true
    9.51 +            );
    9.52 +    assert(status == PEP_STATUS_OK);
    9.53 +    
    9.54 +    status = set_up_ident_from_scratch(session,
    9.55 +                "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc",
    9.56 +                "pep.test.bob@pep-project.org", NULL, bob_user_id.c_str(), "Bob's Burgers",
    9.57 +                NULL, false
    9.58 +            );
    9.59 +    assert(status == PEP_STATUS_OK);
    9.60 +            
    9.61 +    status = set_up_ident_from_scratch(session,
    9.62 +                "test_keys/pub/pep-test-carol-0x42A85A42_pub.asc",
    9.63 +                "pep-test-carol@pep-project.org", NULL, carol_user_id.c_str(), "Carol Burnett",
    9.64 +                NULL, false
    9.65 +            );
    9.66 +    assert(status == PEP_STATUS_OK);
    9.67 +    
    9.68 +    status = set_up_ident_from_scratch(session,
    9.69 +                "test_keys/pub/pep-test-dave-0xBB5BCCF6_pub.asc",
    9.70 +                "pep-test-dave@pep-project.org", NULL, dave_user_id.c_str(), 
    9.71 +                "David Hasselhoff (Germans Love Me)", NULL, false
    9.72 +            );
    9.73 +    assert(status == PEP_STATUS_OK);
    9.74 +
    9.75 +    status = set_up_ident_from_scratch(session,
    9.76 +                "test_keys/pub/pep-test-erin-0x9F8D7CBA_pub.asc",
    9.77 +                "pep-test-erin@pep-project.org", NULL, erin_user_id.c_str(), 
    9.78 +                "Éirinn go Brách", NULL, false
    9.79 +            );
    9.80 +    assert(status == PEP_STATUS_OK);
    9.81 +
    9.82 +    status = set_up_ident_from_scratch(session,
    9.83 +                "test_keys/pub/pep.test.fenris-0x4F3D2900_pub.asc",
    9.84 +                "pep.test.fenris@thisstilldoesntwork.lu", NULL, fenris_user_id.c_str(), 
    9.85 +                "Fenris Leto Hawke", NULL, false
    9.86 +            );
    9.87 +    assert(status == PEP_STATUS_OK);
    9.88 +}
    9.89 +
    9.90 +void DeleteKeyTests::check_delete_single_pubkey() {
    9.91 +    import_test_keys();
    9.92 +    stringlist_t* keylist = NULL;
    9.93 +
    9.94 +    // Is it there?
    9.95 +    PEP_STATUS status = find_keys(session, fenris_fpr, &keylist);
    9.96 +    TEST_ASSERT(status == PEP_STATUS_OK);
    9.97 +    TEST_ASSERT(keylist && keylist->value);    
    9.98 +    TEST_ASSERT_MSG(strcmp(keylist->value, fenris_fpr) == 0, "Wrong key found?!?!");
    9.99 +    free_stringlist(keylist);
   9.100 +    keylist = NULL;
   9.101 +    
   9.102 +    // Great, now delete it.
   9.103 +    status = delete_keypair(session, fenris_fpr);
   9.104 +    TEST_ASSERT(status == PEP_STATUS_OK);    
   9.105 +    
   9.106 +    // Is it gone?
   9.107 +    status = find_keys(session, fenris_fpr, &keylist);
   9.108 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   9.109 +    TEST_ASSERT(!keylist);    
   9.110 +    
   9.111 +    // Yay.    
   9.112 +}
   9.113 +
   9.114 +void DeleteKeyTests::check_delete_pub_priv_keypair() {
   9.115 +    import_test_keys();
   9.116 +    stringlist_t* keylist = NULL;
   9.117 +
   9.118 +    // Is it there?
   9.119 +    PEP_STATUS status = find_keys(session, alice_fpr, &keylist);
   9.120 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.121 +    TEST_ASSERT(keylist && keylist->value);    
   9.122 +    TEST_ASSERT_MSG(strcmp(keylist->value, alice_fpr) == 0, "Wrong key found?!?!");
   9.123 +    free_stringlist(keylist);
   9.124 +    keylist = NULL;
   9.125 +    
   9.126 +    // Great, now delete it.
   9.127 +    status = delete_keypair(session, alice_fpr);
   9.128 +    TEST_ASSERT(status == PEP_STATUS_OK);    
   9.129 +    
   9.130 +    // Is it gone?
   9.131 +    status = find_keys(session, alice_fpr, &keylist);
   9.132 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   9.133 +    TEST_ASSERT(!keylist);    
   9.134 +    
   9.135 +    // Yay.    
   9.136 +}
   9.137 +
   9.138 +void DeleteKeyTests::check_delete_multiple_keys() {
   9.139 +    import_test_keys();
   9.140 +    stringlist_t* keylist = NULL;
   9.141 +
   9.142 +    // Are they there?
   9.143 +    PEP_STATUS status = find_keys(session, alice_fpr, &keylist);
   9.144 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.145 +    TEST_ASSERT(keylist && keylist->value);    
   9.146 +    TEST_ASSERT_MSG(strcmp(keylist->value, alice_fpr) == 0, keylist->value);
   9.147 +    free_stringlist(keylist);
   9.148 +    keylist = NULL;
   9.149 +
   9.150 +    status = find_keys(session, dave_fpr, &keylist);
   9.151 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.152 +    TEST_ASSERT(keylist && keylist->value);    
   9.153 +    TEST_ASSERT_MSG(strcmp(keylist->value, dave_fpr) == 0, "Wrong key found?!?!");
   9.154 +    free_stringlist(keylist);
   9.155 +    keylist = NULL;
   9.156 +
   9.157 +    status = find_keys(session, fenris_fpr, &keylist);
   9.158 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.159 +    TEST_ASSERT(keylist && keylist->value);    
   9.160 +    TEST_ASSERT_MSG(strcmp(keylist->value, fenris_fpr) == 0, "Wrong key found?!?!");
   9.161 +    free_stringlist(keylist);
   9.162 +    keylist = NULL;
   9.163 +    
   9.164 +    // Great, now delete it.
   9.165 +    status = delete_keypair(session, alice_fpr);
   9.166 +    TEST_ASSERT(status == PEP_STATUS_OK);    
   9.167 +
   9.168 +    status = delete_keypair(session, dave_fpr);
   9.169 +    TEST_ASSERT(status == PEP_STATUS_OK);    
   9.170 +
   9.171 +    status = delete_keypair(session, fenris_fpr);
   9.172 +    TEST_ASSERT(status == PEP_STATUS_OK);    
   9.173 +
   9.174 +    // Is it gone?
   9.175 +    status = find_keys(session, alice_fpr, &keylist);
   9.176 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   9.177 +    TEST_ASSERT(!keylist);    
   9.178 +
   9.179 +    status = find_keys(session, dave_fpr, &keylist);
   9.180 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   9.181 +    TEST_ASSERT(!keylist);    
   9.182 +
   9.183 +    status = find_keys(session, fenris_fpr, &keylist);
   9.184 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   9.185 +    TEST_ASSERT(!keylist);    
   9.186 +    
   9.187 +    // Yay. Make sure everyone else is still there.
   9.188 +    status = find_keys(session, bob_fpr, &keylist);
   9.189 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.190 +    TEST_ASSERT(keylist && keylist->value);    
   9.191 +    TEST_ASSERT_MSG(strcmp(keylist->value, bob_fpr) == 0, "Wrong key found?!?!");
   9.192 +    free_stringlist(keylist);
   9.193 +    keylist = NULL;
   9.194 +
   9.195 +    status = find_keys(session, carol_fpr, &keylist);
   9.196 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.197 +    TEST_ASSERT(keylist && keylist->value);    
   9.198 +    TEST_ASSERT_MSG(strcmp(keylist->value, carol_fpr) == 0, "Wrong key found?!?!");
   9.199 +    free_stringlist(keylist);
   9.200 +    keylist = NULL;
   9.201 +
   9.202 +    status = find_keys(session, erin_fpr, &keylist);
   9.203 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.204 +    TEST_ASSERT(keylist && keylist->value);    
   9.205 +    TEST_ASSERT_MSG(strcmp(keylist->value, erin_fpr) == 0, "Wrong key found?!?!");
   9.206 +    free_stringlist(keylist);
   9.207 +    keylist = NULL;
   9.208 +}
   9.209 +
   9.210 +void DeleteKeyTests::check_delete_all_keys() {
   9.211 +    import_test_keys();
   9.212 +    stringlist_t* keylist = NULL;
   9.213 +
   9.214 +    // Are they there?
   9.215 +    PEP_STATUS status = find_keys(session, alice_fpr, &keylist);
   9.216 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.217 +    TEST_ASSERT(keylist && keylist->value);    
   9.218 +    TEST_ASSERT_MSG(strcmp(keylist->value, alice_fpr) == 0, keylist->value);
   9.219 +    free_stringlist(keylist);
   9.220 +    keylist = NULL;
   9.221 +
   9.222 +    status = find_keys(session, bob_fpr, &keylist);
   9.223 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.224 +    TEST_ASSERT(keylist && keylist->value);    
   9.225 +    TEST_ASSERT_MSG(strcmp(keylist->value, bob_fpr) == 0, "Wrong key found?!?!");
   9.226 +    free_stringlist(keylist);
   9.227 +    keylist = NULL;
   9.228 +
   9.229 +    status = find_keys(session, carol_fpr, &keylist);
   9.230 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.231 +    TEST_ASSERT(keylist && keylist->value);    
   9.232 +    TEST_ASSERT_MSG(strcmp(keylist->value, carol_fpr) == 0, "Wrong key found?!?!");
   9.233 +    free_stringlist(keylist);
   9.234 +    keylist = NULL;
   9.235 +
   9.236 +    status = find_keys(session, dave_fpr, &keylist);
   9.237 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.238 +    TEST_ASSERT(keylist && keylist->value);    
   9.239 +    TEST_ASSERT_MSG(strcmp(keylist->value, dave_fpr) == 0, "Wrong key found?!?!");
   9.240 +    free_stringlist(keylist);
   9.241 +    keylist = NULL;
   9.242 +
   9.243 +    status = find_keys(session, erin_fpr, &keylist);
   9.244 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.245 +    TEST_ASSERT(keylist && keylist->value);    
   9.246 +    TEST_ASSERT_MSG(strcmp(keylist->value, erin_fpr) == 0, "Wrong key found?!?!");
   9.247 +    free_stringlist(keylist);
   9.248 +    keylist = NULL;
   9.249 +
   9.250 +    status = find_keys(session, fenris_fpr, &keylist);
   9.251 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.252 +    TEST_ASSERT(keylist && keylist->value);    
   9.253 +    TEST_ASSERT_MSG(strcmp(keylist->value, fenris_fpr) == 0, "Wrong key found?!?!");
   9.254 +    free_stringlist(keylist);
   9.255 +    keylist = NULL;
   9.256 +    
   9.257 +    // Great, now delete it.
   9.258 +    status = delete_keypair(session, alice_fpr);
   9.259 +    TEST_ASSERT(status == PEP_STATUS_OK);    
   9.260 +
   9.261 +    status = delete_keypair(session, bob_fpr);
   9.262 +    TEST_ASSERT(status == PEP_STATUS_OK);    
   9.263 +
   9.264 +    status = delete_keypair(session, carol_fpr);
   9.265 +    TEST_ASSERT(status == PEP_STATUS_OK);    
   9.266 +
   9.267 +    status = delete_keypair(session, dave_fpr);
   9.268 +    TEST_ASSERT(status == PEP_STATUS_OK);    
   9.269 +
   9.270 +    status = delete_keypair(session, erin_fpr);
   9.271 +    TEST_ASSERT(status == PEP_STATUS_OK);    
   9.272 +
   9.273 +    status = delete_keypair(session, fenris_fpr);
   9.274 +    TEST_ASSERT(status == PEP_STATUS_OK);    
   9.275 +
   9.276 +    // Is it gone?
   9.277 +    status = find_keys(session, alice_fpr, &keylist);
   9.278 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   9.279 +    TEST_ASSERT(!keylist);    
   9.280 +
   9.281 +    status = find_keys(session, bob_fpr, &keylist);
   9.282 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   9.283 +    TEST_ASSERT(!keylist);    
   9.284 +
   9.285 +    status = find_keys(session, carol_fpr, &keylist);
   9.286 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   9.287 +    TEST_ASSERT(!keylist);    
   9.288 +
   9.289 +    status = find_keys(session, dave_fpr, &keylist);
   9.290 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   9.291 +    TEST_ASSERT(!keylist);    
   9.292 +
   9.293 +    status = find_keys(session, erin_fpr, &keylist);
   9.294 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   9.295 +    TEST_ASSERT(!keylist);    
   9.296 +
   9.297 +    status = find_keys(session, fenris_fpr, &keylist);
   9.298 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   9.299 +    TEST_ASSERT(!keylist);    
   9.300 +    
   9.301 +    // Yay. 
   9.302 +}
   9.303 +
   9.304 +void DeleteKeyTests::check_delete_key_not_found() {
   9.305 +    import_test_keys();
   9.306 +    stringlist_t* keylist = NULL;
   9.307 +
   9.308 +    // Is it there?
   9.309 +    PEP_STATUS status = find_keys(session, "74D79B4496E289BD8A71B70BA8E2C4530019697D", &keylist);
   9.310 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.311 +    TEST_ASSERT(!keylist);    
   9.312 +    
   9.313 +    // Great, now delete it.
   9.314 +    status = delete_keypair(session, "74D79B4496E289BD8A71B70BA8E2C4530019697D");
   9.315 +    TEST_ASSERT(status == PEP_KEY_NOT_FOUND);    
   9.316 +    
   9.317 +    // Is it still gone?
   9.318 +    status = find_keys(session, "74D79B4496E289BD8A71B70BA8E2C4530019697D", &keylist);
   9.319 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   9.320 +    TEST_ASSERT(!keylist);    
   9.321 +    
   9.322 +    // Yay.        
   9.323 +}
   9.324 +
   9.325 +void DeleteKeyTests::check_delete_empty_keyring() {
   9.326 +    stringlist_t* keylist = NULL;
   9.327 +
   9.328 +    // Is it there?
   9.329 +    PEP_STATUS status = find_keys(session, "74D79B4496E289BD8A71B70BA8E2C4530019697D", &keylist);
   9.330 +    TEST_ASSERT(status == PEP_STATUS_OK);
   9.331 +    TEST_ASSERT(!keylist);    
   9.332 +    
   9.333 +    // Great, now delete it.
   9.334 +    status = delete_keypair(session, "74D79B4496E289BD8A71B70BA8E2C4530019697D");
   9.335 +    TEST_ASSERT(status == PEP_KEY_NOT_FOUND);    
   9.336 +    
   9.337 +    // Is it still gone?
   9.338 +    status = find_keys(session, "74D79B4496E289BD8A71B70BA8E2C4530019697D", &keylist);
   9.339 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   9.340 +    TEST_ASSERT(!keylist);    
   9.341 +    
   9.342 +    // Yay.            
   9.343 +}