bastardised in-between state of conversion. guaranteed to be broken. googletest
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Mon, 26 Aug 2019 13:38:21 +0200
branchgoogletest
changeset 401537ef8c764f83
parent 4014 fa60b97b0b25
child 4016 9884f49e0f1f
bastardised in-between state of conversion. guaranteed to be broken.
.hgignore
gtest/Makefile
gtest/gtest_firstpass.py
gtest/src/AppleMailTest.cc
gtest/src/BCCTest.cc
gtest/src/BlacklistAcceptNewKeyTest.cc
gtest/src/BlacklistTest.cc
gtest/src/Engine.cc
gtest/src/Engine.h
gtest/src/ExportKeyTest.cc
test/0x6FF00E97.asc
test/0x70DCF575.asc
test/0xC9C2EE39.asc
test/6FF00E97_sec.asc
test/70DCF575_sec.asc
test/C9C2EE39_sec.asc
test/Makefile
test/blacklisted_pub.asc
test/blacklisted_pub2.asc
test/genscripts.py
test/gensuitemaker.py
test/gentestshell.py
test/gtest_firstpass.py
test/include/TestConstants.h
test/include/pEpEngine_test.h
test/include/pEpTestStatic.h
test/include/test_util.h
test/src/AppleMailTest.cc
test/src/BCCTest.cc
test/src/BlacklistAcceptNewKeyTest.cc
test/src/BlacklistTest.cc
test/src/BloblistTests.cc
test/src/CaseAndDotAddressTests.cc
test/src/CheckRenewedExpiredKeyTrustStatusTests.cc
test/src/CrashdumpTests.cc
test/src/DecorateTests.cc
test/src/DecryptAttachPrivateKeyTrustedTests.cc
test/src/DecryptAttachPrivateKeyUntrustedTests.cc
test/src/DeleteKeyTests.cc
test/src/EncryptAttachPrivateKeyTests.cc
test/src/EncryptForIdentityTests.cc
test/src/EncryptMissingPrivateKeyTests.cc
test/src/Engine.cc
test/src/Engine.h
test/src/Engine358Tests.cc
test/src/Engine463Tests.cc
test/src/EngineTestIndividualSuite.cc
test/src/EngineTestSessionSuite.cc
test/src/EngineTestSuite.cc
test/src/EnterLeaveDeviceGroupTests.cc
test/src/ExpiredSubkeyTests.cc
test/src/ExportKeyTest.cc
test/src/ExternalRevokeTests.cc
test/src/GetKeyRatingForUserTests.cc
test/src/HeaderKeyImportTests.cc
test/src/I18nTests.cc
test/src/IOS1664Tests.cc
test/src/IdentityListTests.cc
test/src/KeyAttachmentTests.cc
test/src/KeyResetMessageTests.cc
test/src/KeyeditTests.cc
test/src/KeyringImportTests.cc
test/src/LeastColorGroupTests.cc
test/src/LeastCommonDenomColorTests.cc
test/src/LiteralFilenameTests.cc
test/src/LookupTests.cc
test/src/LotsOfKeysTests.cc
test/src/MapAsn1Tests.cc
test/src/Message2_1Tests.cc
test/src/MessageApiTests.cc
test/src/MessageNullFromTests.cc
test/src/MessageTwoPointOhTests.cc
test/src/MimeTests.cc
test/src/NewUpdateIdAndMyselfTests.cc
test/src/NoOwnIdentWritesOnDecryptTests.cc
test/src/OwnIdentitiesRetrieveTests.cc
test/src/OwnKeysRetrieveTests.cc
test/src/PepSubjectReceivedTests.cc
test/src/PgpBinaryTests.cc
test/src/PgpListKeysTests.cc
test/src/ReencryptPlusExtraKeysTests.cc
test/src/RevocationTests.cc
test/src/RevokeRegenAttachTests.cc
test/src/SenderFPRTests.cc
test/src/SequenceTests.cc
test/src/SignOnlyTests.cc
test/src/SimpleBodyNotAltTests.cc
test/src/StringlistTests.cc
test/src/StringpairListTests.cc
test/src/StrnstrTests.cc
test/src/SubkeyRatingEvalTests.cc
test/src/SuiteMaker.cc
test/src/SyncTests.cc
test/src/TestConstants.h
test/src/TestDriver.cc
test/src/TrustManipulationTests.cc
test/src/TrustwordsTests.cc
test/src/URIAddressTests.cc
test/src/UserIDAliasTests.cc
test/src/UserIdCollisionTests.cc
test/src/VerifyTests.cc
test/src/engine_tests/BloblistTests.cc
test/src/engine_tests/CaseAndDotAddressTests.cc
test/src/engine_tests/CheckRenewedExpiredKeyTrustStatusTests.cc
test/src/engine_tests/CrashdumpTests.cc
test/src/engine_tests/DecorateTests.cc
test/src/engine_tests/DecryptAttachPrivateKeyTrustedTests.cc
test/src/engine_tests/DecryptAttachPrivateKeyUntrustedTests.cc
test/src/engine_tests/DeleteKeyTests.cc
test/src/engine_tests/EncryptAttachPrivateKeyTests.cc
test/src/engine_tests/EncryptForIdentityTests.cc
test/src/engine_tests/EncryptMissingPrivateKeyTests.cc
test/src/engine_tests/Engine358Tests.cc
test/src/engine_tests/Engine463Tests.cc
test/src/engine_tests/EnterLeaveDeviceGroupTests.cc
test/src/engine_tests/ExpiredSubkeyTests.cc
test/src/engine_tests/ExportKeyTests.cc
test/src/engine_tests/ExternalRevokeTests.cc
test/src/engine_tests/GetKeyRatingForUserTests.cc
test/src/engine_tests/HeaderKeyImportTests.cc
test/src/engine_tests/I18nTests.cc
test/src/engine_tests/IOS1664Tests.cc
test/src/engine_tests/IdentityListTests.cc
test/src/engine_tests/IntegrityTests.do.not.run.before.ENGINE-434
test/src/engine_tests/KeyAttachmentTests.cc
test/src/engine_tests/KeyResetMessageTests.cc
test/src/engine_tests/KeyeditTests.cc
test/src/engine_tests/KeyringImportTests.cc
test/src/engine_tests/LeastColorGroupTests.cc
test/src/engine_tests/LeastCommonDenomColorTests.cc
test/src/engine_tests/LiteralFilenameTests.cc
test/src/engine_tests/LookupTests.cc
test/src/engine_tests/LotsOfKeysTests.cc
test/src/engine_tests/MapAsn1Tests.cc
test/src/engine_tests/Message2_1Tests.cc
test/src/engine_tests/MessageApiTests.cc
test/src/engine_tests/MessageNullFromTests.cc
test/src/engine_tests/MessageTwoPointOhTests.cc
test/src/engine_tests/MimeTests.cc
test/src/engine_tests/NewUpdateIdAndMyselfTests.cc
test/src/engine_tests/NoOwnIdentWritesOnDecryptTests.cc
test/src/engine_tests/OwnIdentitiesRetrieveTests.cc
test/src/engine_tests/OwnKeysRetrieveTests.cc
test/src/engine_tests/PepSubjectReceivedTests.cc
test/src/engine_tests/PgpBinaryTests.cc
test/src/engine_tests/PgpListKeysTests.cc
test/src/engine_tests/ReencryptPlusExtraKeysTests.cc
test/src/engine_tests/RevocationTests.cc
test/src/engine_tests/RevokeRegenAttachTests.cc
test/src/engine_tests/SenderFPRTests.cc
test/src/engine_tests/SequenceTests.cc
test/src/engine_tests/SignOnlyTests.cc
test/src/engine_tests/SimpleBodyNotAltTests.cc
test/src/engine_tests/StringlistTests.cc
test/src/engine_tests/StringpairListTests.cc
test/src/engine_tests/StrnstrTests.cc
test/src/engine_tests/SubkeyRatingEvalTests.cc
test/src/engine_tests/SyncTests.cc
test/src/engine_tests/TrustManipulationTests.cc
test/src/engine_tests/TrustwordsTests.cc
test/src/engine_tests/URIAddressTests.cc
test/src/engine_tests/UserIDAliasTests.cc
test/src/engine_tests/UserIdCollisionTests.cc
test/src/engine_tests/VerifyTests.cc
test/src/pEpEngine_test.h
test/src/pEpTestOutput.cc
test/src/pEpTestStatic.h
test/src/test_util.cc
test/src/test_util.h
test/src/util/test_util.cc
test/test_keys/pub/blacklisted_pub.asc
test/test_keys/pub/blacklisted_pub2.asc
     1.1 --- a/.hgignore	Mon Aug 26 12:41:39 2019 +0200
     1.2 +++ b/.hgignore	Mon Aug 26 13:38:21 2019 +0200
     1.3 @@ -78,11 +78,8 @@
     1.4  sync/.statemachines
     1.5  sync/.copy
     1.6  test/msg_2.0.asc
     1.7 -test/*Tests
     1.8  test/*.txt
     1.9  lldb-history
    1.10  *.swo
    1.11 -test/.scripts
    1.12 -test/.suitemaker
    1.13 -gtest/EngineTests
    1.14 -gtest/googletest
    1.15 +test/EngineTests
    1.16 +test/googletest
     2.1 --- a/gtest/Makefile	Mon Aug 26 12:41:39 2019 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,117 +0,0 @@
     2.4 -# Copyright 2019, 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 -HERE:=$(CURDIR)
    2.10 -
    2.11 -include ../Makefile.conf
    2.12 -
    2.13 -GTEST_DIR:=googletest/googletest
    2.14 -SRCS:=$(wildcard src/*.cc) $(wildcard src/*/*.cc)
    2.15 -OBJS:=$(addsuffix .o,$(basename $(SRCS)))
    2.16 -DEPS:=$(OBJS:.o=.d)
    2.17 -
    2.18 -LDFLAGS+= -L../asn.1 -L../src $(ETPAN_LIB) $(CPPUNIT_LIB)
    2.19 -
    2.20 -TARGET:=EngineTests 
    2.21 -
    2.22 -ifeq ($(OPENPGP),GPG)
    2.23 -    LDFLAGS+= $(GPGME_LIB)
    2.24 -else ifeq ($(OPENPGP),NETPGP)
    2.25 -    LDFLAGS+= $(NETGPG_LIB)
    2.26 -endif
    2.27 -
    2.28 -LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1
    2.29 -
    2.30 -ifeq ($(BUILD_FOR),Linux)
    2.31 -    LDLIBS+= -luuid
    2.32 -endif
    2.33 -
    2.34 -ifeq ($(OPENPGP),SEQUOIA)
    2.35 -    LDFLAGS+= $(SEQUOIA_LDFLAGS)
    2.36 -    LDLIBS+= $(SEQUOIA_LIB)
    2.37 -    CXXFLAGS+= $(SEQUOIA_CFLAGS) -DUSE_SEQUOIA
    2.38 -    INC_FLAGS+= $(SEQUOIA_INC)
    2.39 -endif
    2.40 -
    2.41 -ifdef SQLITE3_FROM_OS
    2.42 -    LDLIBS+= -lsqlite3
    2.43 -endif
    2.44 -
    2.45 -ifeq ($(OPENPGP),GPG)
    2.46 -    #LDLIBS+= -lgpgme
    2.47 -else ifeq ($(OPENPGP),NETPGP)
    2.48 -    LDLIBS+= -lnetpgp
    2.49 -    ifeq ($(BUILD_FOR),Linux)
    2.50 -        LDLIBS+= -ltre
    2.51 -    endif
    2.52 -endif
    2.53 -
    2.54 -CXXFLAGS:=$(filter-out -DNDEBUG,$(CXXFLAGS))
    2.55 -
    2.56 -# FIXME Possibly missing incdirs: ASN1C_INC
    2.57 -CXXFLAGS+= -I./include -I../sync $(CPPUNIT_INC) $(INC_FLAGS) -Wno-deprecated
    2.58 -
    2.59 -ifeq ($(OPENPGP),GPG)
    2.60 -    CXXFLAGS+= -DUSE_GPG $(GPGME_INC)
    2.61 -else ifeq ($(OPENPGP),NETPGP)
    2.62 -    CXXFLAGS+= -DUSE_NETPGP $(NETPGP_INC)
    2.63 -endif
    2.64 -
    2.65 -EXTRA_LIB_PATHS=.:../src:
    2.66 -ifdef ETPAN_LIB
    2.67 -    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
    2.68 -endif
    2.69 -ifdef GPGME_LIB
    2.70 -    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)):
    2.71 -endif
    2.72 -ifdef NETPGP_LIB
    2.73 -    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(NETPGP_LIB)):
    2.74 -endif
    2.75 -ifdef CPPUNIT_LIB
    2.76 -    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(CPPUNIT_LIB)):
    2.77 -endif
    2.78 -
    2.79 -# Remove trailing ':'
    2.80 -EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=)
    2.81 -
    2.82 -ifeq ($(BUILD_FOR),Darwin)
    2.83 -    LIBPATH=DYLD_LIBRARY_PATH
    2.84 -else
    2.85 -    LIBPATH=LD_LIBRARY_PATH
    2.86 -endif
    2.87 -
    2.88 -# FIXME: this forces a path on execution which overrides system paths for
    2.89 -#        libraries like iconv and causes runtime errors.
    2.90 -#TEST_CMD_PFX=$(LIBPATH)=$(EXTRA_LIB_PATHS)
    2.91 -TEST_CMD_PFX=
    2.92 -
    2.93 -.PHONY: all clean test
    2.94 -
    2.95 -all:
    2.96 -	make $(TARGET)
    2.97 -
    2.98 -%.d: %.cc
    2.99 -	$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< | sed -e 's,\($*\)\.o[ :]*,\1.o $@: ,g' > $@
   2.100 -
   2.101 -$(TARGET): $(OBJS) gtest-all.o gtest_main.o
   2.102 -#	$(LINK.cc) $(OBJS) $(LOADLIBES) $(LDLIBS) -o $@
   2.103 -	${CXX} ${LDFLAGS} -L${PREFIX}/lib -o $@ $^ -lpEpEngine $(LDLIBS)
   2.104 -
   2.105 -gtest-all.o: $(GTEST_DIR)/src/gtest-all.cc
   2.106 -	${CXX} ${CXXFLAGS} $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -isystem $(GTEST_DIR)/include -o $@ -c $<
   2.107 -
   2.108 -gtest_main.o: $(GTEST_DIR)/src/gtest_main.cc
   2.109 -	${CXX} ${CXXFLAGS} $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -isystem $(GTEST_DIR)/include -o $@ -c $<
   2.110 -
   2.111 -test: all
   2.112 -	$(TEST_CMD_PFX) $(TEST_DEBUGGER) ./$(TARGET)
   2.113 -
   2.114 -clean:
   2.115 -	$(RM) $(TARGET) $(TARGET).o $(TARGET).d $(OBJS) $(notdir $(basename $(OBJS))) $(DEPS)
   2.116 -
   2.117 -# If only the goal 'clean' is given, do not generate and include the '%.d' files.¬
   2.118 -ifneq ($(MAKECMDGOALS),clean)
   2.119 -    -include $(DEPS)
   2.120 -endif
     3.1 --- a/gtest/gtest_firstpass.py	Mon Aug 26 12:41:39 2019 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,340 +0,0 @@
     3.4 -import re 
     3.5 -import sys
     3.6 -
     3.7 -def tb(n):
     3.8 -    retval = ""
     3.9 -    for i in range(n):
    3.10 -        retval = retval + "    "
    3.11 -    return retval
    3.12 -        
    3.13 -fixture_in = False 
    3.14 -removing_old_constructor = False
    3.15 -constructor_done = False
    3.16 -modline = None
    3.17 -eat_next_line = False;
    3.18 -filename = sys.argv[1]
    3.19 -outfile = sys.argv[2]
    3.20 -
    3.21 -newfile = open(outfile,'w')
    3.22 -
    3.23 -with open(filename) as fp: 
    3.24 -    for line in fp:
    3.25 -        if (eat_next_line):
    3.26 -            eat_next_line = False;
    3.27 -            continue;
    3.28 -        line = line.rstrip();
    3.29 -        
    3.30 -        if not fixture_in:
    3.31 -            if (removing_old_constructor):
    3.32 -                if "}" in line:
    3.33 -                    removing_old_constructor = False  
    3.34 -                    constructor_done = True 
    3.35 -                continue
    3.36 -            else:        
    3.37 -                if (line.find("namespace") >= 0):
    3.38 -                    continue
    3.39 -                if (line.find("Tests.h") >= 0):
    3.40 -                    continue
    3.41 -                if (line.find("cpptest") >= 0):
    3.42 -                    continue 
    3.43 -                if (line.find("EngineTestSuite.h") >= 0 or line.find("EngineTestIndividualSuite.h") >= 0 or line.find("EngineTestSessionSuite.h") >= 0):
    3.44 -                    continue
    3.45 -                
    3.46 -                if (modline == None):                
    3.47 -                    modline = re.sub(r'(.*)Tests::(.*)Tests\(string suitename, string test_home_dir\) :', r'\1Test', line)                
    3.48 -                    
    3.49 -                if(modline == line):
    3.50 -                    newfile.write(line + "\n")
    3.51 -                    modline = None
    3.52 -                    continue
    3.53 -                else:
    3.54 -                    if not (constructor_done):
    3.55 -                        removing_old_constructor = True
    3.56 -                        continue    
    3.57 -                        
    3.58 -                    #*Tests::*Tests(string suitename, string test_home_dir)
    3.59 -                    # Put in fixture blob
    3.60 -                    # - delete through first }
    3.61 -                    #print(modline) 
    3.62 -                    newfile.write("#include \"Engine.h\"\n\n")                    
    3.63 -                    newfile.write("#include <gtest/gtest.h>\n\n\n")
    3.64 -                    newfile.write("namespace {\n\n\t//The fixture for " + modline + "\n")
    3.65 -                    newfile.write(tb(1) + "class " + modline + " : public ::testing::Test {\n")
    3.66 -                    newfile.write(tb(2) + "public:\n")
    3.67 -                    newfile.write(tb(3) + "Engine* engine;\n")
    3.68 -                    newfile.write(tb(3) + "PEP_SESSION session;\n\n")
    3.69 -                    newfile.write(tb(2) + "protected:\n")
    3.70 -                    newfile.write(tb(3) + "// You can remove any or all of the following functions if its body\n")
    3.71 -                    newfile.write(tb(3) + "// is empty.\n")
    3.72 -                    newfile.write(tb(3) + "" + modline + "() {\n")
    3.73 -                    newfile.write(tb(4) + "// You can do set-up work for each test here.\n")
    3.74 -                    newfile.write(tb(4) + "test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name();\n")
    3.75 -                    newfile.write(tb(4) + "test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();\n")
    3.76 -                    newfile.write(tb(4) + "test_path = get_main_test_home_dir() + \"/\" + test_suite_name + \"/\" + test_name;\n")
    3.77 -                    newfile.write(tb(3) + "}\n\n")
    3.78 -                    newfile.write(tb(3) + "~" + modline + "() override {\n")
    3.79 -                    newfile.write(tb(4) + "// You can do clean-up work that doesn't throw exceptions here.\n")
    3.80 -                    newfile.write(tb(3) + "}\n\n")
    3.81 -                    newfile.write(tb(3) + "// If the constructor and destructor are not enough for setting up\n")
    3.82 -                    newfile.write(tb(3) + "// and cleaning up each test, you can define the following methods:\n\n")
    3.83 -                    newfile.write(tb(3) + "void SetUp() override {\n")
    3.84 -                    newfile.write(tb(4) + "// Code here will be called immediately after the constructor (right\n")
    3.85 -                    newfile.write(tb(4) + "// before each test).\n")
    3.86 -                    newfile.write("\n" + tb(4) + "// Leave this empty if there are no files to copy to the home directory path\n")
    3.87 -                    newfile.write(tb(4) + "std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();\n")                                        
    3.88 -                    newfile.write("\n" + tb(4) + "// Get a new test Engine.\n")                    
    3.89 -                    newfile.write(tb(4) + "engine = new Engine(test_path);\n");
    3.90 -                    newfile.write(tb(4) + "ASSERT_NE(engine, nullptr);\n")
    3.91 -                    newfile.write("\n" + tb(4) + "// Ok, let's initialize test directories etc.\n")                                        
    3.92 -                    newfile.write(tb(4) + "engine->prep(NULL, NULL, init_files);\n")
    3.93 -                    newfile.write("\n" + tb(4) + "// Ok, try to start this bugger.\n")                    
    3.94 -                    newfile.write(tb(4) + "engine->start();\n")                    
    3.95 -                    newfile.write(tb(4) + "ASSERT_NE(engine->session, nullptr);\n")                    
    3.96 -                    newfile.write(tb(4) + "session = engine->session;\n") 
    3.97 -                    newfile.write("\n" + tb(4) + "// Engine is up. Keep on truckin\'\n");                                                            
    3.98 -                    newfile.write(tb(3) + "}\n\n")
    3.99 -                    newfile.write(tb(3) + "void TearDown() override {\n")
   3.100 -                    newfile.write(tb(4) + "// Code here will be called immediately after each test (right\n")
   3.101 -                    newfile.write(tb(4) + "// before the destructor).\n")   
   3.102 -                    newfile.write(tb(4) + "engine->shut_down();\n")
   3.103 -                    newfile.write(tb(4) + "delete engine;\n")                    
   3.104 -                    newfile.write(tb(4) + "engine = NULL;\n")                    
   3.105 -                    newfile.write(tb(4) + "session = NULL;\n")                    
   3.106 -                    newfile.write(tb(3) + "}\n\n")
   3.107 -                    newfile.write(tb(2) + "private:\n");
   3.108 -                    newfile.write(tb(3) + "const char* test_suite_name;\n")
   3.109 -                    newfile.write(tb(3) + "const char* test_name;\n")                                                            
   3.110 -                    newfile.write(tb(3) + "string test_path;\n") 
   3.111 -                    newfile.write(tb(3) + "// Objects declared here can be used by all tests in the " + modline + " suite.\n\n")
   3.112 -                    newfile.write(tb(1) + "};\n\n")
   3.113 -                    newfile.write("}  // namespace\n\n\n")
   3.114 -
   3.115 -                    fixture_in = True
   3.116 -        else:
   3.117 -            #void *Tests::check*() {
   3.118 -            # -> TEST_F(*Test, check*) {
   3.119 -            modline = re.sub(r'void\s*(.*)Tests::check(.*)\(\)\s*{', r'TEST_F(\1Test, check\2) {', line)
   3.120 -            if (line != modline):
   3.121 -                newfile.write(modline + "\n")
   3.122 -                continue
   3.123 -                
   3.124 -            #TEST_ASSERT(true)
   3.125 -            # -> <nothing>                
   3.126 -            if (line.find("TEST_ASSERT(true)") >= 0):
   3.127 -                continue
   3.128 -                
   3.129 -            #TEST_ASSERT_MSG(strcmp(blah,blah) == 0, *)
   3.130 -            #TEST_ASSERT(strcmp(blah,blah == 0))
   3.131 -            # -> ASSERT_STREQ(blah,blah)
   3.132 -            modline = re.sub(r'TEST_ASSERT_MSG\(\s*strcmp\(\s*(.*),\s*(.*)\)\s*==\s*0\s*,.*\);', r'ASSERT_STREQ(\1, \2);', line)
   3.133 -            if (line != modline):
   3.134 -                newfile.write(modline + "\n")
   3.135 -                continue
   3.136 -            modline = re.sub(r'TEST_ASSERT\(\s*strcmp\(\s*(.*),\s*(.*)\)\s*==\s*0\);', r'ASSERT_STREQ(\1, \2);', line)
   3.137 -            if (line != modline):
   3.138 -                newfile.write(modline + "\n")
   3.139 -                continue
   3.140 -
   3.141 -            #TEST_ASSERT_MSG(strcmp(blah,blah) != 0, *)
   3.142 -            #TEST_ASSERT(strcmp(blah,blah != 0))
   3.143 -            # -> ASSERT_STREQ(blah,blah)
   3.144 -            modline = re.sub(r'TEST_ASSERT_MSG\(\s*strcmp\(\s*(.*),\s*(.*)\)\s*!=\s*0\s*,.*\);', r'ASSERT_STRNE(\1, \2);', line)
   3.145 -            if (line != modline):
   3.146 -                newfile.write(modline + "\n")
   3.147 -                continue
   3.148 -            modline = re.sub(r'TEST_ASSERT\(\s*strcmp\(\s*(.*),\s*(.*)\)\s*!=\s*0\);', r'ASSERT_STRNE(\1, \2);', line)
   3.149 -            if (line != modline):
   3.150 -                newfile.write(modline + "\n")
   3.151 -                continue
   3.152 -                
   3.153 -            #TEST_ASSERT_MSG(<x> == NULL, *);
   3.154 -            #TEST_ASSERT(<x> == NULL);
   3.155 -            # -> ASSERT_EQ(<x>, nullptr);
   3.156 -            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*==\s*NULL,.*\);',r'ASSERT_EQ(\1, nullptr);', line)
   3.157 -            if (line != modline):
   3.158 -                newfile.write(modline + "\n")
   3.159 -                continue
   3.160 -            modline = re.sub(r'TEST_ASSERT\((.*)\s*==\s*NULL\);', r'ASSERT_EQ(\1, nullptr);',line)
   3.161 -            if (line != modline):
   3.162 -                newfile.write(modline + "\n")
   3.163 -                continue
   3.164 -            
   3.165 -            #TEST_ASSERT_MSG(<x> != NULL, *);
   3.166 -            #TEST_ASSERT(<x> != NULL);
   3.167 -            # -> ASSERT_NE(<x>, nullptr);
   3.168 -            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*!=\s*NULL,.*\);',r'ASSERT_NE(\1, nullptr);', line)
   3.169 -            if (line != modline):
   3.170 -                newfile.write(modline + "\n")
   3.171 -                continue
   3.172 -            modline = re.sub(r'TEST_ASSERT\((.*)\s*!=\s*NULL\);', r'ASSERT_NE(\1, nullptr);',line)
   3.173 -            if (line != modline):
   3.174 -                newfile.write(modline + "\n")
   3.175 -                continue
   3.176 -            
   3.177 -            #TEST_ASSERT_MSG(<x> == <y>, *);
   3.178 -            #TEST_ASSERT(<x> == <y>);
   3.179 -            # -> ASSERT_EQ(<x>, <y>);
   3.180 -            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*==\s*(.*),.*\);', r'ASSERT_EQ(\1, \2);',line)
   3.181 -            if (line != modline):
   3.182 -                newfile.write(modline + "\n")
   3.183 -                continue
   3.184 -            modline = re.sub(r'TEST_ASSERT\((.*)\s*==\s*(.*)\);', r'ASSERT_EQ(\1, \2);',line)
   3.185 -            if (line != modline):
   3.186 -                newfile.write(modline + "\n")
   3.187 -                continue
   3.188 -            
   3.189 -            #TEST_ASSERT_MSG(<x> != <y>, *);
   3.190 -            #TEST_ASSERT(<x> != <y>);
   3.191 -            # -> ASSERT_NE(<x>, <y>);
   3.192 -            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*!=\s*(.*),.*\);', r'ASSERT_NE(\1, \2);',line)
   3.193 -            if (line != modline):
   3.194 -                newfile.write(modline + "\n")
   3.195 -                continue
   3.196 -            modline = re.sub(r'TEST_ASSERT\((.*)\s*!=\s*(.*)\);', r'ASSERT_NE(\1, \2);',line)
   3.197 -            if (line != modline):
   3.198 -                newfile.write(modline + "\n")
   3.199 -                continue
   3.200 -            
   3.201 -            #TEST_ASSERT_MSG(<x> >= <y>, *);
   3.202 -            #TEST_ASSERT(<x> >= <y>);
   3.203 -            # -> ASSERT_GE(<x>, <y>);
   3.204 -            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*[^-]>=\s*(.*),.*\);', r'ASSERT_GE(\1, \2);',line)
   3.205 -            if (line != modline):
   3.206 -                newfile.write(modline + "\n")
   3.207 -                continue
   3.208 -            modline = re.sub(r'TEST_ASSERT\((.*)\s*[^-]>=\s*(.*)\);', r'ASSERT_GE(\1, \2);',line)
   3.209 -            if (line != modline):
   3.210 -                newfile.write(modline + "\n")
   3.211 -                continue
   3.212 -            
   3.213 -            #TEST_ASSERT_MSG(<x> > <y>, *);
   3.214 -            #TEST_ASSERT(<x> > <y>);
   3.215 -            # -> ASSERT_GT(<x>, <y>);
   3.216 -            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*[^-]>\s*(.*),.*\);', r'ASSERT_GT(\1, \2);',line)
   3.217 -            if (line != modline):
   3.218 -                newfile.write(modline + "\n")
   3.219 -                continue
   3.220 -            modline = re.sub(r'TEST_ASSERT\((.*)\s*[^-]>\s*(.*)\);', r'ASSERT_GT(\1, \2);',line)
   3.221 -            if (line != modline):
   3.222 -                newfile.write(modline + "\n")
   3.223 -                continue
   3.224 -            
   3.225 -            #TEST_ASSERT_MSG(<x> <= <y>, *);
   3.226 -            #TEST_ASSERT(<x> <= <y>);
   3.227 -            # -> ASSERT_LE(<x>, <y>);
   3.228 -            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*<=\s*(.*),.*\);', r'ASSERT_LE(\1, \2);',line)
   3.229 -            if (line != modline):
   3.230 -                newfile.write(modline + "\n")
   3.231 -                continue
   3.232 -            modline = re.sub(r'TEST_ASSERT\((.*)\s*<=\s*(.*)\);', r'ASSERT_LE(\1, \2);',line)
   3.233 -            if (line != modline):
   3.234 -                newfile.write(modline + "\n")
   3.235 -                continue
   3.236 -            
   3.237 -            #TEST_ASSERT_MSG(<x> < <y>, *);
   3.238 -            #TEST_ASSERT(<x> < <y>);
   3.239 -            # -> ASSERT_LT(<x>, <y>);
   3.240 -            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*<\s*(.*),.*\);', r'ASSERT_LT(\1, \2);',line)
   3.241 -            if (line != modline):
   3.242 -                newfile.write(modline + "\n")
   3.243 -                continue
   3.244 -            modline = re.sub(r'TEST_ASSERT\((.*)\s*<\s*(.*)\);', r'ASSERT_LT(\1, \2);',line)
   3.245 -            if (line != modline):
   3.246 -                newfile.write(modline + "\n")
   3.247 -                continue
   3.248 -
   3.249 -            #TEST_ASSERT_MSG(slurp_and_import_key(
   3.250 -            #TEST_ASSERT(slurp_and_import_key(
   3.251 -            # -> ASSERT_TRUE(slurp_and_import_key(
   3.252 -            modline = re.sub(r'TEST_ASSERT_MSG\(slurp_and_import_key', r'ASSERT_TRUE(slurp_and_import_key',line)
   3.253 -            if (line != modline):
   3.254 -                if not line.endswith(";"):
   3.255 -                    eat_next_line = True
   3.256 -                    modline = re.sub(r'\),', r'));', modline);
   3.257 -                newfile.write(modline + "\n")
   3.258 -                continue
   3.259 -            modline = re.sub(r'TEST_ASSERT\(slurp_and_import_key', r'ASSERT_TRUE(slurp_and_import_key',line)
   3.260 -            if (line != modline):
   3.261 -                newfile.write(modline + "\n")
   3.262 -                continue
   3.263 -            
   3.264 -            #TEST_ASSERT_MSG(!<x>, *);
   3.265 -            #TEST_ASSERT(!<x>);
   3.266 -            # -> ASSERT_FALSE(<x>);
   3.267 -            mgroup = re.match(r'TEST_ASSERT_MSG\(!(.*),.*\);', line.lstrip());
   3.268 -            if (mgroup == None):
   3.269 -                mgroup = re.match(r'TEST_ASSERT\(!(.*)\);', line.lstrip());
   3.270 -            
   3.271 -            if (mgroup != None):
   3.272 -                matchphrase = mgroup.group(0)
   3.273 -                is_pointer = False
   3.274 -                while True:
   3.275 -                    answer = input("ATTENTION: INPUT REQUIRED: In line " + line.lstrip() + ", is " + matchphrase + " a pointer? (y/n)")
   3.276 -                    if (answer == "y" or answer == "Y"):
   3.277 -                        is_pointer = True
   3.278 -                        break
   3.279 -                    elif (answer != "n" and answer != 'N'):
   3.280 -                        print("\'" + answer + "\' is not a valid answer. Please answer with 'y' or 'n'.") 
   3.281 -                        continue
   3.282 -                    break;       
   3.283 -                
   3.284 -                if (is_pointer):
   3.285 -                    modline = re.sub(r'TEST_ASSERT_MSG\(!(.*),.*\);',r'ASSERT_NE(\1, nullptr);', line)
   3.286 -                    if (line != modline):
   3.287 -                        newfile.write(modline + "\n")
   3.288 -                        continue
   3.289 -                    modline = re.sub(r'TEST_ASSERT\(!(.*)\);', r'ASSERT_NE(\1, nullptr);',line)
   3.290 -                    if (line != modline):
   3.291 -                        newfile.write(modline + "\n")
   3.292 -                        continue
   3.293 -                else:        
   3.294 -                    modline = re.sub(r'TEST_ASSERT_MSG\(!(.*),.*\);',r'ASSERT_FALSE(\1);', line)
   3.295 -                    if (line != modline):
   3.296 -                        newfile.write(modline + "\n")
   3.297 -                        continue
   3.298 -                    modline = re.sub(r'TEST_ASSERT\(!(.*)\);', r'ASSERT_FALSE(\1);',line)
   3.299 -                    if (line != modline):
   3.300 -                        newfile.write(modline + "\n")
   3.301 -                        continue
   3.302 -                                            
   3.303 -            #TEST_ASSERT_MSG(<x>, *);
   3.304 -            #TEST_ASSERT(<x>);
   3.305 -            # -> ASSERT_TRUE(<x>);
   3.306 -            mgroup = re.match(r'TEST_ASSERT_MSG\((.*),.*\);', line.lstrip());
   3.307 -            if (mgroup == None):
   3.308 -                mgroup = re.match(r'TEST_ASSERT\((.*)\);', line.lstrip());
   3.309 -            
   3.310 -            if (mgroup != None):
   3.311 -                matchphrase = mgroup.group(1)
   3.312 -                is_pointer = False
   3.313 -                while True:
   3.314 -                    answer = input("ATTENTION: INPUT REQUIRED: In line " + line.lstrip() + ", is " + matchphrase + " a pointer? (y/n)")
   3.315 -                    if (answer == "y" or answer == "Y"):
   3.316 -                        is_pointer = True
   3.317 -                        break
   3.318 -                    elif (answer != "n" and answer != 'N'):
   3.319 -                        print("\'" + answer + "\' is not a valid answer. Please answer with 'y' or 'n'.") 
   3.320 -                        continue
   3.321 -                    break;       
   3.322 -                
   3.323 -                if (is_pointer):
   3.324 -                    modline = re.sub(r'TEST_ASSERT_MSG\((.*),.*\);',r'ASSERT_NE(\1, nullptr);', line)
   3.325 -                    if (line != modline):
   3.326 -                        newfile.write(modline + "\n")
   3.327 -                        continue
   3.328 -                    modline = re.sub(r'TEST_ASSERT\((.*)\);', r'ASSERT_NE(\1, nullptr);',line)
   3.329 -                    if (line != modline):
   3.330 -                        newfile.write(modline + "\n")
   3.331 -                        continue
   3.332 -                else:        
   3.333 -                    modline = re.sub(r'TEST_ASSERT_MSG\((.*),.*\);',r'ASSERT_TRUE(\1);', line)
   3.334 -                    if (line != modline):
   3.335 -                        newfile.write(modline + "\n")
   3.336 -                        continue
   3.337 -                    modline = re.sub(r'TEST_ASSERT\((.*)\);', r'ASSERT_TRUE(\1);',line)
   3.338 -                    if (line != modline):
   3.339 -                        newfile.write(modline + "\n")
   3.340 -                        continue
   3.341 -            
   3.342 -            #Ok, it's something else. Print line and go.
   3.343 -            newfile.write(line + "\n")
     4.1 --- a/gtest/src/AppleMailTest.cc	Mon Aug 26 12:41:39 2019 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,211 +0,0 @@
     4.4 -// This file is under GNU General Public License 3.0
     4.5 -// see LICENSE.txt
     4.6 -
     4.7 -#include <stdlib.h>
     4.8 -#include <string.h>
     4.9 -#include <iostream>
    4.10 -#include <fstream>
    4.11 -#include <string>
    4.12 -#include <cstring> // for strcmp()
    4.13 -#include "platform.h"
    4.14 -#include <iostream>
    4.15 -#include <fstream>
    4.16 -#include <sstream>
    4.17 -#include "keymanagement.h"
    4.18 -#include "message_api.h"
    4.19 -#include "mime.h"
    4.20 -#include "test_util.h" // for slurp()
    4.21 -#include "TestConstants.h"
    4.22 -
    4.23 -
    4.24 -
    4.25 -#include "Engine.h"
    4.26 -
    4.27 -#include <gtest/gtest.h>
    4.28 -
    4.29 -
    4.30 -namespace {
    4.31 -
    4.32 -	//The fixture for AppleMailTest
    4.33 -    class AppleMailTest : public ::testing::Test {
    4.34 -        public:
    4.35 -            Engine* engine;
    4.36 -            PEP_SESSION session;
    4.37 -
    4.38 -        protected:
    4.39 -            // You can remove any or all of the following functions if its body
    4.40 -            // is empty.
    4.41 -            AppleMailTest() {
    4.42 -                // You can do set-up work for each test here.
    4.43 -                test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name();
    4.44 -                test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
    4.45 -                test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
    4.46 -            }
    4.47 -
    4.48 -            ~AppleMailTest() override {
    4.49 -                // You can do clean-up work that doesn't throw exceptions here.
    4.50 -            }
    4.51 -
    4.52 -            // If the constructor and destructor are not enough for setting up
    4.53 -            // and cleaning up each test, you can define the following methods:
    4.54 -
    4.55 -            void SetUp() override {
    4.56 -                // Code here will be called immediately after the constructor (right
    4.57 -                // before each test).
    4.58 -
    4.59 -                // Leave this empty if there are no files to copy to the home directory path
    4.60 -                std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
    4.61 -
    4.62 -                // Get a new test Engine.
    4.63 -                engine = new Engine(test_path);
    4.64 -                ASSERT_NE(engine, nullptr);
    4.65 -
    4.66 -                // Ok, let's initialize test directories etc.
    4.67 -                engine->prep(NULL, NULL, init_files);
    4.68 -
    4.69 -                // Ok, try to start this bugger.
    4.70 -                engine->start();
    4.71 -                ASSERT_NE(engine->session, nullptr);
    4.72 -                session = engine->session;
    4.73 -
    4.74 -                // Engine is up. Keep on truckin'
    4.75 -            }
    4.76 -
    4.77 -            void TearDown() override {
    4.78 -                // Code here will be called immediately after each test (right
    4.79 -                // before the destructor).
    4.80 -                engine->shut_down();
    4.81 -                delete engine;
    4.82 -                engine = NULL;
    4.83 -                session = NULL;
    4.84 -            }
    4.85 -
    4.86 -        private:
    4.87 -            const char* test_suite_name;
    4.88 -            const char* test_name;
    4.89 -            string test_path;
    4.90 -            // Objects declared here can be used by all tests in the AppleMailTest suite.
    4.91 -
    4.92 -    };
    4.93 -
    4.94 -}  // namespace
    4.95 -
    4.96 -
    4.97 -TEST_F(AppleMailTest, check_apple_mail_text_signed_encrypted) {
    4.98 -
    4.99 -    const char* mailfile = "test_mails/apple_mail_TC_signed_encrypted.eml";
   4.100 -
   4.101 -    const string keytextkey1 = slurp("test_keys/pub/pep-test-apple-0x1CCBC7D7_pub.asc");
   4.102 -    const string keytextkey2 = slurp("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
   4.103 -    const string keytextkey3 = slurp("test_keys/pub/pep-test-recip-0x08DB0AEE_pub.asc");
   4.104 -
   4.105 -    PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
   4.106 -    PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
   4.107 -    PEP_STATUS statuskey3 = import_key(session, keytextkey3.c_str(), keytextkey3.length(), NULL);
   4.108 -
   4.109 -    const string mailtext = slurp(mailfile);
   4.110 -    pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE", PEP_OWN_USERID, "pEp Test Recipient");
   4.111 -    me->me = true;
   4.112 -    PEP_STATUS status = set_own_key(session, me, "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE");
   4.113 -
   4.114 -    pEp_identity * you = new_identity("pep.test.apple@pep-project.org", NULL, "pep.test.apple@pep-project.org", "pEp Apple Test");
   4.115 -    you->me = false;
   4.116 -    status = update_identity(session, you);
   4.117 -
   4.118 -    trust_personal_key(session, you);
   4.119 -
   4.120 -    status = update_identity(session, you);
   4.121 -
   4.122 -    message* msg_ptr = nullptr;
   4.123 -    message* dest_msg = nullptr;
   4.124 -    stringlist_t* keylist = nullptr;
   4.125 -    PEP_rating rating;
   4.126 -    PEP_decrypt_flags_t flags = 0;
   4.127 -
   4.128 -    message* final_ptr = nullptr;
   4.129 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
   4.130 -    ASSERT_EQ(status , PEP_STATUS_OK);
   4.131 -    ASSERT_NE(msg_ptr, nullptr);
   4.132 -
   4.133 -    update_identity(session, msg_ptr->from);
   4.134 -    update_identity(session, msg_ptr->to->ident);
   4.135 -
   4.136 -    final_ptr = msg_ptr;
   4.137 -
   4.138 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
   4.139 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
   4.140 -
   4.141 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
   4.142 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
   4.143 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
   4.144 -
   4.145 -    ASSERT_EQ(color_from_rating(rating) , PEP_color_green);
   4.146 -
   4.147 -    if (final_ptr == dest_msg)
   4.148 -    	free_message(dest_msg);
   4.149 -    free_message(msg_ptr);
   4.150 -    free_stringlist(keylist);
   4.151 -}
   4.152 -
   4.153 -TEST_F(AppleMailTest, check_apple_mail_html_signed_encrypted) {
   4.154 -
   4.155 -    // Start state copy
   4.156 -    // N.B. As part of breaking up formerly monolith tests into individual tests, I've copied state setup from the
   4.157 -    // original functions into many functions. It should, when there's time, either be refactored (if necessary for this
   4.158 -    // test) or removed (if not).
   4.159 -    const string keytextkey1 = slurp("test_keys/pub/pep-test-apple-0x1CCBC7D7_pub.asc");
   4.160 -    const string keytextkey2 = slurp("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
   4.161 -    const string keytextkey3 = slurp("test_keys/pub/pep-test-recip-0x08DB0AEE_pub.asc");
   4.162 -
   4.163 -    PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
   4.164 -    PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
   4.165 -    PEP_STATUS statuskey3 = import_key(session, keytextkey3.c_str(), keytextkey3.length(), NULL);
   4.166 -
   4.167 -    pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE", PEP_OWN_USERID, "pEp Test Recipient");
   4.168 -    me->me = true;
   4.169 -    PEP_STATUS status = set_own_key(session, me, "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE");
   4.170 -
   4.171 -    pEp_identity * you = new_identity("pep.test.apple@pep-project.org", NULL, "pep.test.apple@pep-project.org", "pEp Apple Test");
   4.172 -    you->me = false;
   4.173 -    status = update_identity(session, you);
   4.174 -
   4.175 -    trust_personal_key(session, you);
   4.176 -
   4.177 -    status = update_identity(session, you);
   4.178 -
   4.179 -    // End state copy
   4.180 -
   4.181 -    message* msg_ptr = nullptr;
   4.182 -    message* dest_msg = nullptr;
   4.183 -    message* final_ptr = nullptr;
   4.184 -    stringlist_t* keylist = nullptr;
   4.185 -    PEP_rating rating;
   4.186 -    PEP_decrypt_flags_t flags = 0;
   4.187 -
   4.188 -    const char* mailfile2 = "test_mails/apple_mail_TC_html_signed_encrypted.eml";
   4.189 -    const string mailtext2 = slurp(mailfile2);
   4.190 -
   4.191 -    status = mime_decode_message(mailtext2.c_str(), mailtext2.length(), &msg_ptr);
   4.192 -    ASSERT_EQ(status, PEP_STATUS_OK);
   4.193 -    ASSERT_NE(msg_ptr, nullptr);
   4.194 -    final_ptr = msg_ptr;
   4.195 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
   4.196 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
   4.197 -
   4.198 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
   4.199 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
   4.200 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
   4.201 -
   4.202 -    ASSERT_EQ(color_from_rating(rating) , PEP_color_green);
   4.203 -
   4.204 -    if (final_ptr == dest_msg)
   4.205 -    	free_message(dest_msg);
   4.206 -    free_message(msg_ptr);
   4.207 -    free_stringlist(keylist);
   4.208 -
   4.209 -    msg_ptr = nullptr;
   4.210 -    dest_msg = nullptr;
   4.211 -    final_ptr = nullptr;
   4.212 -    keylist = nullptr;
   4.213 -    rating = PEP_rating_unreliable;
   4.214 -}
     5.1 --- a/gtest/src/BCCTest.cc	Mon Aug 26 12:41:39 2019 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,128 +0,0 @@
     5.4 -// This file is under GNU General Public License 3.0
     5.5 -// see LICENSE.txt
     5.6 -
     5.7 -#include <stdlib.h>
     5.8 -#include <string>
     5.9 -#include <cstring>
    5.10 -#include <assert.h>
    5.11 -
    5.12 -#include "pEpEngine.h"
    5.13 -#include "message_api.h"
    5.14 -#include "TestConstants.h"
    5.15 -
    5.16 -#include "test_util.h"
    5.17 -
    5.18 -
    5.19 -#include "Engine.h"
    5.20 -
    5.21 -#include <gtest/gtest.h>
    5.22 -
    5.23 -
    5.24 -namespace {
    5.25 -
    5.26 -	//The fixture for BCCTest
    5.27 -    class BCCTest : public ::testing::Test {
    5.28 -        public:
    5.29 -            Engine* engine;
    5.30 -            PEP_SESSION session;
    5.31 -
    5.32 -        protected:
    5.33 -            // You can remove any or all of the following functions if its body
    5.34 -            // is empty.
    5.35 -            BCCTest() {
    5.36 -                // You can do set-up work for each test here.
    5.37 -                test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name();
    5.38 -                test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
    5.39 -                test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
    5.40 -            }
    5.41 -
    5.42 -            ~BCCTest() override {
    5.43 -                // You can do clean-up work that doesn't throw exceptions here.
    5.44 -            }
    5.45 -
    5.46 -            // If the constructor and destructor are not enough for setting up
    5.47 -            // and cleaning up each test, you can define the following methods:
    5.48 -
    5.49 -            void SetUp() override {
    5.50 -                // Code here will be called immediately after the constructor (right
    5.51 -                // before each test).
    5.52 -
    5.53 -                // Leave this empty if there are no files to copy to the home directory path
    5.54 -                std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
    5.55 -
    5.56 -                // Get a new test Engine.
    5.57 -                engine = new Engine(test_path);
    5.58 -                ASSERT_NE(engine, nullptr);
    5.59 -
    5.60 -                // Ok, let's initialize test directories etc.
    5.61 -                engine->prep(NULL, NULL, init_files);
    5.62 -
    5.63 -                // Ok, try to start this bugger.
    5.64 -                engine->start();
    5.65 -                ASSERT_NE(engine->session, nullptr);
    5.66 -                session = engine->session;
    5.67 -
    5.68 -                // Engine is up. Keep on truckin'
    5.69 -                
    5.70 -                string keystr = slurp("test_keys/priv/bcc_test_dude_0-0x1CCCFC41_priv.asc");
    5.71 -                PEP_STATUS status = import_key(session, keystr.c_str(), keystr.size(), NULL);
    5.72 -                ASSERT_TRUE(status == PEP_TEST_KEY_IMPORT_SUCCESS);    
    5.73 -                pEp_identity * me = new_identity("bcc_test_dude_0@darthmama.cool", "0AE9AA3E320595CF93296BDFA155AC491CCCFC41", PEP_OWN_USERID, "BCC Test Sender");    
    5.74 -                status = set_own_key(session, me, "0AE9AA3E320595CF93296BDFA155AC491CCCFC41");
    5.75 -                keystr = slurp("test_keys/pub/bcc_test_dude_0-0x1CCCFC41_pub.asc");
    5.76 -                status = import_key(session, keystr.c_str(), keystr.size(), NULL);
    5.77 -                ASSERT_TRUE(status == PEP_TEST_KEY_IMPORT_SUCCESS);
    5.78 -                keystr = slurp("test_keys/pub/bcc_test_dude_1-0xDAC746BE_pub.asc");
    5.79 -                status = import_key(session, keystr.c_str(), keystr.size(), NULL);
    5.80 -                ASSERT_TRUE(status == PEP_TEST_KEY_IMPORT_SUCCESS);
    5.81 -                keystr = slurp("test_keys/pub/bcc_test_dude_2-0x53CECCF7_pub.asc");
    5.82 -                status = import_key(session, keystr.c_str(), keystr.size(), NULL);
    5.83 -                ASSERT_TRUE(status == PEP_TEST_KEY_IMPORT_SUCCESS);    
    5.84 -
    5.85 -            }
    5.86 -
    5.87 -            void TearDown() override {
    5.88 -                // Code here will be called immediately after each test (right
    5.89 -                // before the destructor).
    5.90 -                engine->shut_down();
    5.91 -                delete engine;
    5.92 -                engine = NULL;
    5.93 -                session = NULL;
    5.94 -            }
    5.95 -
    5.96 -        private:
    5.97 -            const char* test_suite_name;
    5.98 -            const char* test_name;
    5.99 -            string test_path;
   5.100 -            // Objects declared here can be used by all tests in the BCCTest suite.
   5.101 -
   5.102 -    };
   5.103 -
   5.104 -}  // namespace
   5.105 -
   5.106 -TEST_F(BCCTest, check_single_BCC) {
   5.107 -    PEP_STATUS status = PEP_UNKNOWN_ERROR;
   5.108 -
   5.109 -    // 0AE9AA3E320595CF93296BDFA155AC491CCCFC41
   5.110 -    // D0AF2F9695E186A8DC058B935FE2793DDAC746BE
   5.111 -    // B36E468E7A381946FCDBDDFA84B1F3E853CECCF7
   5.112 -    pEp_identity* sender = new_identity("bcc_test_dude_0@darthmama.cool", NULL, PEP_OWN_USERID, "BCC Test Sender");
   5.113 -    pEp_identity* open_recip = new_identity("bcc_test_dude_1@darthmama.cool", NULL, NULL, "BCC Test Recip");
   5.114 -    pEp_identity* bcc_recip = new_identity("bcc_test_dude_2@darthmama.cool", NULL, NULL, "BCC Super Sekrit Test Recip");
   5.115 -
   5.116 -    message *msg = new_message(PEP_dir_outgoing);
   5.117 -    ASSERT_NE(msg, nullptr);
   5.118 -    msg->from = sender;
   5.119 -//    msg->to = new_identity_list(open_recip); FYI, this is supposed to fail for now. Unfortunately.
   5.120 -    msg->bcc = new_identity_list(bcc_recip);
   5.121 -    msg->shortmsg = strdup("Hello, world");
   5.122 -    msg->longmsg = strdup("Your mother was a hamster and your father smelt of elderberries.");
   5.123 -    msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   5.124 -
   5.125 -    message *enc_msg = nullptr;
   5.126 -    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
   5.127 -
   5.128 -    ASSERT_EQ(status, PEP_STATUS_OK);
   5.129 -    free_message(msg);
   5.130 -    free_message(enc_msg);
   5.131 -}
     6.1 --- a/gtest/src/BlacklistAcceptNewKeyTest.cc	Mon Aug 26 12:41:39 2019 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,160 +0,0 @@
     6.4 -// This file is under GNU General Public License 3.0
     6.5 -// see LICENSE.txt
     6.6 -
     6.7 -#include <stdlib.h>
     6.8 -#include <string>
     6.9 -#include <cstring> // for strcmp()
    6.10 -
    6.11 -#include "test_util.h"
    6.12 -#include "TestConstants.h"
    6.13 -
    6.14 -#include "pEpEngine.h"
    6.15 -#include "blacklist.h"
    6.16 -#include "keymanagement.h"
    6.17 -#include "message_api.h"
    6.18 -#include "mime.h"
    6.19 -
    6.20 -
    6.21 -
    6.22 -#include "Engine.h"
    6.23 -
    6.24 -#include <gtest/gtest.h>
    6.25 -
    6.26 -
    6.27 -namespace {
    6.28 -
    6.29 -	//The fixture for BlacklistAcceptNewKeyTest
    6.30 -    class BlacklistAcceptNewKeyTest : public ::testing::Test {
    6.31 -        public:
    6.32 -            Engine* engine;
    6.33 -            PEP_SESSION session;
    6.34 -
    6.35 -        protected:
    6.36 -            // You can remove any or all of the following functions if its body
    6.37 -            // is empty.
    6.38 -            BlacklistAcceptNewKeyTest() {
    6.39 -                // You can do set-up work for each test here.
    6.40 -                test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name();
    6.41 -                test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
    6.42 -                test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
    6.43 -            }
    6.44 -
    6.45 -            ~BlacklistAcceptNewKeyTest() override {
    6.46 -                // You can do clean-up work that doesn't throw exceptions here.
    6.47 -            }
    6.48 -
    6.49 -            // If the constructor and destructor are not enough for setting up
    6.50 -            // and cleaning up each test, you can define the following methods:
    6.51 -
    6.52 -            void SetUp() override {
    6.53 -                // Code here will be called immediately after the constructor (right
    6.54 -                // before each test).
    6.55 -
    6.56 -                // Leave this empty if there are no files to copy to the home directory path
    6.57 -                std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
    6.58 -
    6.59 -                // Get a new test Engine.
    6.60 -                engine = new Engine(test_path);
    6.61 -                ASSERT_NE(engine, nullptr);
    6.62 -
    6.63 -                // Ok, let's initialize test directories etc.
    6.64 -                engine->prep(NULL, NULL, init_files);
    6.65 -
    6.66 -                // Ok, try to start this bugger.
    6.67 -                engine->start();
    6.68 -                ASSERT_NE(engine->session, nullptr);
    6.69 -                session = engine->session;
    6.70 -
    6.71 -                // Engine is up. Keep on truckin'
    6.72 -            }
    6.73 -
    6.74 -            void TearDown() override {
    6.75 -                // Code here will be called immediately after each test (right
    6.76 -                // before the destructor).
    6.77 -                engine->shut_down();
    6.78 -                delete engine;
    6.79 -                engine = NULL;
    6.80 -                session = NULL;
    6.81 -            }
    6.82 -
    6.83 -        private:
    6.84 -            const char* test_suite_name;
    6.85 -            const char* test_name;
    6.86 -            string test_path;
    6.87 -            // Objects declared here can be used by all tests in the BlacklistAcceptNewKeyTest suite.
    6.88 -
    6.89 -    };
    6.90 -
    6.91 -}  // namespace
    6.92 -
    6.93 -
    6.94 -TEST_F(BlacklistAcceptNewKeyTest, check_blacklist_accept_new_key) {
    6.95 -
    6.96 -    // blacklist test code
    6.97 -
    6.98 -    cout << "blacklist only key for identity / add key / check which key is used" << endl;
    6.99 -
   6.100 -    // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
   6.101 -
   6.102 -    /* read the key into memory */
   6.103 -    const string keytext = slurp("blacklisted_pub.asc");
   6.104 -
   6.105 -    /* import it into pep */
   6.106 -    PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
   6.107 -
   6.108 -    const char* bl_fpr_1 = "279765A2FEB5B7C731B861D93E4CEFD9F7AF4684";
   6.109 -    bool is_blacklisted = false;
   6.110 -
   6.111 -    pEp_identity* blacklisted_identity = new_identity("blacklistedkeys@kgrothoff.org",
   6.112 -                                                      bl_fpr_1,
   6.113 -                                                      NULL,
   6.114 -                                                      "Blacklist Keypair");
   6.115 -    PEP_STATUS status8 = update_identity(session, blacklisted_identity);
   6.116 -    PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
   6.117 -    PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
   6.118 -    ASSERT_TRUE(is_blacklisted);
   6.119 -    PEP_STATUS status11 = update_identity(session, blacklisted_identity);
   6.120 -    ASSERT_EQ(status11 , PEP_STATUS_OK);
   6.121 -    ASSERT_STREQ(bl_fpr_1, blacklisted_identity->fpr);
   6.122 -
   6.123 -    bool id_def, us_def, addr_def;
   6.124 -    status11 = get_valid_pubkey(session, blacklisted_identity,
   6.125 -                                &id_def, &us_def, &addr_def, true);
   6.126 -    ASSERT_EQ(blacklisted_identity->comm_type , PEP_ct_unknown);
   6.127 -
   6.128 -    if (!(blacklisted_identity->fpr))
   6.129 -        cout << "OK! blacklisted_identity->fpr is empty. Yay!" << endl;
   6.130 -    else
   6.131 -        cout << "Not OK. blacklisted_identity->fpr is " << blacklisted_identity->fpr << "." << endl
   6.132 -             << "Expected it to be empty." << endl;
   6.133 -    ASSERT_TRUE(blacklisted_identity->fpr == NULL || blacklisted_identity->fpr[0] == '\0');
   6.134 -
   6.135 -    /* identity is blacklisted. Now let's read in a message which contains a new key for that ID. */
   6.136 -
   6.137 -    const char* new_key = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B";
   6.138 -    const string mailtext = slurp("test_mails/blacklist_new_key_attached.eml");
   6.139 -    pEp_identity * me1 = new_identity("blacklist_test@kgrothoff.org", NULL, PEP_OWN_USERID, "Blacklisted Key Message Recipient");
   6.140 -
   6.141 -    PEP_STATUS status = update_identity(session, me1);
   6.142 -    message* msg_ptr = nullptr;
   6.143 -    message* dest_msg = nullptr;
   6.144 -    stringlist_t* keylist = nullptr;
   6.145 -    PEP_rating rating;
   6.146 -    PEP_decrypt_flags_t flags = 0;
   6.147 -
   6.148 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
   6.149 -    ASSERT_EQ(status , PEP_STATUS_OK);
   6.150 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
   6.151 -
   6.152 -    PEP_STATUS status12 = get_valid_pubkey(session, blacklisted_identity,
   6.153 -                                           &id_def, &us_def, &addr_def, true);
   6.154 -
   6.155 -    ASSERT_STRCASEEQ(blacklisted_identity->fpr, new_key);
   6.156 -
   6.157 -    PEP_STATUS status13 = blacklist_delete(session, bl_fpr_1);
   6.158 -    PEP_STATUS status14 = update_identity(session, blacklisted_identity);
   6.159 -
   6.160 -    free_message(msg_ptr);
   6.161 -    free_message(dest_msg);
   6.162 -    free_stringlist(keylist);
   6.163 -}
     7.1 --- a/gtest/src/BlacklistTest.cc	Mon Aug 26 12:41:39 2019 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,261 +0,0 @@
     7.4 -// This file is under GNU General Public License 3.0
     7.5 -// see LICENSE.txt
     7.6 -
     7.7 -// #include <iostream>
     7.8 -// #include <iostream>
     7.9 -// #include <fstream>
    7.10 -// #include <string>
    7.11 -// #include <cstring> // for strcmp()
    7.12 -// #include <TEST_ASSERT.h>
    7.13 -// #include "blacklist.h"
    7.14 -// #include "keymanagement.h"
    7.15 -// #include "test_util.h"
    7.16 -//
    7.17 -// // This file is under GNU General Public License 3.0
    7.18 -// // see LICENSE.txt
    7.19 -
    7.20 -#include <stdlib.h>
    7.21 -#include <string>
    7.22 -#include <cstring> // for strcmp()
    7.23 -
    7.24 -
    7.25 -#include <assert.h>
    7.26 -
    7.27 -#include "pEpEngine.h"
    7.28 -
    7.29 -#include "blacklist.h"
    7.30 -#include "keymanagement.h"
    7.31 -#include "test_util.h"
    7.32 -#include "TestConstants.h"
    7.33 -
    7.34 -
    7.35 -
    7.36 -#include "Engine.h"
    7.37 -
    7.38 -#include <gtest/gtest.h>
    7.39 -
    7.40 -
    7.41 -namespace {
    7.42 -
    7.43 -	//The fixture for BlacklistTest
    7.44 -    class BlacklistTest : public ::testing::Test {
    7.45 -        public:
    7.46 -            Engine* engine;
    7.47 -            PEP_SESSION session;
    7.48 -
    7.49 -        protected:
    7.50 -            // You can remove any or all of the following functions if its body
    7.51 -            // is empty.
    7.52 -            BlacklistTest() {
    7.53 -                // You can do set-up work for each test here.
    7.54 -                test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name();
    7.55 -                test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
    7.56 -                test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
    7.57 -            }
    7.58 -
    7.59 -            ~BlacklistTest() override {
    7.60 -                // You can do clean-up work that doesn't throw exceptions here.
    7.61 -            }
    7.62 -
    7.63 -            // If the constructor and destructor are not enough for setting up
    7.64 -            // and cleaning up each test, you can define the following methods:
    7.65 -
    7.66 -            void SetUp() override {
    7.67 -                // Code here will be called immediately after the constructor (right
    7.68 -                // before each test).
    7.69 -
    7.70 -                // Leave this empty if there are no files to copy to the home directory path
    7.71 -                std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
    7.72 -
    7.73 -                // Get a new test Engine.
    7.74 -                engine = new Engine(test_path);
    7.75 -                ASSERT_NE(engine, nullptr);
    7.76 -
    7.77 -                // Ok, let's initialize test directories etc.
    7.78 -                engine->prep(NULL, NULL, init_files);
    7.79 -
    7.80 -                // Ok, try to start this bugger.
    7.81 -                engine->start();
    7.82 -                ASSERT_NE(engine->session, nullptr);
    7.83 -                session = engine->session;
    7.84 -
    7.85 -                // Engine is up. Keep on truckin'
    7.86 -            }
    7.87 -
    7.88 -            void TearDown() override {
    7.89 -                // Code here will be called immediately after each test (right
    7.90 -                // before the destructor).
    7.91 -                engine->shut_down();
    7.92 -                delete engine;
    7.93 -                engine = NULL;
    7.94 -                session = NULL;
    7.95 -            }
    7.96 -
    7.97 -        private:
    7.98 -            const char* test_suite_name;
    7.99 -            const char* test_name;
   7.100 -            string test_path;
   7.101 -            // Objects declared here can be used by all tests in the BlacklistTest suite.
   7.102 -
   7.103 -    };
   7.104 -
   7.105 -}  // namespace
   7.106 -
   7.107 -
   7.108 -TEST_F(BlacklistTest, check_blacklist) {
   7.109 -    // blacklist test code
   7.110 -
   7.111 -    cout << "adding 23 to blacklist\n";
   7.112 -    PEP_STATUS status2 = blacklist_add(session, "23");
   7.113 -    ASSERT_EQ(status2 , PEP_STATUS_OK);
   7.114 -    cout << "added.\n";
   7.115 -
   7.116 -    bool listed;
   7.117 -    PEP_STATUS status3 = blacklist_is_listed(session, "23", &listed);
   7.118 -    ASSERT_EQ(status3 , PEP_STATUS_OK);
   7.119 -    ASSERT_TRUE(listed);
   7.120 -    cout << "23 is listed.\n";
   7.121 -
   7.122 -    stringlist_t *blacklist;
   7.123 -    PEP_STATUS status6 = blacklist_retrieve(session, &blacklist);
   7.124 -    ASSERT_EQ(status6 , PEP_STATUS_OK);
   7.125 -    ASSERT_NE(blacklist, nullptr);
   7.126 -
   7.127 -    bool in23 = false;
   7.128 -    cout << "the blacklist contains now: ";
   7.129 -    for (stringlist_t *bl = blacklist; bl && bl->value; bl = bl->next) {
   7.130 -        cout << bl->value << ", ";
   7.131 -        if (std::strcmp(bl->value, "23") == 0)
   7.132 -            in23 = true;
   7.133 -    }
   7.134 -    cout << "END\n";
   7.135 -    ASSERT_TRUE(in23);
   7.136 -    free_stringlist(blacklist);
   7.137 -
   7.138 -    cout << "deleting 23 from blacklist\n";
   7.139 -    PEP_STATUS status4 = blacklist_delete(session, "23");
   7.140 -    ASSERT_EQ(status4 , PEP_STATUS_OK);
   7.141 -    cout << "deleted.\n";
   7.142 -
   7.143 -    PEP_STATUS status5 = blacklist_is_listed(session, "23", &listed);
   7.144 -    ASSERT_EQ(status5 , PEP_STATUS_OK);
   7.145 -    ASSERT_TRUE(!listed);
   7.146 -    cout << "23 is not listed any more.\n";
   7.147 -
   7.148 -    cout << "blacklist only key for identity / unblacklist key / add key" << endl;
   7.149 -
   7.150 -
   7.151 -    // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
   7.152 -
   7.153 -    const string keytext = slurp("blacklisted_pub.asc");
   7.154 -
   7.155 -    /* FIXME: put in automated test stuff (N.B. only gdb mem examination to this point to get
   7.156 -     *        fix in */
   7.157 -    /* import it into pep */
   7.158 -    PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
   7.159 -
   7.160 -    const char* bl_fpr_1 = "279765A2FEB5B7C731B861D93E4CEFD9F7AF4684";
   7.161 -    const char* bl_fpr_2 = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B";
   7.162 -    bool is_blacklisted = false;
   7.163 -
   7.164 -    // Clean up from previous runs
   7.165 -    PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
   7.166 -    if (is_blacklisted) {
   7.167 -        is_blacklisted = false;
   7.168 -        blacklist_delete(session, bl_fpr_1);
   7.169 -    }
   7.170 -
   7.171 -    pEp_identity* blacklisted_identity = new_identity("blacklistedkeys@kgrothoff.org",
   7.172 -                                                      bl_fpr_1,
   7.173 -                                                      NULL,
   7.174 -                                                      "Blacklist Keypair");
   7.175 -
   7.176 -    PEP_STATUS status8 = update_identity(session, blacklisted_identity);
   7.177 -
   7.178 -    // THERE IS NO BLACKLISTING OF PEP KEYS
   7.179 -    //blacklisted_identity->comm_type = PEP_ct_pEp;
   7.180 -    blacklisted_identity->comm_type = PEP_ct_OpenPGP_unconfirmed;
   7.181 -
   7.182 -    PEP_STATUS status99 = set_identity(session, blacklisted_identity);
   7.183 -
   7.184 -    trust_personal_key(session, blacklisted_identity);
   7.185 -
   7.186 -    PEP_STATUS status999 = update_identity(session, blacklisted_identity);
   7.187 -
   7.188 -    ASSERT_EQ(blacklisted_identity->comm_type , PEP_ct_OpenPGP);
   7.189 -
   7.190 -    PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
   7.191 -    status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
   7.192 -    PEP_STATUS status11 = update_identity(session, blacklisted_identity);
   7.193 -    /* new!!! */
   7.194 -    ASSERT_TRUE(is_blacklisted);
   7.195 -    ASSERT_EQ(status11 , PEP_STATUS_OK);
   7.196 -    ASSERT_STREQ(bl_fpr_1, blacklisted_identity->fpr);
   7.197 -
   7.198 -    bool id_def, us_def, addr_def;
   7.199 -    status11 = get_valid_pubkey(session, blacklisted_identity,
   7.200 -                                &id_def, &us_def, &addr_def, true);
   7.201 -
   7.202 -    if (!(blacklisted_identity->fpr))
   7.203 -        cout << "OK! blacklisted_identity->fpr is empty. Yay!" << endl;
   7.204 -    else if (strcmp(blacklisted_identity->fpr, bl_fpr_2) == 0)
   7.205 -        cout << "OK! While this should be empty, you are probably running " <<
   7.206 -                "this in your home directory instead of the test environment " <<
   7.207 -                "and have leftover keys. This is an acceptable result here then. But you " <<
   7.208 -                "should probably clean up after yourself :)" << endl;
   7.209 -    else
   7.210 -        cout << "Not OK. blacklisted_identity->fpr is " << blacklisted_identity->fpr << "." << endl
   7.211 -             << "Expected it to be empty or (possibly) " << bl_fpr_2 << endl;
   7.212 -
   7.213 -    ASSERT_TRUE(blacklisted_identity->fpr == NULL || blacklisted_identity->fpr[0] == '\0' || strcmp(blacklisted_identity->fpr, bl_fpr_2) == 0);
   7.214 -
   7.215 -    pEp_identity *me = new_identity("alice@peptest.ch", NULL, "423", "Alice Miller");
   7.216 -    ASSERT_NE(me, nullptr);
   7.217 -    PEP_STATUS status24 = myself(session, me);
   7.218 -    ASSERT_EQ(status24 , PEP_STATUS_OK);
   7.219 -
   7.220 -    message *msg23 = new_message(PEP_dir_outgoing);
   7.221 -    ASSERT_NE(msg23, nullptr);
   7.222 -    msg23->from = me;
   7.223 -    msg23->to = new_identity_list(identity_dup(blacklisted_identity));
   7.224 -    ASSERT_TRUE(msg23->to != NULL && msg23->to->ident != NULL);
   7.225 -    PEP_rating rating23;
   7.226 -
   7.227 -    cout << "testing outgoing_message_rating() with blacklisted key in to\n";
   7.228 -    PEP_STATUS status23 = outgoing_message_rating(session, msg23, &rating23);
   7.229 -    ASSERT_EQ(status23 , PEP_STATUS_OK);
   7.230 -    ASSERT_EQ(rating23 , PEP_rating_unencrypted);
   7.231 -
   7.232 -    free_message(msg23);
   7.233 -
   7.234 -    const string keytext2 = slurp("blacklisted_pub2.asc");
   7.235 -    PEP_STATUS status14 = import_key(session, keytext2.c_str(), keytext2.length(), NULL);
   7.236 -
   7.237 -    pEp_identity* blacklisted_identity2 = new_identity("blacklistedkeys@kgrothoff.org",
   7.238 -                                                       bl_fpr_2,
   7.239 -                                                        NULL,
   7.240 -                                                       "Blacklist Keypair");
   7.241 -    PEP_STATUS status15 = update_identity(session, blacklisted_identity2);
   7.242 -    //
   7.243 -    // ASSERT_EQ((blacklisted_identity2->fpr && strcmp(blacklisted_identity2->fpr, bl_fpr_2) , 0), "blacklisted_identity2->fpr && strcmp(blacklisted_identity2->fpr);
   7.244 -    // if (blacklisted_identity2->fpr && strcmp(blacklisted_identity2->fpr, bl_fpr_2) == 0)
   7.245 -    //     cout << "blacklisted identity's fpr successfully replaced by the unblacklisted one" << endl;
   7.246 -    // // else
   7.247 -    // //     cout << "blacklisted_identity->fpr should be " << bl_fpr_2 << " but is " << blacklisted_identity->fpr << endl;
   7.248 -    //
   7.249 -    // PEP_STATUS status12 = blacklist_delete(session, bl_fpr_1);
   7.250 -    // PEP_STATUS status13 = update_identity(session, blacklisted_identity);
   7.251 -    //
   7.252 -    // pEp_identity* stored_identity = new_identity("blacklistedkeys@kgrothoff.org",
   7.253 -    //                                               NULL,
   7.254 -    //                                               blacklisted_identity->user_id,
   7.255 -    //                                               "Blacklist Keypair");
   7.256 -    //
   7.257 -    // PEP_STATUS status00 = update_identity(session, stored_identity);
   7.258 -    //
   7.259 -    // // FIXME
   7.260 -    // // ASSERT_EQ(stored_identity->comm_type , PEP_ct_pEp);
   7.261 -
   7.262 -    free_identity(blacklisted_identity);
   7.263 -    free_identity(blacklisted_identity2);
   7.264 -}
     8.1 --- a/gtest/src/Engine.cc	Mon Aug 26 12:41:39 2019 +0200
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,203 +0,0 @@
     8.4 -#include <stdlib.h>
     8.5 -#include <sys/stat.h>
     8.6 -#include <errno.h>
     8.7 -#include <stdlib.h>
     8.8 -#include <unistd.h>
     8.9 -#include <ftw.h>
    8.10 -#include <assert.h>
    8.11 -#include <fstream>
    8.12 -#include <iostream>
    8.13 -#include <sys/types.h>
    8.14 -#include <sys/stat.h>
    8.15 -
    8.16 -#include <string>
    8.17 -#include <vector>
    8.18 -#include <utility>
    8.19 -
    8.20 -#include "platform_unix.h"
    8.21 -
    8.22 -#include "test_util.h"
    8.23 -#include "Engine.h"
    8.24 -#include "pEpTestStatic.h"
    8.25 -#include <algorithm>
    8.26 -#include "TestConstants.h"
    8.27 -
    8.28 -using namespace std;
    8.29 -
    8.30 -// Constructor
    8.31 -Engine::Engine(string engine_home_dir) {
    8.32 -    // FIXME: deal with base
    8.33 -    engine_home = engine_home_dir;
    8.34 -            
    8.35 -    real_home = getenv("HOME");
    8.36 -    cached_messageToSend = NULL;
    8.37 -    cached_inject_sync_event = NULL;
    8.38 -}
    8.39 -
    8.40 -Engine::~Engine() {}
    8.41 -
    8.42 -void Engine::prep(messageToSend_t mts, inject_sync_event_t ise, 
    8.43 -                  std::vector<std::pair<std::string, std::string>> init_files) {
    8.44 -    if (engine_home.empty())
    8.45 -        throw std::runtime_error("Engine setup: BAD INITIALISATION. No test home.");
    8.46 -    
    8.47 -    cached_messageToSend = mts;
    8.48 -    cached_inject_sync_event = ise;
    8.49 -
    8.50 -    int success = 0;
    8.51 -    struct stat dirchk;
    8.52 -        
    8.53 -    if (stat(engine_home.c_str(), &dirchk) == 0) {
    8.54 -        if (!S_ISDIR(dirchk.st_mode))
    8.55 -            throw std::runtime_error(("ENGINE SETUP: The test directory, " + engine_home + " exists, but is not a directory.").c_str()); 
    8.56 -                    
    8.57 -        struct stat buf;
    8.58 -
    8.59 -        if (stat(engine_home.c_str(), &buf) == 0) {
    8.60 -            int success = nftw((engine_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
    8.61 -        }
    8.62 -    }
    8.63 -    else {
    8.64 -        // Look, we're not creating all of these dirs...
    8.65 -        const int errchk = system((string("mkdir -p ") + engine_home).c_str());
    8.66 -        if (errchk != 0)
    8.67 -            throw std::runtime_error("ENGINE SETUP: Error creating a test directory.");        
    8.68 -    }
    8.69 -
    8.70 -    process_file_queue(engine_home, init_files);
    8.71 -
    8.72 -    // We will set homedirs etc outside this function. Right now, we're just making sure we can.
    8.73 -    // Let's make sure we're not trying to run it under the real current home, however.
    8.74 -    
    8.75 -    if (engine_home.compare(real_home) == 0 || engine_home.compare(real_home + "/") == 0)
    8.76 -        throw std::runtime_error("ENGINE SETUP: Cowardly refusing to set up for playing in what looks like the real home directory.");
    8.77 -    
    8.78 -}
    8.79 -
    8.80 -void Engine::start() {    
    8.81 -    if (engine_home.empty())
    8.82 -        throw std::runtime_error("Engine start: BAD INITIALISATION. No test home. Did you call Engine::prep() first?");
    8.83 -
    8.84 -    assert(engine_home.compare(real_home) != 0);
    8.85 -    assert(engine_home.compare(real_home + "/") != 0);
    8.86 -    cout << "Test home directory is " << engine_home << endl;
    8.87 -    
    8.88 -    int success = 0;
    8.89 -    
    8.90 -#ifdef USE_GPG
    8.91 -    char* tmp = NULL;
    8.92 -
    8.93 -    success = system("gpgconf --kill all");
    8.94 -    if (success != 0)
    8.95 -        throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");    
    8.96 -    tmp = getenv("GNUPGHOME");
    8.97 -
    8.98 -    prev_pgp_home.clear();
    8.99 -    
   8.100 -    if (tmp)
   8.101 -        prev_pgp_home = tmp;
   8.102 -
   8.103 -    if (engine_home.compare(real_home + "/gnupg") == 0 || engine_home.compare(real_home + "gnupg") == 0 ||
   8.104 -        engine_home.compare(real_home + "/.gnupg") == 0 || engine_home.compare(real_home + ".gnupg") == 0 ||
   8.105 -        engine_home.compare(prev_pgp_home) == 0 || engine_home.compare(prev_pgp_home + "/gnupg") == 0 ||
   8.106 -        engine_home.compare(prev_pgp_home + "gnupg") == 0 || engine_home.compare(prev_pgp_home + "/.gnupg") == 0 ||
   8.107 -        engine_home.compare(prev_pgp_home + ".gnupg") == 0)
   8.108 -        throw std::runtime_error("Engine start: new pgp homedir threatens to mess up user pgp homedir (and delete all their keys). NO DICE.");
   8.109 -    
   8.110 -    success = setenv("GNUPGHOME", (engine_home + "/gnupg").c_str(), 1);
   8.111 -    if (success != 0)
   8.112 -        throw std::runtime_error("SETUP: Error when setting GNUPGHOME.");
   8.113 -
   8.114 -    cout << "New GNUPGHOME is " << getenv("GNUPGHOME") << endl << endl;
   8.115 -
   8.116 -#endif
   8.117 -    
   8.118 -    success = setenv("HOME", engine_home.c_str(), 1);
   8.119 -    if (success != 0)
   8.120 -        throw std::runtime_error("SETUP: Cannot set engine_home for init.");
   8.121 -            
   8.122 -    unix_local_db(true);
   8.123 -    gpg_conf(true);
   8.124 -    gpg_agent_conf(true);
   8.125 -        
   8.126 -    PEP_STATUS status = init(&session, cached_messageToSend, cached_inject_sync_event);
   8.127 -    assert(status == PEP_STATUS_OK);
   8.128 -    assert(session);
   8.129 -
   8.130 -#ifdef USE_GPG
   8.131 -    success = system("gpgconf --create-socketdir");
   8.132 -    if (success != 0)
   8.133 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --create-socketdir'.");        
   8.134 -    system("gpg-connect-agent /bye 2>/dev/null");   // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
   8.135 -#endif
   8.136 -}
   8.137 -
   8.138 -void Engine::copy_conf_file_to_test_dir(const char* dest_path, const char* conf_orig_path, const char* conf_dest_name) {
   8.139 -    string conf_dest_path = dest_path;
   8.140 -    
   8.141 -    struct stat pathinfo;
   8.142 -
   8.143 -    if(stat(conf_dest_path.c_str(), &pathinfo) != 0) {
   8.144 -        int errchk = mkdir(conf_dest_path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
   8.145 -        if (errchk != 0)
   8.146 -            throw std::runtime_error("Error accessing conf file directory.");
   8.147 -    }
   8.148 -    
   8.149 -    conf_dest_path += "/";
   8.150 -    conf_dest_path += conf_dest_name;
   8.151 -    
   8.152 -    ifstream src(conf_orig_path);
   8.153 -    ofstream dst(conf_dest_path.c_str(), ios::trunc);
   8.154 -    
   8.155 -    assert(src);
   8.156 -    assert(dst);
   8.157 -    
   8.158 -    dst << src.rdbuf();
   8.159 -     
   8.160 -    src.close();
   8.161 -    dst.close();
   8.162 -}
   8.163 -
   8.164 -void Engine::process_file_queue(string dirname, vector<pair<string, string>> file_queue) {
   8.165 -    if (file_queue.empty())
   8.166 -        return;
   8.167 -        
   8.168 -    vector<pair<string, string>>::iterator it;
   8.169 -    
   8.170 -    for (it = file_queue.begin(); it != file_queue.end(); it++) {
   8.171 -        copy_conf_file_to_test_dir(dirname.c_str(), it->first.c_str(), it->second.c_str());
   8.172 -    }
   8.173 -    
   8.174 -    file_queue.clear();
   8.175 -}
   8.176 -
   8.177 -void Engine::shut_down() {
   8.178 -    release(session);
   8.179 -    session = NULL;
   8.180 -        
   8.181 -    int success = 0;    
   8.182 -
   8.183 -#ifdef USE_GPG 
   8.184 -    success = system("gpgconf --kill all");
   8.185 -    if (success != 0)
   8.186 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --kill all'.");
   8.187 -    success = system("gpgconf --remove-socketdir");            
   8.188 -    if (success != 0)
   8.189 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --remove-socketdir'.");    
   8.190 -
   8.191 -    success = setenv("GNUPGHOME", prev_pgp_home.c_str(), 1);
   8.192 -    if (success != 0)
   8.193 -        throw std::runtime_error("RESTORE: Warning - cannot restore GNUPGHOME. Either set environment variable manually back to your home, or quit this session!");
   8.194 -#endif
   8.195 -                
   8.196 -    success = nftw((engine_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
   8.197 -    
   8.198 -    success = setenv("HOME", real_home.c_str(), 1);
   8.199 -    if (success != 0)
   8.200 -        throw std::runtime_error("RESTORE: Cannot reset home directory! Either set environment variable manually back to your home, or quit this session!");
   8.201 -
   8.202 -    unix_local_db(true);
   8.203 -    gpg_conf(true);
   8.204 -    gpg_agent_conf(true);
   8.205 -
   8.206 -}
     9.1 --- a/gtest/src/Engine.h	Mon Aug 26 12:41:39 2019 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,34 +0,0 @@
     9.4 -#ifndef ENGINE_TEST_SUITE_H
     9.5 -#define ENGINE_TEST_SUITE_H
     9.6 -
     9.7 -#include <string>
     9.8 -#include <map>
     9.9 -#include <vector>
    9.10 -#include <utility>
    9.11 -#include "pEpEngine.h"
    9.12 -
    9.13 -using namespace std;
    9.14 -
    9.15 -class Engine {
    9.16 -    public:
    9.17 -        Engine(string engine_home_dir);
    9.18 -        virtual ~Engine();
    9.19 -        
    9.20 -        void prep(messageToSend_t mts, inject_sync_event_t ise, std::vector<std::pair<std::string, std::string>> init_files);
    9.21 -        void start();
    9.22 -        void shut_down();
    9.23 -
    9.24 -        PEP_SESSION session;
    9.25 -        
    9.26 -    protected:
    9.27 -        string engine_home;
    9.28 -        string real_home;
    9.29 -        string prev_pgp_home;
    9.30 -        
    9.31 -        messageToSend_t cached_messageToSend;
    9.32 -        inject_sync_event_t cached_inject_sync_event;
    9.33 -        	
    9.34 -        void copy_conf_file_to_test_dir(const char* dest_path, const char* conf_orig_path, const char* conf_dest_name);        
    9.35 -        void process_file_queue(std::string dirname, std::vector<std::pair<std::string, std::string>> file_queue);
    9.36 -};
    9.37 -#endif
    10.1 --- a/gtest/src/ExportKeyTest.cc	Mon Aug 26 12:41:39 2019 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,179 +0,0 @@
    10.4 -// This file is under GNU General Public License 3.0
    10.5 -// see LICENSE.txt
    10.6 -
    10.7 -#include <stdlib.h>
    10.8 -#include <cstring>
    10.9 -#include <string>
   10.10 -
   10.11 -#include "test_util.h"
   10.12 -
   10.13 -#include "pEpEngine.h"
   10.14 -
   10.15 -
   10.16 -
   10.17 -#include "Engine.h"
   10.18 -
   10.19 -#include <gtest/gtest.h>
   10.20 -
   10.21 -
   10.22 -namespace {
   10.23 -
   10.24 -	//The fixture for ExportKeyTest
   10.25 -    class ExportKeyTest : public ::testing::Test {
   10.26 -        public:
   10.27 -            Engine* engine;
   10.28 -            PEP_SESSION session;
   10.29 -
   10.30 -        protected:
   10.31 -            // You can remove any or all of the following functions if its body
   10.32 -            // is empty.
   10.33 -            ExportKeyTest() {
   10.34 -                // You can do set-up work for each test here.
   10.35 -                test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name();
   10.36 -                test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
   10.37 -                test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
   10.38 -            }
   10.39 -
   10.40 -            ~ExportKeyTest() override {
   10.41 -                // You can do clean-up work that doesn't throw exceptions here.
   10.42 -            }
   10.43 -
   10.44 -            // If the constructor and destructor are not enough for setting up
   10.45 -            // and cleaning up each test, you can define the following methods:
   10.46 -
   10.47 -            void SetUp() override {
   10.48 -                // Code here will be called immediately after the constructor (right
   10.49 -                // before each test).
   10.50 -
   10.51 -                // Leave this empty if there are no files to copy to the home directory path
   10.52 -                std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
   10.53 -
   10.54 -                // Get a new test Engine.
   10.55 -                engine = new Engine(test_path);
   10.56 -                ASSERT_NE(engine, nullptr);
   10.57 -
   10.58 -                // Ok, let's initialize test directories etc.
   10.59 -                engine->prep(NULL, NULL, init_files);
   10.60 -
   10.61 -                // Ok, try to start this bugger.
   10.62 -                engine->start();
   10.63 -                ASSERT_NE(engine->session, nullptr);
   10.64 -                session = engine->session;
   10.65 -
   10.66 -                // Engine is up. Keep on truckin'
   10.67 -            }
   10.68 -
   10.69 -            void TearDown() override {
   10.70 -                // Code here will be called immediately after each test (right
   10.71 -                // before the destructor).
   10.72 -
   10.73 -                // While it would be nice to have this in the destructor, it can throw exceptions, so it's here.
   10.74 -                engine->shut_down();
   10.75 -                delete engine;
   10.76 -                engine = NULL;
   10.77 -                session = NULL;
   10.78 -            }
   10.79 -
   10.80 -        private:
   10.81 -            const char* test_suite_name;
   10.82 -            const char* test_name;
   10.83 -            string test_path;
   10.84 -            // Objects declared here can be used by all tests in the ExportKeyTest suite.
   10.85 -
   10.86 -    };
   10.87 -
   10.88 -}  // namespace
   10.89 -
   10.90 -
   10.91 -TEST_F(ExportKeyTest, check_export_key_no_key) {
   10.92 -    char* keydata = NULL;
   10.93 -    size_t keysize = 0;
   10.94 -    PEP_STATUS status = export_key(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39",
   10.95 -                                   &keydata, &keysize);
   10.96 -    ASSERT_EQ(status , PEP_KEY_NOT_FOUND);
   10.97 -    free(keydata);
   10.98 -    keydata = NULL;
   10.99 -    keysize = 0;
  10.100 -    status = export_secret_key(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39",
  10.101 -                                   &keydata, &keysize);
  10.102 -    ASSERT_EQ(status , PEP_KEY_NOT_FOUND);
  10.103 -    free(keydata);
  10.104 -
  10.105 -}
  10.106 -
  10.107 -TEST_F(ExportKeyTest, check_export_key_pubkey) {
  10.108 -    // Own pub key
  10.109 -    ASSERT_TRUE(slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc"));
  10.110 -
  10.111 -    char* keydata = NULL;
  10.112 -    size_t keysize = 0;
  10.113 -    stringlist_t* keylist = NULL;
  10.114 -    PEP_STATUS status = find_keys(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", &keylist);
  10.115 -    ASSERT_TRUE(keylist && keylist->value);
  10.116 -    ASSERT_STREQ(keylist->value, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39");
  10.117 -    free_stringlist(keylist);
  10.118 -
  10.119 -    status = export_key(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39",
  10.120 -                                   &keydata, &keysize);
  10.121 -    ASSERT_EQ(status , PEP_STATUS_OK);
  10.122 -    ASSERT_NE(keydata, nullptr);
  10.123 -    ASSERT_GT(keysize, 0);
  10.124 -
  10.125 -    free(keydata);
  10.126 -}
  10.127 -
  10.128 -TEST_F(ExportKeyTest, check_export_key_secret_key) {
  10.129 -    ASSERT_TRUE(slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc"));
  10.130 -    ASSERT_TRUE(slurp_and_import_key(session, "test_keys/priv/pep-test-bob-0xC9C2EE39_priv.asc"));
  10.131 -    char* keydata = NULL;
  10.132 -    size_t keysize = 0;
  10.133 -    stringlist_t* keylist = NULL;
  10.134 -    PEP_STATUS status = find_keys(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", &keylist);
  10.135 -    ASSERT_TRUE(keylist && keylist->value);
  10.136 -    ASSERT_STREQ(keylist->value, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39");
  10.137 -    free_stringlist(keylist);
  10.138 -    keylist = NULL;
  10.139 -
  10.140 -    bool has_private = false;
  10.141 -    contains_priv_key(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", &has_private);
  10.142 -    ASSERT_TRUE(has_private);
  10.143 -
  10.144 -    status = export_key(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39",
  10.145 -                                   &keydata, &keysize);
  10.146 -    ASSERT_EQ(status , PEP_STATUS_OK);
  10.147 -    ASSERT_NE(keydata, nullptr);
  10.148 -    ASSERT_GT(keysize, 0);
  10.149 -
  10.150 -    free(keydata);
  10.151 -    keydata = NULL;
  10.152 -    keysize = 0;
  10.153 -    status = export_secret_key(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39",
  10.154 -                                   &keydata, &keysize);
  10.155 -    ASSERT_EQ(status , PEP_STATUS_OK);
  10.156 -
  10.157 -    free(keydata);
  10.158 -}
  10.159 -
  10.160 -
  10.161 -TEST_F(ExportKeyTest, check_export_key_no_secret_key) {
  10.162 -    // Own pub key
  10.163 -    ASSERT_TRUE(slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc"));
  10.164 -
  10.165 -    char* keydata = NULL;
  10.166 -    size_t keysize = 0;
  10.167 -    stringlist_t* keylist = NULL;
  10.168 -    PEP_STATUS status = find_keys(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", &keylist);
  10.169 -    ASSERT_TRUE(keylist && keylist->value);
  10.170 -    ASSERT_STREQ(keylist->value, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39");
  10.171 -
  10.172 -    status = export_key(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39",
  10.173 -                                   &keydata, &keysize);
  10.174 -    ASSERT_EQ(status , PEP_STATUS_OK);
  10.175 -    free(keydata);
  10.176 -    keydata = NULL;
  10.177 -    keysize = 0;
  10.178 -    status = export_secret_key(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39",
  10.179 -                                   &keydata, &keysize);
  10.180 -    ASSERT_EQ(status , PEP_KEY_NOT_FOUND);
  10.181 -    free(keydata);
  10.182 -}
    11.1 --- a/test/0x6FF00E97.asc	Mon Aug 26 12:41:39 2019 +0200
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,30 +0,0 @@
    11.4 ------BEGIN PGP PUBLIC KEY BLOCK-----
    11.5 -
    11.6 -mQENBFV4PbEBCADTmjGDsoti/VPoZ3w2oCjLBNq1jWIGMkbiUgCGUQjVsNrSZ80U
    11.7 -7RmA3Pcu3hhiVQNBGA32vL6NPhSJPanVd77s6XVZg+Gq7llbGGkuIxSkJvVrWzYc
    11.8 -kjMsAInlJ8Ll0kHHbgATOlO5OtQ21bLCfWZPSq74HEVzQAPtCGYFvOgpCktKTjms
    11.9 -GXe9ysiYN8CEWMVNbDqXmvFhi4UifpITeQBVM7dtlBw5SoeLZpsHIlKF5i5WPkNw
   11.10 -7nuMag/+lRpOqvPumhOmqybWHuAR/Dq0pOOPh6BzZ4OzOBL96aWUe1dcnIZeBEm8
   11.11 -oRxYC3nN95YsjtrLK4BQZTYDTzeh8FIccsLdABEBAAG0RHBFcCBUZXN0IEFsaWNl
   11.12 -ICh0ZXN0IGtleSBkb24ndCB1c2UpIDxwZXAudGVzdC5hbGljZUBwZXAtcHJvamVj
   11.13 -dC5vcmc+iQE4BBMBAgAiBQJVeD2xAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIX
   11.14 -gAAKCRCpQR0Xb/AOl5JjCADEBoordVBCmphG6EY+u5yjj/xeQN4Kc1Rl06Ii6m18
   11.15 -4hnF/osxnTicr+A6Hpwf8whXULuSwXvfuOsVOQdIc2e+1zrecTqyNUWuRs3T7uZ2
   11.16 -5dvROg1XZuajMPf3wh5lX2rPRhOt3UNXJjQfc1MSYXpmT+PoqFXBzMqJUo2DYcw6
   11.17 -MSZekoWkIzFXG2s2YNwILwPnLnMesFtzU6mn9qhfoFsQA6aku8AbG+SNehNZvGuu
   11.18 -UiBmu+4UYNoc/RJa7vNWECv9qZQsT820CuoOZS9MFV7nQlgkGoPerlGXil0vkOG1
   11.19 -gsuQD8QkuaTQpn1vYvRcC0P27qLfrqlPv2Ih2hoIV9tJuQENBFV4PbEBCADQwKB9
   11.20 -7t2B2nweprfpbH8QgLCzJYaAMrpcaUaJqm+J3C9eaepRXTXGtst1zaLbooG2b3QH
   11.21 -fDzI2CEYMxO5ynmmSBOe06VKw/PagBzK5ur/eOycl0ZPFSXdlDj30BQPvRdJvLS4
   11.22 -OTMdoKoGpsZDY4hOYj67oHo3TFtrLJCvZruPARkI/pXiOX9FqH4wquNNaYW1qwk/
   11.23 -Wq3k/gOMwp0xjvc01MbadaiiVquJk6jjPrd2wP4FYxIADAllzMpwFAJSWvgCfmqV
   11.24 -bukYOnaCp3QRQXQkc78TdqGXbD5uwJzkxxiEsMmiGT+7RDLIKwXheKmmGXSwgi8m
   11.25 -+EndUiqMTvOdjyUBABEBAAGJAR8EGAECAAkFAlV4PbECGwwACgkQqUEdF2/wDpeQ
   11.26 -VQgArnfQ7uvG0po/CPepbrdytI2n63U5dm/MFMsvXpZYVYLO/mROc+akZCPwS0yx
   11.27 -tSMKK+tYM9leQx58r89c+K1GeZoko7xziwmZbt5zEITiJp5L6gg7k6CczskPMx07
   11.28 -gY8ooscBC3cFJhz1A0o73BKPR7J0iupaNmI3sTd1/RNQm6573kGGwc4m2bcQttvN
   11.29 -5ox8yimn2QnK3D+6A+Mmzi3Rd11tF+tAWJIsfaEgDJZn9mOdUkV2ckoSk1K5Pptp
   11.30 -XSsKLOL+e2WuxSMIr8AVeRqkbYYK6UzX6qIgQIrMOuaXqtRaNxNccnzIS1YtdtYE
   11.31 -RSnTaBotNp/FF2wfI7BNFP6r0A==
   11.32 -=wSWl
   11.33 ------END PGP PUBLIC KEY BLOCK-----
    12.1 --- a/test/0x70DCF575.asc	Mon Aug 26 12:41:39 2019 +0200
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,30 +0,0 @@
    12.4 ------BEGIN PGP PUBLIC KEY BLOCK-----
    12.5 -
    12.6 -mQENBFV4PvYBCADR7kaFLsLFDuGE11u3q2K6eTspAkczU1ahPnSXaVGOIbCQGuL6
    12.7 -MiDET4vXAY/y1picqJ8OuIe2k0S8eDRIYIHF8arhgTkZQny6Cfy7nheWNnxSZBIo
    12.8 -K/8Zqa9dbNBWwHp2l7LOqM3hS8a0O1mQQrrMlV55qnXWJQFaI3P/nlaGUfe+5DuD
    12.9 -tDom8xJicE8an5nhbsyKyNxlYVePVsQVFiLHMVoNZ6eyfyb/nTBdAdQ0KLZM0vDC
   12.10 -8df/VTevytf/PgunziqD67HuDx8Uxyeht5REIrcBEyrgtnvTkVjZJ2MpbXcY2kam
   12.11 -36OH8T4JoBkxlqjU6UiiqV+k04QzAvmp2/anABEBAAG0Q3BFcCBUZXN0IEpvaG4g
   12.12 -KHRlc3Qga2V5LCBkb24ndCB1c2UpIDxwZXAudGVzdC5qb2huQHBlcC1wcm9qZWN0
   12.13 -Lm9yZz6JATgEEwECACIFAlV4PvYCGwMGCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheA
   12.14 -AAoJEBNc1tFw3PV1rQsIAIGxmMHjAQqsZB7CQAdEdWxM+YkGZPAOqMYZrVaf+wiI
   12.15 -kMP25B9JaSYRccYbI+k+Vg19l5vqVv/ixgDLntZWJFt3LakKkTY3R8ghhKImlVVo
   12.16 -gj6ASho0rUoHLpCLuo0t+N+DGTjBOi1tu90U9L3poPsgYOij6pw226M6zXsvsk4h
   12.17 -Uuljq9ZysKbjGEoqahOLf7p7gjrtCceOQfqnXKNE9QlpQtw/pnwTa97gVR4l7DaK
   12.18 -UEXzASobjEywfCoMH9SaoVL5M/FsIkMSasg6H+J4U8YdxE5x2BRbTQe+90/RlVg5
   12.19 -bNCK9nMKBMBr0KeeJn9JZRykwKOgV5vZl0lQ5BEKEia5AQ0EVXg+9gEIAMEvDo98
   12.20 -6hv9pk4YKLLRhZVyp3KiDQ2ymjdl8v/kh2f3s2roNhF5o2pTfq51oTCIex0Wiyri
   12.21 -7o/1V21e3wYS14uRzF86a5cvmOdR/w1+NuW7hoW9RWBEaC7O4N/TtU7AAQmav8mA
   12.22 -CJBHwdoE98BKmJNAG3SOh/kSdh5HZrL5Yrx4tX7dkJOXI2Jql0IS4R37dmAX5K+9
   12.23 -MqIFDJf0I73iiBGr0v6mbOCEonBznF/6H905Ci2uPZ38DHixN2cyToZg7CkTfC7K
   12.24 -8xmHFv1lcRzlTMyNC0xOlirYPPlhnGslyiyTJqHVyrH/Z788x6wV9ifPnDZfGmRk
   12.25 -C2V8HTBRQhdIuREAEQEAAYkBHwQYAQIACQUCVXg+9gIbDAAKCRATXNbRcNz1dUKv
   12.26 -B/46nvjKNTtPJXidArkPP8rY57kEVWg8spkqBWIeV3AGMzh9qVfRRv4Pfl9IgHaO
   12.27 -vXkoKip9D4zvgpB566gIiE3B3Y4vEzToiBxqVo5L5gzmbG6J1cQdHz6rmKSHPf4z
   12.28 -rNQbCxaGXIJ697mlfKIiIBrV67sH3Xm2l6ECp8PiQGImLFaBI2SbuLSHSz1nC910
   12.29 -ln8AhSYAYlxYBdateo3IZwAZSQibCF/xChvnDcDjZa9GWo3iMlSPAoKXacbrdenj
   12.30 -F/X9yyoeTtTNTuNDGr9Sms72wU+SAYErLDcik1pRhNDmLXEjQC7eBT9WFemkfOVj
   12.31 -mDKjonb9yAz6knxC5kRE5ChX
   12.32 -=csku
   12.33 ------END PGP PUBLIC KEY BLOCK-----
    13.1 --- a/test/0xC9C2EE39.asc	Mon Aug 26 12:41:39 2019 +0200
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,30 +0,0 @@
    13.4 ------BEGIN PGP PUBLIC KEY BLOCK-----
    13.5 -
    13.6 -mQENBFV4Pl8BCACuukQLwsHftH5jkVsSL7COFhamNsEE8lZ8MG1f1Rx5ztPuZTna
    13.7 -YXyWODgpj2Bxz0TcP+Q17GbLKse7TWD1k9i1RzLWz8ZSCLYq2TtjLWPleVuGGWeq
    13.8 -Y3tTWHC/nFbivolNPA0mL2038TGdBolPaZiPZ4P8wuQVYNfDqi4utcezGDNS8OHh
    13.9 -EPhfyKKoSM79HLoUPc6xsfimxPMrylI/i8bFvfDYz5vmydefvAxNhqjLH3Gmhj1p
   13.10 -nInsraEiyh7Y2zAxCfr6hD9nky7WixBinKFFhQpcUu1o+Ie6UGwLVbTyRMOcRsob
   13.11 -yahqA/m2HfDRj1Y+n8HHqsQkB2BtmMYXla3jABEBAAG0QXBFcCBUZXN0IEJvYiAo
   13.12 -dGVzdCBrZXksIGRvbid0IHVzZSkgPHBlcC50ZXN0LmJvYkBwZXAtcHJvamVjdC5v
   13.13 -cmc+iQE4BBMBAgAiBQJVeD5fAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAK
   13.14 -CRBZv/SIycLuOaR5CACj3E6ykNqjGS5PzghYfLJso6j954QzLwOozTzU/3/HWH4l
   13.15 -C3Jmfr0pGI51KZ6Xevrp3N9SxRqruJCFRtwNeH3ujIgDh/UHCUEsP/+d74SOenIB
   13.16 -YGUKE1OJmh8/LQdkNSc6JNdzJjDWdKeh6cAMFvWju/Nqtl/l0FGspQU9dmCMtzkK
   13.17 -gmwoKZW56aEVZ2lTxqNEo1aQ+lLrNueBq0/Q5kAVEzUG7Ufm19wXjWenEMeeElX3
   13.18 -UAGudLJuckx7uD8W/yBwqrRAbaCSeZf6RVBLz96ekjWrVfMnmjkPuQPPt5cs98Rx
   13.19 -QTpxk7b6xLaWXymhA6cYU+FAW4DpbjfJjMWIFDcKuQENBFV4Pl8BCADKQ2SV6gjR
   13.20 -5N69xVdiCaefjwobrXR1niuBHBNTXMJwPk2xv+e7fY28RK1BzODYCzBhpltvRoCc
   13.21 -Ji9S7Rqyz81nbxnw/1TaKtn6dDDhZPVHjN3vasDueM6xTEfEihNc0Owf4wz9SBju
   13.22 -redUVkdTxU7FxSgVP10dOxhdtkjWjGW1DF6WlYA8BAIEdbpoheJHz3NFkhPQ8Dlz
   13.23 -o7Ioe2t7vrTztcBX11o2e+FPOq1SmhEr78wbROAyCVAXK+8qDh4zDq8iAMZK/KnZ
   13.24 -rm6pP00+iBRcb+JQgn3Gn+hU0lgE3YB9kBJLeWaHxEPNnnNNvW/BMl53ctf8Ip+p
   13.25 -zpA1K/S23KU7ABEBAAGJAR8EGAECAAkFAlV4Pl8CGwwACgkQWb/0iMnC7jlqbwf/
   13.26 -dP4sXDRiR5uVMh5WhOn1S8MnHZhLWAQ6fI9/KxggCPhgY6zAgszPMutzBsQlV4P6
   13.27 -QX30d99IMJrzGYYxjN7Z6fF7us9u103+GTzGQH7/47JG0eSTSaKQvqEaN1+6M/OB
   13.28 -ZKcwNW6xHa+lhIS5nJGV3Oey/RFQwucBujQbtyjDN3aGshwqzhJXFBlF3RqFzLxu
   13.29 -AJmeOVedaKvdPjRhgFuxhkicUhVp27qXQCpDpkUkj9hb75yCE6pAzopO6s65yHsn
   13.30 -FyehwgyMrfpTPlPM86B1LH4IEwSaOrEJSdHnnFD8nnSIjRyfra3dsI/RVNmYX8Ek
   13.31 -MGICzoR4lWcYFShJQM6QQg==
   13.32 -=ugiE
   13.33 ------END PGP PUBLIC KEY BLOCK-----
    14.1 --- a/test/6FF00E97_sec.asc	Mon Aug 26 12:41:39 2019 +0200
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,57 +0,0 @@
    14.4 ------BEGIN PGP PRIVATE KEY BLOCK-----
    14.5 -
    14.6 -lQOYBFV4PbEBCADTmjGDsoti/VPoZ3w2oCjLBNq1jWIGMkbiUgCGUQjVsNrSZ80U
    14.7 -7RmA3Pcu3hhiVQNBGA32vL6NPhSJPanVd77s6XVZg+Gq7llbGGkuIxSkJvVrWzYc
    14.8 -kjMsAInlJ8Ll0kHHbgATOlO5OtQ21bLCfWZPSq74HEVzQAPtCGYFvOgpCktKTjms
    14.9 -GXe9ysiYN8CEWMVNbDqXmvFhi4UifpITeQBVM7dtlBw5SoeLZpsHIlKF5i5WPkNw
   14.10 -7nuMag/+lRpOqvPumhOmqybWHuAR/Dq0pOOPh6BzZ4OzOBL96aWUe1dcnIZeBEm8
   14.11 -oRxYC3nN95YsjtrLK4BQZTYDTzeh8FIccsLdABEBAAEAB/sFU/ukPwoi9PwtwH/D
   14.12 -/rA8tf5GYKKgNULTKanRN/8w7LhJ0mOtKmjcvKj0z6CqDduqiS8pDL4cH4QiP/mn
   14.13 -UFjhu6iZ3oDjMc64dudANQNQZyfzHNOl5bChAEMG16cZz58oyJLCMEvuOYvaH7pV
   14.14 -w7/ZKcWc7OQzyh/ivNm0kjni2fMJbX6H11obmpnHH1iw3twoNYCP/c4k0FbYeGen
   14.15 -GAptQY8A0oZoaFtx5kCU8qdRl+SfPVfBDGecP/dtt7DiaNWYQYSwlf1PxORhDFM4
   14.16 -/bihze623Hm/BczG73H2Vv+oKaE1y/GMIqc26RIcTiVYPkdKeob1BtfhCw2xEeUm
   14.17 -BhhxBADTqchhV9Q5XEe0uDT8u/9U/ULeoF+12C0wgDkJIKkd07URubr77Cv3gHp0
   14.18 -9ZJqWP/sMcD7HgeyUIxGYP9abGQy+AsHVvignaovCwif6N7PP877kGG2K+Z0V3Os
   14.19 -TlqHkls5+rmtxyHTVNumH3DuMJ47J+7C0UL5CuPPvDRNO942bQQA/+0lLF9Nm3NQ
   14.20 -0MnUOlgQVQvfuUDmwj89LSJ1gPWVQ0RpzDLG+FSVwg4L1mtzgIZ7XTA6nFUZts4W
   14.21 -zBUCqKeC92I2WtKehhGAxfHnVlm1M9Iuv9EzRlJWhkm5wuPXEEZMyhQohFuc2k5w
   14.22 -Lq/GUcXqzzTYWDHjBecccgSXrf98uDEEAIRvSiI98caA7Bl7iaz9CcGk6FnOSis2
   14.23 -buTG7fGRFkujntOETshiMU2IJ7SDi5MySeYtvF7oQgz6qBNq8fiCHWS3Y7iIBRIR
   14.24 -XNf5lpkm43CJkXpX7ZDkG6VS3lErV6KSPIB+gy3l0+xYSJMZcfYUnTU2ZSRmdldn
   14.25 -vZfO5hHlZ1eqSt+0RHBFcCBUZXN0IEFsaWNlICh0ZXN0IGtleSBkb24ndCB1c2Up
   14.26 -IDxwZXAudGVzdC5hbGljZUBwZXAtcHJvamVjdC5vcmc+iQE4BBMBAgAiBQJVeD2x
   14.27 -AhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRCpQR0Xb/AOl5JjCADEBoor
   14.28 -dVBCmphG6EY+u5yjj/xeQN4Kc1Rl06Ii6m184hnF/osxnTicr+A6Hpwf8whXULuS
   14.29 -wXvfuOsVOQdIc2e+1zrecTqyNUWuRs3T7uZ25dvROg1XZuajMPf3wh5lX2rPRhOt
   14.30 -3UNXJjQfc1MSYXpmT+PoqFXBzMqJUo2DYcw6MSZekoWkIzFXG2s2YNwILwPnLnMe
   14.31 -sFtzU6mn9qhfoFsQA6aku8AbG+SNehNZvGuuUiBmu+4UYNoc/RJa7vNWECv9qZQs
   14.32 -T820CuoOZS9MFV7nQlgkGoPerlGXil0vkOG1gsuQD8QkuaTQpn1vYvRcC0P27qLf
   14.33 -rqlPv2Ih2hoIV9tJnQOYBFV4PbEBCADQwKB97t2B2nweprfpbH8QgLCzJYaAMrpc
   14.34 -aUaJqm+J3C9eaepRXTXGtst1zaLbooG2b3QHfDzI2CEYMxO5ynmmSBOe06VKw/Pa
   14.35 -gBzK5ur/eOycl0ZPFSXdlDj30BQPvRdJvLS4OTMdoKoGpsZDY4hOYj67oHo3TFtr
   14.36 -LJCvZruPARkI/pXiOX9FqH4wquNNaYW1qwk/Wq3k/gOMwp0xjvc01MbadaiiVquJ
   14.37 -k6jjPrd2wP4FYxIADAllzMpwFAJSWvgCfmqVbukYOnaCp3QRQXQkc78TdqGXbD5u
   14.38 -wJzkxxiEsMmiGT+7RDLIKwXheKmmGXSwgi8m+EndUiqMTvOdjyUBABEBAAEAB/sG
   14.39 -nGJmGT1m/k/HNY2A4ncugybQEOiJe4xy6VYVqBc8GPl1OS/gR64wlst1daT6T+iL
   14.40 -9KEKl3os0Z8QWetpCzhERkd8dInT5vCnFdQjmaxtmVX5RQynK+gntDOZfHuq08Nj
   14.41 -/0pZWbK3KzEAliw/SCyx78hPuelY7OL/Ge7okR2FjdXmtcMLw7NN+0c+hoSAuDiV
   14.42 -jbPlegga6iaGljIJCapf1YkmwuUZc2pCEfoxllRdQ8UKSLwht4LPb5jBOAiynw4W
   14.43 -lMY/5hZwRVG2NfOXbwC1kMUQcItBJviKQXaaruqXX7jnglWbCrgg/tQJ6EUkLy76
   14.44 -InM6/0NX6StNEY4vau95BADeTwBLkJqkcAxX21GoT9UjhRh9yhKgehER1cplrhE3
   14.45 -B3HuEzvCCr+mRCPyK7J0pE3LQkqccDW19noOtsjl6ODStXjk4Pp/MFftJrIx9s9u
   14.46 -JFv5RTTVBxjS8hRRHF49rMYeOKpcD02Id+u3UL1ISuX40Ljvz6oacO9XA73gkA7L
   14.47 -aQQA8GOupiWYvZwYPTJ8glUfafEtniNspTOtEDayvMAOHiWIrLzhQ0e6AS1LDB8E
   14.48 -YWu+GUI9661PRMn1SlhX9vZhGzSllGxk9CyBbeKhyuiQ34s8M0pwHLmT89bBqZhk
   14.49 -/0wsRqkrKHkcJYkcLLlYw5zAGrm3kvyQgjf6Tiq2d+rU0dkD/AxnmEWqC08ovLZo
   14.50 -vEZR+JKWlAp8l4YS5f5suPD6PiKeLinCujpq7VbsyhcZQNo1oA7qgLvUFwz2lyRi
   14.51 -eCDBCndXYLzJ1LPkHXv0ZcxrSLUSpNpWekEM5sBug8i3z4vhh4EA30gdOYqLPquu
   14.52 -BQoyFrPysylnvHTVRkA/wBy5E7Y0OnyJAR8EGAECAAkFAlV4PbECGwwACgkQqUEd
   14.53 -F2/wDpeQVQgArnfQ7uvG0po/CPepbrdytI2n63U5dm/MFMsvXpZYVYLO/mROc+ak
   14.54 -ZCPwS0yxtSMKK+tYM9leQx58r89c+K1GeZoko7xziwmZbt5zEITiJp5L6gg7k6Cc
   14.55 -zskPMx07gY8ooscBC3cFJhz1A0o73BKPR7J0iupaNmI3sTd1/RNQm6573kGGwc4m
   14.56 -2bcQttvN5ox8yimn2QnK3D+6A+Mmzi3Rd11tF+tAWJIsfaEgDJZn9mOdUkV2ckoS
   14.57 -k1K5PptpXSsKLOL+e2WuxSMIr8AVeRqkbYYK6UzX6qIgQIrMOuaXqtRaNxNccnzI
   14.58 -S1YtdtYERSnTaBotNp/FF2wfI7BNFP6r0A==
   14.59 -=kV7k
   14.60 ------END PGP PRIVATE KEY BLOCK-----
    15.1 --- a/test/70DCF575_sec.asc	Mon Aug 26 12:41:39 2019 +0200
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,57 +0,0 @@
    15.4 ------BEGIN PGP PRIVATE KEY BLOCK-----
    15.5 -
    15.6 -lQOYBFV4PvYBCADR7kaFLsLFDuGE11u3q2K6eTspAkczU1ahPnSXaVGOIbCQGuL6
    15.7 -MiDET4vXAY/y1picqJ8OuIe2k0S8eDRIYIHF8arhgTkZQny6Cfy7nheWNnxSZBIo
    15.8 -K/8Zqa9dbNBWwHp2l7LOqM3hS8a0O1mQQrrMlV55qnXWJQFaI3P/nlaGUfe+5DuD
    15.9 -tDom8xJicE8an5nhbsyKyNxlYVePVsQVFiLHMVoNZ6eyfyb/nTBdAdQ0KLZM0vDC
   15.10 -8df/VTevytf/PgunziqD67HuDx8Uxyeht5REIrcBEyrgtnvTkVjZJ2MpbXcY2kam
   15.11 -36OH8T4JoBkxlqjU6UiiqV+k04QzAvmp2/anABEBAAEAB/9oTPtKlmX8pB0V9C3E
   15.12 -fmlJ/ouPH2uiq4hCCpbA13nGpSRlJIabCibPgjoXM9aCL26Zfwmvtazv4BFplktb
   15.13 -nl87qotdCOgGjcsMX4Pq72wGnMF96ew/e0R+SpkvUK3ePDlcDJixJptLkWuDBm3E
   15.14 -R/MpTBkpV7C+GZqnXy/104RnrRB6BuE+YbcKxYAV5rF8yCeZBysiwUSefuQtOKRF
   15.15 -cx7g+SLD2V+mKSdOlTHn6CwzD9EFCKVJrGVusOvGg+t/wac8ecr7PT8Ogv7HfHO2
   15.16 -zFCU9E3JGNQAQ5a6MKIMsbA7MRHrBnX4zOYNQGjY4bjW3RhuGbwU3+mU/qwxwiap
   15.17 -kcMRBADSamYgsPpdlye9TNedF7gvLo4KCz1UfQhJs3kS7XZRuv2VpT0uMfz75a19
   15.18 -n5Ibi0J4kIVVuQQsl5H55DWVQh4g+xt/seAXmfH4xa5AF/3uh1wCcTATXy+7+kOi
   15.19 -KvRezdqd3azOTp/brDiIPWqZT0e7oATuRQ4NlTE754SR/i8DeQQA/2j8iL32XY9v
   15.20 -qyHzHXW3zvKiVTb3WYXOrLqQMtkuLJwWbXufqgXoS1KSSLG8pNhjAVbuVlQsXpdd
   15.21 -hFrRgiROefwzLbuw/zW97bylmqzsgzxxZR6crW/O6pLXCki/eaeBCjYyqL3+lLa1
   15.22 -7xxP5yQffeiCf8DZ1DxWEKioYLT5Ix8D/iPkmlrJYPVm4OSOhXma2o1x9s295YQ6
   15.23 -ZO1Afs0UI2S2wqsBa97D+ZVr/tLdDTTbV5C++UqPm2ActA84Kw6StDZFE+q9zYgz
   15.24 -0y29/eo7BdWqEGQRscJWtqYyLIuGzGsCbY95YkbVnWgG6zPSASk7K3qPX9ICR+1I
   15.25 -LU4WVMsBmNcEQE60Q3BFcCBUZXN0IEpvaG4gKHRlc3Qga2V5LCBkb24ndCB1c2Up
   15.26 -IDxwZXAudGVzdC5qb2huQHBlcC1wcm9qZWN0Lm9yZz6JATgEEwECACIFAlV4PvYC
   15.27 -GwMGCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEBNc1tFw3PV1rQsIAIGxmMHj
   15.28 -AQqsZB7CQAdEdWxM+YkGZPAOqMYZrVaf+wiIkMP25B9JaSYRccYbI+k+Vg19l5vq
   15.29 -Vv/ixgDLntZWJFt3LakKkTY3R8ghhKImlVVogj6ASho0rUoHLpCLuo0t+N+DGTjB
   15.30 -Oi1tu90U9L3poPsgYOij6pw226M6zXsvsk4hUuljq9ZysKbjGEoqahOLf7p7gjrt
   15.31 -CceOQfqnXKNE9QlpQtw/pnwTa97gVR4l7DaKUEXzASobjEywfCoMH9SaoVL5M/Fs
   15.32 -IkMSasg6H+J4U8YdxE5x2BRbTQe+90/RlVg5bNCK9nMKBMBr0KeeJn9JZRykwKOg
   15.33 -V5vZl0lQ5BEKEiadA5gEVXg+9gEIAMEvDo986hv9pk4YKLLRhZVyp3KiDQ2ymjdl
   15.34 -8v/kh2f3s2roNhF5o2pTfq51oTCIex0Wiyri7o/1V21e3wYS14uRzF86a5cvmOdR
   15.35 -/w1+NuW7hoW9RWBEaC7O4N/TtU7AAQmav8mACJBHwdoE98BKmJNAG3SOh/kSdh5H
   15.36 -ZrL5Yrx4tX7dkJOXI2Jql0IS4R37dmAX5K+9MqIFDJf0I73iiBGr0v6mbOCEonBz
   15.37 -nF/6H905Ci2uPZ38DHixN2cyToZg7CkTfC7K8xmHFv1lcRzlTMyNC0xOlirYPPlh
   15.38 -nGslyiyTJqHVyrH/Z788x6wV9ifPnDZfGmRkC2V8HTBRQhdIuREAEQEAAQAH/Rpx
   15.39 -QPp1/CtxqDJXTzbOxAylQXNI6CWAVWiQzVamZrxd5NKUz1XMAwi6PgROOI6Gl+du
   15.40 -3wSzRDkzOVDQpBFWQeeqQMGmIvTyQGklSZaEuKnwZaTnt9fJ9UK28YPhnBcX4+x3
   15.41 -IJpJqqJpGAkqFeldrI23QCrPmaAHnWBeoJmN1ix60iqABA8OvPODmLQaPEMlQrlw
   15.42 -UFQSfdDwWj0RFrj54SyltX1kYHZNI5WLsen31kswFcOImuNJjl0n5uaj2pQcbodW
   15.43 -uyDRjM+F0ZfsfytgOyKQKdkVpbK6Jn5gQTt0YfMhdC9z7Hhp2NcQGIjXVxw5Hc/B
   15.44 -v7d43MGsDJIwDFJ2r3sEAMuE5bAdD3GXGSjXDVzm/uhYXztuPu6Xe+67eaayQv4j
   15.45 -eoL+YXUeHyeKbCfX7mLF6SBChMQhoMQyqwIJ8RWJNn5PKwW+eQSZV8pxP/OCfK50
   15.46 -TrSTNL3eIEl5to6sHZsJpjvP4hYKnnMskaMDOAbUNz7TNhGro/lTCYceTYk1A0cP
   15.47 -BADy/+J8ZHinnPw9Pc4K3+qfVS/FZcUoRpMg39KFF10ZGtCqKfebAX2ypGmOQPb/
   15.48 -kdCfFq+pk0nXXwe7zjcSNPFkVyAViV8OMKj0AF1k1fhkgQtYCwFO9tZ7ArUf4Eoq
   15.49 -q3uDNzOeYnNP9EGJHXoJ/lTbcXhpyY6Qn25IyGIVMIz93wP+OskBmMS7eQ94mKs6
   15.50 -iYX/2FzKBXpKtTiLssM2adpcdVyNrfKD4i8y1acYGl08QFjPURYbri1+CuKzaNbN
   15.51 -cXlE9XPI8eQ01f5+484xc0bRDDSnrbh9wD/32EJ++uImFKjKEqFok8pe6936gX+x
   15.52 -mnku9lnxjcw0iNYnS1Tks09K3Jw7oYkBHwQYAQIACQUCVXg+9gIbDAAKCRATXNbR
   15.53 -cNz1dUKvB/46nvjKNTtPJXidArkPP8rY57kEVWg8spkqBWIeV3AGMzh9qVfRRv4P
   15.54 -fl9IgHaOvXkoKip9D4zvgpB566gIiE3B3Y4vEzToiBxqVo5L5gzmbG6J1cQdHz6r
   15.55 -mKSHPf4zrNQbCxaGXIJ697mlfKIiIBrV67sH3Xm2l6ECp8PiQGImLFaBI2SbuLSH
   15.56 -Sz1nC910ln8AhSYAYlxYBdateo3IZwAZSQibCF/xChvnDcDjZa9GWo3iMlSPAoKX
   15.57 -acbrdenjF/X9yyoeTtTNTuNDGr9Sms72wU+SAYErLDcik1pRhNDmLXEjQC7eBT9W
   15.58 -FemkfOVjmDKjonb9yAz6knxC5kRE5ChX
   15.59 -=7r/5
   15.60 ------END PGP PRIVATE KEY BLOCK-----
    16.1 --- a/test/C9C2EE39_sec.asc	Mon Aug 26 12:41:39 2019 +0200
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,57 +0,0 @@
    16.4 ------BEGIN PGP PRIVATE KEY BLOCK-----
    16.5 -
    16.6 -lQOYBFV4Pl8BCACuukQLwsHftH5jkVsSL7COFhamNsEE8lZ8MG1f1Rx5ztPuZTna
    16.7 -YXyWODgpj2Bxz0TcP+Q17GbLKse7TWD1k9i1RzLWz8ZSCLYq2TtjLWPleVuGGWeq
    16.8 -Y3tTWHC/nFbivolNPA0mL2038TGdBolPaZiPZ4P8wuQVYNfDqi4utcezGDNS8OHh
    16.9 -EPhfyKKoSM79HLoUPc6xsfimxPMrylI/i8bFvfDYz5vmydefvAxNhqjLH3Gmhj1p
   16.10 -nInsraEiyh7Y2zAxCfr6hD9nky7WixBinKFFhQpcUu1o+Ie6UGwLVbTyRMOcRsob
   16.11 -yahqA/m2HfDRj1Y+n8HHqsQkB2BtmMYXla3jABEBAAEAB/wKqiU2GVr1zJ5iqGZ7
   16.12 -hS9zDk3imXjAuwpK7GlfAVk9snSRpycK7IrxeX8s3J30qsOxGv5sYvOUcGK35kCs
   16.13 -eV78RyfthmM8WMcs28ATgE7WtkhyUAGmTwnuq9+Ldz9MYEUHUrEaXnTkBocFmd0I
   16.14 -Qx5qZLvHHtDtRx4HfAJZz0/5kj8KyKYB5cYsvRoLYdCWuxeIbJu5FYtHHBywNFnZ
   16.15 -Qt8STaQqZPD0gPh3ahzY8KYJFZbSFpGfaH0AX5dkFpUJdyad4R2c9ZOmnaK3W0Ba
   16.16 -cdQSdi66iiT0UG7f6ECR9HfI+nVfshOVLZA90p+LqLW51S7iBeFAoZyYfKuNrE9b
   16.17 -pV3VBADNf9Ec2CJ3jo2LrTrkN1HkcjmwdosFQWaDaXtRmV/GidWAyTS+JzaxnS1A
   16.18 -Y9klOqJktVNegrrkk+Xo6jHxkneGucDSsxpIVIcqTa2LGrt1E1eHNYwuEPIyHvl3
   16.19 -gPmfLCuetu+qp97+EOJBklSJi4ljPcAo7i+WI4Nsni6Q6eF7XQQA2aqRpIBmDdFY
   16.20 -9x3uAMDO3mSqIiEJWPiFZHs/qKGezJUgl4hrsjuiUWiD1gcPSS0zJRcZZ7GLYb9r
   16.21 -1uJOnzOtTLexEnAa0VJ9Svci+jtRX6HVETAnYqn9AQ/0sYvmTmWKge7q7BJHGnyv
   16.22 -YbyXmCwGyV8/cvSS8Mmh8iMYWg6mej8D/jN0ymPP9jGeuFav6Va/T8j+Fdl0zTVT
   16.23 -MkFPizlxJEev6PA9QKvAWo4iqRA3SIdqjrZpPcpwhalV5cK4KfHlh8/GagjU9kFS
   16.24 -JvUarmLZqoDqKT6cHb2OzcNBeCsuKGthraT1G+8NpXIgNr6a+5upo83pbL4RarPn
   16.25 -3u2JgSX0RPKDP8y0QXBFcCBUZXN0IEJvYiAodGVzdCBrZXksIGRvbid0IHVzZSkg
   16.26 -PHBlcC50ZXN0LmJvYkBwZXAtcHJvamVjdC5vcmc+iQE4BBMBAgAiBQJVeD5fAhsD
   16.27 -BgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRBZv/SIycLuOaR5CACj3E6ykNqj
   16.28 -GS5PzghYfLJso6j954QzLwOozTzU/3/HWH4lC3Jmfr0pGI51KZ6Xevrp3N9SxRqr
   16.29 -uJCFRtwNeH3ujIgDh/UHCUEsP/+d74SOenIBYGUKE1OJmh8/LQdkNSc6JNdzJjDW
   16.30 -dKeh6cAMFvWju/Nqtl/l0FGspQU9dmCMtzkKgmwoKZW56aEVZ2lTxqNEo1aQ+lLr
   16.31 -NueBq0/Q5kAVEzUG7Ufm19wXjWenEMeeElX3UAGudLJuckx7uD8W/yBwqrRAbaCS
   16.32 -eZf6RVBLz96ekjWrVfMnmjkPuQPPt5cs98RxQTpxk7b6xLaWXymhA6cYU+FAW4Dp
   16.33 -bjfJjMWIFDcKnQOYBFV4Pl8BCADKQ2SV6gjR5N69xVdiCaefjwobrXR1niuBHBNT
   16.34 -XMJwPk2xv+e7fY28RK1BzODYCzBhpltvRoCcJi9S7Rqyz81nbxnw/1TaKtn6dDDh
   16.35 -ZPVHjN3vasDueM6xTEfEihNc0Owf4wz9SBjuredUVkdTxU7FxSgVP10dOxhdtkjW
   16.36 -jGW1DF6WlYA8BAIEdbpoheJHz3NFkhPQ8Dlzo7Ioe2t7vrTztcBX11o2e+FPOq1S
   16.37 -mhEr78wbROAyCVAXK+8qDh4zDq8iAMZK/KnZrm6pP00+iBRcb+JQgn3Gn+hU0lgE
   16.38 -3YB9kBJLeWaHxEPNnnNNvW/BMl53ctf8Ip+pzpA1K/S23KU7ABEBAAEAB/0UO5/y
   16.39 -aSoUXl8zv5ZpWGA8E1x7qU3MPZQfgwtMhwEXplEyVelHSvIkjQAsjridPqf1KhAy
   16.40 -dkHY8kRAo4xMqoHjIMIzu+76hgKDzcoH+gfumOD97qwPDub/kGBg1j5v8KGg4knD
   16.41 -L8pNXKMWlNeSFzDf6BmFipmfb3EVYBiIMceIz97c4BGvs29TC2wIKmJBRbWu9eS7
   16.42 -vqkBj8rEGi+pEnzTFvcZTMkoU6Uj/HifpvQ7BcOzUQ/1tiGQMEPv8oPMWmKudqBw
   16.43 -53e7RoYCZmTzuzI5fNvNcNT1EcUQmAfkgT6zvQuY63DAdECVx2f0p7MlgGA9ncQb
   16.44 -IVVdBtJXfwsAFmthBADXmavPPgiC8nU1q8e2pB0pmS3/uflPdmh+xKs0MxylDgSO
   16.45 -H9Ar7g9duxsrjxxHzlkTb0Am2XeWww3fBO762VH9VCAPH3FRoHGNCnY6Ix0MyikW
   16.46 -g4Gs66QXHMTNweOa9zk+cZS6N0H6dDis6x+9M1FCeJzy3gXaq+vfV5LfGeXMYQQA
   16.47 -8CnyHE7rjoqGNPnTWetuYgo6yhYJudbhO0uDewR5MdP1gwpTUmYl5RD41LSwTSGp
   16.48 -VSbjtct5dQg2ZhjUWxXcx1OC+aMafmDPi6S32mwbgfNtfTCIygM8CPDjdWbFu1ba
   16.49 -KbPA9Lc/SHgpg0vbdiZ4PWOqsqnig834r+3VfLX/dxsEANAWGGJRNTHmIwoC4HsV
   16.50 -+KiyApbBRw2TCHxJjlzFY2OFpe8RuGKE7HpKiSYjarGxP0RlESrbie0nbJ8FooIH
   16.51 -gY2ipO3khgK4MK1Xua405mNVzge9oNJPgWEtLabubimVnTwjU6O7m79Xl+R9BYb1
   16.52 -GVZm7f/WMDL7BsNVvhMVjdgiOOOJAR8EGAECAAkFAlV4Pl8CGwwACgkQWb/0iMnC
   16.53 -7jlqbwf/dP4sXDRiR5uVMh5WhOn1S8MnHZhLWAQ6fI9/KxggCPhgY6zAgszPMutz
   16.54 -BsQlV4P6QX30d99IMJrzGYYxjN7Z6fF7us9u103+GTzGQH7/47JG0eSTSaKQvqEa
   16.55 -N1+6M/OBZKcwNW6xHa+lhIS5nJGV3Oey/RFQwucBujQbtyjDN3aGshwqzhJXFBlF
   16.56 -3RqFzLxuAJmeOVedaKvdPjRhgFuxhkicUhVp27qXQCpDpkUkj9hb75yCE6pAzopO
   16.57 -6s65yHsnFyehwgyMrfpTPlPM86B1LH4IEwSaOrEJSdHnnFD8nnSIjRyfra3dsI/R
   16.58 -VNmYX8EkMGICzoR4lWcYFShJQM6QQg==
   16.59 -=rBox
   16.60 ------END PGP PRIVATE KEY BLOCK-----
    17.1 --- a/test/Makefile	Mon Aug 26 12:41:39 2019 +0200
    17.2 +++ b/test/Makefile	Mon Aug 26 13:38:21 2019 +0200
    17.3 @@ -1,4 +1,4 @@
    17.4 -# Copyright 2017, pEp Foundation
    17.5 +# Copyright 2019, pEp Foundation
    17.6  # This file is part of pEpEngine
    17.7  # This file may be used under the terms of the GNU General Public License version 3
    17.8  # see LICENSE.txt
    17.9 @@ -7,19 +7,14 @@
   17.10  
   17.11  include ../Makefile.conf
   17.12  
   17.13 -# User's without python3 will skip the generated parts of the test suite. That's OK.
   17.14 -PY_ENV:=$(shell command -v python3 2> /dev/null)
   17.15 -
   17.16 -TEST_HOME=$(HERE)/pEp_test_home
   17.17 -
   17.18 -TARGET=TestDriver
   17.19 -
   17.20 +GTEST_DIR:=googletest/googletest
   17.21  SRCS:=$(wildcard src/*.cc) $(wildcard src/*/*.cc)
   17.22  OBJS:=$(addsuffix .o,$(basename $(SRCS)))
   17.23  DEPS:=$(OBJS:.o=.d)
   17.24  
   17.25 +LDFLAGS+= -L../asn.1 -L../src $(ETPAN_LIB) $(CPPUNIT_LIB)
   17.26  
   17.27 -LDFLAGS+= -L../asn.1 -L../src $(ETPAN_LIB) $(CPPUNIT_LIB)
   17.28 +TARGET:=EngineTests 
   17.29  
   17.30  ifeq ($(OPENPGP),GPG)
   17.31      LDFLAGS+= $(GPGME_LIB)
   17.32 @@ -27,8 +22,7 @@
   17.33      LDFLAGS+= $(NETGPG_LIB)
   17.34  endif
   17.35  
   17.36 -
   17.37 -LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1 -lcpptest
   17.38 +LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1
   17.39  
   17.40  ifeq ($(BUILD_FOR),Linux)
   17.41      LDLIBS+= -luuid
   17.42 @@ -54,7 +48,6 @@
   17.43      endif
   17.44  endif
   17.45  
   17.46 -
   17.47  CXXFLAGS:=$(filter-out -DNDEBUG,$(CXXFLAGS))
   17.48  
   17.49  # FIXME Possibly missing incdirs: ASN1C_INC
   17.50 @@ -66,7 +59,6 @@
   17.51      CXXFLAGS+= -DUSE_NETPGP $(NETPGP_INC)
   17.52  endif
   17.53  
   17.54 -
   17.55  EXTRA_LIB_PATHS=.:../src:
   17.56  ifdef ETPAN_LIB
   17.57      EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
   17.58 @@ -98,40 +90,26 @@
   17.59  .PHONY: all clean test
   17.60  
   17.61  all:
   17.62 -	make .suitemaker
   17.63 -	make $(TARGET) .scripts
   17.64 -	touch .suitemaker
   17.65 +	make $(TARGET)
   17.66  
   17.67  %.d: %.cc
   17.68  	$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< | sed -e 's,\($*\)\.o[ :]*,\1.o $@: ,g' > $@
   17.69  
   17.70 -.suitemaker: src
   17.71 -ifndef PY_ENV
   17.72 -	@echo "WARNING: Can't find python3 - this is fine unless you're adding test suites. If so, please install python3."
   17.73 -else
   17.74 -ifndef EXCLUDE
   17.75 -	$(PY_ENV) gensuitemaker.py
   17.76 -else
   17.77 -	# Comma-separated list, no spaces
   17.78 -	$(PY_ENV) gensuitemaker.py --exclude=$(EXCLUDE)
   17.79 -endif
   17.80 -endif
   17.81 +$(TARGET): $(OBJS) gtest-all.o gtest_main.o
   17.82 +#	$(LINK.cc) $(OBJS) $(LOADLIBES) $(LDLIBS) -o $@
   17.83 +	${CXX} ${LDFLAGS} -L${PREFIX}/lib -o $@ $^ -lpEpEngine $(LDLIBS)
   17.84  
   17.85 -$(TARGET): $(OBJS)
   17.86 -	$(LINK.cc) $(OBJS) $(LOADLIBES) $(LDLIBS) -o $@
   17.87 +gtest-all.o: $(GTEST_DIR)/src/gtest-all.cc
   17.88 +	${CXX} ${CXXFLAGS} $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -isystem $(GTEST_DIR)/include -o $@ -c $<
   17.89  
   17.90 -.scripts:
   17.91 -ifdef PY_ENV
   17.92 -	$(PY_ENV) genscripts.py
   17.93 -	touch .scripts
   17.94 -endif
   17.95 +gtest_main.o: $(GTEST_DIR)/src/gtest_main.cc
   17.96 +	${CXX} ${CXXFLAGS} $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -isystem $(GTEST_DIR)/include -o $@ -c $<
   17.97  
   17.98  test: all
   17.99  	$(TEST_CMD_PFX) $(TEST_DEBUGGER) ./$(TARGET)
  17.100  
  17.101  clean:
  17.102  	$(RM) $(TARGET) $(TARGET).o $(TARGET).d $(OBJS) $(notdir $(basename $(OBJS))) $(DEPS)
  17.103 -	$(RM) $(HERE)/*Tests msg_2.0.asc $(HERE)/pEp_test_home .scripts .suitemaker
  17.104  
  17.105  # If only the goal 'clean' is given, do not generate and include the '%.d' files.¬
  17.106  ifneq ($(MAKECMDGOALS),clean)
    18.1 --- a/test/blacklisted_pub.asc	Mon Aug 26 12:41:39 2019 +0200
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,30 +0,0 @@
    18.4 ------BEGIN PGP PUBLIC KEY BLOCK-----
    18.5 -
    18.6 -mQENBFf+rQ4BCADTfYb/3Xo5HEVevG18DfE/tpEnoPEbu4LFcd9tYkgqw9O0NkKi
    18.7 -TuWH0puJr5M+GZHRbF1E9l4bVE4p8r49u5Fsq+2TyY+oo4VFA89tGp+Dte1oSSjb
    18.8 -m8DSKY1/V+9iQ6+snpZ4jY0YdLQT0VlW3cPyoJovmHF0skGnvXeTWVe8bt/c8cUe
    18.9 -REzOBNFy7Ze84b5E5oGr6ieXurVe6cD+n6HVUtFlD6XjGN9ksbtsK20TQL/qnoC0
   18.10 -OHK5eLj+IDMUyGadqvbvNtGRLMJOgtQE2Fb7uieoMwGE4C6DDq6HbUWaiDu2H5qq
   18.11 -3qeSB5nSV2OtM/iwsp4kJu7opJzpWifCuIrVABEBAAG0VUJsYWNrbGlzdCBLZXlw
   18.12 -YWlyIChETyBOT1QgVVNFIEZPUiBPVEhFUiBURVNUUyBQTEVBU0UpIDxibGFja2xp
   18.13 -c3RlZGtleXNAa2dyb3Rob2ZmLm9yZz6JATgEEwEIACIFAlf+rQ4CGwMGCwkIBwMC
   18.14 -BhUIAgkKCwQWAgMBAh4BAheAAAoJED5M79n3r0aErIIH/A17SlEjB14vzLDTU8vE
   18.15 -slS8qPP7eB4dh+vm9DhjF4grilHBJs0ilLW5pbd09lzqwCC7qVMgdLeaDhFQZIzv
   18.16 -e4S6Bg/Whc1yOTIxBX2F252Lvd3NrS3BoFdQTlAvLL8StjuvdssHu0m7RM0Bg2Ef
   18.17 -//IqFt/2r5ZJEgVst9/CnRVxDKQ5n+UaqM0MjAzG7abhm+QvbhYJyMeRjIZ7uIUr
   18.18 -4siHrUNs9P3yfBY5RaFT7DXe4J1OtWHDkjYs9fo/ZOP4xbQGXl/xCi775+qrLv0u
   18.19 -hh5ancPk3/yX+pMdDn47oyNIKtFykHvg57Og8spzwwmG9seagylQfPTtIUGGNOTh
   18.20 -cd+5AQ0EV/6tDgEIAKY5Ihv1TxpWgXfK+uTZju45Mz71o56afYEUU2UmZlxCqZW7
   18.21 -4CYLVNzdqaEJAYWuG3zQPvqe+7/c5GPxLiptE9Z3bMDHrb4liq9vnb+OiDzjjNhO
   18.22 -Ali7xgBidUZrMFwgpzhhHftYc9gSWjguWx3dbTirljP7o5Pa7R0/n1CZiVXeJdQ7
   18.23 -aFR2hAvl9NmjEc6l/Sl13AF8HPhiUJE5/DdgrLbQemp+YwOJHQPvHmoOuu4KdHmh
   18.24 -BOhG9fNkac95cSR9M6uz2Fr5j2sXCz8j+KFaNscLymO36aMEjXLCRQ43Q0DdH1Mc
   18.25 -501ghhgmNYoGW9vWy0vj4NYfCcHECKdcNyiU1EcAEQEAAYkBHwQYAQgACQUCV/6t
   18.26 -DgIbDAAKCRA+TO/Z969GhNgaB/sF7z99VM5/+VaJHCLymExqeyvZfuYDJ7cUmyMW
   18.27 -X5nblBQoI1KJd9hLj8vhNrEZOJsAwH6blnFbdHkHdoOWIX2KErHuc8h4sNL/3LpW
   18.28 -cI8gqtqeOtqNwAtDxaUxYWPxQNc0akBD9IfaXf9ywBZxdNXYQ8+fX/BLDZcX+vPN
   18.29 -xvfvNISwuSaBQk3NlTvzP2OWssLvwzsmhoq4Hv0C+gLtBWLj1a2eCW1f7CG07F6U
   18.30 -L4y9YbRL0b73rRlPkVYApz2hw5w9YtQ+r16C12SRHc6HzE0pafg53m4apvxFTZo/
   18.31 -1Y0B+KJaUEWyl5wxrrL33JPV9dMiKPEXTeJrCDf+waFUtJUM
   18.32 -=dI7l
   18.33 ------END PGP PUBLIC KEY BLOCK-----
    19.1 --- a/test/blacklisted_pub2.asc	Mon Aug 26 12:41:39 2019 +0200
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,30 +0,0 @@
    19.4 ------BEGIN PGP PUBLIC KEY BLOCK-----
    19.5 -
    19.6 -mQENBFf+0HIBCADU5QsLhLIsSxdpKfvkfui5UuWWEWo5jRfySSSADQuMdLpPgxpG
    19.7 -kCz2cQRFA7kYHrdTINE4gvDqNxfAkNNGWVOeG6agBwLieg0KYzxMy3qNaLuye6xw
    19.8 -pX7NKgkCuVV9agcwfoWVHq+fkGIcwo9GTksPNEFB4cySaUqyjzq/fbYOtEjHRL0F
    19.9 -WpQu7rb1xdEtm7ce7JtRpAek45NLzsUN+NOEMc5nIz9r7jLSqmv0JIvQmrfgInft
   19.10 -tswRBSjxOC1Age1goODcOd6ezdRvH2pTjBhVzyNLjBIb9HcYEAK8hS5ZOtnpvMo4
   19.11 -aEAcWJI2r/nSCfHLMfh2oguZCMKg3sGyb0zlABEBAAG0X0JsYWNrbGlzdGVkIEtl
   19.12 -eXBhaXIgKFNFQ09ORCBLRVlQQUlSIC0gT05MWSBGT1IgQkxBQ0tMSVNUIFRFU1RT
   19.13 -KSA8YmxhY2tsaXN0ZWRrZXlzQGtncm90aG9mZi5vcmc+iQE4BBMBCAAiBQJX/tBy
   19.14 -AhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRDEruu+fmJwG2vqCACAdcKd
   19.15 -EG6AH99ag1h/9jHIa0HLq/ngTZBjIsps56FWFFhDNiui+9G3iyzCGeip1ASyU1Vm
   19.16 -0Wa5hd7hXuEA40zrpe6BnzEOQlB3lfBuUtt+VodpbsKOtU+7zNYJHRgzJlwcyIgv
   19.17 -y16Lk3gglVR0WdhKLBgzQvxKcHdCzfpn1s6z00fa4Ec7ryOacWr3LEcOgFP1bIOD
   19.18 -Qb5S28Rojnr8XIOMZmrTVCgNv7UtcBaICw+EnunS+TA4XkU3PrEXCgNg3jyu8IL1
   19.19 -BlOvhXSJNZ6QEA/sZtxNquQRoE4rPjP1ir2XtXlmBcOQN1BP0J0yslGH/OhJT2hK
   19.20 -ZWCJvU1vzkWV/OoiuQENBFf+0HIBCACxbXWwI4Bc9nCEBUR8k4nZkQz1G6A1sOB8
   19.21 -YXd8yMZw62EoJ0zD4WZ7z+Jm5qMWrOic9RFS0AWEuhta2MDJdK2l57iVT9mkto69
   19.22 -nC1UeBWIlcY8FJ42OxiWjWNz1Ftq9qYF3Pc93s+8oHDhjX6iWm/vN3a9lBCIdNM4
   19.23 -fEI55/fpMBMAO1YNr9Z6Sulhhqg3cJ57zlbwe9OGcTPBkBHewagpImwGT3CrjcyE
   19.24 -tteQM2jZnktVR6a72UXqbWwUQJoQuzs9Xi+/zjk5QrxO1///ZL/dDywD9FYSxz7v
   19.25 -sHKwn+r8iqogHqR3jmhpdWgkFNW2plV3lXCHNKwswIHJatl4BFAFABEBAAGJAR8E
   19.26 -GAEIAAkFAlf+0HICGwwACgkQxK7rvn5icBv7FQgAr1nXfZdTeZHTLt6UR3xgBkSk
   19.27 -5beeQDl/97fM1GD6OAn9BUUae840kuzAf9Pav4ADPtiqCeCeyeRW5K0N33dDmvAF
   19.28 -EqPLHuRfj7yViAhlFICqu2ckYqyb7BBf/LOlG2GEtZFzwruYKz/rmiBLRq0UnQMv
   19.29 -4fZZVs6FrnUEOVZsM0ALZPGzwT0LyU6OxVIRTkEGMBmdvcAIcos/S0XD6BjhP8b0
   19.30 -6+Y9Ld4nxVutjyZg/34PStHd3vtpN62VZzGQozWYBtseJ/APcoA7fnxGB8E+Q3TZ
   19.31 -QzxVfC3VMqFkMU1Xy+6bBP//zsnYaGM3VFlKi40hrBsJmxbOODoG7Yxsn9wGRg==
   19.32 -=sTND
   19.33 ------END PGP PUBLIC KEY BLOCK-----
    20.1 --- a/test/genscripts.py	Mon Aug 26 12:41:39 2019 +0200
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,29 +0,0 @@
    20.4 -#! /usr/bin/env python3
    20.5 -
    20.6 -# This file is under GNU General Public License 3.0
    20.7 -# see LICENSE.txt
    20.8 -
    20.9 -from os import listdir, getcwd
   20.10 -from os.path import isfile, join
   20.11 -from re import sub
   20.12 -import os
   20.13 -import stat
   20.14 -import datetime
   20.15 -
   20.16 -srcpath = join(getcwd(), "src/engine_tests")
   20.17 -
   20.18 -ls = listdir(srcpath)
   20.19 -
   20.20 -for f in ls:
   20.21 -    if isfile(join(srcpath, f)):
   20.22 -        if (f.endswith(".cc")):
   20.23 -            suite = sub('\.cc$', '', f)
   20.24 -            outfile = open(suite, 'w')
   20.25 -            output = (
   20.26 -                "#!/bin/bash\n"
   20.27 -                "# This is a convenience script for launching individual tests and tab completion with TestDriver \n\n" +
   20.28 -                "./TestDriver " + suite + "\n\n")
   20.29 -            outfile.write(output)
   20.30 -            os.chmod(suite, 
   20.31 -                     (stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH | stat.S_IXGRP | stat.S_IXOTH))
   20.32 -            outfile.close()
    21.1 --- a/test/gensuitemaker.py	Mon Aug 26 12:41:39 2019 +0200
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,112 +0,0 @@
    21.4 -#! /usr/bin/env python3
    21.5 -
    21.6 -# This file is under GNU General Public License 3.0
    21.7 -# see LICENSE.txt
    21.8 -
    21.9 -import argparse
   21.10 -from os import listdir, getcwd
   21.11 -from os.path import isfile, join
   21.12 -from re import sub
   21.13 -import datetime
   21.14 -
   21.15 -srcpath = join(getcwd(), "src/engine_tests")
   21.16 -
   21.17 -ls = listdir(srcpath)
   21.18 -
   21.19 -suites = []
   21.20 -
   21.21 -indent = "    "
   21.22 -
   21.23 -parser = argparse.ArgumentParser()
   21.24 -parser.add_argument("--exclude", "-x", help="Comma-separated list of tests to exclude from test suite build")
   21.25 -
   21.26 -args = parser.parse_args()
   21.27 -
   21.28 -exclude_arg = args.exclude
   21.29 -exclude_list = []
   21.30 -if exclude_arg:
   21.31 -    exclude_list = exclude_arg.split(",")
   21.32 -    for x in exclude_list:
   21.33 -        x.replace(" ","")
   21.34 -for f in ls:
   21.35 -    if isfile(join(srcpath, f)):
   21.36 -        if (f.endswith(".cc")):
   21.37 -            suite = sub('\.cc$', '', f)
   21.38 -            if not suite in exclude_list:
   21.39 -                suites.append(suite)
   21.40 -
   21.41 -license = (''
   21.42 -'// This file is under GNU General Public License 3.0\n'
   21.43 -'// see LICENSE.txt\n\n')
   21.44 -
   21.45 -
   21.46 -header = license + "//\n// src/SuiteMaker.cc generated by gensuitemaker.py - changes may be overwritten. You've been warned!\n//\n\n"
   21.47 -
   21.48 -header += (''
   21.49 -'#include <cpptest.h>\n'
   21.50 -'#include <cpptest-suite.h>\n'
   21.51 -'#include <memory>\n'
   21.52 -'#include <vector>\n'
   21.53 -'#include "SuiteMaker.h"\n')
   21.54 -
   21.55 -suiteincludes = ""
   21.56 -
   21.57 -for s in suites:
   21.58 -    suiteincludes += '#include "' + s + '.h"\n'
   21.59 -
   21.60 -output = header + "\n// Begin where we generate stuff\n" + suiteincludes + "\n"
   21.61 -
   21.62 -output += ("\n"
   21.63 -"const char* SuiteMaker::all_suites[] = {\n")
   21.64 -
   21.65 -first = True
   21.66 -
   21.67 -for s in suites:
   21.68 -    output += indent + '"' + s + '",\n'
   21.69 -
   21.70 -output += "};\n\n"
   21.71 -
   21.72 -output += (
   21.73 -'// This file is generated, so magic constants are ok.\n'
   21.74 -'int SuiteMaker::num_suites = ')
   21.75 -
   21.76 -output += str(len(suites)) + ";\n\n"
   21.77 -    
   21.78 -output += "void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {\n"
   21.79 -
   21.80 -first = True
   21.81 -
   21.82 -for s in suites:
   21.83 -    output += indent
   21.84 -    
   21.85 -    if not first:
   21.86 -        output += "else "
   21.87 -    else:
   21.88 -        first = False
   21.89 -    
   21.90 -    output += ('if (strcmp(test_class_name, "' + s + '") == 0)\n' + 
   21.91 -               indent + indent + '*test_suite = new ' + s + '(test_class_name, test_home);\n')
   21.92 -        
   21.93 -output += "}\n\n"
   21.94 -
   21.95 -output += (
   21.96 -'void SuiteMaker::suitemaker_buildlist(const char** test_class_names, int num_to_run, const char* test_home, std::vector<Test::Suite*>& test_suites) {\n'
   21.97 -'    for (int i = 0; i < num_to_run; i++) {\n'
   21.98 -'        Test::Suite* suite = NULL;\n'
   21.99 -'        SuiteMaker::suitemaker_build(test_class_names[i], test_home, &suite);\n'
  21.100 -'        if (!suite)\n'
  21.101 -'            throw std::runtime_error("Could not create a test suite instance."); // FIXME, better error, cleanup, obviously\n'
  21.102 -'        test_suites.push_back(suite);\n'
  21.103 -'    }\n'    
  21.104 -'}'
  21.105 -'\n'
  21.106 -'void SuiteMaker::suitemaker_buildall(const char* test_home, std::vector<Test::Suite*>& test_suites) {\n'
  21.107 -'    SuiteMaker::suitemaker_buildlist(SuiteMaker::all_suites, SuiteMaker::num_suites, test_home, test_suites);\n'
  21.108 -'}\n\n')
  21.109 -
  21.110 -suitemaker = open("src/SuiteMaker.cc", 'w') 
  21.111 -suitemaker.write(output)
  21.112 -suitemaker.close()
  21.113 -
  21.114 -generated_at = ("src/SuiteMaker.cc" + " generated at " + datetime.datetime.now().strftime('%c'))
  21.115 -print(generated_at)
    22.1 --- a/test/gentestshell.py	Mon Aug 26 12:41:39 2019 +0200
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,124 +0,0 @@
    22.4 -#! /usr/bin/env python3
    22.5 -
    22.6 -import argparse
    22.7 -import os
    22.8 -import subprocess
    22.9 -import re
   22.10 -
   22.11 -def decamel(name):
   22.12 -    retval = re.sub('([A-Z])', r'_\1', name).lower()
   22.13 -    return re.sub('^_', r'', retval) 
   22.14 -
   22.15 -parser = argparse.ArgumentParser()
   22.16 -parser.add_argument("suite_name", help="(convention is <NameInUpperCamelCase>, e.g. StringpairList - suite created will then be StringpairListTests)")
   22.17 -parser.add_argument("--clobber", "-c", help="Overwrite extant files (must be explicitly indicated)", action='store_true')
   22.18 -
   22.19 -gengroup = parser.add_mutually_exclusive_group()
   22.20 -gengroup.add_argument("--no_src", help="Generate header only, no source", action='store_true')
   22.21 -gengroup.add_argument("--no_hdr", help="Generate source only, no header", action='store_true')
   22.22 -
   22.23 -typegroup = parser.add_mutually_exclusive_group()
   22.24 -typegroup.add_argument("--test", "-t", help="Just generate a generic test suite (no engine initialisation or db/gpg setup/teardown - default)", action='store_true')
   22.25 -typegroup.add_argument("--indiv", "-i", help="Generate a test suite with engine initialisation/release and gpg/db teardown between each test function", action='store_true')
   22.26 -typegroup.add_argument("--session", "-s", help="Generate a test suite with engine initialisation/release and gpg/db teardown only at the beginning and end of the test suite", action='store_true')
   22.27 -
   22.28 -args = parser.parse_args()
   22.29 -
   22.30 -suitename = args.suite_name
   22.31 -test_suite = suitename + "Tests"
   22.32 -
   22.33 -superclass = "EngineTestSuite"
   22.34 -
   22.35 -if args.indiv: 
   22.36 -    superclass = "EngineTestIndividualSuite"
   22.37 -elif args.session:
   22.38 -    superclass = "EngineTestSessionSuite"
   22.39 -
   22.40 -print("\nCreating " + test_suite + " as an " + superclass + "\n")
   22.41 -
   22.42 -uncamel = decamel(suitename)
   22.43 -print(uncamel)
   22.44 -
   22.45 -
   22.46 -nspace = "using namespace std;\n\n"
   22.47 -
   22.48 -license = ("// This file is under GNU General Public License 3.0\n"
   22.49 -           "// see LICENSE.txt\n\n")
   22.50 -
   22.51 -default_single_testname = "check_" + re.sub('_tests$', r'', uncamel) 
   22.52 -
   22.53 -if not args.no_hdr:
   22.54 -    
   22.55 -    header_def = uncamel.upper() + "_H"
   22.56 -
   22.57 -    deftxt = "#ifndef " + header_def + "\n#define " + header_def + "\n\n"
   22.58 -
   22.59 -    header_inc = ("#include <string>\n" 
   22.60 -                  "#include \"" + superclass + ".h\"\n\n")
   22.61 -
   22.62 -    header = license + deftxt + header_inc + nspace
   22.63 -
   22.64 -
   22.65 -    classdef = "class " + test_suite + " : public " + superclass + " {\n" + \
   22.66 -               "    public:\n" + \
   22.67 -               "        " + test_suite + "(string test_suite, string test_home_dir);\n" + \
   22.68 -               "    private:\n" \
   22.69 -               "        void " + default_single_testname + "();\n" + \
   22.70 -               "};\n" 
   22.71 -
   22.72 -    header_file = header + classdef + "\n#endif\n"
   22.73 -
   22.74 -    #print(header_file)
   22.75 -
   22.76 -    do_write = True
   22.77 -    hfile_name = test_suite + ".h"
   22.78 -    hfile_path = os.path.join(os.path.join(os.getcwd(), "include"), hfile_name)
   22.79 -
   22.80 -    if not args.clobber:
   22.81 -        if (os.path.isfile(hfile_path)):
   22.82 -            print(hfile_path + " exists. Not writing header file. Use --clobber to overwrite.")
   22.83 -            do_write = False
   22.84 -
   22.85 -    if do_write:
   22.86 -        header_out = open(hfile_path, 'w')
   22.87 -        header_out.write(header_file)
   22.88 -        header_out.close()
   22.89 -
   22.90 -if not args.no_src:
   22.91 -    src_inc = ('#include <stdlib.h>\n'
   22.92 -               '#include <cstring>\n'
   22.93 -               '#include <string>\n\n'
   22.94 -               '#include <cpptest.h>\n'
   22.95 -               '#include "test_util.h"\n\n'
   22.96 -               '#include "pEpEngine.h"\n\n'
   22.97 -               '#include "' + superclass +'.h"\n'
   22.98 -               '#include "' + test_suite + '.h"\n\n')
   22.99 -
  22.100 -    test_suite_prefix = test_suite + "::"
  22.101 -    fname = test_suite_prefix + default_single_testname
  22.102 -
  22.103 -    constructor = test_suite_prefix + test_suite + "(string suitename, string test_home_dir) :\n" + \
  22.104 -                  "    " + superclass + "::" + superclass + "(suitename, test_home_dir) {\n" + \
  22.105 -                  "    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string(\"" + fname + "\"),\n" + \
  22.106 -                  "                                                                      static_cast<Func>(&" + fname + ")));\n" + \
  22.107 -                  "}\n\n"
  22.108 -                  
  22.109 -    def_funct = "void " + test_suite_prefix + default_single_testname + "() {\n" + \
  22.110 -                "    TEST_ASSERT(true);\n" + \
  22.111 -                "}\n\n"
  22.112 -
  22.113 -    src_file = license + src_inc + nspace + constructor + def_funct
  22.114 -
  22.115 -    do_write = True
  22.116 -    sfile_name = test_suite + ".cc"
  22.117 -    sfile_path = os.path.join(os.path.join(os.getcwd(), "src/engine_tests"), sfile_name)
  22.118 -
  22.119 -    if not args.clobber:
  22.120 -        if (os.path.isfile(sfile_path)):
  22.121 -            print(sfile_path + " exists. Not writing source file. Use --clobber to overwrite.")
  22.122 -            do_write = False
  22.123 -
  22.124 -    if do_write:
  22.125 -        src_out = open(sfile_path, 'w')
  22.126 -        src_out.write(src_file)
  22.127 -        src_out.close()
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/test/gtest_firstpass.py	Mon Aug 26 13:38:21 2019 +0200
    23.3 @@ -0,0 +1,340 @@
    23.4 +import re 
    23.5 +import sys
    23.6 +
    23.7 +def tb(n):
    23.8 +    retval = ""
    23.9 +    for i in range(n):
   23.10 +        retval = retval + "    "
   23.11 +    return retval
   23.12 +        
   23.13 +fixture_in = False 
   23.14 +removing_old_constructor = False
   23.15 +constructor_done = False
   23.16 +modline = None
   23.17 +eat_next_line = False;
   23.18 +filename = sys.argv[1]
   23.19 +outfile = sys.argv[2]
   23.20 +
   23.21 +newfile = open(outfile,'w')
   23.22 +
   23.23 +with open(filename) as fp: 
   23.24 +    for line in fp:
   23.25 +        if (eat_next_line):
   23.26 +            eat_next_line = False;
   23.27 +            continue;
   23.28 +        line = line.rstrip();
   23.29 +        
   23.30 +        if not fixture_in:
   23.31 +            if (removing_old_constructor):
   23.32 +                if "}" in line:
   23.33 +                    removing_old_constructor = False  
   23.34 +                    constructor_done = True 
   23.35 +                continue
   23.36 +            else:        
   23.37 +                if (line.find("namespace") >= 0):
   23.38 +                    continue
   23.39 +                if (line.find("Tests.h") >= 0):
   23.40 +                    continue
   23.41 +                if (line.find("cpptest") >= 0):
   23.42 +                    continue 
   23.43 +                if (line.find("EngineTestSuite.h") >= 0 or line.find("EngineTestIndividualSuite.h") >= 0 or line.find("EngineTestSessionSuite.h") >= 0):
   23.44 +                    continue
   23.45 +                
   23.46 +                if (modline == None):                
   23.47 +                    modline = re.sub(r'(.*)Tests::(.*)Tests\(string suitename, string test_home_dir\) :', r'\1Test', line)                
   23.48 +                    
   23.49 +                if(modline == line):
   23.50 +                    newfile.write(line + "\n")
   23.51 +                    modline = None
   23.52 +                    continue
   23.53 +                else:
   23.54 +                    if not (constructor_done):
   23.55 +                        removing_old_constructor = True
   23.56 +                        continue    
   23.57 +                        
   23.58 +                    #*Tests::*Tests(string suitename, string test_home_dir)
   23.59 +                    # Put in fixture blob
   23.60 +                    # - delete through first }
   23.61 +                    #print(modline) 
   23.62 +                    newfile.write("#include \"Engine.h\"\n\n")                    
   23.63 +                    newfile.write("#include <gtest/gtest.h>\n\n\n")
   23.64 +                    newfile.write("namespace {\n\n\t//The fixture for " + modline + "\n")
   23.65 +                    newfile.write(tb(1) + "class " + modline + " : public ::testing::Test {\n")
   23.66 +                    newfile.write(tb(2) + "public:\n")
   23.67 +                    newfile.write(tb(3) + "Engine* engine;\n")
   23.68 +                    newfile.write(tb(3) + "PEP_SESSION session;\n\n")
   23.69 +                    newfile.write(tb(2) + "protected:\n")
   23.70 +                    newfile.write(tb(3) + "// You can remove any or all of the following functions if its body\n")
   23.71 +                    newfile.write(tb(3) + "// is empty.\n")
   23.72 +                    newfile.write(tb(3) + "" + modline + "() {\n")
   23.73 +                    newfile.write(tb(4) + "// You can do set-up work for each test here.\n")
   23.74 +                    newfile.write(tb(4) + "test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name();\n")
   23.75 +                    newfile.write(tb(4) + "test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();\n")
   23.76 +                    newfile.write(tb(4) + "test_path = get_main_test_home_dir() + \"/\" + test_suite_name + \"/\" + test_name;\n")
   23.77 +                    newfile.write(tb(3) + "}\n\n")
   23.78 +                    newfile.write(tb(3) + "~" + modline + "() override {\n")
   23.79 +                    newfile.write(tb(4) + "// You can do clean-up work that doesn't throw exceptions here.\n")
   23.80 +                    newfile.write(tb(3) + "}\n\n")
   23.81 +                    newfile.write(tb(3) + "// If the constructor and destructor are not enough for setting up\n")
   23.82 +                    newfile.write(tb(3) + "// and cleaning up each test, you can define the following methods:\n\n")
   23.83 +                    newfile.write(tb(3) + "void SetUp() override {\n")
   23.84 +                    newfile.write(tb(4) + "// Code here will be called immediately after the constructor (right\n")
   23.85 +                    newfile.write(tb(4) + "// before each test).\n")
   23.86 +                    newfile.write("\n" + tb(4) + "// Leave this empty if there are no files to copy to the home directory path\n")
   23.87 +                    newfile.write(tb(4) + "std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();\n")                                        
   23.88 +                    newfile.write("\n" + tb(4) + "// Get a new test Engine.\n")                    
   23.89 +                    newfile.write(tb(4) + "engine = new Engine(test_path);\n");
   23.90 +                    newfile.write(tb(4) + "ASSERT_NE(engine, nullptr);\n")
   23.91 +                    newfile.write("\n" + tb(4) + "// Ok, let's initialize test directories etc.\n")                                        
   23.92 +                    newfile.write(tb(4) + "engine->prep(NULL, NULL, init_files);\n")
   23.93 +                    newfile.write("\n" + tb(4) + "// Ok, try to start this bugger.\n")                    
   23.94 +                    newfile.write(tb(4) + "engine->start();\n")                    
   23.95 +                    newfile.write(tb(4) + "ASSERT_NE(engine->session, nullptr);\n")                    
   23.96 +                    newfile.write(tb(4) + "session = engine->session;\n") 
   23.97 +                    newfile.write("\n" + tb(4) + "// Engine is up. Keep on truckin\'\n");                                                            
   23.98 +                    newfile.write(tb(3) + "}\n\n")
   23.99 +                    newfile.write(tb(3) + "void TearDown() override {\n")
  23.100 +                    newfile.write(tb(4) + "// Code here will be called immediately after each test (right\n")
  23.101 +                    newfile.write(tb(4) + "// before the destructor).\n")   
  23.102 +                    newfile.write(tb(4) + "engine->shut_down();\n")
  23.103 +                    newfile.write(tb(4) + "delete engine;\n")                    
  23.104 +                    newfile.write(tb(4) + "engine = NULL;\n")                    
  23.105 +                    newfile.write(tb(4) + "session = NULL;\n")                    
  23.106 +                    newfile.write(tb(3) + "}\n\n")
  23.107 +                    newfile.write(tb(2) + "private:\n");
  23.108 +                    newfile.write(tb(3) + "const char* test_suite_name;\n")
  23.109 +                    newfile.write(tb(3) + "const char* test_name;\n")                                                            
  23.110 +                    newfile.write(tb(3) + "string test_path;\n") 
  23.111 +                    newfile.write(tb(3) + "// Objects declared here can be used by all tests in the " + modline + " suite.\n\n")
  23.112 +                    newfile.write(tb(1) + "};\n\n")
  23.113 +                    newfile.write("}  // namespace\n\n\n")
  23.114 +
  23.115 +                    fixture_in = True
  23.116 +        else:
  23.117 +            #void *Tests::check*() {
  23.118 +            # -> TEST_F(*Test, check*) {
  23.119 +            modline = re.sub(r'void\s*(.*)Tests::check(.*)\(\)\s*{', r'TEST_F(\1Test, check\2) {', line)
  23.120 +            if (line != modline):
  23.121 +                newfile.write(modline + "\n")
  23.122 +                continue
  23.123 +                
  23.124 +            #TEST_ASSERT(true)
  23.125 +            # -> <nothing>                
  23.126 +            if (line.find("TEST_ASSERT(true)") >= 0):
  23.127 +                continue
  23.128 +                
  23.129 +            #TEST_ASSERT_MSG(strcmp(blah,blah) == 0, *)
  23.130 +            #TEST_ASSERT(strcmp(blah,blah == 0))
  23.131 +            # -> ASSERT_STREQ(blah,blah)
  23.132 +            modline = re.sub(r'TEST_ASSERT_MSG\(\s*strcmp\(\s*(.*),\s*(.*)\)\s*==\s*0\s*,.*\);', r'ASSERT_STREQ(\1, \2);', line)
  23.133 +            if (line != modline):
  23.134 +                newfile.write(modline + "\n")
  23.135 +                continue
  23.136 +            modline = re.sub(r'TEST_ASSERT\(\s*strcmp\(\s*(.*),\s*(.*)\)\s*==\s*0\);', r'ASSERT_STREQ(\1, \2);', line)
  23.137 +            if (line != modline):
  23.138 +                newfile.write(modline + "\n")
  23.139 +                continue
  23.140 +
  23.141 +            #TEST_ASSERT_MSG(strcmp(blah,blah) != 0, *)
  23.142 +            #TEST_ASSERT(strcmp(blah,blah != 0))
  23.143 +            # -> ASSERT_STREQ(blah,blah)
  23.144 +            modline = re.sub(r'TEST_ASSERT_MSG\(\s*strcmp\(\s*(.*),\s*(.*)\)\s*!=\s*0\s*,.*\);', r'ASSERT_STRNE(\1, \2);', line)
  23.145 +            if (line != modline):
  23.146 +                newfile.write(modline + "\n")
  23.147 +                continue
  23.148 +            modline = re.sub(r'TEST_ASSERT\(\s*strcmp\(\s*(.*),\s*(.*)\)\s*!=\s*0\);', r'ASSERT_STRNE(\1, \2);', line)
  23.149 +            if (line != modline):
  23.150 +                newfile.write(modline + "\n")
  23.151 +                continue
  23.152 +                
  23.153 +            #TEST_ASSERT_MSG(<x> == NULL, *);
  23.154 +            #TEST_ASSERT(<x> == NULL);
  23.155 +            # -> ASSERT_EQ(<x>, nullptr);
  23.156 +            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*==\s*NULL,.*\);',r'ASSERT_EQ(\1, nullptr);', line)
  23.157 +            if (line != modline):
  23.158 +                newfile.write(modline + "\n")
  23.159 +                continue
  23.160 +            modline = re.sub(r'TEST_ASSERT\((.*)\s*==\s*NULL\);', r'ASSERT_EQ(\1, nullptr);',line)
  23.161 +            if (line != modline):
  23.162 +                newfile.write(modline + "\n")
  23.163 +                continue
  23.164 +            
  23.165 +            #TEST_ASSERT_MSG(<x> != NULL, *);
  23.166 +            #TEST_ASSERT(<x> != NULL);
  23.167 +            # -> ASSERT_NE(<x>, nullptr);
  23.168 +            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*!=\s*NULL,.*\);',r'ASSERT_NE(\1, nullptr);', line)
  23.169 +            if (line != modline):
  23.170 +                newfile.write(modline + "\n")
  23.171 +                continue
  23.172 +            modline = re.sub(r'TEST_ASSERT\((.*)\s*!=\s*NULL\);', r'ASSERT_NE(\1, nullptr);',line)
  23.173 +            if (line != modline):
  23.174 +                newfile.write(modline + "\n")
  23.175 +                continue
  23.176 +            
  23.177 +            #TEST_ASSERT_MSG(<x> == <y>, *);
  23.178 +            #TEST_ASSERT(<x> == <y>);
  23.179 +            # -> ASSERT_EQ(<x>, <y>);
  23.180 +            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*==\s*(.*),.*\);', r'ASSERT_EQ(\1, \2);',line)
  23.181 +            if (line != modline):
  23.182 +                newfile.write(modline + "\n")
  23.183 +                continue
  23.184 +            modline = re.sub(r'TEST_ASSERT\((.*)\s*==\s*(.*)\);', r'ASSERT_EQ(\1, \2);',line)
  23.185 +            if (line != modline):
  23.186 +                newfile.write(modline + "\n")
  23.187 +                continue
  23.188 +            
  23.189 +            #TEST_ASSERT_MSG(<x> != <y>, *);
  23.190 +            #TEST_ASSERT(<x> != <y>);
  23.191 +            # -> ASSERT_NE(<x>, <y>);
  23.192 +            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*!=\s*(.*),.*\);', r'ASSERT_NE(\1, \2);',line)
  23.193 +            if (line != modline):
  23.194 +                newfile.write(modline + "\n")
  23.195 +                continue
  23.196 +            modline = re.sub(r'TEST_ASSERT\((.*)\s*!=\s*(.*)\);', r'ASSERT_NE(\1, \2);',line)
  23.197 +            if (line != modline):
  23.198 +                newfile.write(modline + "\n")
  23.199 +                continue
  23.200 +            
  23.201 +            #TEST_ASSERT_MSG(<x> >= <y>, *);
  23.202 +            #TEST_ASSERT(<x> >= <y>);
  23.203 +            # -> ASSERT_GE(<x>, <y>);
  23.204 +            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*[^-]>=\s*(.*),.*\);', r'ASSERT_GE(\1, \2);',line)
  23.205 +            if (line != modline):
  23.206 +                newfile.write(modline + "\n")
  23.207 +                continue
  23.208 +            modline = re.sub(r'TEST_ASSERT\((.*)\s*[^-]>=\s*(.*)\);', r'ASSERT_GE(\1, \2);',line)
  23.209 +            if (line != modline):
  23.210 +                newfile.write(modline + "\n")
  23.211 +                continue
  23.212 +            
  23.213 +            #TEST_ASSERT_MSG(<x> > <y>, *);
  23.214 +            #TEST_ASSERT(<x> > <y>);
  23.215 +            # -> ASSERT_GT(<x>, <y>);
  23.216 +            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*[^-]>\s*(.*),.*\);', r'ASSERT_GT(\1, \2);',line)
  23.217 +            if (line != modline):
  23.218 +                newfile.write(modline + "\n")
  23.219 +                continue
  23.220 +            modline = re.sub(r'TEST_ASSERT\((.*)\s*[^-]>\s*(.*)\);', r'ASSERT_GT(\1, \2);',line)
  23.221 +            if (line != modline):
  23.222 +                newfile.write(modline + "\n")
  23.223 +                continue
  23.224 +            
  23.225 +            #TEST_ASSERT_MSG(<x> <= <y>, *);
  23.226 +            #TEST_ASSERT(<x> <= <y>);
  23.227 +            # -> ASSERT_LE(<x>, <y>);
  23.228 +            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*<=\s*(.*),.*\);', r'ASSERT_LE(\1, \2);',line)
  23.229 +            if (line != modline):
  23.230 +                newfile.write(modline + "\n")
  23.231 +                continue
  23.232 +            modline = re.sub(r'TEST_ASSERT\((.*)\s*<=\s*(.*)\);', r'ASSERT_LE(\1, \2);',line)
  23.233 +            if (line != modline):
  23.234 +                newfile.write(modline + "\n")
  23.235 +                continue
  23.236 +            
  23.237 +            #TEST_ASSERT_MSG(<x> < <y>, *);
  23.238 +            #TEST_ASSERT(<x> < <y>);
  23.239 +            # -> ASSERT_LT(<x>, <y>);
  23.240 +            modline = re.sub(r'TEST_ASSERT_MSG\((.*)\s*<\s*(.*),.*\);', r'ASSERT_LT(\1, \2);',line)
  23.241 +            if (line != modline):
  23.242 +                newfile.write(modline + "\n")
  23.243 +                continue
  23.244 +            modline = re.sub(r'TEST_ASSERT\((.*)\s*<\s*(.*)\);', r'ASSERT_LT(\1, \2);',line)
  23.245 +            if (line != modline):
  23.246 +                newfile.write(modline + "\n")
  23.247 +                continue
  23.248 +
  23.249 +            #TEST_ASSERT_MSG(slurp_and_import_key(
  23.250 +            #TEST_ASSERT(slurp_and_import_key(
  23.251 +            # -> ASSERT_TRUE(slurp_and_import_key(
  23.252 +            modline = re.sub(r'TEST_ASSERT_MSG\(slurp_and_import_key', r'ASSERT_TRUE(slurp_and_import_key',line)
  23.253 +            if (line != modline):
  23.254 +                if not line.endswith(";"):
  23.255 +                    eat_next_line = True
  23.256 +                    modline = re.sub(r'\),', r'));', modline);
  23.257 +                newfile.write(modline + "\n")
  23.258 +                continue
  23.259 +            modline = re.sub(r'TEST_ASSERT\(slurp_and_import_key', r'ASSERT_TRUE(slurp_and_import_key',line)
  23.260 +            if (line != modline):
  23.261 +                newfile.write(modline + "\n")
  23.262 +                continue
  23.263 +            
  23.264 +            #TEST_ASSERT_MSG(!<x>, *);
  23.265 +            #TEST_ASSERT(!<x>);
  23.266 +            # -> ASSERT_FALSE(<x>);
  23.267 +            mgroup = re.match(r'TEST_ASSERT_MSG\(!(.*),.*\);', line.lstrip());
  23.268 +            if (mgroup == None):
  23.269 +                mgroup = re.match(r'TEST_ASSERT\(!(.*)\);', line.lstrip());
  23.270 +            
  23.271 +            if (mgroup != None):
  23.272 +                matchphrase = mgroup.group(0)
  23.273 +                is_pointer = False
  23.274 +                while True:
  23.275 +                    answer = input("ATTENTION: INPUT REQUIRED: In line " + line.lstrip() + ", is " + matchphrase + " a pointer? (y/n)")
  23.276 +                    if (answer == "y" or answer == "Y"):
  23.277 +                        is_pointer = True
  23.278 +                        break
  23.279 +                    elif (answer != "n" and answer != 'N'):
  23.280 +                        print("\'" + answer + "\' is not a valid answer. Please answer with 'y' or 'n'.") 
  23.281 +                        continue
  23.282 +                    break;       
  23.283 +                
  23.284 +                if (is_pointer):
  23.285 +                    modline = re.sub(r'TEST_ASSERT_MSG\(!(.*),.*\);',r'ASSERT_NE(\1, nullptr);', line)
  23.286 +                    if (line != modline):
  23.287 +                        newfile.write(modline + "\n")
  23.288 +                        continue
  23.289 +                    modline = re.sub(r'TEST_ASSERT\(!(.*)\);', r'ASSERT_NE(\1, nullptr);',line)
  23.290 +                    if (line != modline):
  23.291 +                        newfile.write(modline + "\n")
  23.292 +                        continue
  23.293 +                else:        
  23.294 +                    modline = re.sub(r'TEST_ASSERT_MSG\(!(.*),.*\);',r'ASSERT_FALSE(\1);', line)
  23.295 +                    if (line != modline):
  23.296 +                        newfile.write(modline + "\n")
  23.297 +                        continue
  23.298 +                    modline = re.sub(r'TEST_ASSERT\(!(.*)\);', r'ASSERT_FALSE(\1);',line)
  23.299 +                    if (line != modline):
  23.300 +                        newfile.write(modline + "\n")
  23.301 +                        continue
  23.302 +                                            
  23.303 +            #TEST_ASSERT_MSG(<x>, *);
  23.304 +            #TEST_ASSERT(<x>);
  23.305 +            # -> ASSERT_TRUE(<x>);
  23.306 +            mgroup = re.match(r'TEST_ASSERT_MSG\((.*),.*\);', line.lstrip());
  23.307 +            if (mgroup == None):
  23.308 +                mgroup = re.match(r'TEST_ASSERT\((.*)\);', line.lstrip());
  23.309 +            
  23.310 +            if (mgroup != None):
  23.311 +                matchphrase = mgroup.group(1)
  23.312 +                is_pointer = False
  23.313 +                while True:
  23.314 +                    answer = input("ATTENTION: INPUT REQUIRED: In line " + line.lstrip() + ", is " + matchphrase + " a pointer? (y/n)")
  23.315 +                    if (answer == "y" or answer == "Y"):
  23.316 +                        is_pointer = True
  23.317 +                        break
  23.318 +                    elif (answer != "n" and answer != 'N'):
  23.319 +                        print("\'" + answer + "\' is not a valid answer. Please answer with 'y' or 'n'.") 
  23.320 +                        continue
  23.321 +                    break;       
  23.322 +                
  23.323 +                if (is_pointer):
  23.324 +                    modline = re.sub(r'TEST_ASSERT_MSG\((.*),.*\);',r'ASSERT_NE(\1, nullptr);', line)
  23.325 +                    if (line != modline):
  23.326 +                        newfile.write(modline + "\n")
  23.327 +                        continue
  23.328 +                    modline = re.sub(r'TEST_ASSERT\((.*)\);', r'ASSERT_NE(\1, nullptr);',line)
  23.329 +                    if (line != modline):
  23.330 +                        newfile.write(modline + "\n")
  23.331 +                        continue
  23.332 +                else:        
  23.333 +                    modline = re.sub(r'TEST_ASSERT_MSG\((.*),.*\);',r'ASSERT_TRUE(\1);', line)
  23.334 +                    if (line != modline):
  23.335 +                        newfile.write(modline + "\n")
  23.336 +                        continue
  23.337 +                    modline = re.sub(r'TEST_ASSERT\((.*)\);', r'ASSERT_TRUE(\1);',line)
  23.338 +                    if (line != modline):
  23.339 +                        newfile.write(modline + "\n")
  23.340 +                        continue
  23.341 +            
  23.342 +            #Ok, it's something else. Print line and go.
  23.343 +            newfile.write(line + "\n")
    24.1 --- a/test/include/TestConstants.h	Mon Aug 26 12:41:39 2019 +0200
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,12 +0,0 @@
    24.4 -#ifndef TEST_CONSTANTS_H
    24.5 -#define TEST_CONSTANTS_H
    24.6 -
    24.7 -#ifndef USE_NETPGP
    24.8 -#define PEP_TEST_KEY_IMPORT_SUCCESS PEP_KEY_IMPORTED
    24.9 -#define PEP_TEST_NO_KEY_IMPORT PEP_NO_KEY_IMPORTED
   24.10 -#else
   24.11 -#define PEP_TEST_KEY_IMPORT_SUCCESS PEP_KEY_IMPORT_STATUS_UNKNOWN
   24.12 -#define PEP_TEST_NO_KEY_IMPORT PEP_KEY_IMPORT_STATUS_UNKNOWN
   24.13 -#endif
   24.14 -
   24.15 -#endif
    25.1 --- a/test/include/pEpEngine_test.h	Mon Aug 26 12:41:39 2019 +0200
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,4 +0,0 @@
    25.4 -#include <iomanip>
    25.5 -
    25.6 -#define ASSERT_STATUS(status) { cout << setfill('0') << "status: 0x" << hex << setw(4) << status << "\n"; assert(status == PEP_STATUS_OK); cout << std::dec; }
    25.7 -
    26.1 --- a/test/include/pEpTestStatic.h	Mon Aug 26 12:41:39 2019 +0200
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,25 +0,0 @@
    26.4 -// This file is under GNU General Public License 3.0
    26.5 -// see LICENSE.txt
    26.6 -
    26.7 -#ifndef PEP_TEST_STATIC_H
    26.8 -#define PEP_TEST_STATIC_H
    26.9 -
   26.10 -#include <string>
   26.11 -
   26.12 -using namespace std;
   26.13 -
   26.14 -class pEpTestStatic {
   26.15 -    public:
   26.16 -        static size_t getMaxPathSize();
   26.17 -        static size_t sun_path_size;
   26.18 -        static size_t getAvailablePathChars(string keypath_str);
   26.19 -        static size_t available_path_chars;
   26.20 -        static const size_t classname_chars;
   26.21 -        static const size_t testnum_path_chars;
   26.22 -        static const size_t max_test_num;
   26.23 -
   26.24 -    private:
   26.25 -        pEpTestStatic() {};
   26.26 -};
   26.27 -
   26.28 -#endif
    27.1 --- a/test/include/test_util.h	Mon Aug 26 12:41:39 2019 +0200
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,237 +0,0 @@
    27.4 -#ifndef PEP_TEST_UTILS_H
    27.5 -#define PEP_TEST_UTILS_H
    27.6 -
    27.7 -#include <string>
    27.8 -#include <stdlib.h>
    27.9 -#include <sys/stat.h>
   27.10 -#include <ftw.h>
   27.11 -
   27.12 -#include "pEpEngine.h"
   27.13 -#include "message_api.h"
   27.14 -#include "aux_mime_msg.h"
   27.15 -
   27.16 -void test_init();
   27.17 -
   27.18 -bool file_exists(std::string filename);
   27.19 -
   27.20 -extern std::string _main_test_home_dir;
   27.21 -
   27.22 -std::string get_main_test_home_dir();
   27.23 -
   27.24 -typedef enum _pEp_test_ident_preset {
   27.25 -    ALICE,
   27.26 -    APPLE,
   27.27 -    BOB,
   27.28 -    CAROL,
   27.29 -    DAVE,
   27.30 -    ERIN,
   27.31 -    FRANK,
   27.32 -    GABRIELLE,
   27.33 -    JOHN,
   27.34 -    ALEX,
   27.35 -    ALEX_0,
   27.36 -    ALEX_1,
   27.37 -    ALEX_2,
   27.38 -    ALEX_3,
   27.39 -    ALEX_4,
   27.40 -    ALEX_5,
   27.41 -    ALEX_6A,
   27.42 -    ALEX_6B,
   27.43 -    ALEX_6C,
   27.44 -    ALEX_6D,
   27.45 -    BELLA,
   27.46 -    FENRIS,
   27.47 -    SERCULLEN,
   27.48 -    INQUISITOR,
   27.49 -    BERND
   27.50 -} pEp_test_ident_preset;
   27.51 -
   27.52 -PEP_STATUS set_up_preset(PEP_SESSION session,
   27.53 -                         pEp_test_ident_preset preset_name,
   27.54 -                         bool set_identity, 
   27.55 -                         bool set_pep,
   27.56 -                         bool trust,
   27.57 -                         bool set_own, 
   27.58 -                         bool setup_private, 
   27.59 -                         pEp_identity** ident);
   27.60 -
   27.61 -
   27.62 -PEP_STATUS read_file_and_import_key(PEP_SESSION session, const char* fname);
   27.63 -PEP_STATUS set_up_ident_from_scratch(PEP_SESSION session, 
   27.64 -                                     const char* key_fname,
   27.65 -                                     const char* address,
   27.66 -                                     const char* fpr,
   27.67 -                                     const char* user_id,
   27.68 -                                     const char* username,
   27.69 -                                     pEp_identity** ret_ident,
   27.70 -                                     bool is_priv);
   27.71 -
   27.72 -// string equality (case and non-case sensitive)
   27.73 -bool _streq(const char* str1, const char* str2);
   27.74 -bool _strceq(const char* str1, const char* str2);
   27.75 -
   27.76 -// reads a whole file and returns it as std::string
   27.77 -// throws std::runtime_error() if the file cannot be read. Empty file is not an error.
   27.78 -std::string slurp(const std::string& filename);
   27.79 -
   27.80 -// dumps char* to file
   27.81 -// throws std::runtime_error() if the file cannot be opened.
   27.82 -void dump_out(const char* filename, const char* outdata);
   27.83 -
   27.84 -// Returns the string value of the input rating enum value. 
   27.85 -const char* tl_rating_string(PEP_rating rating);
   27.86 -
   27.87 -// Returns the string value of the input comm_type enum value. 
   27.88 -const char* tl_ct_string(PEP_comm_type ct);
   27.89 -
   27.90 -// Returns the string value of the input status enum value. 
   27.91 -const char* tl_status_string(PEP_STATUS status);
   27.92 -
   27.93 -std::string tl_ident_flags_String(identity_flags_t fl);
   27.94 -
   27.95 -// Grabs a new uuid for your randomish string needs.
   27.96 -char* get_new_uuid();
   27.97 -
   27.98 -bool slurp_and_import_key(PEP_SESSION session, const char* key_filename);
   27.99 -
  27.100 -bool slurp_message_and_import_key(PEP_SESSION session, const char* message_fname, std::string& message, const char* key_filename);
  27.101 -
  27.102 -int util_delete_filepath(const char *filepath, 
  27.103 -                         const struct stat *file_stat, 
  27.104 -                         int ftw_info, 
  27.105 -                         struct FTW * ftw_struct);
  27.106 -                         
  27.107 -#ifndef ENIGMAIL_MAY_USE_THIS
  27.108 -
  27.109 -// MIME_decrypt_message() - decrypt a MIME message, with MIME output
  27.110 -//
  27.111 -//  parameters:
  27.112 -//      session (in)            session handle
  27.113 -//      mimetext (in)           MIME encoded text to decrypt
  27.114 -//      size (in)               size of mime text to decode (in order to decrypt)
  27.115 -//      mime_plaintext (out)    decrypted, encoded message
  27.116 -//      keylist (inout)         in: stringlist with additional keyids for reencryption if needed
  27.117 -//                                  (will be freed and replaced with output keylist)
  27.118 -//                              out: stringlist with keyids
  27.119 -//      rating (out)            rating for the message
  27.120 -//      flags (inout)           flags to signal special decryption features (see below)
  27.121 -//      modified_src (out)      modified source string, if decrypt had reason to change it
  27.122 -//
  27.123 -//  return value:
  27.124 -//      decrypt status          if everything worked with MIME encode/decode, 
  27.125 -//                              the status of the decryption is returned 
  27.126 -//                              (PEP_STATUS_OK or decryption error status)
  27.127 -//      PEP_BUFFER_TOO_SMALL    if encoded message size is too big to handle
  27.128 -//      PEP_CANNOT_CREATE_TEMP_FILE
  27.129 -//                              if there are issues with temp files; in
  27.130 -//                              this case errno will contain the underlying
  27.131 -//                              error
  27.132 -//      PEP_OUT_OF_MEMORY       if not enough memory could be allocated
  27.133 -//
  27.134 -//  flag values:
  27.135 -//      in:
  27.136 -//          PEP_decrypt_flag_untrusted_server
  27.137 -//              used to signal that decrypt function should engage in behaviour
  27.138 -//              specified for when the server storing the source is untrusted.
  27.139 -//      out:
  27.140 -//          PEP_decrypt_flag_own_private_key
  27.141 -//              private key was imported for one of our addresses (NOT trusted
  27.142 -//              or set to be used - handshake/trust is required for that)
  27.143 -//          PEP_decrypt_flag_src_modified
  27.144 -//              indicates that the modified_src field should contain a modified
  27.145 -//              version of the source, at the moment always as a result of the
  27.146 -//              input flags. 
  27.147 -//          PEP_decrypt_flag_consume
  27.148 -//              used by sync 
  27.149 -//          PEP_decrypt_flag_ignore
  27.150 -//              used by sync 
  27.151 -// 
  27.152 -//  caveat:
  27.153 -//      the decrypted, encoded mime text will go to the ownership of the caller; mimetext
  27.154 -//      will remain in the ownership of the caller
  27.155 -PEP_STATUS MIME_decrypt_message(
  27.156 -    PEP_SESSION session,
  27.157 -    const char *mimetext,
  27.158 -    size_t size,
  27.159 -    char** mime_plaintext,
  27.160 -    stringlist_t **keylist,
  27.161 -    PEP_rating *rating,
  27.162 -    PEP_decrypt_flags_t *flags,
  27.163 -    char** modified_src
  27.164 -);
  27.165 -
  27.166 -// MIME_encrypt_message() - encrypt a MIME message, with MIME output
  27.167 -//
  27.168 -//  parameters:
  27.169 -//      session (in)            session handle
  27.170 -//      mimetext (in)           MIME encoded text to encrypt
  27.171 -//      size (in)               size of input mime text
  27.172 -//      extra (in)              extra keys for encryption
  27.173 -//      mime_ciphertext (out)   encrypted, encoded message
  27.174 -//      enc_format (in)         encrypted format
  27.175 -//      flags (in)              flags to set special encryption features
  27.176 -//
  27.177 -//  return value:
  27.178 -//      PEP_STATUS_OK           if everything worked
  27.179 -//      PEP_BUFFER_TOO_SMALL    if encoded message size is too big to handle
  27.180 -//      PEP_CANNOT_CREATE_TEMP_FILE
  27.181 -//                              if there are issues with temp files; in
  27.182 -//                              this case errno will contain the underlying
  27.183 -//                              error
  27.184 -//      PEP_OUT_OF_MEMORY       if not enough memory could be allocated
  27.185 -//
  27.186 -//  caveat:
  27.187 -//      the encrypted, encoded mime text will go to the ownership of the caller; mimetext
  27.188 -//      will remain in the ownership of the caller
  27.189 -DYNAMIC_API PEP_STATUS MIME_encrypt_message(
  27.190 -    PEP_SESSION session,
  27.191 -    const char *mimetext,
  27.192 -    size_t size,
  27.193 -    stringlist_t* extra,
  27.194 -    char** mime_ciphertext,
  27.195 -    PEP_enc_format enc_format,
  27.196 -    PEP_encrypt_flags_t flags
  27.197 -);
  27.198 -
  27.199 -
  27.200 -// MIME_encrypt_message_for_self() - encrypt MIME message for user's identity only,
  27.201 -//                              ignoring recipients and other identities from
  27.202 -//                              the message, with MIME output
  27.203 -//  parameters:
  27.204 -//      session (in)            session handle
  27.205 -//      target_id (in)          self identity this message should be encrypted for
  27.206 -//      mimetext (in)           MIME encoded text to encrypt
  27.207 -//      size (in)               size of input mime text
  27.208 -//      extra (in)              extra keys for encryption
  27.209 -//      mime_ciphertext (out)   encrypted, encoded message
  27.210 -//      enc_format (in)         encrypted format
  27.211 -//      flags (in)              flags to set special encryption features
  27.212 -//
  27.213 -//  return value:
  27.214 -//      PEP_STATUS_OK           if everything worked
  27.215 -//      PEP_BUFFER_TOO_SMALL    if encoded message size is too big to handle
  27.216 -//      PEP_CANNOT_CREATE_TEMP_FILE
  27.217 -//                              if there are issues with temp files; in
  27.218 -//                              this case errno will contain the underlying
  27.219 -//                              error
  27.220 -//      PEP_OUT_OF_MEMORY       if not enough memory could be allocated
  27.221 -//
  27.222 -//  caveat:
  27.223 -//      the encrypted, encoded mime text will go to the ownership of the caller; mimetext
  27.224 -//      will remain in the ownership of the caller
  27.225 -PEP_STATUS MIME_encrypt_message_for_self(
  27.226 -    PEP_SESSION session,
  27.227 -    pEp_identity* target_id,
  27.228 -    const char *mimetext,
  27.229 -    size_t size,
  27.230 -    stringlist_t* extra,
  27.231 -    char** mime_ciphertext,
  27.232 -    PEP_enc_format enc_format,
  27.233 -    PEP_encrypt_flags_t flags
  27.234 -);
  27.235 -
  27.236 -#endif
  27.237 -
  27.238 -
  27.239 -        
  27.240 -#endif
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/test/src/AppleMailTest.cc	Mon Aug 26 13:38:21 2019 +0200
    28.3 @@ -0,0 +1,211 @@
    28.4 +// This file is under GNU General Public License 3.0
    28.5 +// see LICENSE.txt
    28.6 +
    28.7 +#include <stdlib.h>
    28.8 +#include <string.h>
    28.9 +#include <iostream>
   28.10 +#include <fstream>
   28.11 +#include <string>
   28.12 +#include <cstring> // for strcmp()
   28.13 +#include "platform.h"
   28.14 +#include <iostream>
   28.15 +#include <fstream>
   28.16 +#include <sstream>
   28.17 +#include "keymanagement.h"
   28.18 +#include "message_api.h"
   28.19 +#include "mime.h"
   28.20 +#include "test_util.h" // for slurp()
   28.21 +#include "TestConstants.h"
   28.22 +
   28.23 +
   28.24 +
   28.25 +#include "Engine.h"
   28.26 +
   28.27 +#include <gtest/gtest.h>
   28.28 +
   28.29 +
   28.30 +namespace {
   28.31 +
   28.32 +	//The fixture for AppleMailTest
   28.33 +    class AppleMailTest : public ::testing::Test {
   28.34 +        public:
   28.35 +            Engine* engine;
   28.36 +            PEP_SESSION session;
   28.37 +
   28.38 +        protected:
   28.39 +            // You can remove any or all of the following functions if its body
   28.40 +            // is empty.
   28.41 +            AppleMailTest() {
   28.42 +                // You can do set-up work for each test here.
   28.43 +                test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name();
   28.44 +                test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
   28.45 +                test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
   28.46 +            }
   28.47 +
   28.48 +            ~AppleMailTest() override {
   28.49 +                // You can do clean-up work that doesn't throw exceptions here.
   28.50 +            }
   28.51 +
   28.52 +            // If the constructor and destructor are not enough for setting up
   28.53 +            // and cleaning up each test, you can define the following methods:
   28.54 +
   28.55 +            void SetUp() override {
   28.56 +                // Code here will be called immediately after the constructor (right
   28.57 +                // before each test).
   28.58 +
   28.59 +                // Leave this empty if there are no files to copy to the home directory path
   28.60 +                std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
   28.61 +
   28.62 +                // Get a new test Engine.
   28.63 +                engine = new Engine(test_path);
   28.64 +                ASSERT_NE(engine, nullptr);
   28.65 +
   28.66 +                // Ok, let's initialize test directories etc.
   28.67 +                engine->prep(NULL, NULL, init_files);
   28.68 +
   28.69 +                // Ok, try to start this bugger.
   28.70 +                engine->start();
   28.71 +                ASSERT_NE(engine->session, nullptr);
   28.72 +                session = engine->session;
   28.73 +
   28.74 +                // Engine is up. Keep on truckin'
   28.75 +            }
   28.76 +
   28.77 +            void TearDown() override {
   28.78 +                // Code here will be called immediately after each test (right
   28.79 +                // before the destructor).
   28.80 +                engine->shut_down();
   28.81 +                delete engine;
   28.82 +                engine = NULL;
   28.83 +                session = NULL;
   28.84 +            }
   28.85 +
   28.86 +        private:
   28.87 +            const char* test_suite_name;
   28.88 +            const char* test_name;
   28.89 +            string test_path;
   28.90 +            // Objects declared here can be used by all tests in the AppleMailTest suite.
   28.91 +
   28.92 +    };
   28.93 +
   28.94 +}  // namespace
   28.95 +
   28.96 +
   28.97 +TEST_F(AppleMailTest, check_apple_mail_text_signed_encrypted) {
   28.98 +
   28.99 +    const char* mailfile = "test_mails/apple_mail_TC_signed_encrypted.eml";
  28.100 +
  28.101 +    const string keytextkey1 = slurp("test_keys/pub/pep-test-apple-0x1CCBC7D7_pub.asc");
  28.102 +    const string keytextkey2 = slurp("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
  28.103 +    const string keytextkey3 = slurp("test_keys/pub/pep-test-recip-0x08DB0AEE_pub.asc");
  28.104 +
  28.105 +    PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
  28.106 +    PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
  28.107 +    PEP_STATUS statuskey3 = import_key(session, keytextkey3.c_str(), keytextkey3.length(), NULL);
  28.108 +
  28.109 +    const string mailtext = slurp(mailfile);
  28.110 +    pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE", PEP_OWN_USERID, "pEp Test Recipient");
  28.111 +    me->me = true;
  28.112 +    PEP_STATUS status = set_own_key(session, me, "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE");
  28.113 +
  28.114 +    pEp_identity * you = new_identity("pep.test.apple@pep-project.org", NULL, "pep.test.apple@pep-project.org", "pEp Apple Test");
  28.115 +    you->me = false;
  28.116 +    status = update_identity(session, you);
  28.117 +
  28.118 +    trust_personal_key(session, you);
  28.119 +
  28.120 +    status = update_identity(session, you);
  28.121 +
  28.122 +    message* msg_ptr = nullptr;
  28.123 +    message* dest_msg = nullptr;
  28.124 +    stringlist_t* keylist = nullptr;
  28.125 +    PEP_rating rating;
  28.126 +    PEP_decrypt_flags_t flags = 0;
  28.127 +
  28.128 +    message* final_ptr = nullptr;
  28.129 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  28.130 +    ASSERT_EQ(status , PEP_STATUS_OK);
  28.131 +    ASSERT_NE(msg_ptr, nullptr);
  28.132 +
  28.133 +    update_identity(session, msg_ptr->from);
  28.134 +    update_identity(session, msg_ptr->to->ident);
  28.135 +
  28.136 +    final_ptr = msg_ptr;
  28.137 +
  28.138 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  28.139 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
  28.140 +
  28.141 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  28.142 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  28.143 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  28.144 +
  28.145 +    ASSERT_EQ(color_from_rating(rating) , PEP_color_green);
  28.146 +
  28.147 +    if (final_ptr == dest_msg)
  28.148 +    	free_message(dest_msg);
  28.149 +    free_message(msg_ptr);
  28.150 +    free_stringlist(keylist);
  28.151 +}
  28.152 +
  28.153 +TEST_F(AppleMailTest, check_apple_mail_html_signed_encrypted) {
  28.154 +
  28.155 +    // Start state copy
  28.156 +    // N.B. As part of breaking up formerly monolith tests into individual tests, I've copied state setup from the
  28.157 +    // original functions into many functions. It should, when there's time, either be refactored (if necessary for this
  28.158 +    // test) or removed (if not).
  28.159 +    const string keytextkey1 = slurp("test_keys/pub/pep-test-apple-0x1CCBC7D7_pub.asc");
  28.160 +    const string keytextkey2 = slurp("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
  28.161 +    const string keytextkey3 = slurp("test_keys/pub/pep-test-recip-0x08DB0AEE_pub.asc");
  28.162 +
  28.163 +    PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
  28.164 +    PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
  28.165 +    PEP_STATUS statuskey3 = import_key(session, keytextkey3.c_str(), keytextkey3.length(), NULL);
  28.166 +
  28.167 +    pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE", PEP_OWN_USERID, "pEp Test Recipient");
  28.168 +    me->me = true;
  28.169 +    PEP_STATUS status = set_own_key(session, me, "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE");
  28.170 +
  28.171 +    pEp_identity * you = new_identity("pep.test.apple@pep-project.org", NULL, "pep.test.apple@pep-project.org", "pEp Apple Test");
  28.172 +    you->me = false;
  28.173 +    status = update_identity(session, you);
  28.174 +
  28.175 +    trust_personal_key(session, you);
  28.176 +
  28.177 +    status = update_identity(session, you);
  28.178 +
  28.179 +    // End state copy
  28.180 +
  28.181 +    message* msg_ptr = nullptr;
  28.182 +    message* dest_msg = nullptr;
  28.183 +    message* final_ptr = nullptr;
  28.184 +    stringlist_t* keylist = nullptr;
  28.185 +    PEP_rating rating;
  28.186 +    PEP_decrypt_flags_t flags = 0;
  28.187 +
  28.188 +    const char* mailfile2 = "test_mails/apple_mail_TC_html_signed_encrypted.eml";
  28.189 +    const string mailtext2 = slurp(mailfile2);
  28.190 +
  28.191 +    status = mime_decode_message(mailtext2.c_str(), mailtext2.length(), &msg_ptr);
  28.192 +    ASSERT_EQ(status, PEP_STATUS_OK);
  28.193 +    ASSERT_NE(msg_ptr, nullptr);
  28.194 +    final_ptr = msg_ptr;
  28.195 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  28.196 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
  28.197 +
  28.198 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
  28.199 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
  28.200 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
  28.201 +
  28.202 +    ASSERT_EQ(color_from_rating(rating) , PEP_color_green);
  28.203 +
  28.204 +    if (final_ptr == dest_msg)
  28.205 +    	free_message(dest_msg);
  28.206 +    free_message(msg_ptr);
  28.207 +    free_stringlist(keylist);
  28.208 +
  28.209 +    msg_ptr = nullptr;
  28.210 +    dest_msg = nullptr;
  28.211 +    final_ptr = nullptr;
  28.212 +    keylist = nullptr;
  28.213 +    rating = PEP_rating_unreliable;
  28.214 +}
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/test/src/BCCTest.cc	Mon Aug 26 13:38:21 2019 +0200
    29.3 @@ -0,0 +1,128 @@
    29.4 +// This file is under GNU General Public License 3.0
    29.5 +// see LICENSE.txt
    29.6 +
    29.7 +#include <stdlib.h>
    29.8 +#include <string>
    29.9 +#include <cstring>
   29.10 +#include <assert.h>
   29.11 +
   29.12 +#include "pEpEngine.h"
   29.13 +#include "message_api.h"
   29.14 +#include "TestConstants.h"
   29.15 +
   29.16 +#include "test_util.h"
   29.17 +
   29.18 +
   29.19 +#include "Engine.h"
   29.20 +
   29.21 +#include <gtest/gtest.h>
   29.22 +
   29.23 +
   29.24 +namespace {
   29.25 +
   29.26 +	//The fixture for BCCTest
   29.27 +    class BCCTest : public ::testing::Test {
   29.28 +        public:
   29.29 +            Engine* engine;
   29.30 +            PEP_SESSION session;
   29.31 +
   29.32 +        protected:
   29.33 +            // You can remove any or all of the following functions if its body
   29.34 +            // is empty.
   29.35 +            BCCTest() {
   29.36 +                // You can do set-up work for each test here.
   29.37 +                test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name();
   29.38 +                test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
   29.39 +                test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
   29.40 +            }
   29.41 +
   29.42 +            ~BCCTest() override {
   29.43 +                // You can do clean-up work that doesn't throw exceptions here.
   29.44 +            }
   29.45 +
   29.46 +            // If the constructor and destructor are not enough for setting up
   29.47 +            // and cleaning up each test, you can define the following methods:
   29.48 +
   29.49 +            void SetUp() override {
   29.50 +                // Code here will be called immediately after the constructor (right
   29.51 +                // before each test).
   29.52 +
   29.53 +                // Leave this empty if there are no files to copy to the home directory path
   29.54 +                std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
   29.55 +
   29.56 +                // Get a new test Engine.
   29.57 +                engine = new Engine(test_path);
   29.58 +                ASSERT_NE(engine, nullptr);
   29.59 +
   29.60 +                // Ok, let's initialize test directories etc.
   29.61 +                engine->prep(NULL, NULL, init_files);
   29.62 +
   29.63 +                // Ok, try to start this bugger.
   29.64 +                engine->start();
   29.65 +                ASSERT_NE(engine->session, nullptr);
   29.66 +                session = engine->session;
   29.67 +
   29.68 +                // Engine is up. Keep on truckin'
   29.69 +                
   29.70 +                string keystr = slurp("test_keys/priv/bcc_test_dude_0-0x1CCCFC41_priv.asc");
   29.71 +                PEP_STATUS status = import_key(session, keystr.c_str(), keystr.size(), NULL);
   29.72 +                ASSERT_TRUE(status == PEP_TEST_KEY_IMPORT_SUCCESS);    
   29.73 +                pEp_identity * me = new_identity("bcc_test_dude_0@darthmama.cool", "0AE9AA3E320595CF93296BDFA155AC491CCCFC41", PEP_OWN_USERID, "BCC Test Sender");    
   29.74 +                status = set_own_key(session, me, "0AE9AA3E320595CF93296BDFA155AC491CCCFC41");
   29.75 +                keystr = slurp("test_keys/pub/bcc_test_dude_0-0x1CCCFC41_pub.asc");
   29.76 +                status = import_key(session, keystr.c_str(), keystr.size(), NULL);
   29.77 +                ASSERT_TRUE(status == PEP_TEST_KEY_IMPORT_SUCCESS);
   29.78 +                keystr = slurp("test_keys/pub/bcc_test_dude_1-0xDAC746BE_pub.asc");
   29.79 +                status = import_key(session, keystr.c_str(), keystr.size(), NULL);
   29.80 +                ASSERT_TRUE(status == PEP_TEST_KEY_IMPORT_SUCCESS);
   29.81 +                keystr = slurp("test_keys/pub/bcc_test_dude_2-0x53CECCF7_pub.asc");
   29.82 +                status = import_key(session, keystr.c_str(), keystr.size(), NULL);
   29.83 +                ASSERT_TRUE(status == PEP_TEST_KEY_IMPORT_SUCCESS);    
   29.84 +
   29.85 +            }
   29.86 +
   29.87 +            void TearDown() override {
   29.88 +                // Code here will be called immediately after each test (right
   29.89 +                // before the destructor).
   29.90 +                engine->shut_down();
   29.91 +                delete engine;
   29.92 +                engine = NULL;
   29.93 +                session = NULL;
   29.94 +            }
   29.95 +
   29.96 +        private:
   29.97 +            const char* test_suite_name;
   29.98 +            const char* test_name;
   29.99 +            string test_path;
  29.100 +            // Objects declared here can be used by all tests in the BCCTest suite.
  29.101 +
  29.102 +    };
  29.103 +
  29.104 +}  // namespace
  29.105 +
  29.106 +TEST_F(BCCTest, check_single_BCC) {
  29.107 +    PEP_STATUS status = PEP_UNKNOWN_ERROR;
  29.108 +
  29.109 +    // 0AE9AA3E320595CF93296BDFA155AC491CCCFC41
  29.110 +    // D0AF2F9695E186A8DC058B935FE2793DDAC746BE
  29.111 +    // B36E468E7A381946FCDBDDFA84B1F3E853CECCF7
  29.112 +    pEp_identity* sender = new_identity("bcc_test_dude_0@darthmama.cool", NULL, PEP_OWN_USERID, "BCC Test Sender");
  29.113 +    pEp_identity* open_recip = new_identity("bcc_test_dude_1@darthmama.cool", NULL, NULL, "BCC Test Recip");
  29.114 +    pEp_identity* bcc_recip = new_identity("bcc_test_dude_2@darthmama.cool", NULL, NULL, "BCC Super Sekrit Test Recip");
  29.115 +
  29.116 +    message *msg = new_message(PEP_dir_outgoing);
  29.117 +    ASSERT_NE(msg, nullptr);
  29.118 +    msg->from = sender;
  29.119 +//    msg->to = new_identity_list(open_recip); FYI, this is supposed to fail for now. Unfortunately.
  29.120 +    msg->bcc = new_identity_list(bcc_recip);
  29.121 +    msg->shortmsg = strdup("Hello, world");
  29.122 +    msg->longmsg = strdup("Your mother was a hamster and your father smelt of elderberries.");
  29.123 +    msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  29.124 +
  29.125 +    message *enc_msg = nullptr;
  29.126 +    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
  29.127 +
  29.128 +    ASSERT_EQ(status, PEP_STATUS_OK);
  29.129 +    free_message(msg);
  29.130 +    free_message(enc_msg);
  29.131 +}
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/test/src/BlacklistAcceptNewKeyTest.cc	Mon Aug 26 13:38:21 2019 +0200
    30.3 @@ -0,0 +1,160 @@
    30.4 +// This file is under GNU General Public License 3.0
    30.5 +// see LICENSE.txt
    30.6 +
    30.7 +#include <stdlib.h>
    30.8 +#include <string>
    30.9 +#include <cstring> // for strcmp()
   30.10 +
   30.11 +#include "test_util.h"
   30.12 +#include "TestConstants.h"
   30.13 +
   30.14 +#include "pEpEngine.h"
   30.15 +#include "blacklist.h"
   30.16 +#include "keymanagement.h"
   30.17 +#include "message_api.h"
   30.18 +#include "mime.h"
   30.19 +
   30.20 +
   30.21 +
   30.22 +#include "Engine.h"
   30.23 +
   30.24 +#include <gtest/gtest.h>
   30.25 +
   30.26 +
   30.27 +namespace {
   30.28 +
   30.29 +	//The fixture for BlacklistAcceptNewKeyTest
   30.30 +    class BlacklistAcceptNewKeyTest : public ::testing::Test {
   30.31 +        public:
   30.32 +            Engine* engine;
   30.33 +            PEP_SESSION session;
   30.34 +
   30.35 +        protected:
   30.36 +            // You can remove any or all of the following functions if its body
   30.37 +            // is empty.
   30.38 +            BlacklistAcceptNewKeyTest() {
   30.39 +                // You can do set-up work for each test here.
   30.40 +                test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name();
   30.41 +                test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
   30.42 +                test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
   30.43 +            }
   30.44 +
   30.45 +            ~BlacklistAcceptNewKeyTest() override {
   30.46 +                // You can do clean-up work that doesn't throw exceptions here.
   30.47 +            }
   30.48 +
   30.49 +            // If the constructor and destructor are not enough for setting up
   30.50 +            // and cleaning up each test, you can define the following methods:
   30.51 +
   30.52 +            void SetUp() override {
   30.53 +                // Code here will be called immediately after the constructor (right
   30.54 +                // before each test).
   30.55 +
   30.56 +                // Leave this empty if there are no files to copy to the home directory path
   30.57 +                std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
   30.58 +
   30.59 +                // Get a new test Engine.
   30.60 +                engine = new Engine(test_path);
   30.61 +                ASSERT_NE(engine, nullptr);
   30.62 +
   30.63 +                // Ok, let's initialize test directories etc.
   30.64 +                engine->prep(NULL, NULL, init_files);
   30.65 +
   30.66 +                // Ok, try to start this bugger.
   30.67 +                engine->start();
   30.68 +                ASSERT_NE(engine->session, nullptr);
   30.69 +                session = engine->session;
   30.70 +
   30.71 +                // Engine is up. Keep on truckin'
   30.72 +            }
   30.73 +
   30.74 +            void TearDown() override {
   30.75 +                // Code here will be called immediately after each test (right
   30.76 +                // before the destructor).
   30.77 +                engine->shut_down();
   30.78 +                delete engine;
   30.79 +                engine = NULL;
   30.80 +                session = NULL;
   30.81 +            }
   30.82 +
   30.83 +        private:
   30.84 +            const char* test_suite_name;
   30.85 +            const char* test_name;
   30.86 +            string test_path;
   30.87 +            // Objects declared here can be used by all tests in the BlacklistAcceptNewKeyTest suite.
   30.88 +
   30.89 +    };
   30.90 +
   30.91 +}  // namespace
   30.92 +
   30.93 +
   30.94 +TEST_F(BlacklistAcceptNewKeyTest, check_blacklist_accept_new_key) {
   30.95 +
   30.96 +    // blacklist test code
   30.97 +
   30.98 +    cout << "blacklist only key for identity / add key / check which key is used" << endl;
   30.99 +
  30.100 +    // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
  30.101 +
  30.102 +    /* read the key into memory */
  30.103 +    const string keytext = slurp("blacklisted_pub.asc");
  30.104 +
  30.105 +    /* import it into pep */
  30.106 +    PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
  30.107 +
  30.108 +    const char* bl_fpr_1 = "279765A2FEB5B7C731B861D93E4CEFD9F7AF4684";
  30.109 +    bool is_blacklisted = false;
  30.110 +
  30.111 +    pEp_identity* blacklisted_identity = new_identity("blacklistedkeys@kgrothoff.org",
  30.112 +                                                      bl_fpr_1,
  30.113 +                                                      NULL,
  30.114 +                                                      "Blacklist Keypair");
  30.115 +    PEP_STATUS status8 = update_identity(session, blacklisted_identity);
  30.116 +    PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
  30.117 +    PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
  30.118 +    ASSERT_TRUE(is_blacklisted);
  30.119 +    PEP_STATUS status11 = update_identity(session, blacklisted_identity);
  30.120 +    ASSERT_EQ(status11 , PEP_STATUS_OK);
  30.121 +    ASSERT_STREQ(bl_fpr_1, blacklisted_identity->fpr);
  30.122 +
  30.123 +    bool id_def, us_def, addr_def;
  30.124 +    status11 = get_valid_pubkey(session, blacklisted_identity,
  30.125 +                                &id_def, &us_def, &addr_def, true);
  30.126 +    ASSERT_EQ(blacklisted_identity->comm_type , PEP_ct_unknown);
  30.127 +
  30.128 +    if (!(blacklisted_identity->fpr))
  30.129 +        cout << "OK! blacklisted_identity->fpr is empty. Yay!" << endl;
  30.130 +    else
  30.131 +        cout << "Not OK. blacklisted_identity->fpr is " << blacklisted_identity->fpr << "." << endl
  30.132 +             << "Expected it to be empty." << endl;
  30.133 +    ASSERT_TRUE(blacklisted_identity->fpr == NULL || blacklisted_identity->fpr[0] == '\0');
  30.134 +
  30.135 +    /* identity is blacklisted. Now let's read in a message which contains a new key for that ID. */
  30.136 +
  30.137 +    const char* new_key = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B";
  30.138 +    const string mailtext = slurp("test_mails/blacklist_new_key_attached.eml");
  30.139 +    pEp_identity * me1 = new_identity("blacklist_test@kgrothoff.org", NULL, PEP_OWN_USERID, "Blacklisted Key Message Recipient");
  30.140 +
  30.141 +    PEP_STATUS status = update_identity(session, me1);
  30.142 +    message* msg_ptr = nullptr;
  30.143 +    message* dest_msg = nullptr;
  30.144 +    stringlist_t* keylist = nullptr;
  30.145 +    PEP_rating rating;
  30.146 +    PEP_decrypt_flags_t flags = 0;
  30.147 +
  30.148 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
  30.149 +    ASSERT_EQ(status , PEP_STATUS_OK);
  30.150 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
  30.151 +
  30.152 +    PEP_STATUS status12 = get_valid_pubkey(session, blacklisted_identity,
  30.153 +                                           &id_def, &us_def, &addr_def, true);
  30.154 +
  30.155 +    ASSERT_STRCASEEQ(blacklisted_identity->fpr, new_key);
  30.156 +
  30.157 +    PEP_STATUS status13 = blacklist_delete(session, bl_fpr_1);
  30.158 +    PEP_STATUS status14 = update_identity(session, blacklisted_identity);
  30.159 +
  30.160 +    free_message(msg_ptr);
  30.161 +    free_message(dest_msg);
  30.162 +    free_stringlist(keylist);
  30.163 +}
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/test/src/BlacklistTest.cc	Mon Aug 26 13:38:21 2019 +0200
    31.3 @@ -0,0 +1,261 @@
    31.4 +// This file is under GNU General Public License 3.0
    31.5 +// see LICENSE.txt
    31.6 +
    31.7 +// #include <iostream>
    31.8 +// #include <iostream>
    31.9 +// #include <fstream>
   31.10 +// #include <string>
   31.11 +// #include <cstring> // for strcmp()
   31.12 +// #include <TEST_ASSERT.h>
   31.13 +// #include "blacklist.h"
   31.14 +// #include "keymanagement.h"
   31.15 +// #include "test_util.h"
   31.16 +//
   31.17 +// // This file is under GNU General Public License 3.0
   31.18 +// // see LICENSE.txt
   31.19 +
   31.20 +#include <stdlib.h>
   31.21 +#include <string>
   31.22 +#include <cstring> // for strcmp()
   31.23 +
   31.24 +
   31.25 +#include <assert.h>
   31.26 +
   31.27 +#include "pEpEngine.h"
   31.28 +
   31.29 +#include "blacklist.h"
   31.30 +#include "keymanagement.h"
   31.31 +#include "test_util.h"
   31.32 +#include "TestConstants.h"
   31.33 +
   31.34 +
   31.35 +
   31.36 +#include "Engine.h"
   31.37 +
   31.38 +#include <gtest/gtest.h>
   31.39 +
   31.40 +
   31.41 +namespace {
   31.42 +
   31.43 +	//The fixture for BlacklistTest
   31.44 +    class BlacklistTest : public ::testing::Test {
   31.45 +        public:
   31.46 +            Engine* engine;
   31.47 +            PEP_SESSION session;
   31.48 +
   31.49 +        protected:
   31.50 +            // You can remove any or all of the following functions if its body
   31.51 +            // is empty.
   31.52 +            BlacklistTest() {
   31.53 +                // You can do set-up work for each test here.
   31.54 +                test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name();
   31.55 +                test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
   31.56 +                test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
   31.57 +            }
   31.58 +
   31.59 +            ~BlacklistTest() override {
   31.60 +                // You can do clean-up work that doesn't throw exceptions here.
   31.61 +            }
   31.62 +
   31.63 +            // If the constructor and destructor are not enough for setting up
   31.64 +            // and cleaning up each test, you can define the following methods:
   31.65 +
   31.66 +            void SetUp() override {
   31.67 +                // Code here will be called immediately after the constructor (right
   31.68 +                // before each test).
   31.69 +
   31.70 +                // Leave this empty if there are no files to copy to the home directory path
   31.71 +                std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
   31.72 +
   31.73 +                // Get a new test Engine.
   31.74 +                engine = new Engine(test_path);
   31.75 +                ASSERT_NE(engine, nullptr);
   31.76 +
   31.77 +                // Ok, let's initialize test directories etc.
   31.78 +                engine->prep(NULL, NULL, init_files);
   31.79 +
   31.80 +                // Ok, try to start this bugger.
   31.81 +                engine->start();
   31.82 +                ASSERT_NE(engine->session, nullptr);
   31.83 +                session = engine->session;
   31.84 +
   31.85 +                // Engine is up. Keep on truckin'
   31.86 +            }
   31.87 +
   31.88 +            void TearDown() override {
   31.89 +                // Code here will be called immediately after each test (right
   31.90 +                // before the destructor).
   31.91 +                engine->shut_down();
   31.92 +                delete engine;
   31.93 +                engine = NULL;
   31.94 +                session = NULL;
   31.95 +            }
   31.96 +
   31.97 +        private:
   31.98 +            const char* test_suite_name;
   31.99 +            const char* test_name;
  31.100 +            string test_path;
  31.101 +            // Objects declared here can be used by all tests in the BlacklistTest suite.
  31.102 +
  31.103 +    };
  31.104 +
  31.105 +}  // namespace
  31.106 +
  31.107 +
  31.108 +TEST_F(BlacklistTest, check_blacklist) {
  31.109 +    // blacklist test code
  31.110 +
  31.111 +    cout << "adding 23 to blacklist\n";
  31.112 +    PEP_STATUS status2 = blacklist_add(session, "23");
  31.113 +    ASSERT_EQ(status2 , PEP_STATUS_OK);
  31.114 +    cout << "added.\n";
  31.115 +
  31.116 +    bool listed;
  31.117 +    PEP_STATUS status3 = blacklist_is_listed(session, "23", &listed);
  31.118 +    ASSERT_EQ(status3 , PEP_STATUS_OK);
  31.119 +    ASSERT_TRUE(listed);
  31.120 +    cout << "23 is listed.\n";
  31.121 +
  31.122 +    stringlist_t *blacklist;
  31.123 +    PEP_STATUS status6 = blacklist_retrieve(session, &blacklist);
  31.124 +    ASSERT_EQ(status6 , PEP_STATUS_OK);
  31.125 +    ASSERT_NE(blacklist, nullptr);
  31.126 +
  31.127 +    bool in23 = false;
  31.128 +    cout << "the blacklist contains now: ";
  31.129 +    for (stringlist_t *bl = blacklist; bl && bl->value; bl = bl->next) {
  31.130 +        cout << bl->value << ", ";
  31.131 +        if (std::strcmp(bl->value, "23") == 0)
  31.132 +            in23 = true;
  31.133 +    }
  31.134 +    cout << "END\n";
  31.135 +    ASSERT_TRUE(in23);
  31.136 +    free_stringlist(blacklist);
  31.137 +
  31.138 +    cout << "deleting 23 from blacklist\n";
  31.139 +    PEP_STATUS status4 = blacklist_delete(session, "23");
  31.140 +    ASSERT_EQ(status4 , PEP_STATUS_OK);
  31.141 +    cout << "deleted.\n";
  31.142 +
  31.143 +    PEP_STATUS status5 = blacklist_is_listed(session, "23", &listed);
  31.144 +    ASSERT_EQ(status5 , PEP_STATUS_OK);
  31.145 +    ASSERT_TRUE(!listed);
  31.146 +    cout << "23 is not listed any more.\n";
  31.147 +
  31.148 +    cout << "blacklist only key for identity / unblacklist key / add key" << endl;
  31.149 +
  31.150 +
  31.151 +    // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
  31.152 +
  31.153 +    const string keytext = slurp("blacklisted_pub.asc");
  31.154 +
  31.155 +    /* FIXME: put in automated test stuff (N.B. only gdb mem examination to this point to get
  31.156 +     *        fix in */
  31.157 +    /* import it into pep */
  31.158 +    PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
  31.159 +
  31.160 +    const char* bl_fpr_1 = "279765A2FEB5B7C731B861D93E4CEFD9F7AF4684";
  31.161 +    const char* bl_fpr_2 = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B";
  31.162 +    bool is_blacklisted = false;
  31.163 +
  31.164 +    // Clean up from previous runs
  31.165 +    PEP_STATUS status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
  31.166 +    if (is_blacklisted) {
  31.167 +        is_blacklisted = false;
  31.168 +        blacklist_delete(session, bl_fpr_1);
  31.169 +    }
  31.170 +
  31.171 +    pEp_identity* blacklisted_identity = new_identity("blacklistedkeys@kgrothoff.org",
  31.172 +                                                      bl_fpr_1,
  31.173 +                                                      NULL,
  31.174 +                                                      "Blacklist Keypair");
  31.175 +
  31.176 +    PEP_STATUS status8 = update_identity(session, blacklisted_identity);
  31.177 +
  31.178 +    // THERE IS NO BLACKLISTING OF PEP KEYS
  31.179 +    //blacklisted_identity->comm_type = PEP_ct_pEp;
  31.180 +    blacklisted_identity->comm_type = PEP_ct_OpenPGP_unconfirmed;
  31.181 +
  31.182 +    PEP_STATUS status99 = set_identity(session, blacklisted_identity);
  31.183 +
  31.184 +    trust_personal_key(session, blacklisted_identity);
  31.185 +
  31.186 +    PEP_STATUS status999 = update_identity(session, blacklisted_identity);
  31.187 +
  31.188 +    ASSERT_EQ(blacklisted_identity->comm_type , PEP_ct_OpenPGP);
  31.189 +
  31.190 +    PEP_STATUS status9 = blacklist_add(session, bl_fpr_1);
  31.191 +    status10 = blacklist_is_listed(session, bl_fpr_1, &is_blacklisted);
  31.192 +    PEP_STATUS status11 = update_identity(session, blacklisted_identity);
  31.193 +    /* new!!! */
  31.194 +    ASSERT_TRUE(is_blacklisted);
  31.195 +    ASSERT_EQ(status11 , PEP_STATUS_OK);
  31.196 +    ASSERT_STREQ(bl_fpr_1, blacklisted_identity->fpr);
  31.197 +
  31.198 +    bool id_def, us_def, addr_def;
  31.199 +    status11 = get_valid_pubkey(session, blacklisted_identity,
  31.200 +                                &id_def, &us_def, &addr_def, true);
  31.201 +
  31.202 +    if (!(blacklisted_identity->fpr))
  31.203 +        cout << "OK! blacklisted_identity->fpr is empty. Yay!" << endl;
  31.204 +    else if (strcmp(blacklisted_identity->fpr, bl_fpr_2) == 0)
  31.205 +        cout << "OK! While this should be empty, you are probably running " <<
  31.206 +                "this in your home directory instead of the test environment " <<
  31.207 +                "and have leftover keys. This is an acceptable result here then. But you " <<
  31.208 +                "should probably clean up after yourself :)" << endl;
  31.209 +    else
  31.210 +        cout << "Not OK. blacklisted_identity->fpr is " << blacklisted_identity->fpr << "." << endl
  31.211 +             << "Expected it to be empty or (possibly) " << bl_fpr_2 << endl;
  31.212 +
  31.213 +    ASSERT_TRUE(blacklisted_identity->fpr == NULL || blacklisted_identity->fpr[0] == '\0' || strcmp(blacklisted_identity->fpr, bl_fpr_2) == 0);
  31.214 +
  31.215 +    pEp_identity *me = new_identity("alice@peptest.ch", NULL, "423", "Alice Miller");
  31.216 +    ASSERT_NE(me, nullptr);
  31.217 +    PEP_STATUS status24 = myself(session, me);
  31.218 +    ASSERT_EQ(status24 , PEP_STATUS_OK);
  31.219 +
  31.220 +    message *msg23 = new_message(PEP_dir_outgoing);
  31.221 +    ASSERT_NE(msg23, nullptr);
  31.222 +    msg23->from = me;
  31.223 +    msg23->to = new_identity_list(identity_dup(blacklisted_identity));
  31.224 +    ASSERT_TRUE(msg23->to != NULL && msg23->to->ident != NULL);
  31.225 +    PEP_rating rating23;
  31.226 +
  31.227 +    cout << "testing outgoing_message_rating() with blacklisted key in to\n";
  31.228 +    PEP_STATUS status23 = outgoing_message_rating(session, msg23, &rating23);
  31.229 +    ASSERT_EQ(status23 , PEP_STATUS_OK);
  31.230 +    ASSERT_EQ(rating23 , PEP_rating_unencrypted);
  31.231 +
  31.232 +    free_message(msg23);
  31.233 +
  31.234 +    const string keytext2 = slurp("blacklisted_pub2.asc");
  31.235 +    PEP_STATUS status14 = import_key(session, keytext2.c_str(), keytext2.length(), NULL);
  31.236 +
  31.237 +    pEp_identity* blacklisted_identity2 = new_identity("blacklistedkeys@kgrothoff.org",
  31.238 +                                                       bl_fpr_2,
  31.239 +                                                        NULL,
  31.240 +                                                       "Blacklist Keypair");
  31.241 +    PEP_STATUS status15 = update_identity(session, blacklisted_identity2);
  31.242 +    //
  31.243 +    // ASSERT_EQ((blacklisted_identity2->fpr && strcmp(blacklisted_identity2->fpr, bl_fpr_2) , 0), "blacklisted_identity2->fpr && strcmp(blacklisted_identity2->fpr);
  31.244 +    // if (blacklisted_identity2->fpr && strcmp(blacklisted_identity2->fpr, bl_fpr_2) == 0)
  31.245 +    //     cout << "blacklisted identity's fpr successfully replaced by the unblacklisted one" << endl;
  31.246 +    // // else
  31.247 +    // //     cout << "blacklisted_identity->fpr should be " << bl_fpr_2 << " but is " << blacklisted_identity->fpr << endl;
  31.248 +    //
  31.249 +    // PEP_STATUS status12 = blacklist_delete(session, bl_fpr_1);
  31.250 +    // PEP_STATUS status13 = update_identity(session, blacklisted_identity);
  31.251 +    //
  31.252 +    // pEp_identity* stored_identity = new_identity("blacklistedkeys@kgrothoff.org",
  31.253 +    //                                               NULL,
  31.254 +    //                                               blacklisted_identity->user_id,
  31.255 +    //                                               "Blacklist Keypair");
  31.256 +    //
  31.257 +    // PEP_STATUS status00 = update_identity(session, stored_identity);
  31.258 +    //
  31.259 +    // // FIXME
  31.260 +    // // ASSERT_EQ(stored_identity->comm_type , PEP_ct_pEp);
  31.261 +
  31.262 +    free_identity(blacklisted_identity);
  31.263 +    free_identity(blacklisted_identity2);
  31.264 +}
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/test/src/BloblistTests.cc	Mon Aug 26 13:38:21 2019 +0200
    32.3 @@ -0,0 +1,129 @@
    32.4 +// This file is under GNU General Public License 3.0
    32.5 +// see LICENSE.txt
    32.6 +
    32.7 +#include <stdlib.h>
    32.8 +#include <string.h>
    32.9 +#include "platform.h"
   32.10 +#include <iostream>
   32.11 +#include <fstream>
   32.12 +#include <assert.h>
   32.13 +#include <cpptest.h>
   32.14 +
   32.15 +#include "bloblist.h"
   32.16 +#include "TestConstants.h"
   32.17 +
   32.18 +#include "EngineTestSuite.h"
   32.19 +#include "BloblistTests.h"
   32.20 +
   32.21 +using namespace std;
   32.22 +
   32.23 +BloblistTests::BloblistTests(string suitename, string test_home_dir) : 
   32.24 +    EngineTestSuite::EngineTestSuite(suitename, test_home_dir) {            
   32.25 +    TEST_ADD(BloblistTests::check_bloblists);
   32.26 +}
   32.27 +
   32.28 +bool BloblistTests::test_blob_equals(size_t size1, char* blob1, size_t size2, char* blob2) {
   32.29 +    if (size1 != size2)
   32.30 +        return false;
   32.31 +    size_t i;
   32.32 +    for (i = 0; i < size1; i++) {
   32.33 +        if (blob1[i] != blob2[i])
   32.34 +            return false;
   32.35 +    }
   32.36 +    return true;
   32.37 +}
   32.38 +
   32.39 +bool BloblistTests::test_bloblist_node_equals(bloblist_t* val1, bloblist_t* val2) {
   32.40 +    assert(val1);
   32.41 +    assert(val2);
   32.42 +    assert(val1->size == val2->size);
   32.43 +    assert(test_blob_equals(val1->size, val1->value, val2->size, val2->value));
   32.44 +    return( ((!val1->mime_type && !val2->mime_type) || (strcmp(val1->mime_type, val2->mime_type) == 0))
   32.45 +        && ((!val1->filename && !val2->filename) || (strcmp(val1->filename, val2->filename) == 0)));
   32.46 +}
   32.47 +
   32.48 +void BloblistTests::check_bloblists() {
   32.49 +    cout << "\n*** data structures: bloblist_test ***\n\n";
   32.50 +    char* text1 = strdup("This is just some text.");
   32.51 +    char* text2 = strdup("More text.");
   32.52 +    char* text3 = strdup("Unpleasant news and witty one-liners.");
   32.53 +    char* text4 = strdup("I AM URDNOT WREX AND THIS IS MY PLANET!");
   32.54 +    bloblist_t* bl1 = new_bloblist(text1, strlen(text1) + 1, "text/plain", NULL);
   32.55 +    bloblist_t* bl2 = new_bloblist(text2, strlen(text2) + 1, "text/richtext", "bob.rtf");
   32.56 +    bloblist_t* bl3 = new_bloblist(text3, strlen(text3) + 1, NULL, "dummy.bin");
   32.57 +    bloblist_t* bl4 = new_bloblist(text4, strlen(text4) + 1, NULL, NULL);
   32.58 +    
   32.59 +    bloblist_t* bl_arr[4] = {bl1, bl2, bl3, bl4};
   32.60 +        
   32.61 +    int i;
   32.62 +        
   32.63 +    cout << "duping one-element bloblist...\n";
   32.64 +    
   32.65 +    bloblist_t* new_bl = bloblist_dup(bl1);
   32.66 +    TEST_ASSERT_MSG((new_bl), "new_bl");
   32.67 +    TEST_ASSERT_MSG((test_bloblist_node_equals(bl1, new_bl)), "test_bloblist_node_equals(bl1, new_bl)");
   32.68 +    TEST_ASSERT_MSG((new_bl->next == NULL), "new_bl->next == NULL");
   32.69 +    TEST_ASSERT_MSG((bl1->value != new_bl->value), "bl1->value != new_bl->value");
   32.70 +    TEST_ASSERT_MSG((bl1->mime_type != new_bl->mime_type || !(bl1->mime_type || new_bl->mime_type)), "bl1->mime_type != new_bl->mime_type || !(bl1->mime_type || new_bl->mime_type)");
   32.71 +    TEST_ASSERT_MSG((bl1->filename != new_bl->filename || !(bl1->filename || new_bl->filename)), "bl1->filename != new_bl->filename || !(bl1->filename || new_bl->filename)");
   32.72 +    cout << "one-element bloblist duplicated.\n\n";
   32.73 +    
   32.74 +    cout << "freeing bloblist...\n";
   32.75 +    free_bloblist(new_bl);
   32.76 +    new_bl = NULL;
   32.77 +    
   32.78 +    bloblist_t* p;
   32.79 +    cout << "\ncreating four-element list...\n";
   32.80 +    bloblist_t* to_copy = bl_arr[0];
   32.81 +    new_bl = bloblist_add(new_bl, strdup(to_copy->value), to_copy->size, to_copy->mime_type, to_copy->filename);
   32.82 +    for (i = 1; i < 4; i++) {
   32.83 +        to_copy = bl_arr[i];
   32.84 +        p = bloblist_add(new_bl, strdup(to_copy->value), to_copy->size, to_copy->mime_type, to_copy->filename);
   32.85 +
   32.86 +        TEST_ASSERT_MSG((p), "p");
   32.87 +    }
   32.88 +    
   32.89 +    p = new_bl;
   32.90 +    
   32.91 +    for (i = 0; i < 4; i++) {
   32.92 +        TEST_ASSERT_MSG((p), "p");
   32.93 +        
   32.94 +        TEST_ASSERT_MSG((test_bloblist_node_equals(p, bl_arr[i])), "test_bloblist_node_equals(p, bl_arr[i])");
   32.95 +        TEST_ASSERT_MSG((p->value != bl_arr[i]->value), "p->value != bl_arr[i]->value");
   32.96 +        TEST_ASSERT_MSG((p->mime_type != bl_arr[i]->mime_type || !(p->mime_type || bl_arr[i]->mime_type)), "p->mime_type != bl_arr[i]->mime_type || !(p->mime_type || bl_arr[i]->mime_type)");
   32.97 +        TEST_ASSERT_MSG((p->filename != bl_arr[i]->filename || !(p->filename || bl_arr[i]->filename)), "p->filename != bl_arr[i]->filename || !(p->filename || bl_arr[i]->filename)");
   32.98 +        
   32.99 +        p = p->next;
  32.100 +    }
  32.101 +    TEST_ASSERT_MSG((p == NULL), "p == NULL");
  32.102 +    
  32.103 +    cout << "\nduplicating four-element list...\n\n";
  32.104 +    bloblist_t* duplist = bloblist_dup(new_bl);
  32.105 +    
  32.106 +    p = new_bl;
  32.107 +    bloblist_t* dup_p = duplist;
  32.108 +    
  32.109 +    while (dup_p) {
  32.110 +        TEST_ASSERT_MSG((test_bloblist_node_equals(p, dup_p)), "test_bloblist_node_equals(p, dup_p)");
  32.111 +        TEST_ASSERT_MSG((p != dup_p), "p != dup_p");
  32.112 +        TEST_ASSERT_MSG((p->value != dup_p->value), "p->value != dup_p->value");
  32.113 +        TEST_ASSERT_MSG((p->mime_type != dup_p->mime_type || !(p->mime_type || dup_p->mime_type)), "p->mime_type != dup_p->mime_type || !(p->mime_type || dup_p->mime_type)");
  32.114 +        TEST_ASSERT_MSG((p->filename != dup_p->filename || !(p->filename || dup_p->filename)), "p->filename != dup_p->filename || !(p->filename || dup_p->filename)");
  32.115 +
  32.116 +        dup_p = dup_p->next;
  32.117 +        p = p->next;
  32.118 +        TEST_ASSERT_MSG(((p == NULL) == (dup_p == NULL)), "(p == NULL) == (dup_p == NULL)");
  32.119 +    }
  32.120 +    cout << "\nfour-element bloblist successfully duplicated.\n\n";
  32.121 +
  32.122 +    cout << "freeing bloblists...\n";
  32.123 +    free_bloblist(new_bl);
  32.124 +    free_bloblist(duplist);
  32.125 +    new_bl = NULL;
  32.126 +    duplist = NULL;
  32.127 +    free(text1);
  32.128 +    free(text2);
  32.129 +    free(text3);
  32.130 +    free(text4);    
  32.131 +    cout << "done.\n";
  32.132 +}
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/test/src/CaseAndDotAddressTests.cc	Mon Aug 26 13:38:21 2019 +0200
    33.3 @@ -0,0 +1,86 @@
    33.4 +// This file is under GNU General Public License 3.0
    33.5 +// see LICENSE.txt
    33.6 +
    33.7 +#include <stdlib.h>
    33.8 +#include <string.h>
    33.9 +#include <time.h>
   33.10 +#include "platform.h"
   33.11 +#include <iostream>
   33.12 +#include <fstream>
   33.13 +#include "mime.h"
   33.14 +#include "message_api.h"
   33.15 +#include "test_util.h"
   33.16 +#include "TestConstants.h"
   33.17 +
   33.18 +#include "EngineTestSuite.h"
   33.19 +#include "EngineTestSessionSuite.h"
   33.20 +#include "CaseAndDotAddressTests.h"
   33.21 +
   33.22 +using namespace std;
   33.23 +
   33.24 +CaseAndDotAddressTests::CaseAndDotAddressTests(string suitename, string test_home_dir) : 
   33.25 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {            
   33.26 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CaseAndDotAddressTests::check_case_and_dot_address"),
   33.27 +                                                                      static_cast<Func>(&CaseAndDotAddressTests::check_case_and_dot_address)));
   33.28 +}
   33.29 +
   33.30 +void CaseAndDotAddressTests::check_case_and_dot_address() {
   33.31 +    cout << "\n*** case_and_dot_address_test.cc ***\n\n";
   33.32 +    
   33.33 +    char* user_id = get_new_uuid();
   33.34 +    
   33.35 +    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   33.36 +
   33.37 +    const char* alice_email_case = "pEp.teST.AlICe@pEP-pRoJeCt.ORG";
   33.38 +    const char* alice_email_dot = "pe.p.te.st.a.l.i.ce@pep-project.org";
   33.39 +    const char* alice_email_dotless = "peptestalice@pep-project.org";
   33.40 +    const char* alice_email_case_and_dot = "PE.p.teS.t.ALICE@pep-project.OrG";
   33.41 +
   33.42 +    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
   33.43 +    TEST_ASSERT_MSG((statuspub == PEP_TEST_KEY_IMPORT_SUCCESS), "statuspub == PEP_STATUS_OK");
   33.44 +
   33.45 +    pEp_identity * alice_id = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", user_id, "Alice Test");
   33.46 +
   33.47 +    PEP_STATUS status = trust_personal_key(session, alice_id);
   33.48 +
   33.49 +    pEp_identity * new_alice_id = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", user_id, "Alice Test");
   33.50 +    status = update_identity(session, new_alice_id);
   33.51 +    TEST_ASSERT_MSG((new_alice_id->fpr), "new_alice_id->fpr");
   33.52 +    TEST_ASSERT_MSG((strcmp(new_alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(new_alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
   33.53 +    free_identity(new_alice_id);
   33.54 +    free_identity(alice_id);
   33.55 +    alice_id = NULL;
   33.56 +    new_alice_id = NULL;
   33.57 +
   33.58 +    alice_id = new_identity(alice_email_case, NULL, user_id, "Alice Test");
   33.59 +    status = update_identity(session, alice_id);
   33.60 +    TEST_ASSERT_MSG((alice_id->fpr), "alice_id->fpr");
   33.61 +    cout << "Alice email: " << alice_email_case << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
   33.62 +    TEST_ASSERT_MSG((strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
   33.63 +    free_identity(alice_id);
   33.64 +    alice_id = NULL;
   33.65 +
   33.66 +    alice_id = new_identity(alice_email_dot, NULL, user_id, "Alice Test");
   33.67 +    status = update_identity(session, alice_id);
   33.68 +    TEST_ASSERT_MSG((alice_id->fpr), "alice_id->fpr");
   33.69 +    cout << "Alice email: " << alice_email_dot << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
   33.70 +    TEST_ASSERT_MSG((strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
   33.71 +    free_identity(alice_id);
   33.72 +    alice_id = NULL;
   33.73 +
   33.74 +    alice_id = new_identity(alice_email_dotless, NULL, user_id, "Alice Test");
   33.75 +    status = update_identity(session, alice_id);
   33.76 +    TEST_ASSERT_MSG((alice_id->fpr), "alice_id->fpr");
   33.77 +    cout << "Alice email: " << alice_email_dotless << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
   33.78 +    TEST_ASSERT_MSG((strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
   33.79 +    free_identity(alice_id);
   33.80 +    alice_id = NULL;
   33.81 +
   33.82 +    alice_id = new_identity(alice_email_case_and_dot, NULL, user_id, "Alice Test");
   33.83 +    status = update_identity(session, alice_id);
   33.84 +    TEST_ASSERT_MSG((alice_id->fpr), "alice_id->fpr");
   33.85 +    cout << "Alice email: " << alice_email_case_and_dot << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
   33.86 +    TEST_ASSERT_MSG((strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
   33.87 +    free_identity(alice_id);
   33.88 +    alice_id = NULL;
   33.89 +}
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/test/src/CheckRenewedExpiredKeyTrustStatusTests.cc	Mon Aug 26 13:38:21 2019 +0200
    34.3 @@ -0,0 +1,308 @@
    34.4 +// This file is under GNU General Public License 3.0
    34.5 +// see LICENSE.txt
    34.6 +
    34.7 +#include "TestConstants.h"
    34.8 +#include <stdlib.h>
    34.9 +#include <string>
   34.10 +#include <cstring>
   34.11 +
   34.12 +#include "pEpEngine.h"
   34.13 +
   34.14 +#include <cpptest.h>
   34.15 +#include "test_util.h"
   34.16 +#include "EngineTestIndividualSuite.h"
   34.17 +#include "CheckRenewedExpiredKeyTrustStatusTests.h"
   34.18 +
   34.19 +using namespace std;
   34.20 +
   34.21 +CheckRenewedExpiredKeyTrustStatusTests::CheckRenewedExpiredKeyTrustStatusTests(string suitename, string test_home_dir) :
   34.22 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
   34.23 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status"),
   34.24 +                                                                      static_cast<Func>(&CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status)));
   34.25 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_user"),
   34.26 +                                                                      static_cast<Func>(&CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_user)));
   34.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_pEp_user"),
   34.28 +                                                                      static_cast<Func>(&CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_pEp_user)));
   34.29 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_pEp_user"),
   34.30 +                                                                      static_cast<Func>(&CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_pEp_user)));                                                                  
   34.31 +}
   34.32 +
   34.33 +void CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status() {
   34.34 +    bool ok = false;
   34.35 +    ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   34.36 +    TEST_ASSERT(ok);    
   34.37 +    ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
   34.38 +    TEST_ASSERT(ok);
   34.39 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
   34.40 +    TEST_ASSERT(ok);
   34.41 +
   34.42 +    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
   34.43 +    pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
   34.44 +
   34.45 +    PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
   34.46 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   34.47 +
   34.48 +    // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
   34.49 +    // the expired key:
   34.50 +    const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
   34.51 +    
   34.52 +    char* decrypted_msg = NULL;
   34.53 +    stringlist_t* keylist_used = nullptr;
   34.54 +    char* modified_src = NULL;
   34.55 +    
   34.56 +    PEP_rating rating;
   34.57 +    PEP_decrypt_flags_t flags = 0;
   34.58 +     
   34.59 +    status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
   34.60 +    TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
   34.61 +
   34.62 +    free(decrypted_msg);
   34.63 +    decrypted_msg = NULL;
   34.64 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
   34.65 +    TEST_ASSERT(ok);    
   34.66 +
   34.67 +    pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
   34.68 +    message* msg2 = new_message(PEP_dir_outgoing);    
   34.69 +
   34.70 +    msg2->from = alice_from;
   34.71 +    msg2->to = new_identity_list(expired_inquisitor);
   34.72 +    msg2->shortmsg = strdup("Blah!");
   34.73 +    msg2->longmsg = strdup("Blahblahblah!");
   34.74 +    msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   34.75 +
   34.76 +    status = outgoing_message_rating(session, msg2, &rating);
   34.77 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   34.78 +    TEST_ASSERT_MSG((rating == PEP_rating_reliable), tl_rating_string(rating));    
   34.79 +
   34.80 +    status = get_trust(session, expired_inquisitor);
   34.81 +    TEST_ASSERT_MSG(expired_inquisitor->comm_type == PEP_ct_OpenPGP_unconfirmed, tl_ct_string(expired_inquisitor->comm_type));
   34.82 +    free_message(msg2);
   34.83 +}
   34.84 +
   34.85 +void CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_user() {
   34.86 +    bool ok = false;
   34.87 +    ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   34.88 +    TEST_ASSERT(ok);    
   34.89 +    ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
   34.90 +    TEST_ASSERT(ok);
   34.91 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
   34.92 +    TEST_ASSERT(ok);
   34.93 +
   34.94 +    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
   34.95 +    pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
   34.96 +
   34.97 +    PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
   34.98 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   34.99 +
  34.100 +    const char* inquisitor_fpr = "8E8D2381AE066ABE1FEE509821BA977CA4728718";
  34.101 +    pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", "8E8D2381AE066ABE1FEE509821BA977CA4728718", "TOFU_inquisitor@darthmama.org", "Lady Claire Trevelyan");
  34.102 +    status = set_identity(session, expired_inquisitor);
  34.103 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  34.104 +    expired_inquisitor->comm_type = PEP_ct_OpenPGP; // confirmed 
  34.105 +    status = set_trust(session, expired_inquisitor);
  34.106 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  34.107 +    status = get_trust(session, expired_inquisitor);
  34.108 +    TEST_ASSERT_MSG(expired_inquisitor->comm_type == PEP_ct_OpenPGP, tl_ct_string(expired_inquisitor->comm_type));
  34.109 +    
  34.110 +    // Ok, now update_identity - we'll discover it's expired
  34.111 +    status = update_identity(session, expired_inquisitor);
  34.112 +    TEST_ASSERT_MSG((status == PEP_KEY_UNSUITABLE), tl_status_string(status));
  34.113 +    PEP_comm_type ct = expired_inquisitor->comm_type;    
  34.114 +    TEST_ASSERT_MSG(ct == PEP_ct_key_not_found, tl_ct_string(ct));
  34.115 +    TEST_ASSERT(!expired_inquisitor->fpr);
  34.116 +    
  34.117 +    expired_inquisitor->fpr = strdup(inquisitor_fpr);
  34.118 +    status = get_trust(session, expired_inquisitor);
  34.119 +    ct = expired_inquisitor->comm_type;    
  34.120 +    TEST_ASSERT(status == PEP_STATUS_OK);
  34.121 +    TEST_ASSERT_MSG(ct == PEP_ct_key_expired_but_confirmed, tl_ct_string(ct));
  34.122 +    
  34.123 +    // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
  34.124 +    // the expired key:
  34.125 +    const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
  34.126 +    
  34.127 +    char* decrypted_msg = NULL;
  34.128 +    stringlist_t* keylist_used = nullptr;
  34.129 +    char* modified_src = NULL;
  34.130 +    
  34.131 +    PEP_rating rating;
  34.132 +    PEP_decrypt_flags_t flags = 0;
  34.133 +     
  34.134 +    status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
  34.135 +    TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
  34.136 +
  34.137 +    free(decrypted_msg);
  34.138 +    decrypted_msg = NULL;
  34.139 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
  34.140 +    TEST_ASSERT(ok);    
  34.141 +
  34.142 +    pEp_identity* expired_inquisitor1 = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
  34.143 +    
  34.144 +    status = update_identity(session, expired_inquisitor1);
  34.145 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  34.146 +    status = get_trust(session, expired_inquisitor1);
  34.147 +    TEST_ASSERT_MSG(expired_inquisitor1->comm_type == PEP_ct_OpenPGP, tl_ct_string(expired_inquisitor1->comm_type));
  34.148 +
  34.149 +    message* msg2 = new_message(PEP_dir_outgoing);    
  34.150 +
  34.151 +    msg2->from = alice_from;
  34.152 +    msg2->to = new_identity_list(expired_inquisitor1);
  34.153 +    msg2->shortmsg = strdup("Blah!");
  34.154 +    msg2->longmsg = strdup("Blahblahblah!");
  34.155 +    msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  34.156 +
  34.157 +    status = outgoing_message_rating(session, msg2, &rating);
  34.158 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  34.159 +    TEST_ASSERT_MSG((rating >= PEP_rating_trusted), tl_rating_string(rating));    
  34.160 +
  34.161 +    free_message(msg2);
  34.162 +}
  34.163 +
  34.164 +void CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_pEp_user() {
  34.165 +    bool ok = false;
  34.166 +    ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
  34.167 +    TEST_ASSERT(ok);    
  34.168 +    ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
  34.169 +    TEST_ASSERT(ok);
  34.170 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
  34.171 +    TEST_ASSERT(ok);
  34.172 +
  34.173 +    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
  34.174 +    pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
  34.175 +
  34.176 +    PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
  34.177 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  34.178 +
  34.179 +    const char* inquisitor_fpr = "8E8D2381AE066ABE1FEE509821BA977CA4728718";
  34.180 +    pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", "8E8D2381AE066ABE1FEE509821BA977CA4728718", "TOFU_inquisitor@darthmama.org", "Lady Claire Trevelyan");
  34.181 +    status = set_identity(session, expired_inquisitor);
  34.182 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  34.183 +    expired_inquisitor->comm_type = PEP_ct_pEp_unconfirmed;  
  34.184 +    status = set_trust(session, expired_inquisitor);
  34.185 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  34.186 +    
  34.187 +    bool pEp_user = false;
  34.188 +    status = is_pEp_user(session, expired_inquisitor, &pEp_user);
  34.189 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  34.190 +    TEST_ASSERT(pEp_user);
  34.191 +
  34.192 +    // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
  34.193 +    // the expired key:
  34.194 +    const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
  34.195 +
  34.196 +    char* decrypted_msg = NULL;
  34.197 +    stringlist_t* keylist_used = nullptr;
  34.198 +    char* modified_src = NULL;
  34.199 +
  34.200 +    PEP_rating rating;
  34.201 +    PEP_decrypt_flags_t flags = 0;
  34.202 +
  34.203 +    status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
  34.204 +    TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
  34.205 +
  34.206 +    free(decrypted_msg);
  34.207 +    decrypted_msg = NULL;
  34.208 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
  34.209 +    TEST_ASSERT(ok);    
  34.210 +
  34.211 +    pEp_identity* expired_inquisitor1 = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
  34.212 +    message* msg2 = new_message(PEP_dir_outgoing);    
  34.213 +
  34.214 +    msg2->from = alice_from;
  34.215 +    msg2->to = new_identity_list(expired_inquisitor1);
  34.216 +    msg2->shortmsg = strdup("Blah!");
  34.217 +    msg2->longmsg = strdup("Blahblahblah!");
  34.218 +    msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  34.219 +
  34.220 +    status = outgoing_message_rating(session, msg2, &rating);
  34.221 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  34.222 +    TEST_ASSERT_MSG((rating == PEP_rating_reliable), tl_rating_string(rating));    
  34.223 +
  34.224 +    status = get_trust(session, expired_inquisitor);
  34.225 +    TEST_ASSERT_MSG(expired_inquisitor1->comm_type == PEP_ct_pEp_unconfirmed, tl_ct_string(expired_inquisitor1->comm_type));
  34.226 +    free_message(msg2);
  34.227 +}
  34.228 +
  34.229 +void CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_pEp_user() {
  34.230 +    bool ok = false;
  34.231 +    ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
  34.232 +    TEST_ASSERT(ok);    
  34.233 +    ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
  34.234 +    TEST_ASSERT(ok);
  34.235 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
  34.236 +    TEST_ASSERT(ok);
  34.237 +
  34.238 +    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
  34.239 +    pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
  34.240 +
  34.241 +    PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
  34.242 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  34.243 +
  34.244 +    const char* inquisitor_fpr = "8E8D2381AE066ABE1FEE509821BA977CA4728718";
  34.245 +    pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", "8E8D2381AE066ABE1FEE509821BA977CA4728718", "TOFU_inquisitor@darthmama.org", "Lady Claire Trevelyan");
  34.246 +    status = set_identity(session, expired_inquisitor);
  34.247 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  34.248 +    expired_inquisitor->comm_type = PEP_ct_pEp; // confirmed 
  34.249 +    status = set_trust(session, expired_inquisitor);
  34.250 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  34.251 +    status = get_trust(session, expired_inquisitor);
  34.252 +    TEST_ASSERT_MSG(expired_inquisitor->comm_type == PEP_ct_pEp, tl_ct_string(expired_inquisitor->comm_type));
  34.253 +
  34.254 +    bool pEp_user = false;
  34.255 +    status = is_pEp_user(session, expired_inquisitor, &pEp_user);
  34.256 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  34.257 +    TEST_ASSERT(pEp_user);
  34.258 +    
  34.259 +    // Ok, now update_identity - we'll discover it's expired
  34.260 +    status = update_identity(session, expired_inquisitor);
  34.261 +    TEST_ASSERT_MSG((status == PEP_KEY_UNSUITABLE), tl_status_string(status));
  34.262 +    PEP_comm_type ct = expired_inquisitor->comm_type;    
  34.263 +    TEST_ASSERT_MSG(ct == PEP_ct_key_not_found, tl_ct_string(ct));
  34.264 +    TEST_ASSERT(!expired_inquisitor->fpr);
  34.265 +    
  34.266 +    expired_inquisitor->fpr = strdup(inquisitor_fpr);
  34.267 +    status = get_trust(session, expired_inquisitor);
  34.268 +    ct = expired_inquisitor->comm_type;    
  34.269 +    TEST_ASSERT(status == PEP_STATUS_OK);
  34.270 +    TEST_ASSERT_MSG(ct == PEP_ct_key_expired_but_confirmed, tl_ct_string(ct));
  34.271 +    
  34.272 +    // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
  34.273 +    // the expired key:
  34.274 +    const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
  34.275 +    
  34.276 +    char* decrypted_msg = NULL;
  34.277 +    stringlist_t* keylist_used = nullptr;
  34.278 +    char* modified_src = NULL;
  34.279 +    
  34.280 +    PEP_rating rating;
  34.281 +    PEP_decrypt_flags_t flags = 0;
  34.282 +     
  34.283 +    status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
  34.284 +    TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
  34.285 +
  34.286 +    free(decrypted_msg);
  34.287 +    decrypted_msg = NULL;
  34.288 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
  34.289 +    TEST_ASSERT(ok);    
  34.290 +
  34.291 +    pEp_identity* expired_inquisitor1 = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
  34.292 +    
  34.293 +    status = update_identity(session, expired_inquisitor1);
  34.294 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  34.295 +    status = get_trust(session, expired_inquisitor1);
  34.296 +    TEST_ASSERT_MSG(expired_inquisitor1->comm_type == PEP_ct_pEp, tl_ct_string(expired_inquisitor1->comm_type));
  34.297 +
  34.298 +    message* msg2 = new_message(PEP_dir_outgoing);    
  34.299 +
  34.300 +    msg2->from = alice_from;
  34.301 +    msg2->to = new_identity_list(expired_inquisitor1);
  34.302 +    msg2->shortmsg = strdup("Blah!");
  34.303 +    msg2->longmsg = strdup("Blahblahblah!");
  34.304 +    msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  34.305 +
  34.306 +    status = outgoing_message_rating(session, msg2, &rating);
  34.307 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  34.308 +    TEST_ASSERT_MSG((rating >= PEP_rating_trusted), tl_rating_string(rating));    
  34.309 +
  34.310 +    free_message(msg2);
  34.311 +}
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/test/src/CrashdumpTests.cc	Mon Aug 26 13:38:21 2019 +0200
    35.3 @@ -0,0 +1,27 @@
    35.4 +// This file is under GNU General Public License 3.0
    35.5 +// see LICENSE.txt
    35.6 +
    35.7 +#include "TestConstants.h"
    35.8 +#include <stdlib.h>
    35.9 +#include <string>
   35.10 +
   35.11 +#include "pEpEngine.h"
   35.12 +
   35.13 +#include "EngineTestSessionSuite.h"
   35.14 +#include "CrashdumpTests.h"
   35.15 +
   35.16 +using namespace std;
   35.17 +
   35.18 +CrashdumpTests::CrashdumpTests(string suitename, string test_home_dir) :
   35.19 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   35.20 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CrashdumpTests::check_crashdump"),
   35.21 +                                                                      static_cast<Func>(&CrashdumpTests::check_crashdump)));
   35.22 +}
   35.23 +
   35.24 +void CrashdumpTests::check_crashdump() {
   35.25 +    // MODULE test code
   35.26 +    char *text;
   35.27 +    PEP_STATUS status2 = get_crashdump_log(session, 0, &text);
   35.28 +    TEST_ASSERT_MSG((status2 == PEP_STATUS_OK), "status2 == PEP_STATUS_OK");
   35.29 +    cout << text;
   35.30 +}
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/test/src/DecorateTests.cc	Mon Aug 26 13:38:21 2019 +0200
    36.3 @@ -0,0 +1,92 @@
    36.4 +// This file is under GNU General Public License 3.0
    36.5 +// see LICENSE.txt
    36.6 +
    36.7 +#include "TestConstants.h"
    36.8 +#include <cpptest.h>
    36.9 +#include <cpptest-suite.h>
   36.10 +#include <cpptest-textoutput.h>
   36.11 +#include <stdlib.h>
   36.12 +#include <string.h>
   36.13 +#include "platform.h"
   36.14 +#include <iostream>
   36.15 +#include <fstream>
   36.16 +#include <assert.h>
   36.17 +#include <sstream>
   36.18 +#include "mime.h"
   36.19 +#include "message_api.h"
   36.20 +#include "test_util.h"
   36.21 +
   36.22 +#include "EngineTestSuite.h"
   36.23 +#include "EngineTestSessionSuite.h"
   36.24 +#include "DecorateTests.h"
   36.25 +
   36.26 +using namespace std;
   36.27 +
   36.28 +DecorateTests::DecorateTests(string suitename, string test_home_dir) :
   36.29 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   36.30 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DecorateTests::check_decorate"),
   36.31 +                                                                      static_cast<Func>(&DecorateTests::check_decorate)));
   36.32 +}
   36.33 +
   36.34 +void DecorateTests::check_decorate() {
   36.35 +
   36.36 +    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   36.37 +    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
   36.38 +    const string bob_pub_key = slurp("test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");
   36.39 +    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
   36.40 +    PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
   36.41 +    PEP_STATUS statusbob = import_key(session, bob_pub_key.c_str(), bob_pub_key.length(), NULL);
   36.42 +    TEST_ASSERT_MSG((statuspub == PEP_TEST_KEY_IMPORT_SUCCESS), "statuspub == PEP_STATUS_OK");
   36.43 +    TEST_ASSERT_MSG((statuspriv == PEP_TEST_KEY_IMPORT_SUCCESS), "statuspriv == PEP_STATUS_OK");
   36.44 +    TEST_ASSERT_MSG((statusbob == PEP_TEST_KEY_IMPORT_SUCCESS), "statusbob == PEP_STATUS_OK");
   36.45 +
   36.46 +    cout << "creating message…\n";
   36.47 +    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
   36.48 +    pEp_identity* alice_dup = identity_dup(alice);
   36.49 +    PEP_STATUS status = set_own_key(session, alice_dup, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
   36.50 +    TEST_ASSERT(status == PEP_STATUS_OK);
   36.51 +    free_identity(alice_dup);
   36.52 +
   36.53 +    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test");
   36.54 +    alice->me = true;
   36.55 +    identity_list* to_list = new_identity_list(bob); // to bob
   36.56 +    message* outgoing_message = new_message(PEP_dir_outgoing);
   36.57 +    TEST_ASSERT_MSG((outgoing_message), "outgoing_message");
   36.58 +    outgoing_message->from = alice;
   36.59 +    outgoing_message->to = to_list;
   36.60 +    outgoing_message->shortmsg = strdup("Greetings, humans!");
   36.61 +    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   36.62 +    outgoing_message->longmsg = strdup("This is a dumb message.\nBut it's done.\n");
   36.63 +    TEST_ASSERT_MSG((outgoing_message->longmsg), "outgoing_message->longmsg");
   36.64 +    cout << "message created.\n";
   36.65 +
   36.66 +    char* encoded_text = nullptr;
   36.67 +
   36.68 +    message* encrypted_msg = nullptr;
   36.69 +    cout << "calling encrypt_message\n";
   36.70 +    status = encrypt_message (session, outgoing_message, NULL, &encrypted_msg, PEP_enc_PGP_MIME, 0);
   36.71 +    cout << "encrypt_message() returns " << tl_status_string(status) << '.' << endl;
   36.72 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
   36.73 +    TEST_ASSERT_MSG((encrypted_msg), "encrypted_msg");
   36.74 +    cout << "message encrypted.\n";
   36.75 +
   36.76 +    status = mime_encode_message(encrypted_msg, false, &encoded_text);
   36.77 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
   36.78 +    TEST_ASSERT_MSG((encoded_text), "encoded_text");
   36.79 +
   36.80 +    bool contains_version = false;
   36.81 +
   36.82 +    const char* version_str = "X-pEp-Version: ";
   36.83 +    size_t version_prefix_len = strlen(version_str);
   36.84 +
   36.85 +    istringstream f(encoded_text);
   36.86 +    string enc_string;
   36.87 +    while (getline(f, enc_string)) {
   36.88 +        if (strncmp(enc_string.c_str(), version_str, version_prefix_len) == 0)
   36.89 +            contains_version = true;
   36.90 +    }
   36.91 +    TEST_ASSERT_MSG((contains_version), "contains_version");
   36.92 +
   36.93 +    if (contains_version)
   36.94 +        cout << "Version string in encrypted message, as it should be." << endl;
   36.95 +}
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/test/src/DecryptAttachPrivateKeyTrustedTests.cc	Mon Aug 26 13:38:21 2019 +0200
    37.3 @@ -0,0 +1,140 @@
    37.4 +// This file is under GNU General Public License 3.0
    37.5 +// see LICENSE.txt
    37.6 +
    37.7 +// FIXME: the private key tests should be combined
    37.8 +
    37.9 +#include "TestConstants.h"
   37.10 +#include <stdlib.h>
   37.11 +#include <string>
   37.12 +#include <cstring>
   37.13 +
   37.14 +#include "pEpEngine.h"
   37.15 +
   37.16 +#include "mime.h"
   37.17 +#include "message_api.h"
   37.18 +#include "keymanagement.h"
   37.19 +#include "test_util.h"
   37.20 +
   37.21 +#include "EngineTestSessionSuite.h"
   37.22 +#include "DecryptAttachPrivateKeyTrustedTests.h"
   37.23 +
   37.24 +using namespace std;
   37.25 +
   37.26 +DecryptAttachPrivateKeyTrustedTests::DecryptAttachPrivateKeyTrustedTests(string suitename, string test_home_dir) :
   37.27 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   37.28 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DecryptAttachPrivateKeyTrustedTests::check_decrypt_attach_private_key_trusted"),
   37.29 +                                                                      static_cast<Func>(&DecryptAttachPrivateKeyTrustedTests::check_decrypt_attach_private_key_trusted)));
   37.30 +}
   37.31 +
   37.32 +void DecryptAttachPrivateKeyTrustedTests::check_decrypt_attach_private_key_trusted() {
   37.33 +
   37.34 +    const char* own_uid = PEP_OWN_USERID;
   37.35 +
   37.36 +    cout << "Importing keys..." << endl;
   37.37 +    
   37.38 +    string input_key;
   37.39 +    const char* main_addr = "priv-key-import-test-main@darthmama.cool";
   37.40 +    pEp_identity* main_me = NULL;
   37.41 +    const char* fpr_main_me = "13A9F97964A2B52520CAA40E51BCA783C065A213";    
   37.42 +    pEp_identity* same_addr_same_uid = NULL;
   37.43 +    const char* fpr_same_addr_same_uid = "8AB616A3BD51DEF714B5E688EFFB540C3276D2E5";
   37.44 +        
   37.45 +    PEP_STATUS status = PEP_STATUS_OK;
   37.46 +
   37.47 +    // key for main own user
   37.48 +    // 
   37.49 +    // 13A9F97964A2B52520CAA40E51BCA783C065A213    
   37.50 +    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0xC065A213_pub.asc");
   37.51 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   37.52 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), tl_status_string(status));
   37.53 +
   37.54 +    input_key = slurp("test_keys/priv/priv-key-import-test-main_0-0xC065A213_priv.asc");
   37.55 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   37.56 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), tl_status_string(status));
   37.57 +
   37.58 +    // ensure there's no private key - doesn't work in automated tests, sadly. Uncommon when running script manually.
   37.59 +    bool has_priv = false;
   37.60 +        
   37.61 +    // key with same address and user_id
   37.62 +    // 8AB616A3BD51DEF714B5E688EFFB540C3276D2E5
   37.63 +    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0x3276D2E5_pub.asc");
   37.64 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   37.65 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), tl_status_string(status));
   37.66 +
   37.67 +    
   37.68 +    cout << "Setting up own identity with default key " << fpr_main_me << endl;
   37.69 +    // Own identity with default key etc
   37.70 +    main_me = new_identity(main_addr, fpr_main_me, own_uid, "PrivateKey Import Test");
   37.71 +    status = set_own_key(session, main_me, fpr_main_me);
   37.72 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   37.73 +
   37.74 +    TEST_ASSERT_MSG((strcmp(main_me->fpr, fpr_main_me) == 0), "strcmp(main_me->fpr, fpr_main_me) == 0");
   37.75 +    cout << "Done!" << endl << endl;
   37.76 +    
   37.77 +    cout << "Setting up sender identities and resetting key trust." << endl;
   37.78 +    cout << "Same address, same user_id - address: " << main_addr << ", user_id: " << own_uid << ", fpr: " << fpr_same_addr_same_uid << endl;  
   37.79 +    same_addr_same_uid = new_identity(main_addr, fpr_same_addr_same_uid, own_uid, "PrivateKey Import Test");
   37.80 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY), tl_status_string(status));
   37.81 +    TEST_ASSERT_MSG(((same_addr_same_uid->comm_type & PEP_ct_confirmed) != PEP_ct_confirmed), tl_ct_string(same_addr_same_uid->comm_type));
   37.82 +
   37.83 +    status = key_reset_trust(session, same_addr_same_uid);
   37.84 +    
   37.85 +    cout << "Done!" << endl << endl;
   37.86 +
   37.87 +    cout << "Reading in message..." << endl;
   37.88 +    
   37.89 +    string encoded_text = slurp("test_mails/priv_key_attach.eml");
   37.90 +
   37.91 +    cout << "Starting test..." << endl;
   37.92 +    // Case 1:
   37.93 +    // Same address, same user_id, untrusted
   37.94 +    cout << "decrypt with attached private key: Same address, same user_id, trusted" << endl;
   37.95 +    char* decrypted_text = NULL;
   37.96 +    stringlist_t* keylist_used = NULL;
   37.97 +    PEP_rating rating;
   37.98 +    PEP_decrypt_flags_t flags = 0;
   37.99 +    char* modified_src = NULL;
  37.100 +    
  37.101 +    cout << "Trusting own key for " << same_addr_same_uid->user_id << " and " << same_addr_same_uid->fpr << endl;
  37.102 +    status = trust_own_key(session, same_addr_same_uid);
  37.103 +    cout << "Status is " << tl_status_string(status) << endl;  
  37.104 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  37.105 +    free(decrypted_text);
  37.106 +    decrypted_text = NULL;
  37.107 +
  37.108 +    status = get_trust(session, same_addr_same_uid);
  37.109 +    cout << tl_ct_string(same_addr_same_uid->comm_type) << endl;
  37.110 +    
  37.111 +    TEST_ASSERT_MSG((same_addr_same_uid->comm_type == PEP_ct_pEp), "same_addr_same_uid->comm_type == PEP_ct_pEp");
  37.112 +    
  37.113 +    flags = 0;
  37.114 +    status = MIME_decrypt_message(session, encoded_text.c_str(), 
  37.115 +                                  encoded_text.size(), &decrypted_text, 
  37.116 +                                  &keylist_used, &rating, &flags,
  37.117 +                                  &modified_src);
  37.118 +
  37.119 +    status = get_trust(session, same_addr_same_uid);
  37.120 +    TEST_ASSERT_MSG((same_addr_same_uid->comm_type == PEP_ct_pEp), "same_addr_same_uid->comm_type == PEP_ct_pEp");
  37.121 +    
  37.122 +    flags = 0;
  37.123 +    status = MIME_decrypt_message(session, encoded_text.c_str(), 
  37.124 +                                  encoded_text.size(), &decrypted_text, 
  37.125 +                                  &keylist_used, &rating, &flags,
  37.126 +                                  &modified_src);
  37.127 +    
  37.128 +    cout << "Status: " << tl_status_string(status) << endl;
  37.129 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  37.130 +
  37.131 +    cout << decrypted_text << endl;
  37.132 +    
  37.133 +    has_priv = false;
  37.134 +    status = contains_priv_key(session, fpr_same_addr_same_uid, &has_priv);
  37.135 +    TEST_ASSERT_MSG((has_priv == true), "has_priv == true");
  37.136 +    cout << "Private key was also imported." << endl;
  37.137 +    
  37.138 +    cout << "PASS!" << endl;
  37.139 +    
  37.140 +    // FIXME: rework this in new framework
  37.141 +    status = key_reset_trust(session, main_me);      
  37.142 +    status = key_reset_trust(session, same_addr_same_uid);      
  37.143 +}
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/test/src/DecryptAttachPrivateKeyUntrustedTests.cc	Mon Aug 26 13:38:21 2019 +0200
    38.3 @@ -0,0 +1,127 @@
    38.4 +// This file is under GNU General Public License 3.0
    38.5 +// see LICENSE.txt
    38.6 +
    38.7 +#include <stdlib.h>
    38.8 +#include "TestConstants.h"
    38.9 +#include <string>
   38.10 +#include <cstring>
   38.11 +#include <cpptest.h>
   38.12 +
   38.13 +#include "mime.h"
   38.14 +#include "message_api.h"
   38.15 +#include "keymanagement.h"
   38.16 +#include "test_util.h"
   38.17 +
   38.18 +#include "pEpEngine.h"
   38.19 +
   38.20 +#include "EngineTestSessionSuite.h"
   38.21 +#include "DecryptAttachPrivateKeyUntrustedTests.h"
   38.22 +
   38.23 +using namespace std;
   38.24 +
   38.25 +DecryptAttachPrivateKeyUntrustedTests::DecryptAttachPrivateKeyUntrustedTests(string suitename, string test_home_dir) :
   38.26 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   38.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DecryptAttachPrivateKeyUntrustedTests::check_decrypt_attach_private_key_untrusted"),
   38.28 +                                                                      static_cast<Func>(&DecryptAttachPrivateKeyUntrustedTests::check_decrypt_attach_private_key_untrusted)));
   38.29 +}
   38.30 +
   38.31 +void DecryptAttachPrivateKeyUntrustedTests::check_decrypt_attach_private_key_untrusted() {
   38.32 +
   38.33 +    const char* own_uid = PEP_OWN_USERID;
   38.34 +
   38.35 +    cout << "Importing keys..." << endl;
   38.36 +    
   38.37 +    string input_key;
   38.38 +    const char* main_addr = "priv-key-import-test-main@darthmama.cool";
   38.39 +    pEp_identity* main_me = NULL;
   38.40 +    const char* fpr_main_me = "13A9F97964A2B52520CAA40E51BCA783C065A213";    
   38.41 +    pEp_identity* same_addr_same_uid = NULL;
   38.42 +    const char* fpr_same_addr_same_uid = "8AB616A3BD51DEF714B5E688EFFB540C3276D2E5";
   38.43 +        
   38.44 +    PEP_STATUS status = PEP_STATUS_OK;
   38.45 +
   38.46 +    // key for main own user
   38.47 +    // 
   38.48 +    // 13A9F97964A2B52520CAA40E51BCA783C065A213    
   38.49 +    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0xC065A213_pub.asc");
   38.50 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   38.51 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), "status == PEP_STATUS_OK");
   38.52 +
   38.53 +    input_key = slurp("test_keys/priv/priv-key-import-test-main_0-0xC065A213_priv.asc");
   38.54 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   38.55 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), "status == PEP_STATUS_OK");
   38.56 +
   38.57 +    // ensure there's no private key - doesn't work in automated tests, sadly. Uncommon when running script manually.
   38.58 +    bool has_priv = false;
   38.59 +    // status = contains_priv_key(session, fpr_same_addr_same_uid, &has_priv);
   38.60 +    // if (status == PEP_STATUS_OK && has_priv) {
   38.61 +    //     cout << "SORRY, have to delete keys here to run test correctly..." << endl;
   38.62 +    //     status = delete_keypair(session, fpr_same_addr_same_uid);
   38.63 +    //     if (status == PEP_STATUS_OK)
   38.64 +    //         cout << "Successfully deleted keypair for " << fpr_same_addr_same_uid << " - will now import the public key only" << endl;
   38.65 +    // }
   38.66 +        
   38.67 +    // key with same address and user_id
   38.68 +    // 8AB616A3BD51DEF714B5E688EFFB540C3276D2E5
   38.69 +    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0x3276D2E5_pub.asc");
   38.70 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   38.71 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), "status == PEP_STATUS_OK");
   38.72 +
   38.73 +    
   38.74 +    cout << "Setting up own identity with default key " << fpr_main_me << endl;
   38.75 +    // Own identity with default key etc
   38.76 +    main_me = new_identity(main_addr, fpr_main_me, own_uid, "PrivateKey Import Test");
   38.77 +    status = set_own_key(session, main_me, fpr_main_me);
   38.78 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
   38.79 +
   38.80 +    TEST_ASSERT_MSG((strcmp(main_me->fpr, fpr_main_me) == 0), "strcmp(main_me->fpr, fpr_main_me) == 0");
   38.81 +    cout << "Done!" << endl << endl;
   38.82 +    
   38.83 +    cout << "Setting up sender identities and resetting key trust." << endl;
   38.84 +    cout << "Same address, same user_id - address: " << main_addr << ", user_id: " << own_uid << ", fpr: " << fpr_same_addr_same_uid << endl;  
   38.85 +    same_addr_same_uid = new_identity(main_addr, fpr_same_addr_same_uid, own_uid, "PrivateKey Import Test");
   38.86 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY), "status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY");
   38.87 +    TEST_ASSERT_MSG(((same_addr_same_uid->comm_type & PEP_ct_confirmed) != PEP_ct_confirmed), "(same_addr_same_uid->comm_type & PEP_ct_confirmed) != PEP_ct_confirmed");
   38.88 +
   38.89 +    status = key_reset_trust(session, same_addr_same_uid);
   38.90 +    
   38.91 +    cout << "Done!" << endl << endl;
   38.92 +
   38.93 +    cout << "Reading in message..." << endl;
   38.94 +    
   38.95 +    string encoded_text = slurp("test_mails/priv_key_attach.eml");
   38.96 +
   38.97 +    cout << "Starting tests..." << endl;
   38.98 +    // Case 1:
   38.99 +    // Same address, same user_id, untrusted
  38.100 +    cout << "Same address, same user_id, untrusted" << endl;
  38.101 +    char* decrypted_text = NULL;
  38.102 +    stringlist_t* keylist_used = NULL;
  38.103 +    PEP_rating rating;
  38.104 +    PEP_decrypt_flags_t flags;
  38.105 +    char* modified_src = NULL;
  38.106 +    
  38.107 +    status = get_trust(session, same_addr_same_uid);
  38.108 +    cout << tl_ct_string(same_addr_same_uid->comm_type) << endl;
  38.109 +    
  38.110 +    TEST_ASSERT_MSG(((same_addr_same_uid->comm_type & PEP_ct_confirmed) != PEP_ct_confirmed), "(same_addr_same_uid->comm_type & PEP_ct_confirmed) != PEP_ct_confirmed");
  38.111 +    
  38.112 +    flags = 0;
  38.113 +    status = MIME_decrypt_message(session, encoded_text.c_str(), 
  38.114 +                                  encoded_text.size(), &decrypted_text, 
  38.115 +                                  &keylist_used, &rating, &flags,
  38.116 +				  &modified_src);
  38.117 +
  38.118 +    status = get_trust(session, same_addr_same_uid);
  38.119 +    TEST_ASSERT_MSG((same_addr_same_uid->comm_type == PEP_ct_pEp_unconfirmed), "same_addr_same_uid->comm_type == PEP_ct_pEp_unconfirmed");
  38.120 +
  38.121 +    cout << "Case 1 Status: " << tl_status_string(status) << endl; 
  38.122 +    cout << "Private key is not trusted for " << same_addr_same_uid->fpr << ", as desired, as the public key was not trusted." << endl;
  38.123 +    cout << "PASS!" << endl;
  38.124 +
  38.125 +    // Case 2:
  38.126 +    cout << decrypted_text << endl;
  38.127 +    
  38.128 +    status = key_reset_trust(session, main_me);      
  38.129 +    status = key_reset_trust(session, same_addr_same_uid);      
  38.130 +}
    39.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.2 +++ b/test/src/DeleteKeyTests.cc	Mon Aug 26 13:38:21 2019 +0200
    39.3 @@ -0,0 +1,342 @@
    39.4 +// This file is under GNU General Public License 3.0
    39.5 +// see LICENSE.txt
    39.6 +
    39.7 +#include <stdlib.h>
    39.8 +#include <string>
    39.9 +#include <cstring>
   39.10 +#include <cpptest.h>
   39.11 +#include <assert.h>
   39.12 +
   39.13 +#include "pEpEngine.h"
   39.14 +#include "test_util.h"
   39.15 +
   39.16 +#include "EngineTestIndividualSuite.h"
   39.17 +#include "DeleteKeyTests.h"
   39.18 +
   39.19 +using namespace std;
   39.20 +
   39.21 +const string DeleteKeyTests::alice_user_id = PEP_OWN_USERID;
   39.22 +const string DeleteKeyTests::bob_user_id = "BobId";    
   39.23 +const string DeleteKeyTests::carol_user_id = "carolId";
   39.24 +const string DeleteKeyTests::dave_user_id = "DaveId";
   39.25 +const string DeleteKeyTests::erin_user_id = "ErinErinErin";
   39.26 +const string DeleteKeyTests::fenris_user_id = "BadWolf";
   39.27 +
   39.28 +
   39.29 +DeleteKeyTests::DeleteKeyTests(string suitename, string test_home_dir) :
   39.30 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
   39.31 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeleteKeyTests::check_delete_single_pubkey"),
   39.32 +                                                                      static_cast<Func>(&DeleteKeyTests::check_delete_single_pubkey)));
   39.33 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeleteKeyTests::check_delete_pub_priv_keypair"),
   39.34 +                                                                      static_cast<Func>(&DeleteKeyTests::check_delete_pub_priv_keypair)));
   39.35 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeleteKeyTests::check_delete_multiple_keys"),
   39.36 +                                                                      static_cast<Func>(&DeleteKeyTests::check_delete_multiple_keys)));
   39.37 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeleteKeyTests::check_delete_all_keys"),
   39.38 +                                                                      static_cast<Func>(&DeleteKeyTests::check_delete_all_keys)));
   39.39 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeleteKeyTests::check_delete_key_not_found"),
   39.40 +                                                                      static_cast<Func>(&DeleteKeyTests::check_delete_key_not_found)));
   39.41 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeleteKeyTests::check_delete_empty_keyring"),
   39.42 +                                                                      static_cast<Func>(&DeleteKeyTests::check_delete_empty_keyring)));
   39.43 +}
   39.44 +
   39.45 +void DeleteKeyTests::import_test_keys() {
   39.46 +    PEP_STATUS status = read_file_and_import_key(session,
   39.47 +                "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   39.48 +    assert(status == PEP_KEY_IMPORTED);
   39.49 +    status = set_up_ident_from_scratch(session,
   39.50 +                "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
   39.51 +                "pep.test.alice@pep-project.org", alice_fpr, 
   39.52 +                alice_user_id.c_str(), "Alice in Wonderland", NULL, true
   39.53 +            );
   39.54 +    assert(status == PEP_STATUS_OK);
   39.55 +    
   39.56 +    status = set_up_ident_from_scratch(session,
   39.57 +                "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc",
   39.58 +                "pep.test.bob@pep-project.org", NULL, bob_user_id.c_str(), "Bob's Burgers",
   39.59 +                NULL, false
   39.60 +            );
   39.61 +    assert(status == PEP_STATUS_OK);
   39.62 +            
   39.63 +    status = set_up_ident_from_scratch(session,
   39.64 +                "test_keys/pub/pep-test-carol-0x42A85A42_pub.asc",
   39.65 +                "pep-test-carol@pep-project.org", NULL, carol_user_id.c_str(), "Carol Burnett",
   39.66 +                NULL, false
   39.67 +            );
   39.68 +    assert(status == PEP_STATUS_OK);
   39.69 +    
   39.70 +    status = set_up_ident_from_scratch(session,
   39.71 +                "test_keys/pub/pep-test-dave-0xBB5BCCF6_pub.asc",
   39.72 +                "pep-test-dave@pep-project.org", NULL, dave_user_id.c_str(), 
   39.73 +                "David Hasselhoff (Germans Love Me)", NULL, false
   39.74 +            );
   39.75 +    assert(status == PEP_STATUS_OK);
   39.76 +
   39.77 +    status = set_up_ident_from_scratch(session,
   39.78 +                "test_keys/pub/pep-test-erin-0x9F8D7CBA_pub.asc",
   39.79 +                "pep-test-erin@pep-project.org", NULL, erin_user_id.c_str(), 
   39.80 +                "Éirinn go Brách", NULL, false
   39.81 +            );
   39.82 +    assert(status == PEP_STATUS_OK);
   39.83 +
   39.84 +    status = set_up_ident_from_scratch(session,
   39.85 +                "test_keys/pub/pep.test.fenris-0x4F3D2900_pub.asc",
   39.86 +                "pep.test.fenris@thisstilldoesntwork.lu", NULL, fenris_user_id.c_str(), 
   39.87 +                "Fenris Leto Hawke", NULL, false
   39.88 +            );
   39.89 +    assert(status == PEP_STATUS_OK);
   39.90 +}
   39.91 +
   39.92 +void DeleteKeyTests::check_delete_single_pubkey() {
   39.93 +    import_test_keys();
   39.94 +    stringlist_t* keylist = NULL;
   39.95 +
   39.96 +    // Is it there?
   39.97 +    PEP_STATUS status = find_keys(session, fenris_fpr, &keylist);
   39.98 +    TEST_ASSERT(status == PEP_STATUS_OK);
   39.99 +    TEST_ASSERT(keylist && keylist->value);    
  39.100 +    TEST_ASSERT_MSG(strcmp(keylist->value, fenris_fpr) == 0, "Wrong key found?!?!");
  39.101 +    free_stringlist(keylist);
  39.102 +    keylist = NULL;
  39.103 +    
  39.104 +    // Great, now delete it.
  39.105 +    status = delete_keypair(session, fenris_fpr);
  39.106 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  39.107 +    
  39.108 +    // Is it gone?
  39.109 +    status = find_keys(session, fenris_fpr, &keylist);
  39.110 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  39.111 +    TEST_ASSERT(!keylist);    
  39.112 +    
  39.113 +    // Yay.    
  39.114 +}
  39.115 +
  39.116 +void DeleteKeyTests::check_delete_pub_priv_keypair() {
  39.117 +    import_test_keys();
  39.118 +    stringlist_t* keylist = NULL;
  39.119 +
  39.120 +    // Is it there?
  39.121 +    PEP_STATUS status = find_keys(session, alice_fpr, &keylist);
  39.122 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.123 +    TEST_ASSERT(keylist && keylist->value);    
  39.124 +    TEST_ASSERT_MSG(strcmp(keylist->value, alice_fpr) == 0, "Wrong key found?!?!");
  39.125 +    free_stringlist(keylist);
  39.126 +    keylist = NULL;
  39.127 +    
  39.128 +    // Great, now delete it.
  39.129 +    status = delete_keypair(session, alice_fpr);
  39.130 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  39.131 +    
  39.132 +    // Is it gone?
  39.133 +    status = find_keys(session, alice_fpr, &keylist);
  39.134 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  39.135 +    TEST_ASSERT(!keylist);    
  39.136 +    
  39.137 +    // Yay.    
  39.138 +}
  39.139 +
  39.140 +void DeleteKeyTests::check_delete_multiple_keys() {
  39.141 +    import_test_keys();
  39.142 +    stringlist_t* keylist = NULL;
  39.143 +
  39.144 +    // Are they there?
  39.145 +    PEP_STATUS status = find_keys(session, alice_fpr, &keylist);
  39.146 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.147 +    TEST_ASSERT(keylist && keylist->value);    
  39.148 +    TEST_ASSERT_MSG(strcmp(keylist->value, alice_fpr) == 0, keylist->value);
  39.149 +    free_stringlist(keylist);
  39.150 +    keylist = NULL;
  39.151 +
  39.152 +    status = find_keys(session, dave_fpr, &keylist);
  39.153 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.154 +    TEST_ASSERT(keylist && keylist->value);    
  39.155 +    TEST_ASSERT_MSG(strcmp(keylist->value, dave_fpr) == 0, "Wrong key found?!?!");
  39.156 +    free_stringlist(keylist);
  39.157 +    keylist = NULL;
  39.158 +
  39.159 +    status = find_keys(session, fenris_fpr, &keylist);
  39.160 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.161 +    TEST_ASSERT(keylist && keylist->value);    
  39.162 +    TEST_ASSERT_MSG(strcmp(keylist->value, fenris_fpr) == 0, "Wrong key found?!?!");
  39.163 +    free_stringlist(keylist);
  39.164 +    keylist = NULL;
  39.165 +    
  39.166 +    // Great, now delete it.
  39.167 +    status = delete_keypair(session, alice_fpr);
  39.168 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  39.169 +
  39.170 +    status = delete_keypair(session, dave_fpr);
  39.171 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  39.172 +
  39.173 +    status = delete_keypair(session, fenris_fpr);
  39.174 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  39.175 +
  39.176 +    // Is it gone?
  39.177 +    status = find_keys(session, alice_fpr, &keylist);
  39.178 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  39.179 +    TEST_ASSERT(!keylist);    
  39.180 +
  39.181 +    status = find_keys(session, dave_fpr, &keylist);
  39.182 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  39.183 +    TEST_ASSERT(!keylist);    
  39.184 +
  39.185 +    status = find_keys(session, fenris_fpr, &keylist);
  39.186 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  39.187 +    TEST_ASSERT(!keylist);    
  39.188 +    
  39.189 +    // Yay. Make sure everyone else is still there.
  39.190 +    status = find_keys(session, bob_fpr, &keylist);
  39.191 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.192 +    TEST_ASSERT(keylist && keylist->value);    
  39.193 +    TEST_ASSERT_MSG(strcmp(keylist->value, bob_fpr) == 0, "Wrong key found?!?!");
  39.194 +    free_stringlist(keylist);
  39.195 +    keylist = NULL;
  39.196 +
  39.197 +    status = find_keys(session, carol_fpr, &keylist);
  39.198 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.199 +    TEST_ASSERT(keylist && keylist->value);    
  39.200 +    TEST_ASSERT_MSG(strcmp(keylist->value, carol_fpr) == 0, "Wrong key found?!?!");
  39.201 +    free_stringlist(keylist);
  39.202 +    keylist = NULL;
  39.203 +
  39.204 +    status = find_keys(session, erin_fpr, &keylist);
  39.205 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.206 +    TEST_ASSERT(keylist && keylist->value);    
  39.207 +    TEST_ASSERT_MSG(strcmp(keylist->value, erin_fpr) == 0, "Wrong key found?!?!");
  39.208 +    free_stringlist(keylist);
  39.209 +    keylist = NULL;
  39.210 +}
  39.211 +
  39.212 +void DeleteKeyTests::check_delete_all_keys() {
  39.213 +    import_test_keys();
  39.214 +    stringlist_t* keylist = NULL;
  39.215 +
  39.216 +    // Are they there?
  39.217 +    PEP_STATUS status = find_keys(session, alice_fpr, &keylist);
  39.218 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.219 +    TEST_ASSERT(keylist && keylist->value);    
  39.220 +    TEST_ASSERT_MSG(strcmp(keylist->value, alice_fpr) == 0, keylist->value);
  39.221 +    free_stringlist(keylist);
  39.222 +    keylist = NULL;
  39.223 +
  39.224 +    status = find_keys(session, bob_fpr, &keylist);
  39.225 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.226 +    TEST_ASSERT(keylist && keylist->value);    
  39.227 +    TEST_ASSERT_MSG(strcmp(keylist->value, bob_fpr) == 0, "Wrong key found?!?!");
  39.228 +    free_stringlist(keylist);
  39.229 +    keylist = NULL;
  39.230 +
  39.231 +    status = find_keys(session, carol_fpr, &keylist);
  39.232 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.233 +    TEST_ASSERT(keylist && keylist->value);    
  39.234 +    TEST_ASSERT_MSG(strcmp(keylist->value, carol_fpr) == 0, "Wrong key found?!?!");
  39.235 +    free_stringlist(keylist);
  39.236 +    keylist = NULL;
  39.237 +
  39.238 +    status = find_keys(session, dave_fpr, &keylist);
  39.239 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.240 +    TEST_ASSERT(keylist && keylist->value);    
  39.241 +    TEST_ASSERT_MSG(strcmp(keylist->value, dave_fpr) == 0, "Wrong key found?!?!");
  39.242 +    free_stringlist(keylist);
  39.243 +    keylist = NULL;
  39.244 +
  39.245 +    status = find_keys(session, erin_fpr, &keylist);
  39.246 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.247 +    TEST_ASSERT(keylist && keylist->value);    
  39.248 +    TEST_ASSERT_MSG(strcmp(keylist->value, erin_fpr) == 0, "Wrong key found?!?!");
  39.249 +    free_stringlist(keylist);
  39.250 +    keylist = NULL;
  39.251 +
  39.252 +    status = find_keys(session, fenris_fpr, &keylist);
  39.253 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.254 +    TEST_ASSERT(keylist && keylist->value);    
  39.255 +    TEST_ASSERT_MSG(strcmp(keylist->value, fenris_fpr) == 0, "Wrong key found?!?!");
  39.256 +    free_stringlist(keylist);
  39.257 +    keylist = NULL;
  39.258 +    
  39.259 +    // Great, now delete it.
  39.260 +    status = delete_keypair(session, alice_fpr);
  39.261 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  39.262 +
  39.263 +    status = delete_keypair(session, bob_fpr);
  39.264 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  39.265 +
  39.266 +    status = delete_keypair(session, carol_fpr);
  39.267 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  39.268 +
  39.269 +    status = delete_keypair(session, dave_fpr);
  39.270 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  39.271 +
  39.272 +    status = delete_keypair(session, erin_fpr);
  39.273 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  39.274 +
  39.275 +    status = delete_keypair(session, fenris_fpr);
  39.276 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  39.277 +
  39.278 +    // Is it gone?
  39.279 +    status = find_keys(session, alice_fpr, &keylist);
  39.280 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  39.281 +    TEST_ASSERT(!keylist);    
  39.282 +
  39.283 +    status = find_keys(session, bob_fpr, &keylist);
  39.284 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  39.285 +    TEST_ASSERT(!keylist);    
  39.286 +
  39.287 +    status = find_keys(session, carol_fpr, &keylist);
  39.288 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  39.289 +    TEST_ASSERT(!keylist);    
  39.290 +
  39.291 +    status = find_keys(session, dave_fpr, &keylist);
  39.292 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  39.293 +    TEST_ASSERT(!keylist);    
  39.294 +
  39.295 +    status = find_keys(session, erin_fpr, &keylist);
  39.296 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  39.297 +    TEST_ASSERT(!keylist);    
  39.298 +
  39.299 +    status = find_keys(session, fenris_fpr, &keylist);
  39.300 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  39.301 +    TEST_ASSERT(!keylist);    
  39.302 +    
  39.303 +    // Yay. 
  39.304 +}
  39.305 +
  39.306 +void DeleteKeyTests::check_delete_key_not_found() {
  39.307 +    import_test_keys();
  39.308 +    stringlist_t* keylist = NULL;
  39.309 +
  39.310 +    // Is it there?
  39.311 +    PEP_STATUS status = find_keys(session, "74D79B4496E289BD8A71B70BA8E2C4530019697D", &keylist);
  39.312 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.313 +    TEST_ASSERT(!keylist);    
  39.314 +    
  39.315 +    // Great, now delete it.
  39.316 +    status = delete_keypair(session, "74D79B4496E289BD8A71B70BA8E2C4530019697D");
  39.317 +    TEST_ASSERT(status == PEP_KEY_NOT_FOUND);    
  39.318 +    
  39.319 +    // Is it still gone?
  39.320 +    status = find_keys(session, "74D79B4496E289BD8A71B70BA8E2C4530019697D", &keylist);
  39.321 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  39.322 +    TEST_ASSERT(!keylist);    
  39.323 +    
  39.324 +    // Yay.        
  39.325 +}
  39.326 +
  39.327 +void DeleteKeyTests::check_delete_empty_keyring() {
  39.328 +    stringlist_t* keylist = NULL;
  39.329 +
  39.330 +    // Is it there?
  39.331 +    PEP_STATUS status = find_keys(session, "74D79B4496E289BD8A71B70BA8E2C4530019697D", &keylist);
  39.332 +    TEST_ASSERT(status == PEP_STATUS_OK);
  39.333 +    TEST_ASSERT(!keylist);    
  39.334 +    
  39.335 +    // Great, now delete it.
  39.336 +    status = delete_keypair(session, "74D79B4496E289BD8A71B70BA8E2C4530019697D");
  39.337 +    TEST_ASSERT(status == PEP_KEY_NOT_FOUND);    
  39.338 +    
  39.339 +    // Is it still gone?
  39.340 +    status = find_keys(session, "74D79B4496E289BD8A71B70BA8E2C4530019697D", &keylist);
  39.341 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  39.342 +    TEST_ASSERT(!keylist);    
  39.343 +    
  39.344 +    // Yay.            
  39.345 +}
    40.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.2 +++ b/test/src/EncryptAttachPrivateKeyTests.cc	Mon Aug 26 13:38:21 2019 +0200
    40.3 @@ -0,0 +1,291 @@
    40.4 +// This file is under GNU General Public License 3.0
    40.5 +// see LICENSE.txt
    40.6 +
    40.7 +#include <stdlib.h>
    40.8 +#include "TestConstants.h"
    40.9 +#include <string>
   40.10 +#include <cstring>
   40.11 +#include <cpptest.h>
   40.12 +
   40.13 +#include "pEpEngine.h"
   40.14 +
   40.15 +#include "mime.h"
   40.16 +#include "message_api.h"
   40.17 +#include "keymanagement.h"
   40.18 +#include "test_util.h"
   40.19 +
   40.20 +#include "EngineTestSessionSuite.h"
   40.21 +#include "EncryptAttachPrivateKeyTests.h"
   40.22 +
   40.23 +using namespace std;
   40.24 +
   40.25 +EncryptAttachPrivateKeyTests::EncryptAttachPrivateKeyTests(string suitename, string test_home_dir) :
   40.26 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   40.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EncryptAttachPrivateKeyTests::check_encrypt_attach_private_key"),
   40.28 +                                                                      static_cast<Func>(&EncryptAttachPrivateKeyTests::check_encrypt_attach_private_key)));
   40.29 +}
   40.30 +
   40.31 +void EncryptAttachPrivateKeyTests::check_encrypt_attach_private_key() {
   40.32 +
   40.33 +    const char* own_uid = PEP_OWN_USERID;
   40.34 +    const char* diff_uid_0 = "TASTY_TEST_UID_0";
   40.35 +    const char* diff_uid_1 = "TASTY_TEST_UID_1";
   40.36 +
   40.37 +    cout << "Importing keys..." << endl;
   40.38 +    
   40.39 +    string input_key;
   40.40 +    const char* main_addr = "priv-key-import-test-main@darthmama.cool";
   40.41 +    pEp_identity* main_me = NULL;
   40.42 +    const char* fpr_main_me = "8AB616A3BD51DEF714B5E688EFFB540C3276D2E5";
   40.43 +    pEp_identity* same_addr_same_uid = NULL;
   40.44 +    const char* fpr_same_addr_same_uid = "359DD8AC87D1F5E4304D08338D7185F180C8CD87";
   40.45 +    
   40.46 +    pEp_identity* same_addr_diff_uid = NULL;
   40.47 +    const char* fpr_same_addr_diff_uid = "B044B83639E292283A3F6E14C2E64B520B74809C";
   40.48 +
   40.49 +    const char* diff_addr_0 = "priv-key-import-test-other_0@darthmama.cool";
   40.50 +    pEp_identity* diff_addr_same_uid = NULL;
   40.51 +    const char* fpr_diff_addr_same_uid = "C52911EBA0D34B0F549594A15A7A363BD11252C9";
   40.52 +    
   40.53 +    const char* diff_addr_1 = "priv-key-import-test-other_1@darthmama.cool";
   40.54 +    pEp_identity* diff_addr_diff_uid = NULL;
   40.55 +    const char* fpr_diff_addr_diff_uid = "567212EFB8A3A76B1D32B9565F45BEA9C785F20A";
   40.56 +    
   40.57 +    PEP_STATUS status = PEP_STATUS_OK;
   40.58 +
   40.59 +    // key for main own user
   40.60 +    // 8AB616A3BD51DEF714B5E688EFFB540C3276D2E5
   40.61 +    input_key = slurp("test_keys/pub/priv-key-import-test-main_0-0x3276D2E5_pub.asc");
   40.62 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   40.63 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), tl_status_string(status));
   40.64 +
   40.65 +    input_key = slurp("test_keys/priv/priv-key-import-test-main_0-0x3276D2E5_priv.asc");
   40.66 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   40.67 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), tl_status_string(status));
   40.68 +        
   40.69 +    // key with same address and user_id (initially untrusted, then trusted)
   40.70 +    // 359DD8AC87D1F5E4304D08338D7185F180C8CD87
   40.71 +    input_key = slurp("test_keys/pub/priv-key-import-test-main_1-0x80C8CD87_pub.asc");
   40.72 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   40.73 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), tl_status_string(status));
   40.74 +
   40.75 +    // key with same address and to have different (non-aliased) user_id (initially untrusted, then trusted)
   40.76 +    // B044B83639E292283A3F6E14C2E64B520B74809C
   40.77 +    input_key = slurp("test_keys/pub/priv-key-import-test-main_2-0x0B74809C_pub.asc");
   40.78 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   40.79 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), tl_status_string(status));
   40.80 +
   40.81 +    // key with different address to have same user_id (initially untrusted, then trusted)
   40.82 +    // C52911EBA0D34B0F549594A15A7A363BD11252C9
   40.83 +    input_key = slurp("test_keys/pub/priv-key-import-test-other_0-0xD11252C9_pub.asc");
   40.84 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   40.85 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), tl_status_string(status));
   40.86 +        
   40.87 +    // key with different address to have different user_id (initially untrusted, then trusted)
   40.88 +    // 567212EFB8A3A76B1D32B9565F45BEA9C785F20A
   40.89 +    input_key = slurp("test_keys/pub/priv-key-import-test-other_1-0xC785F20A_pub.asc");
   40.90 +    status = import_key(session, input_key.c_str(), input_key.length(), NULL);
   40.91 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), tl_status_string(status));
   40.92 +    cout << "Done!" << endl << endl;
   40.93 +    
   40.94 +    cout << "Setting up own identity with default key " << fpr_main_me << endl;
   40.95 +    // Own identity with default key etc
   40.96 +    main_me = new_identity(main_addr, fpr_main_me, own_uid, "PrivateKey Import Test");
   40.97 +    status = set_own_key(session, main_me, fpr_main_me);
   40.98 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   40.99 +
  40.100 +    TEST_ASSERT_MSG((strcmp(main_me->fpr, fpr_main_me) == 0), "strcmp(main_me->fpr, fpr_main_me) == 0");
  40.101 +    cout << "Done!" << endl << endl;
  40.102 +    
  40.103 +    cout << "Setting up recipient identities and resetting key trust." << endl;
  40.104 +    cout << "#1: same address, same user_id - address: " << main_addr << ", user_id: " << own_uid << ", fpr: " << fpr_same_addr_same_uid << endl;  
  40.105 +    // Identity with same address and user_id - the fpr here will be ignored in update_identity and friends.
  40.106 +    same_addr_same_uid = new_identity(main_addr, fpr_same_addr_same_uid, own_uid, "PrivateKey Import Test");
  40.107 +    status = key_reset_trust(session, same_addr_same_uid);
  40.108 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY), "status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY");
  40.109 +    TEST_ASSERT_MSG((strcmp(same_addr_same_uid->fpr, fpr_same_addr_same_uid) == 0), "strcmp(same_addr_same_uid->fpr, fpr_same_addr_same_uid) == 0");
  40.110 +    
  40.111 +    // Identity with same address and different user_id
  40.112 +    cout << "#2: same address, different user_id - address: " << main_addr << ", user_id: " << diff_uid_0 << ", fpr: " << fpr_same_addr_diff_uid << endl;  
  40.113 +    same_addr_diff_uid = new_identity(main_addr, fpr_same_addr_diff_uid, diff_uid_0, "PrivateKey Import Test");
  40.114 +    TEST_ASSERT_MSG((same_addr_diff_uid), "same_addr_diff_uid");
  40.115 +    status = key_reset_trust(session, same_addr_diff_uid);
  40.116 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY), "status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY");
  40.117 +    TEST_ASSERT_MSG((strcmp(same_addr_diff_uid->fpr, fpr_same_addr_diff_uid) == 0), "strcmp(same_addr_diff_uid->fpr, fpr_same_addr_diff_uid) == 0");
  40.118 +    
  40.119 +    // Identity with diff address and same user_id
  40.120 +    cout << "#3: different address, same user_id - address: " << diff_addr_0 << ", user_id: " << own_uid << ", fpr: " << fpr_diff_addr_same_uid << endl;      
  40.121 +    diff_addr_same_uid = new_identity(diff_addr_0, fpr_diff_addr_same_uid, own_uid, "PrivateKey Import Test");
  40.122 +    TEST_ASSERT_MSG((diff_addr_same_uid), "diff_addr_same_uid");
  40.123 +    status = key_reset_trust(session, diff_addr_same_uid);
  40.124 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY), "status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY");
  40.125 +    TEST_ASSERT_MSG((strcmp(diff_addr_same_uid->fpr, fpr_diff_addr_same_uid) == 0), "strcmp(diff_addr_same_uid->fpr, fpr_diff_addr_same_uid) == 0");
  40.126 +
  40.127 +    // Identity with different address and different user_id
  40.128 +    cout << "#4: different address, different user_id - address: " << diff_addr_1 << ", user_id: " << diff_uid_1 << ", fpr: " << fpr_diff_addr_diff_uid << endl;      
  40.129 +    diff_addr_diff_uid = new_identity(diff_addr_1, fpr_diff_addr_diff_uid, diff_uid_1, "PrivateKey Import Test");
  40.130 +    TEST_ASSERT_MSG((diff_addr_diff_uid), "diff_addr_diff_uid");
  40.131 +    status = key_reset_trust(session, diff_addr_diff_uid);
  40.132 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY), "status == PEP_STATUS_OK || status == PEP_CANNOT_FIND_IDENTITY");
  40.133 +    TEST_ASSERT_MSG((strcmp(diff_addr_diff_uid->fpr, fpr_diff_addr_diff_uid) == 0), "strcmp(diff_addr_diff_uid->fpr, fpr_diff_addr_diff_uid) == 0");
  40.134 +    cout << "Done!" << endl << endl;
  40.135 +
  40.136 +    message* msg_same_addr_same_uid = new_message(PEP_dir_outgoing);
  40.137 +    msg_same_addr_same_uid->from = main_me;
  40.138 +    msg_same_addr_same_uid->shortmsg = strdup("Greetings, humans!");
  40.139 +    msg_same_addr_same_uid->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
  40.140 +    msg_same_addr_same_uid->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  40.141 +
  40.142 +    message* msg_same_addr_diff_uid = message_dup(msg_same_addr_same_uid);
  40.143 +    message* msg_diff_addr_same_uid = message_dup(msg_same_addr_same_uid);       
  40.144 +    message* msg_diff_addr_diff_uid = message_dup(msg_same_addr_same_uid);       
  40.145 +
  40.146 +    cout << "Starting tests..." << endl;
  40.147 +    // Case 1:
  40.148 +    // Same address, same user_id, untrusted
  40.149 +    cout << "Case 1: Same address, same user_id, untrusted" << endl;
  40.150 +    TEST_ASSERT_MSG((msg_same_addr_same_uid), "msg_same_addr_same_uid");        
  40.151 +    identity_list* to_list = new_identity_list(same_addr_same_uid);
  40.152 +    msg_same_addr_same_uid->to = to_list;
  40.153 +    message* enc_same_addr_same_uid_untrusted = NULL;
  40.154 +    status = encrypt_message_and_add_priv_key(session,
  40.155 +                                              msg_same_addr_same_uid,
  40.156 +                                              &enc_same_addr_same_uid_untrusted,
  40.157 +                                              fpr_same_addr_same_uid,
  40.158 +                                              PEP_enc_PGP_MIME,
  40.159 +                                              0);
  40.160 +
  40.161 +    cout << "Case 1 Status: " << tl_status_string(status) << endl;
  40.162 +    TEST_ASSERT_MSG((status == PEP_ILLEGAL_VALUE), "status == PEP_ILLEGAL_VALUE");
  40.163 +    cout << "PASS!" << endl;
  40.164 +    
  40.165 +    // Case 2:
  40.166 +    // Same address, same_user_id, trusted
  40.167 +    cout << "Case 2: Same address, same user_id, trusted" << endl;
  40.168 +    status = trust_own_key(session, same_addr_same_uid);
  40.169 +    cout << "Trust personal key for " << same_addr_same_uid << " gives status " << tl_status_string(status) << " (" << status << ")" << endl;
  40.170 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  40.171 +    message* enc_same_addr_same_uid_trusted = NULL;
  40.172 +    status = encrypt_message_and_add_priv_key(session,
  40.173 +                                              msg_same_addr_same_uid,
  40.174 +                                              &enc_same_addr_same_uid_trusted,
  40.175 +                                              fpr_same_addr_same_uid,
  40.176 +                                              PEP_enc_PGP_MIME,
  40.177 +                                              0);
  40.178 +
  40.179 +    cout << "Case 2 Status: " << tl_status_string(status) << endl;
  40.180 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  40.181 +    cout << "PASS!" << endl;
  40.182 +
  40.183 +    // Case 3:
  40.184 +    // Different address, same user_id, untrusted
  40.185 +    cout << "Case 3: Different address, same user_id, untrusted" << endl;
  40.186 +    TEST_ASSERT_MSG((msg_diff_addr_same_uid), "msg_diff_addr_same_uid");        
  40.187 +    identity_list* to_list_1 = new_identity_list(diff_addr_same_uid);
  40.188 +    msg_diff_addr_same_uid->to = to_list_1;
  40.189 +    message* enc_diff_addr_same_uid_untrusted = NULL;
  40.190 +    status = encrypt_message_and_add_priv_key(session,
  40.191 +                                              msg_diff_addr_same_uid,
  40.192 +                                              &enc_diff_addr_same_uid_untrusted,
  40.193 +                                              fpr_diff_addr_same_uid,
  40.194 +                                              PEP_enc_PGP_MIME,
  40.195 +                                              0);
  40.196 +    
  40.197 +    cout << "Case 3 Status: " << tl_status_string(status) << endl;
  40.198 +    TEST_ASSERT_MSG((status == PEP_ILLEGAL_VALUE), "status == PEP_ILLEGAL_VALUE");
  40.199 +    cout << "PASS!" << endl;
  40.200 +
  40.201 +    // Case 4:
  40.202 +    // Different address, same user_id, trusted
  40.203 +    cout << "Case 4: Different address, same user_id, trusted" << endl;
  40.204 +    status = trust_own_key(session, diff_addr_same_uid);
  40.205 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  40.206 +    message* enc_diff_addr_same_uid_trusted = NULL;
  40.207 +    status = encrypt_message_and_add_priv_key(session,
  40.208 +                                              msg_diff_addr_same_uid,
  40.209 +                                              &enc_diff_addr_same_uid_trusted,
  40.210 +                                              fpr_diff_addr_same_uid,
  40.211 +                                              PEP_enc_PGP_MIME,
  40.212 +                                              0);
  40.213 +                                              
  40.214 +    cout << "Case 4 Status: " << tl_status_string(status) << endl;
  40.215 +    TEST_ASSERT_MSG((status == PEP_ILLEGAL_VALUE), "status == PEP_ILLEGAL_VALUE");
  40.216 +    cout << "PASS!" << endl;
  40.217 +
  40.218 +    // Case 5:
  40.219 +    // Same address, different user_id, untrusted
  40.220 +    cout << "Case 5: Same address, different user_id, untrusted" << endl;    
  40.221 +    TEST_ASSERT_MSG((msg_same_addr_diff_uid), "msg_same_addr_diff_uid");        
  40.222 +    identity_list* to_list_2 = new_identity_list(same_addr_diff_uid);
  40.223 +    msg_same_addr_diff_uid->to = to_list_2;
  40.224 +    message* enc_same_addr_diff_uid_untrusted = NULL;
  40.225 +    status = encrypt_message_and_add_priv_key(session,
  40.226 +                                              msg_same_addr_diff_uid,
  40.227 +                                              &enc_same_addr_diff_uid_untrusted,
  40.228 +                                              fpr_same_addr_diff_uid,
  40.229 +                                              PEP_enc_PGP_MIME,
  40.230 +                                              0);
  40.231 +
  40.232 +    cout << "Case 5 Status: " << tl_status_string(status) << endl;
  40.233 +    TEST_ASSERT_MSG((status == PEP_ILLEGAL_VALUE), "status == PEP_ILLEGAL_VALUE");    
  40.234 +    cout << "PASS!" << endl;
  40.235 +    
  40.236 +    // Case 6:
  40.237 +    // Same address, different user_id, trusted
  40.238 +    cout << "Case 6: Same address, different user_id, trusted" << endl;        
  40.239 +    status = trust_personal_key(session, same_addr_diff_uid);
  40.240 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  40.241 +    message* enc_same_addr_diff_uid_trusted = NULL;
  40.242 +    status = encrypt_message_and_add_priv_key(session,
  40.243 +                                              msg_same_addr_diff_uid,
  40.244 +                                              &enc_same_addr_diff_uid_untrusted,
  40.245 +                                              fpr_same_addr_diff_uid,
  40.246 +                                              PEP_enc_PGP_MIME,
  40.247 +                                              0);
  40.248 +
  40.249 +    cout << "Case 6 Status: " << tl_status_string(status) << endl;
  40.250 +    TEST_ASSERT_MSG((status == PEP_ILLEGAL_VALUE), "status == PEP_ILLEGAL_VALUE");    
  40.251 +    cout << "PASS!" << endl;
  40.252 +
  40.253 +    // Case 7:
  40.254 +    // Different address, different user_id, untrusted
  40.255 +    cout << "Case 7: Different address, different user_id, untrusted" << endl;    
  40.256 +    TEST_ASSERT_MSG((msg_diff_addr_diff_uid), "msg_diff_addr_diff_uid");        
  40.257 +    identity_list* to_list_3 = new_identity_list(diff_addr_diff_uid);
  40.258 +    msg_diff_addr_diff_uid->to = to_list_3;
  40.259 +    message* enc_diff_addr_diff_uid_untrusted = NULL;
  40.260 +    status = encrypt_message_and_add_priv_key(session,
  40.261 +                                              msg_diff_addr_diff_uid,
  40.262 +                                              &enc_diff_addr_diff_uid_untrusted,
  40.263 +                                              fpr_diff_addr_diff_uid,
  40.264 +                                              PEP_enc_PGP_MIME,
  40.265 +                                              0);
  40.266 +
  40.267 +    cout << "Case 7 Status: " << tl_status_string(status) << endl;
  40.268 +    TEST_ASSERT_MSG((status == PEP_ILLEGAL_VALUE), "status == PEP_ILLEGAL_VALUE");
  40.269 +    cout << "PASS!" << endl;
  40.270 +
  40.271 +    // Case 8:
  40.272 +    // Different address, different user_id, trusted
  40.273 +    cout << "Case 8: Different address, different user_id, trusted" << endl;    
  40.274 +    status = trust_personal_key(session, diff_addr_diff_uid);
  40.275 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  40.276 +    message* enc_diff_addr_diff_uid_trusted = NULL;
  40.277 +    status = encrypt_message_and_add_priv_key(session,
  40.278 +                                              msg_diff_addr_diff_uid,
  40.279 +                                              &enc_diff_addr_diff_uid_trusted,
  40.280 +                                              fpr_diff_addr_diff_uid,
  40.281 +                                              PEP_enc_PGP_MIME,
  40.282 +                                              0);
  40.283 +
  40.284 +    cout << "Case 8 Status: " << tl_status_string(status) << endl;
  40.285 +    TEST_ASSERT_MSG((status == PEP_ILLEGAL_VALUE), "status == PEP_ILLEGAL_VALUE");
  40.286 +    cout << "PASS!" << endl;
  40.287 +    
  40.288 +    cout << "Correctly encrypted message:" << endl << endl;                
  40.289 +    char* encrypted_msg_text = NULL;
  40.290 +    mime_encode_message(enc_same_addr_same_uid_trusted, false, &encrypted_msg_text);                                    
  40.291 +    cout << encrypted_msg_text << endl << endl;
  40.292 +    
  40.293 +    // FIXME: Free all the damned things
  40.294 +}
    41.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.2 +++ b/test/src/EncryptForIdentityTests.cc	Mon Aug 26 13:38:21 2019 +0200
    41.3 @@ -0,0 +1,293 @@
    41.4 +// This file is under GNU General Public License 3.0
    41.5 +// see LICENSE.txt
    41.6 +
    41.7 +#include <stdlib.h>
    41.8 +#include "TestConstants.h"
    41.9 +#include <unistd.h>
   41.10 +#include <string>
   41.11 +#include <cstring>
   41.12 +#include <iostream>
   41.13 +#include <fstream>
   41.14 +
   41.15 +#include "pEpEngine.h"
   41.16 +#include "mime.h"
   41.17 +#include "message_api.h"
   41.18 +#include "keymanagement.h"
   41.19 +#include "test_util.h"
   41.20 +
   41.21 +#include <cpptest.h>
   41.22 +#include "EngineTestSessionSuite.h"
   41.23 +#include "EncryptForIdentityTests.h"
   41.24 +
   41.25 +using namespace std;
   41.26 +
   41.27 +EncryptForIdentityTests::EncryptForIdentityTests(string suitename, string test_home_dir) :
   41.28 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   41.29 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EncryptForIdentityTests::check_encrypt_for_identity"),
   41.30 +                                                                      static_cast<Func>(&EncryptForIdentityTests::check_encrypt_for_identity)));
   41.31 +}
   41.32 +
   41.33 +void EncryptForIdentityTests::check_encrypt_for_identity() {
   41.34 +
   41.35 +    // message_api test code
   41.36 +
   41.37 +    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   41.38 +    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
   41.39 +    const string gabrielle_pub_key = slurp("test_keys/pub/pep-test-gabrielle-0xE203586C_pub.asc");
   41.40 +    const string bella_pub_key = slurp("test_keys/pub/pep.test.bella-0xAF516AAE_pub.asc");    
   41.41 +
   41.42 +    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
   41.43 +    PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
   41.44 +    TEST_ASSERT_MSG((statuspub == PEP_TEST_KEY_IMPORT_SUCCESS), "statuspub == PEP_STATUS_OK");
   41.45 +    TEST_ASSERT_MSG((statuspriv == PEP_TEST_KEY_IMPORT_SUCCESS), "statuspriv == PEP_STATUS_OK");
   41.46 +    
   41.47 +    statuspub = import_key(session, gabrielle_pub_key.c_str(), gabrielle_pub_key.length(), NULL);
   41.48 +    TEST_ASSERT_MSG((statuspub == PEP_TEST_KEY_IMPORT_SUCCESS), "statuspub == PEP_STATUS_OK");
   41.49 +    statuspub = import_key(session, bella_pub_key.c_str(), bella_pub_key.length(), NULL);
   41.50 +    TEST_ASSERT_MSG((statuspub == PEP_TEST_KEY_IMPORT_SUCCESS), "statuspub == PEP_STATUS_OK");
   41.51 +
   41.52 +    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
   41.53 +    const char* gabrielle_fpr = "906C9B8349954E82C5623C3C8C541BD4E203586C";
   41.54 +    const char* bella_fpr = "5631BF1357326A02AA470EEEB815EF7FA4516AAE";
   41.55 +    const char* nobody_fpr = "1111111111111111111111111111111111111111";
   41.56 +
   41.57 +    cout << "creating message…\n";
   41.58 +    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Test");
   41.59 +    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test");
   41.60 +    
   41.61 +    alice->me = true;
   41.62 +
   41.63 +    PEP_STATUS mystatus = set_own_key(session, alice, alice_fpr);
   41.64 +    TEST_ASSERT_MSG((mystatus == PEP_STATUS_OK), "mystatus == PEP_STATUS_OK");
   41.65 +
   41.66 +    identity_list* to_list = new_identity_list(bob); // to bob
   41.67 +    message* outgoing_message = new_message(PEP_dir_outgoing);
   41.68 +    TEST_ASSERT_MSG((outgoing_message), "outgoing_message");
   41.69 +    outgoing_message->from = alice;
   41.70 +    outgoing_message->to = to_list;
   41.71 +    outgoing_message->shortmsg = strdup("Greetings, humans!");
   41.72 +    outgoing_message->longmsg = strdup("This is a test of the emergency message system. This is only a test. BEEP.");
   41.73 +    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   41.74 +    cout << "message created.\n";
   41.75 +
   41.76 +    char* encoded_text = nullptr;
   41.77 +    PEP_STATUS status = mime_encode_message(outgoing_message, false, &encoded_text);
   41.78 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
   41.79 +    TEST_ASSERT_MSG((encoded_text), "encoded_text");
   41.80 +
   41.81 +    cout << "decrypted:\n\n";
   41.82 +    cout << encoded_text << "\n";
   41.83 +
   41.84 +    free(encoded_text);
   41.85 +
   41.86 +    message* encrypted_msg = nullptr;
   41.87 +    cout << "calling encrypt_message_for_identity()\n";
   41.88 +    status = encrypt_message_for_self(session, alice, outgoing_message, NULL, &encrypted_msg, PEP_enc_PGP_MIME, PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
   41.89 +    cout << "encrypt_message() returns " << tl_status_string(status) << '.' << endl;
   41.90 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
   41.91 +    TEST_ASSERT_MSG((encrypted_msg), "encrypted_msg");
   41.92 +    cout << "message encrypted.\n";
   41.93 +    
   41.94 +    status = mime_encode_message(encrypted_msg, false, &encoded_text);
   41.95 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
   41.96 +    TEST_ASSERT_MSG((encoded_text), "encoded_text");
   41.97 +
   41.98 +    cout << "encrypted:\n\n";
   41.99 +    cout << encoded_text << "\n";
  41.100 +
  41.101 +    message* decoded_msg = nullptr;
  41.102 +    status = mime_decode_message(encoded_text, strlen(encoded_text), &decoded_msg);
  41.103 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
  41.104 +    const string string3 = encoded_text;
  41.105 +
  41.106 +    unlink("msg_encrypt_for_self.asc");
  41.107 +    ofstream outFile3("msg_encrypt_for_self.asc");
  41.108 +    outFile3.write(string3.c_str(), string3.size());
  41.109 +    outFile3.close();
  41.110 +
  41.111 +    message* decrypted_msg = nullptr;
  41.112 +    stringlist_t* keylist_used = nullptr;
  41.113 +
  41.114 +    PEP_rating rating;
  41.115 +    PEP_decrypt_flags_t flags;
  41.116 +
  41.117 +    flags = 0;
  41.118 +    status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
  41.119 +    TEST_ASSERT_MSG((decrypted_msg), "decrypted_msg");
  41.120 +    TEST_ASSERT_MSG((keylist_used), "keylist_used");
  41.121 +    TEST_ASSERT_MSG((rating), "rating");
  41.122 +    TEST_ASSERT_MSG((status == PEP_DECRYPTED && rating == PEP_rating_unreliable), "status == PEP_DECRYPTED && rating == PEP_rating_unreliable");
  41.123 +    PEP_comm_type ct = encrypted_msg->from->comm_type;
  41.124 +    TEST_ASSERT_MSG((ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed ), "ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed ");
  41.125 +
  41.126 +    cout << "keys used:\n";
  41.127 +
  41.128 +    int i = 0;
  41.129 +
  41.130 +    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++)
  41.131 +    {
  41.132 +        if (i == 0) {
  41.133 +            TEST_ASSERT_MSG((strcasecmp("",kl4->value) == 0), "strcasecmp(\"\",kl4->value) == 0");
  41.134 +        }
  41.135 +        else {
  41.136 +            cout << "\t " << kl4->value << endl;
  41.137 +            TEST_ASSERT_MSG((strcasecmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value) == 0), "strcasecmp(\"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\", kl4->value) == 0");
  41.138 +            cout << "Encrypted for Alice! Yay! It worked!" << endl;
  41.139 +        }
  41.140 +        TEST_ASSERT_MSG((i < 2), "i < 2");
  41.141 +    }
  41.142 +    cout << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;
  41.143 + 
  41.144 +    cout << "freeing messages…\n";
  41.145 +    free_message(encrypted_msg);
  41.146 +    free_message(decrypted_msg);
  41.147 +    free_stringlist (keylist_used);
  41.148 +    cout << "done.\n";
  41.149 +
  41.150 +    cout << "Now encrypt for self with extra keys." << endl;
  41.151 +    stringlist_t* extra_keys = new_stringlist(gabrielle_fpr);
  41.152 +    stringlist_add(extra_keys, bella_fpr);
  41.153 +    encrypted_msg = NULL;
  41.154 +    decrypted_msg = NULL;
  41.155 +    keylist_used = NULL;
  41.156 +
  41.157 +    cout << "calling encrypt_message_for_identity()\n";
  41.158 +    status = encrypt_message_for_self(session, alice, outgoing_message, extra_keys, &encrypted_msg, PEP_enc_PGP_MIME, PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
  41.159 +    cout << "encrypt_message() returns " << tl_status_string(status) << '.' << endl;
  41.160 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
  41.161 +    TEST_ASSERT_MSG((encrypted_msg), "encrypted_msg");
  41.162 +    cout << "message encrypted.\n";
  41.163 +    
  41.164 +    flags = 0;
  41.165 +    status = decrypt_message(session, encrypted_msg, &decrypted_msg, &keylist_used, &rating, &flags);
  41.166 +    TEST_ASSERT_MSG((decrypted_msg), "decrypted_msg");
  41.167 +    TEST_ASSERT_MSG((keylist_used), "keylist_used");
  41.168 +    TEST_ASSERT_MSG((rating), "rating");
  41.169 +    TEST_ASSERT_MSG((status == PEP_DECRYPTED && rating == PEP_rating_unreliable), "status == PEP_DECRYPTED && rating == PEP_rating_unreliable");
  41.170 +    ct = encrypted_msg->from->comm_type;
  41.171 +    TEST_ASSERT_MSG((ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed ), "ct == PEP_ct_pEp || ct == PEP_ct_pEp_unconfirmed || ct == PEP_ct_OpenPGP || ct == PEP_ct_OpenPGP_unconfirmed ");
  41.172 +
  41.173 +    cout << "keys used:\n";
  41.174 +
  41.175 +    for (stringlist_t* incoming_kl = extra_keys; incoming_kl && incoming_kl->value; incoming_kl = incoming_kl->next) {
  41.176 +        bool found = false;
  41.177 +        cout << "Encrypted for: ";
  41.178 +        for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++) {
  41.179 +            if (strcasecmp(incoming_kl->value, kl4->value) == 0) {
  41.180 +                cout << "\t " << kl4->value;
  41.181 +                found = true;
  41.182 +                break;
  41.183 +            }
  41.184 +        }
  41.185 +        cout << endl;
  41.186 +        TEST_ASSERT_MSG((found), "found");
  41.187 +    }
  41.188 +    cout << "Encrypted for all the extra keys!" << endl;
  41.189 +
  41.190 +    bool found = false;
  41.191 +    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next)
  41.192 +    {
  41.193 +        if (strcasecmp(alice_fpr, kl4->value) == 0) {
  41.194 +            found = true;
  41.195 +            cout << "Encrypted also for Alice! Yay!" << endl;
  41.196 +            break;
  41.197 +        }
  41.198 +    }
  41.199 +    TEST_ASSERT_MSG((found), "found");
  41.200 +
  41.201 +    free_message(encrypted_msg);
  41.202 +    encrypted_msg = NULL;
  41.203 +    free_message(decrypted_msg);
  41.204 +    decrypted_msg = NULL;
  41.205 +    free_stringlist(keylist_used);
  41.206 +    keylist_used = NULL;
  41.207 +
  41.208 +    cout << "Now add a bad fpr." << endl;
  41.209 +    
  41.210 +    stringlist_add(extra_keys, nobody_fpr);
  41.211 +    
  41.212 +    cout << "calling encrypt_message_for_identity()\n";
  41.213 +    status = encrypt_message_for_self(session, alice, outgoing_message, extra_keys, &encrypted_msg, PEP_enc_PGP_MIME, PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
  41.214 +    cout << "encrypt_message() returns " << tl_status_string(status) << '.' << endl;
  41.215 +    TEST_ASSERT_MSG((status != PEP_STATUS_OK), "status != PEP_STATUS_OK");
  41.216 +
  41.217 +    free_message(outgoing_message);
  41.218 +    outgoing_message = NULL;
  41.219 +    free_message(encrypted_msg);
  41.220 +    encrypted_msg = NULL;
  41.221 +    free_message(decrypted_msg);
  41.222 +    decrypted_msg = NULL;
  41.223 +    free_stringlist(keylist_used);
  41.224 +    keylist_used = NULL;
  41.225 +
  41.226 +
  41.227 +    cout << "*** Now testing MIME_encrypt_for_self ***" << endl;
  41.228 +
  41.229 +    alice = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
  41.230 +    bob = new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test");
  41.231 +
  41.232 +    cout << "Reading in alice_bob_encrypt_test_plaintext_mime.eml..." << endl;
  41.233 +    
  41.234 +    const string mimetext = slurp("test_mails/alice_bob_encrypt_test_plaintext_mime.eml");
  41.235 +
  41.236 +    cout << "Text read:" << endl;
  41.237 +    cout << mimetext.c_str() << endl;
  41.238 +    char* encrypted_mimetext = nullptr;
  41.239 +    
  41.240 +    cout << "Calling MIME_encrypt_message_for_self" << endl;
  41.241 +    status = MIME_encrypt_message_for_self(session, alice, mimetext.c_str(),
  41.242 +                                           mimetext.size(), 
  41.243 +                                           NULL,
  41.244 +                                           &encrypted_mimetext, 
  41.245 +                                           PEP_enc_PGP_MIME, 
  41.246 +                                           PEP_encrypt_flag_force_unsigned | PEP_encrypt_flag_force_no_attached_key);
  41.247 +    
  41.248 +    cout << "Encrypted message:" << endl;
  41.249 +    cout << encrypted_mimetext << endl;
  41.250 +
  41.251 +    cout << "Calling MIME_decrypt_message" << endl;
  41.252 +    
  41.253 +    char* decrypted_mimetext = nullptr;
  41.254 +    free_stringlist(keylist_used);
  41.255 +    keylist_used = nullptr;
  41.256 +    PEP_decrypt_flags_t mimeflags;
  41.257 +    PEP_rating mimerating;
  41.258 +    char* modified_src = NULL;
  41.259 +
  41.260 +    mimeflags = 0;
  41.261 +    status = MIME_decrypt_message(session,
  41.262 +                                  encrypted_mimetext,
  41.263 +                                  strlen(encrypted_mimetext),
  41.264 +                                  &decrypted_mimetext,
  41.265 +                                  &keylist_used,
  41.266 +                                  &mimerating,
  41.267 +                                  &mimeflags,
  41.268 +				  &modified_src);
  41.269 +
  41.270 +    TEST_ASSERT_MSG((decrypted_mimetext), "decrypted_mimetext");
  41.271 +    TEST_ASSERT_MSG((keylist_used), "keylist_used");
  41.272 +    TEST_ASSERT_MSG((mimerating), "mimerating");
  41.273 +                             
  41.274 +    TEST_ASSERT_MSG((status == PEP_DECRYPTED && mimerating == PEP_rating_unreliable), "status == PEP_DECRYPTED && mimerating == PEP_rating_unreliable");
  41.275 +
  41.276 +    cout << "Decrypted message:" << endl;
  41.277 +    cout << decrypted_mimetext << endl;
  41.278 +
  41.279 +    cout << "keys used:\n";
  41.280 +
  41.281 +    i = 0;
  41.282 +
  41.283 +    for (stringlist_t* kl4 = keylist_used; kl4 && kl4->value; kl4 = kl4->next, i++)
  41.284 +    {
  41.285 +        if (i == 0) {
  41.286 +            TEST_ASSERT_MSG((strcasecmp("",kl4->value) == 0), "strcasecmp(\"\",kl4->value) == 0");
  41.287 +        }
  41.288 +        else {
  41.289 +            cout << "\t " << kl4->value << endl;
  41.290 +            TEST_ASSERT_MSG((strcasecmp("4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", kl4->value) == 0), "strcasecmp(\"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\", kl4->value) == 0");
  41.291 +            cout << "Encrypted for Alice! Yay! It worked!" << endl;
  41.292 +        }
  41.293 +        TEST_ASSERT_MSG((i < 2), "i < 2");
  41.294 +    }
  41.295 +    cout << "Encrypted ONLY for Alice! Test passed. Move along. These are not the bugs you are looking for." << endl;
  41.296 +}
    42.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.2 +++ b/test/src/EncryptMissingPrivateKeyTests.cc	Mon Aug 26 13:38:21 2019 +0200
    42.3 @@ -0,0 +1,86 @@
    42.4 +// This file is under GNU General Public License 3.0
    42.5 +// see LICENSE.txt
    42.6 +
    42.7 +#include "TestConstants.h"
    42.8 +#include <stdlib.h>
    42.9 +#include <iostream>
   42.10 +#include <fstream>
   42.11 +#include <string>
   42.12 +#include <cstring> // for strcmp()
   42.13 +#include <assert.h>
   42.14 +#include <cpptest.h>
   42.15 +
   42.16 +#include "blacklist.h"
   42.17 +#include "keymanagement.h"
   42.18 +#include "message_api.h"
   42.19 +#include "mime.h"
   42.20 +#include "test_util.h"
   42.21 +
   42.22 +#include "pEpEngine.h"
   42.23 +
   42.24 +using namespace std;
   42.25 +
   42.26 +#include "EngineTestSessionSuite.h"
   42.27 +#include "EncryptMissingPrivateKeyTests.h"
   42.28 +
   42.29 +using namespace std;
   42.30 +
   42.31 +EncryptMissingPrivateKeyTests::EncryptMissingPrivateKeyTests(string suitename, string test_home_dir) :
   42.32 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
   42.33 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EncryptMissingPrivateKeyTests::check_encrypt_missing_private_key"),
   42.34 +                                                                      static_cast<Func>(&EncryptMissingPrivateKeyTests::check_encrypt_missing_private_key)));
   42.35 +}
   42.36 +
   42.37 +void EncryptMissingPrivateKeyTests::setup() {
   42.38 +    EngineTestSessionSuite::setup();
   42.39 +    string recip_key = slurp("test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");
   42.40 +    PEP_STATUS status = import_key(session, recip_key.c_str(), recip_key.size(), NULL);
   42.41 +    assert(status == PEP_TEST_KEY_IMPORT_SUCCESS);
   42.42 +}
   42.43 +
   42.44 +void EncryptMissingPrivateKeyTests::check_encrypt_missing_private_key() {
   42.45 +    
   42.46 +    pEp_identity* no_key_identity = new_identity("blacklistself@kgrothoff.org",
   42.47 +                                                      NULL,
   42.48 +                                                      PEP_OWN_USERID,
   42.49 +                                                      "Blacklist Self");
   42.50 +    no_key_identity->me = true;
   42.51 +    PEP_STATUS status8 = myself(session, no_key_identity);
   42.52 +    TEST_ASSERT (status8 == PEP_STATUS_OK);
   42.53 +
   42.54 +    /* Now let's try to encrypt a message. */
   42.55 +        
   42.56 +    message* tmp_msg = NULL;
   42.57 +    message* enc_msg = NULL;
   42.58 +    
   42.59 +    const string mailtext = slurp("test_mails/blacklist_no_key.eml");
   42.60 +
   42.61 +    PEP_STATUS status = mime_decode_message(mailtext.c_str(), mailtext.length(), &tmp_msg);
   42.62 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
   42.63 +    
   42.64 +    status = update_identity(session, tmp_msg->from);
   42.65 +    identity_list* to_list = tmp_msg->to;
   42.66 +
   42.67 +    while (to_list) {
   42.68 +        if (to_list->ident)
   42.69 +            update_identity(session, to_list->ident);
   42.70 +        to_list = to_list->next;
   42.71 +    }
   42.72 +    
   42.73 +    // This isn't incoming, though... so we need to reverse the direction
   42.74 +    tmp_msg->dir = PEP_dir_outgoing;
   42.75 +    status = encrypt_message(session,
   42.76 +                             tmp_msg,
   42.77 +                             NULL,
   42.78 +                             &enc_msg,
   42.79 +                             PEP_enc_PGP_MIME,
   42.80 +                             0);
   42.81 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), "status == PEP_STATUS_OK");
   42.82 +    
   42.83 +
   42.84 +    char* new_key = enc_msg->from->fpr;
   42.85 +    cout << "Encrypted with key " << new_key << endl;
   42.86 +    
   42.87 +    free_message(tmp_msg);    
   42.88 +    free_message(enc_msg);
   42.89 +}
    43.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.2 +++ b/test/src/Engine.cc	Mon Aug 26 13:38:21 2019 +0200
    43.3 @@ -0,0 +1,203 @@
    43.4 +#include <stdlib.h>
    43.5 +#include <sys/stat.h>
    43.6 +#include <errno.h>
    43.7 +#include <stdlib.h>
    43.8 +#include <unistd.h>
    43.9 +#include <ftw.h>
   43.10 +#include <assert.h>
   43.11 +#include <fstream>
   43.12 +#include <iostream>
   43.13 +#include <sys/types.h>
   43.14 +#include <sys/stat.h>
   43.15 +
   43.16 +#include <string>
   43.17 +#include <vector>
   43.18 +#include <utility>
   43.19 +
   43.20 +#include "platform_unix.h"
   43.21 +
   43.22 +#include "test_util.h"
   43.23 +#include "Engine.h"
   43.24 +#include "pEpTestStatic.h"
   43.25 +#include <algorithm>
   43.26 +#include "TestConstants.h"
   43.27 +
   43.28 +using namespace std;
   43.29 +
   43.30 +// Constructor
   43.31 +Engine::Engine(string engine_home_dir) {
   43.32 +    // FIXME: deal with base
   43.33 +    engine_home = engine_home_dir;
   43.34 +            
   43.35 +    real_home = getenv("HOME");
   43.36 +    cached_messageToSend = NULL;
   43.37 +    cached_inject_sync_event = NULL;
   43.38 +}
   43.39 +
   43.40 +Engine::~Engine() {}
   43.41 +
   43.42 +void Engine::prep(messageToSend_t mts, inject_sync_event_t ise, 
   43.43 +                  std::vector<std::pair<std::string, std::string>> init_files) {
   43.44 +    if (engine_home.empty())
   43.45 +        throw std::runtime_error("Engine setup: BAD INITIALISATION. No test home.");
   43.46 +    
   43.47 +    cached_messageToSend = mts;
   43.48 +    cached_inject_sync_event = ise;
   43.49 +
   43.50 +    int success = 0;
   43.51 +    struct stat dirchk;
   43.52 +        
   43.53 +    if (stat(engine_home.c_str(), &dirchk) == 0) {
   43.54 +        if (!S_ISDIR(dirchk.st_mode))
   43.55 +            throw std::runtime_error(("ENGINE SETUP: The test directory, " + engine_home + " exists, but is not a directory.").c_str()); 
   43.56 +                    
   43.57 +        struct stat buf;
   43.58 +
   43.59 +        if (stat(engine_home.c_str(), &buf) == 0) {
   43.60 +            int success = nftw((engine_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
   43.61 +        }
   43.62 +    }
   43.63 +    else {
   43.64 +        // Look, we're not creating all of these dirs...
   43.65 +        const int errchk = system((string("mkdir -p ") + engine_home).c_str());
   43.66 +        if (errchk != 0)
   43.67 +            throw std::runtime_error("ENGINE SETUP: Error creating a test directory.");        
   43.68 +    }
   43.69 +
   43.70 +    process_file_queue(engine_home, init_files);
   43.71 +
   43.72 +    // We will set homedirs etc outside this function. Right now, we're just making sure we can.
   43.73 +    // Let's make sure we're not trying to run it under the real current home, however.
   43.74 +    
   43.75 +    if (engine_home.compare(real_home) == 0 || engine_home.compare(real_home + "/") == 0)
   43.76 +        throw std::runtime_error("ENGINE SETUP: Cowardly refusing to set up for playing in what looks like the real home directory.");
   43.77 +    
   43.78 +}
   43.79 +
   43.80 +void Engine::start() {    
   43.81 +    if (engine_home.empty())
   43.82 +        throw std::runtime_error("Engine start: BAD INITIALISATION. No test home. Did you call Engine::prep() first?");
   43.83 +
   43.84 +    assert(engine_home.compare(real_home) != 0);
   43.85 +    assert(engine_home.compare(real_home + "/") != 0);
   43.86 +    cout << "Test home directory is " << engine_home << endl;
   43.87 +    
   43.88 +    int success = 0;
   43.89 +    
   43.90 +#ifdef USE_GPG
   43.91 +    char* tmp = NULL;
   43.92 +
   43.93 +    success = system("gpgconf --kill all");
   43.94 +    if (success != 0)
   43.95 +        throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");    
   43.96 +    tmp = getenv("GNUPGHOME");
   43.97 +
   43.98 +    prev_pgp_home.clear();
   43.99 +    
  43.100 +    if (tmp)
  43.101 +        prev_pgp_home = tmp;
  43.102 +
  43.103 +    if (engine_home.compare(real_home + "/gnupg") == 0 || engine_home.compare(real_home + "gnupg") == 0 ||
  43.104 +        engine_home.compare(real_home + "/.gnupg") == 0 || engine_home.compare(real_home + ".gnupg") == 0 ||
  43.105 +        engine_home.compare(prev_pgp_home) == 0 || engine_home.compare(prev_pgp_home + "/gnupg") == 0 ||
  43.106 +        engine_home.compare(prev_pgp_home + "gnupg") == 0 || engine_home.compare(prev_pgp_home + "/.gnupg") == 0 ||
  43.107 +        engine_home.compare(prev_pgp_home + ".gnupg") == 0)
  43.108 +        throw std::runtime_error("Engine start: new pgp homedir threatens to mess up user pgp homedir (and delete all their keys). NO DICE.");
  43.109 +    
  43.110 +    success = setenv("GNUPGHOME", (engine_home + "/gnupg").c_str(), 1);
  43.111 +    if (success != 0)
  43.112 +        throw std::runtime_error("SETUP: Error when setting GNUPGHOME.");
  43.113 +
  43.114 +    cout << "New GNUPGHOME is " << getenv("GNUPGHOME") << endl << endl;
  43.115 +
  43.116 +#endif
  43.117 +    
  43.118 +    success = setenv("HOME", engine_home.c_str(), 1);
  43.119 +    if (success != 0)
  43.120 +        throw std::runtime_error("SETUP: Cannot set engine_home for init.");
  43.121 +            
  43.122 +    unix_local_db(true);
  43.123 +    gpg_conf(true);
  43.124 +    gpg_agent_conf(true);
  43.125 +        
  43.126 +    PEP_STATUS status = init(&session, cached_messageToSend, cached_inject_sync_event);
  43.127 +    assert(status == PEP_STATUS_OK);
  43.128 +    assert(session);
  43.129 +
  43.130 +#ifdef USE_GPG
  43.131 +    success = system("gpgconf --create-socketdir");
  43.132 +    if (success != 0)
  43.133 +        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --create-socketdir'.");        
  43.134 +    system("gpg-connect-agent /bye 2>/dev/null");   // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
  43.135 +#endif
  43.136 +}
  43.137 +
  43.138 +void Engine::copy_conf_file_to_test_dir(const char* dest_path, const char* conf_orig_path, const char* conf_dest_name) {
  43.139 +    string conf_dest_path = dest_path;
  43.140 +    
  43.141 +    struct stat pathinfo;
  43.142 +
  43.143 +    if(stat(conf_dest_path.c_str(), &pathinfo) != 0) {
  43.144 +        int errchk = mkdir(conf_dest_path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  43.145 +        if (errchk != 0)
  43.146 +            throw std::runtime_error("Error accessing conf file directory.");
  43.147 +    }
  43.148 +    
  43.149 +    conf_dest_path += "/";
  43.150 +    conf_dest_path += conf_dest_name;
  43.151 +    
  43.152 +    ifstream src(conf_orig_path);
  43.153 +    ofstream dst(conf_dest_path.c_str(), ios::trunc);
  43.154 +    
  43.155 +    assert(src);
  43.156 +    assert(dst);
  43.157 +    
  43.158 +    dst << src.rdbuf();
  43.159 +     
  43.160 +    src.close();
  43.161 +    dst.close();
  43.162 +}
  43.163 +
  43.164 +void Engine::process_file_queue(string dirname, vector<pair<string, string>> file_queue) {
  43.165 +    if (file_queue.empty())
  43.166 +        return;
  43.167 +        
  43.168 +    vector<pair<string, string>>::iterator it;
  43.169 +    
  43.170 +    for (it = file_queue.begin(); it != file_queue.end(); it++) {
  43.171 +        copy_conf_file_to_test_dir(dirname.c_str(), it->first.c_str(), it->second.c_str());
  43.172 +    }
  43.173 +    
  43.174 +    file_queue.clear();
  43.175 +}
  43.176 +
  43.177 +void Engine::shut_down() {
  43.178 +    release(session);
  43.179 +    session = NULL;
  43.180 +        
  43.181 +    int success = 0;    
  43.182 +
  43.183 +#ifdef USE_GPG 
  43.184 +    success = system("gpgconf --kill all");
  43.185 +    if (success != 0)
  43.186 +        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --kill all'.");
  43.187 +    success = system("gpgconf --remove-socketdir");            
  43.188 +    if (success != 0)
  43.189 +        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --remove-socketdir'.");    
  43.190 +
  43.191 +    success = setenv("GNUPGHOME", prev_pgp_home.c_str(), 1);
  43.192 +    if (success != 0)
  43.193 +        throw std::runtime_error("RESTORE: Warning - cannot restore GNUPGHOME. Either set environment variable manually back to your home, or quit this session!");
  43.194 +#endif
  43.195 +                
  43.196 +    success = nftw((engine_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
  43.197 +    
  43.198 +    success = setenv("HOME", real_home.c_str(), 1);
  43.199 +    if (success != 0)
  43.200 +        throw std::runtime_error("RESTORE: Cannot reset home directory! Either set environment variable manually back to your home, or quit this session!");
  43.201 +
  43.202 +    unix_local_db(true);
  43.203 +    gpg_conf(true);
  43.204 +    gpg_agent_conf(true);
  43.205 +
  43.206 +}
    44.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.2 +++ b/test/src/Engine.h	Mon Aug 26 13:38:21 2019 +0200
    44.3 @@ -0,0 +1,34 @@
    44.4 +#ifndef ENGINE_TEST_SUITE_H
    44.5 +#define ENGINE_TEST_SUITE_H
    44.6 +
    44.7 +#include <string>
    44.8 +#include <map>
    44.9 +#include <vector>
   44.10 +#include <utility>
   44.11 +#include "pEpEngine.h"
   44.12 +
   44.13 +using namespace std;
   44.14 +
   44.15 +class Engine {
   44.16 +    public:
   44.17 +        Engine(string engine_home_dir);
   44.18 +        virtual ~Engine();
   44.19 +        
   44.20 +        void prep(messageToSend_t mts, inject_sync_event_t ise, std::vector<std::pair<std::string, std::string>> init_files);
   44.21 +        void start();
   44.22 +        void shut_down();
   44.23 +
   44.24 +        PEP_SESSION session;
   44.25 +        
   44.26 +    protected:
   44.27 +        string engine_home;
   44.28 +        string real_home;
   44.29 +        string prev_pgp_home;
   44.30 +        
   44.31 +        messageToSend_t cached_messageToSend;
   44.32 +        inject_sync_event_t cached_inject_sync_event;
   44.33 +        	
   44.34 +        void copy_conf_file_to_test_dir(const char* dest_path, const char* conf_orig_path, const char* conf_dest_name);        
   44.35 +        void process_file_queue(std::string dirname, std::vector<std::pair<std::string, std::string>> file_queue);
   44.36 +};
   44.37 +#endif
    45.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.2 +++ b/test/src/Engine358Tests.cc	Mon Aug 26 13:38:21 2019 +0200
    45.3 @@ -0,0 +1,55 @@
    45.4 +// This file is under GNU General Public License 3.0
    45.5 +// see LICENSE.txt
    45.6 +
    45.7 +#include "TestConstants.h"
    45.8 +#include <stdlib.h>
    45.9 +#include <string>
   45.10 +#include <cstring>
   45.11 +#include <cpptest.h>
   45.12 +
   45.13 +#include "pEpEngine.h"
   45.14 +
   45.15 +#include "test_util.h"
   45.16 +#include "EngineTestIndividualSuite.h"
   45.17 +#include "Engine358Tests.h"
   45.18 +
   45.19 +using namespace std;
   45.20 +
   45.21 +Engine358Tests::Engine358Tests(string suitename, string test_home_dir) :
   45.22 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
   45.23 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("Engine358Tests::check_engine358"),
   45.24 +                                                                      static_cast<Func>(&Engine358Tests::check_engine358)));
   45.25 +}
   45.26 +
   45.27 +void Engine358Tests::check_engine358() {
   45.28 +    bool ok = false;
   45.29 +    ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   45.30 +    TEST_ASSERT(ok);    
   45.31 +    ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
   45.32 +    TEST_ASSERT(ok);
   45.33 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
   45.34 +    TEST_ASSERT(ok);
   45.35 +
   45.36 +    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
   45.37 +    pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
   45.38 +
   45.39 +    PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
   45.40 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   45.41 +
   45.42 +    pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
   45.43 +    message* msg = new_message(PEP_dir_outgoing);    
   45.44 +
   45.45 +    msg->from = alice_from;
   45.46 +    msg->to = new_identity_list(expired_inquisitor);
   45.47 +    msg->shortmsg = strdup("Blah!");
   45.48 +    msg->longmsg = strdup("Blahblahblah!");
   45.49 +    msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   45.50 +
   45.51 +    message* enc_msg = NULL;
   45.52 +    
   45.53 +    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
   45.54 +    TEST_ASSERT(!enc_msg);
   45.55 +    TEST_ASSERT(msg->to && msg->to->ident);
   45.56 +    TEST_ASSERT_MSG((status == PEP_UNENCRYPTED), tl_status_string(status));
   45.57 +}
   45.58 +
    46.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.2 +++ b/test/src/Engine463Tests.cc	Mon Aug 26 13:38:21 2019 +0200
    46.3 @@ -0,0 +1,173 @@
    46.4 +// This file is under GNU General Public License 3.0
    46.5 +// see LICENSE.txt
    46.6 +
    46.7 +#include "TestConstants.h"
    46.8 +#include <stdlib.h>
    46.9 +#include <string>
   46.10 +
   46.11 +#include "pEpEngine.h"
   46.12 +#include "pEp_internal.h"
   46.13 +#include "test_util.h"
   46.14 +#include "message.h"
   46.15 +
   46.16 +#include "EngineTestIndividualSuite.h"
   46.17 +#include "Engine463Tests.h"
   46.18 +
   46.19 +using namespace std;
   46.20 +
   46.21 +Engine463Tests::Engine463Tests(string suitename, string test_home_dir) :
   46.22 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
   46.23 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("Engine463Tests::check_engine_463_no_own_key"),
   46.24 +                                                                      static_cast<Func>(&Engine463Tests::check_engine_463_no_own_key)));
   46.25 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("Engine463Tests::check_engine_463_own_key"),
   46.26 +                                                                      static_cast<Func>(&Engine463Tests::check_engine_463_own_key)));                                                                  
   46.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("Engine463Tests::check_engine_463_sender_expired_and_renewed"),
   46.28 +                                                                      static_cast<Func>(&Engine463Tests::check_engine_463_sender_expired_and_renewed)));                                                                                                                                    
   46.29 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("Engine463Tests::check_engine_463_reply_recip_expired_and_renewed"),
   46.30 +                                                                      static_cast<Func>(&Engine463Tests::check_engine_463_reply_recip_expired_and_renewed)));                                                                                                                                    
   46.31 +}
   46.32 +
   46.33 +void Engine463Tests::check_engine_463_no_own_key() {
   46.34 +    const string claudio_keys = slurp("test_keys/priv/notfound-alt-pub_and_private.asc");
   46.35 +    const string fake_schleuder_key = slurp("test_keys/pub/fake-schleuder.asc");
   46.36 +    
   46.37 +    PEP_STATUS status = import_key(session, claudio_keys.c_str(), claudio_keys.length(), NULL);
   46.38 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), tl_status_string(status));    
   46.39 +    status = import_key(session, fake_schleuder_key.c_str(), fake_schleuder_key.length(), NULL);
   46.40 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), tl_status_string(status));    
   46.41 +
   46.42 +    // Ok, bring in message, decrypt, and see what happens.
   46.43 +    const string msg = slurp("test_mails/notfound-alt.msg");
   46.44 +
   46.45 +    char* decrypted_msg = NULL;
   46.46 +    stringlist_t* keylist_used = nullptr;
   46.47 +    char* modified_src = NULL;
   46.48 +    
   46.49 +    PEP_rating rating;
   46.50 +    PEP_decrypt_flags_t flags = 0;
   46.51 +     
   46.52 +    status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
   46.53 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   46.54 +}
   46.55 +
   46.56 +void Engine463Tests::check_engine_463_own_key() {
   46.57 +    const string claudio_keys = slurp("test_keys/priv/notfound-alt-pub_and_private.asc");
   46.58 +    const string fake_schleuder_key = slurp("test_keys/pub/fake-schleuder.asc");
   46.59 +    
   46.60 +    PEP_STATUS status = import_key(session, claudio_keys.c_str(), claudio_keys.length(), NULL);
   46.61 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), tl_status_string(status));    
   46.62 +    status = import_key(session, fake_schleuder_key.c_str(), fake_schleuder_key.length(), NULL);
   46.63 +    TEST_ASSERT_MSG((status == PEP_TEST_KEY_IMPORT_SUCCESS), tl_status_string(status));    
   46.64 +
   46.65 +    pEp_identity* own_ident = new_identity("claudio+engine-463@pep.foundation", "A039BC60E43E0DFDDC9DE8663B48C38325210C88", PEP_OWN_USERID, "Not Actually Claudio");
   46.66 +    status = set_own_key(session, own_ident, "A039BC60E43E0DFDDC9DE8663B48C38325210C88");
   46.67 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));    
   46.68 +
   46.69 +    // Ok, bring in message, decrypt, and see what happens.
   46.70 +    const string msg = slurp("test_mails/notfound-alt.msg");
   46.71 +
   46.72 +    char* decrypted_msg = NULL;
   46.73 +    stringlist_t* keylist_used = nullptr;
   46.74 +    char* modified_src = NULL;
   46.75 +    
   46.76 +    PEP_rating rating;
   46.77 +    PEP_decrypt_flags_t flags = 0;
   46.78 +     
   46.79 +    status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
   46.80 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   46.81 +}
   46.82 +
   46.83 +void Engine463Tests::check_engine_463_sender_expired_and_renewed() {
   46.84 +    bool ok = false;
   46.85 +    ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   46.86 +    TEST_ASSERT(ok);    
   46.87 +    ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
   46.88 +    TEST_ASSERT(ok);
   46.89 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
   46.90 +    TEST_ASSERT(ok);
   46.91 +
   46.92 +    // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
   46.93 +    // the expired key:
   46.94 +    const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
   46.95 +    
   46.96 +    char* decrypted_msg = NULL;
   46.97 +    stringlist_t* keylist_used = nullptr;
   46.98 +    char* modified_src = NULL;
   46.99 +    
  46.100 +    PEP_rating rating;
  46.101 +    PEP_decrypt_flags_t flags = 0;
  46.102 +     
  46.103 +    PEP_STATUS status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
  46.104 +    TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
  46.105 +
  46.106 +    free(decrypted_msg);
  46.107 +    decrypted_msg = NULL;
  46.108 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
  46.109 +    TEST_ASSERT(ok);    
  46.110 +
  46.111 +    pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
  46.112 +    
  46.113 +    status = identity_rating(session, expired_inquisitor, &rating);
  46.114 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  46.115 +    TEST_ASSERT_MSG((rating == PEP_rating_reliable), tl_rating_string(rating));
  46.116 +        
  46.117 +    flags = 0;
  46.118 +    
  46.119 +    status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);    
  46.120 +    TEST_ASSERT(decrypted_msg);
  46.121 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  46.122 +    TEST_ASSERT_MSG((rating == PEP_rating_reliable), tl_rating_string(rating));
  46.123 +
  46.124 +    free_identity(expired_inquisitor);
  46.125 +
  46.126 +}
  46.127 +
  46.128 + void Engine463Tests::check_engine_463_reply_recip_expired_and_renewed() {
  46.129 +    bool ok = false;
  46.130 +    ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
  46.131 +    TEST_ASSERT(ok);    
  46.132 +    ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
  46.133 +    TEST_ASSERT(ok);
  46.134 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
  46.135 +    TEST_ASSERT(ok);
  46.136 +
  46.137 +    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
  46.138 +    pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
  46.139 +
  46.140 +    PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
  46.141 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  46.142 +
  46.143 +    // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
  46.144 +    // the expired key:
  46.145 +    const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
  46.146 +    
  46.147 +    char* decrypted_msg = NULL;
  46.148 +    stringlist_t* keylist_used = nullptr;
  46.149 +    char* modified_src = NULL;
  46.150 +    
  46.151 +    PEP_rating rating;
  46.152 +    PEP_decrypt_flags_t flags = 0;
  46.153 +     
  46.154 +    status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
  46.155 +    TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
  46.156 +
  46.157 +    free(decrypted_msg);
  46.158 +    decrypted_msg = NULL;
  46.159 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
  46.160 +    TEST_ASSERT(ok);    
  46.161 +
  46.162 +    pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
  46.163 +    message* msg2 = new_message(PEP_dir_outgoing);    
  46.164 +
  46.165 +    msg2->from = alice_from;
  46.166 +    msg2->to = new_identity_list(expired_inquisitor);
  46.167 +    msg2->shortmsg = strdup("Blah!");
  46.168 +    msg2->longmsg = strdup("Blahblahblah!");
  46.169 +    msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  46.170 +
  46.171 +    status = outgoing_message_rating(session, msg2, &rating);
  46.172 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  46.173 +    TEST_ASSERT_MSG((rating == PEP_rating_reliable), tl_rating_string(rating));    
  46.174 +
  46.175 +    free_message(msg2);
  46.176 +}
    47.1 --- a/test/src/EngineTestIndividualSuite.cc	Mon Aug 26 12:41:39 2019 +0200
    47.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.3 @@ -1,31 +0,0 @@
    47.4 -#include "TestConstants.h"
    47.5 -#include <cpptest.h>
    47.6 -#include <cpptest-suite.h>
    47.7 -#include <cpptest-textoutput.h>
    47.8 -#include <stdlib.h>
    47.9 -#include <unistd.h>
   47.10 -#include <ftw.h>
   47.11 -
   47.12 -#include "EngineTestSuite.h"
   47.13 -#include "EngineTestIndividualSuite.h"
   47.14 -
   47.15 -using namespace std;
   47.16 -
   47.17 -// Constructor
   47.18 -EngineTestIndividualSuite::EngineTestIndividualSuite(string suitename, string test_home_dir) 
   47.19 -    : EngineTestSuite(suitename, test_home_dir) { 
   47.20 -}
   47.21 -
   47.22 -EngineTestIndividualSuite::~EngineTestIndividualSuite() {
   47.23 -    
   47.24 -}
   47.25 -
   47.26 -void EngineTestIndividualSuite::setup() {
   47.27 -    EngineTestSuite::setup();
   47.28 -    set_full_env(); // This will be called by default before every test
   47.29 -}
   47.30 -
   47.31 -void EngineTestIndividualSuite::tear_down() {
   47.32 -    restore_full_env();
   47.33 -    EngineTestSuite::tear_down();
   47.34 -}
    48.1 --- a/test/src/EngineTestSessionSuite.cc	Mon Aug 26 12:41:39 2019 +0200
    48.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.3 @@ -1,31 +0,0 @@
    48.4 -#include <cpptest.h>
    48.5 -#include "TestConstants.h"
    48.6 -#include <cpptest-suite.h>
    48.7 -#include <cpptest-textoutput.h>
    48.8 -#include <stdlib.h>
    48.9 -#include <unistd.h>
   48.10 -#include <ftw.h>
   48.11 -
   48.12 -#include "EngineTestSuite.h"
   48.13 -#include "EngineTestSessionSuite.h"
   48.14 -
   48.15 -using namespace std;
   48.16 -
   48.17 -// Constructor
   48.18 -EngineTestSessionSuite::EngineTestSessionSuite(string suitename, string test_home_dir) 
   48.19 -    : EngineTestSuite(suitename, test_home_dir) {}
   48.20 -
   48.21 -EngineTestSessionSuite::~EngineTestSessionSuite() {}
   48.22 -
   48.23 -void EngineTestSessionSuite::setup() {
   48.24 -    EngineTestSuite::setup();
   48.25 -    if (on_test_number == 1)
   48.26 -        set_full_env();
   48.27 -}
   48.28 -
   48.29 -void EngineTestSessionSuite::tear_down() {
   48.30 -    if (on_test_number == number_of_tests)
   48.31 -        restore_full_env();
   48.32 -        
   48.33 -    EngineTestSuite::tear_down();
   48.34 -}
    49.1 --- a/test/src/EngineTestSuite.cc	Mon Aug 26 12:41:39 2019 +0200
    49.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.3 @@ -1,280 +0,0 @@
    49.4 -#include <stdlib.h>
    49.5 -#include <sys/stat.h>
    49.6 -#include <errno.h>
    49.7 -#include <stdlib.h>
    49.8 -#include <unistd.h>
    49.9 -#include <ftw.h>
   49.10 -#include <assert.h>
   49.11 -#include <fstream>
   49.12 -#include <iostream>
   49.13 -#include <sys/types.h>
   49.14 -#include <sys/stat.h>
   49.15 -#include <cpptest.h>
   49.16 -
   49.17 -#include <string>
   49.18 -#include <vector>
   49.19 -#include <utility>
   49.20 -
   49.21 -#include "platform_unix.h"
   49.22 -
   49.23 -#include "test_util.h"
   49.24 -#include "EngineTestSuite.h"
   49.25 -#include "pEpTestStatic.h"
   49.26 -#include <algorithm>
   49.27 -#include "TestConstants.h"
   49.28 -
   49.29 -using namespace std;
   49.30 -
   49.31 -// Constructor
   49.32 -EngineTestSuite::EngineTestSuite(string suitename, string test_home_dir) {
   49.33 -    // FIXME: deal with base
   49.34 -    test_home = test_home_dir;
   49.35 -            
   49.36 -    number_of_tests = 0;
   49.37 -    on_test_number = 0;
   49.38 -    real_home = getenv("HOME");
   49.39 -    cached_messageToSend = NULL;
   49.40 -    cached_inject_sync_event = NULL;
   49.41 -}
   49.42 -
   49.43 -EngineTestSuite::~EngineTestSuite() {}
   49.44 -
   49.45 -void EngineTestSuite::add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()> test_func) {
   49.46 -    test_map.insert(test_func);
   49.47 -    register_test(test_func.second, test_func.first);
   49.48 -    number_of_tests++;
   49.49 -}
   49.50 -
   49.51 -void EngineTestSuite::copy_conf_file_to_test_dir(const char* dest_path, const char* conf_orig_path, const char* conf_dest_name) {
   49.52 -    string conf_dest_path = dest_path;
   49.53 -    
   49.54 -    struct stat pathinfo;
   49.55 -
   49.56 -    if(stat(conf_dest_path.c_str(), &pathinfo) != 0) {
   49.57 -        int errchk = mkdir(conf_dest_path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
   49.58 -        if (errchk != 0)
   49.59 -            throw std::runtime_error("Error accessing conf file directory.");
   49.60 -    }
   49.61 -    
   49.62 -    conf_dest_path += "/";
   49.63 -    conf_dest_path += conf_dest_name;
   49.64 -    
   49.65 -    ifstream src(conf_orig_path);
   49.66 -    ofstream dst(conf_dest_path.c_str(), ios::trunc);
   49.67 -    
   49.68 -    assert(src);
   49.69 -    assert(dst);
   49.70 -    
   49.71 -    dst << src.rdbuf();
   49.72 -     
   49.73 -    src.close();
   49.74 -    dst.close();
   49.75 -}
   49.76 -
   49.77 -void EngineTestSuite::add_file_to_gpg_dir_queue(string copy_from, string dst_fname) {    
   49.78 -    gpgdir_fileadd_queue.push_back(make_pair(copy_from, dst_fname));
   49.79 -}
   49.80 -
   49.81 -void EngineTestSuite::add_file_to_home_dir_queue(string copy_from, string dst_fname) {
   49.82 -    homedir_fileadd_queue.push_back(make_pair(copy_from, dst_fname));
   49.83 -}
   49.84 -
   49.85 -void EngineTestSuite::process_file_queue(string dirname, vector<pair<string, string>> file_queue) {
   49.86 -    if (file_queue.empty())
   49.87 -        return;
   49.88 -        
   49.89 -    vector<pair<string, string>>::iterator it;
   49.90 -    
   49.91 -    for (it = file_queue.begin(); it != file_queue.end(); it++) {
   49.92 -        copy_conf_file_to_test_dir(dirname.c_str(), it->first.c_str(), it->second.c_str());
   49.93 -    }
   49.94 -    
   49.95 -    file_queue.clear();
   49.96 -}
   49.97 -
   49.98 -void EngineTestSuite::set_full_env() {
   49.99 -    set_full_env(NULL, NULL, NULL);
  49.100 -}
  49.101 -
  49.102 -void EngineTestSuite::set_full_env(const char* gpg_conf_copy_path, const char* gpg_agent_conf_file_copy_path, const char* db_conf_file_copy_path) {
  49.103 -    int success = 0;
  49.104 -    struct stat dirchk;
  49.105 -    
  49.106 -    set_my_name();
  49.107 -
  49.108 -// FIXME
  49.109 -#ifndef USE_NETPGP
  49.110 -#ifndef USE_SEQUOIA
  49.111 -    success = system("gpgconf --kill all");
  49.112 -    if (success != 0)
  49.113 -        throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");    
  49.114 -#endif
  49.115 -#endif
  49.116 -
  49.117 -    if (stat(test_home.c_str(), &dirchk) == 0) {
  49.118 -        if (!S_ISDIR(dirchk.st_mode))
  49.119 -            throw std::runtime_error(("The test directory, " + test_home + "exists, but is not a directory.").c_str()); 
  49.120 -                    
  49.121 -        struct stat buf;
  49.122 -
  49.123 -        if (stat(test_home.c_str(), &buf) == 0) {
  49.124 -            int success = nftw((test_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
  49.125 -        }
  49.126 -    }
  49.127 -    else {
  49.128 -        int errchk = mkdir(test_home.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  49.129 -        cout << errchk << endl;
  49.130 -        if (errchk != 0)
  49.131 -            throw std::runtime_error("Error creating a test directory.");
  49.132 -    }
  49.133 -
  49.134 -    if (my_name.size() > pEpTestStatic::classname_chars)
  49.135 -        my_name.resize(pEpTestStatic::classname_chars);
  49.136 -
  49.137 -    if (on_test_number > pEpTestStatic::max_test_num) {
  49.138 -        cerr << "Warning - there are at least " << pEpTestStatic::max_test_num << " tests in this suite. While this probably won't cause "
  49.139 -             << endl << "problems, there is an obscure possibility that if your test path is REALLY REALLY LONG, tests will fail because gpg-agent "
  49.140 -             << endl << "won't start with huge paths. In general, however, we stop well before these limits, and pEpTestStatic::testnum_path_chars "
  49.141 -             << endl << "is overly conservative, so you probably don't need to worry." << endl;
  49.142 -    }    
  49.143 -
  49.144 -    temp_test_home = test_home + "/" + my_name;
  49.145 -    
  49.146 -    int errchk = mkdir(temp_test_home.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  49.147 -    if (errchk != 0 && errno != EEXIST)
  49.148 -        throw std::runtime_error("Error creating a test directory.");
  49.149 -
  49.150 -    temp_test_home += "/" + to_string(on_test_number);
  49.151 -
  49.152 -    errchk = mkdir(temp_test_home.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  49.153 -    if (errchk != 0)
  49.154 -        throw std::runtime_error("Error creating a test directory.");
  49.155 -
  49.156 -    // TODO: This is *nix specific, which the current testing env is anyway,
  49.157 -    // but it needn't remain so forever and always
  49.158 -
  49.159 -    string home = getenv("HOME");
  49.160 -
  49.161 -    char* tmp = NULL;
  49.162 -    
  49.163 -    tmp = getenv("GNUPGHOME");
  49.164 -
  49.165 -    prev_pgp_home.clear();
  49.166 -    
  49.167 -    if (tmp)
  49.168 -        prev_pgp_home = tmp;
  49.169 -        
  49.170 -    if (temp_test_home.empty())
  49.171 -        throw std::runtime_error("SETUP: BAD INITIALISATION. No test home.");
  49.172 -    
  49.173 -    assert(temp_test_home.compare(home) != 0);
  49.174 -    assert(temp_test_home.compare(home + "/") != 0);
  49.175 -    assert(temp_test_home.compare(home + "/.gnupg") != 0); // This is an EXCLUSION test, so we leave this.
  49.176 -    assert(temp_test_home.compare(home + ".gnupg") != 0);
  49.177 -    assert(temp_test_home.compare(home + "/gnupg") != 0);
  49.178 -    assert(temp_test_home.compare(home + "gnupg") != 0);
  49.179 -    assert(temp_test_home.compare(prev_pgp_home) != 0);
  49.180 -    assert(temp_test_home.compare(prev_pgp_home + "/gnupg") != 0);
  49.181 -    assert(temp_test_home.compare(prev_pgp_home + "gnupg") != 0);
  49.182 -    assert(temp_test_home.compare(prev_pgp_home + "/.gnupg") != 0);
  49.183 -    assert(temp_test_home.compare(prev_pgp_home + ".gnupg") != 0);
  49.184 -
  49.185 -    if (temp_test_home.compare(home) == 0 || temp_test_home.compare(home + "/") == 0 ||
  49.186 -        temp_test_home.compare(home + "/gnupg") == 0 || temp_test_home.compare(home + "gnupg") == 0 ||
  49.187 -        temp_test_home.compare(home + "/.gnupg") == 0 || temp_test_home.compare(home + ".gnupg") == 0 ||
  49.188 -        temp_test_home.compare(prev_pgp_home) == 0 || temp_test_home.compare(prev_pgp_home + "/gnupg") == 0 ||
  49.189 -        temp_test_home.compare(prev_pgp_home + "gnupg") == 0 || temp_test_home.compare(prev_pgp_home + "/.gnupg") == 0 ||
  49.190 -        temp_test_home.compare(prev_pgp_home + ".gnupg") == 0)
  49.191 -        throw std::runtime_error("SETUP: new pgp homedir threatens to mess up user pgp homedir (and delete all their keys). NO DICE.");
  49.192 -    
  49.193 -//    cout << "Ok - checked if new test home will be safe. We'll try and make the directory, deleting it if it has already exists." << endl;
  49.194 -    cout << "Test home directory is " << temp_test_home << endl;
  49.195 -    
  49.196 -    struct stat buf;
  49.197 -    
  49.198 -    success = setenv("GNUPGHOME", (temp_test_home + "/gnupg").c_str(), 1);
  49.199 -    if (success != 0)
  49.200 -        throw std::runtime_error("SETUP: Error when setting GNUPGHOME.");
  49.201 -
  49.202 -    cout << "New GNUPGHOME is " << getenv("GNUPGHOME") << endl << endl;
  49.203 -    
  49.204 -    success = setenv("HOME", temp_test_home.c_str(), 1);
  49.205 -    if (success != 0)
  49.206 -        throw std::runtime_error("SETUP: Cannot set test_home for init.");
  49.207 -
  49.208 -    string tmp_gpg_dir = temp_test_home + "/.gnupg";
  49.209 -
  49.210 -    process_file_queue(tmp_gpg_dir, gpgdir_fileadd_queue);
  49.211 -    process_file_queue(temp_test_home, homedir_fileadd_queue);
  49.212 -
  49.213 -    if (gpg_conf_copy_path)
  49.214 -        copy_conf_file_to_test_dir((temp_test_home + "/gnupg").c_str(), gpg_conf_copy_path, "gpg.conf");
  49.215 -    if (gpg_agent_conf_file_copy_path)        
  49.216 -        copy_conf_file_to_test_dir((temp_test_home + "/gnupg").c_str(), gpg_agent_conf_file_copy_path, "gpg-agent.conf");
  49.217 -    if (db_conf_file_copy_path)
  49.218 -        copy_conf_file_to_test_dir(temp_test_home.c_str(), db_conf_file_copy_path, ".pEp_management.db");
  49.219 -        
  49.220 -    unix_local_db(true);
  49.221 -    gpg_conf(true);
  49.222 -    gpg_agent_conf(true);
  49.223 -    
  49.224 -//    cout << "calling init()\n";
  49.225 -    PEP_STATUS status = init(&session, cached_messageToSend, cached_inject_sync_event);
  49.226 -#ifndef USE_NETPGP
  49.227 -#ifndef USE_SEQUOIA
  49.228 -    success = system("gpgconf --create-socketdir");
  49.229 -    if (success != 0)
  49.230 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --create-socketdir'.");        
  49.231 -    system("gpg-connect-agent /bye 2>/dev/null");   // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
  49.232 -#endif
  49.233 -#endif
  49.234 -
  49.235 -    assert(status == PEP_STATUS_OK);
  49.236 -    assert(session);
  49.237 -//    cout << "init() completed.\n";
  49.238 -
  49.239 -}
  49.240 -
  49.241 -void EngineTestSuite::restore_full_env() {
  49.242 -    release(session);
  49.243 -    session = NULL;
  49.244 -        
  49.245 -    int success = 0;    
  49.246 -
  49.247 -#ifndef USE_NETPGP 
  49.248 -#ifndef USE_SEQUOIA
  49.249 -    success = system("gpgconf --kill all");
  49.250 -    if (success != 0)
  49.251 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --kill all'.");
  49.252 -    success = system("gpgconf --remove-socketdir");            
  49.253 -    if (success != 0)
  49.254 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --remove-socketdir'.");    
  49.255 -#endif
  49.256 -#endif
  49.257 -
  49.258 -    success = setenv("GNUPGHOME", prev_pgp_home.c_str(), 1);
  49.259 -    if (success != 0)
  49.260 -        throw std::runtime_error("RESTORE: Warning - cannot restore GNUPGHOME. Either set environment variable manually back to your home, or quit this session!");
  49.261 -                
  49.262 -    success = nftw((test_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
  49.263 -    
  49.264 -    success = setenv("HOME", real_home.c_str(), 1);
  49.265 -    if (success != 0)
  49.266 -        throw std::runtime_error("RESTORE: Cannot reset home directory! Either set environment variable manually back to your home, or quit this session!");
  49.267 -    // else
  49.268 -    //     cout << "RESTORE: HOME is now " << getenv("HOME") << endl;
  49.269 -    unix_local_db(true);
  49.270 -    gpg_conf(true);
  49.271 -    gpg_agent_conf(true);
  49.272 -
  49.273 -}
  49.274 -
  49.275 -void EngineTestSuite::setup() {
  49.276 -    on_test_number++;
  49.277 -}
  49.278 -
  49.279 -void EngineTestSuite::tear_down() {}
  49.280 -
  49.281 -void EngineTestSuite::set_my_name() {
  49.282 -    my_name = typeid(*this).name();
  49.283 -}
    50.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.2 +++ b/test/src/EnterLeaveDeviceGroupTests.cc	Mon Aug 26 13:38:21 2019 +0200
    50.3 @@ -0,0 +1,969 @@
    50.4 +// This file is under GNU General Public License 3.0
    50.5 +// see LICENSE.txt
    50.6 +
    50.7 +#include <stdlib.h>
    50.8 +#include <string>
    50.9 +#include <cstring>
   50.10 +
   50.11 +#include "pEpEngine.h"
   50.12 +
   50.13 +#include "test_util.h"
   50.14 +#include "sync_api.h"
   50.15 +#include <cpptest.h>
   50.16 +#include "EngineTestIndividualSuite.h"
   50.17 +#include "EnterLeaveDeviceGroupTests.h"
   50.18 +
   50.19 +using namespace std;
   50.20 +
   50.21 +EnterLeaveDeviceGroupTests::EnterLeaveDeviceGroupTests(string suitename, string test_home_dir) :
   50.22 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
   50.23 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_no_own"),
   50.24 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_no_own)));
   50.25 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_empty"),
   50.26 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_empty)));
   50.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_one"),
   50.28 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_one)));
   50.29 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_one_reversed_by_many"),
   50.30 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_reversed_by_many)));
   50.31 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_not_me"),
   50.32 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_not_me)));
   50.33 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_many_w_not_me"),
   50.34 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_many_w_not_me)));
   50.35 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_many_empty"),
   50.36 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_many_empty)));
   50.37 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_add_explicit"),
   50.38 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_add_explicit)));
   50.39 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_one"),
   50.40 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_one)));
   50.41 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many"),
   50.42 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many)));
   50.43 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many_w_not_me"),
   50.44 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many_w_not_me)));
   50.45 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_leave_device_group_empty"),
   50.46 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_leave_device_group_empty)));
   50.47 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_leave_device_group_sole"),
   50.48 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_leave_device_group_sole)));
   50.49 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_leave_device_group_one_in_one_out"),
   50.50 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_leave_device_group_one_in_one_out)));
   50.51 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_leave_device_group_three_in"),
   50.52 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_leave_device_group_three_in)));
   50.53 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_leave_device_group_two_in_one_out"),
   50.54 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_leave_device_group_two_in_one_out)));
   50.55 +}
   50.56 +
   50.57 +void EnterLeaveDeviceGroupTests::check_enter_device_group_no_own() {    
   50.58 +    pEp_identity* alice_id = NULL;
   50.59 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"));
   50.60 +    PEP_STATUS status = set_up_ident_from_scratch(session,
   50.61 +                                "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
   50.62 +                                "pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", 
   50.63 +                                "ALICE", "Alice in Wonderland", &alice_id, false
   50.64 +                        );
   50.65 +                        
   50.66 +    TEST_ASSERT(status == PEP_STATUS_OK);
   50.67 +    status = enter_device_group(session, NULL);
   50.68 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   50.69 +    
   50.70 +    status = update_identity(session, alice_id);
   50.71 +    TEST_ASSERT(!(alice_id->flags & PEP_idf_devicegroup));
   50.72 +    
   50.73 +    free_identity(alice_id);
   50.74 +    TEST_ASSERT(true);
   50.75 +}
   50.76 +
   50.77 +void EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_empty() {    
   50.78 +    pEp_identity* alice_id = NULL;
   50.79 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"));    
   50.80 +    PEP_STATUS status = set_up_ident_from_scratch(session,
   50.81 +                                "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
   50.82 +                                "pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", 
   50.83 +                                "ALICE", "Alice in Wonderland", &alice_id, true
   50.84 +                        );    
   50.85 +
   50.86 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   50.87 +    status = myself(session, alice_id);
   50.88 +    TEST_ASSERT(status == PEP_STATUS_OK);
   50.89 +    TEST_ASSERT(alice_id->me);
   50.90 +    TEST_ASSERT(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
   50.91 +
   50.92 +    pEp_identity* bob_id = NULL;
   50.93 +    status = set_up_ident_from_scratch(session,
   50.94 +                                "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc",
   50.95 +                                "pep.test.bob@pep-project.org", "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", 
   50.96 +                                "BOB", "Bob is not Alice", &bob_id, false
   50.97 +                        );    
   50.98 +    status = update_identity(session, bob_id);
   50.99 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  50.100 +
  50.101 +    status = enter_device_group(session, NULL);
  50.102 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  50.103 +    
  50.104 +    status = myself(session, alice_id);
  50.105 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  50.106 +    TEST_ASSERT_MSG(alice_id->flags & PEP_idf_devicegroup, tl_ident_flags_String(alice_id->flags).c_str());
  50.107 +
  50.108 +    status = update_identity(session, bob_id);
  50.109 +    TEST_ASSERT_MSG(!(bob_id->flags & PEP_idf_devicegroup), tl_ident_flags_String(alice_id->flags).c_str());
  50.110 +
  50.111 +    free_identity(alice_id);
  50.112 +    free_identity(bob_id);
  50.113 +    TEST_ASSERT(true);
  50.114 +}
  50.115 +
  50.116 +void EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_one() {    
  50.117 +    pEp_identity* alice_id = NULL;
  50.118 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"));    
  50.119 +    PEP_STATUS status = set_up_ident_from_scratch(session,
  50.120 +                                "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
  50.121 +                                "pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", 
  50.122 +                                "ALICE", "Alice in Wonderland", &alice_id, true
  50.123 +                        );    
  50.124 +
  50.125 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  50.126 +    status = myself(session, alice_id);
  50.127 +
  50.128 +    TEST_ASSERT(alice_id->me);
  50.129 +    TEST_ASSERT(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
  50.130 +    identity_list* ids_to_group = new_identity_list(alice_id);
  50.131 +    status = enter_device_group(session, ids_to_group);
  50.132 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  50.133 +    
  50.134 +    status = myself(session, alice_id);
  50.135 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  50.136 +    TEST_ASSERT_MSG(alice_id->flags & PEP_idf_devicegroup, tl_ident_flags_String(alice_id->flags).c_str());
  50.137 +                        
  50.138 +    free_identity(alice_id);                        
  50.139 +}
  50.140 +
  50.141 +void EnterLeaveDeviceGroupTests::check_enter_device_group_one_reversed_by_many() {    
  50.142 +    pEp_identity* alice_id = NULL;
  50.143 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"));    
  50.144 +    PEP_STATUS status = set_up_ident_from_scratch(session,
  50.145 +                                "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
  50.146 +                                "pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", 
  50.147 +                                "ALICE", "Alice in Wonderland", &alice_id, true
  50.148 +                        );    
  50.149 +
  50.150 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  50.151 +    status = myself(session, alice_id);
  50.152 +
  50.153 +    pEp_identity* alice_id2 = NULL;
  50.154 +    status = set_up_ident_from_scratch(session,
  50.155 +                                "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
  50.156 +                                "pep.test.alice_2@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", 
  50.157 +                                "ALICE", "Bob is Alice", &alice_id2, true
  50.158 +                        );    
  50.159 +
  50.160 +    pEp_identity* alice_id3 = NULL;
  50.161 +    status = set_up_ident_from_scratch(session,
  50.162 +                                "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
  50.163 +                                "pep.test.alice_3@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", 
  50.164 +                                "ALICE", "Carol is Alice", &alice_id3, true
  50.165 +                        );    
  50.166 +
  50.167 +    // First, add Alice to device group and ensure the other two are not added
  50.168 +    identity_list* ids_to_group = new_identity_list(alice_id);
  50.169 +    status = enter_device_group(session, ids_to_group);
  50.170 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  50.171 +
  50.172 +    status = myself(session, alice_id);
  50.173 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  50.174 +    TEST_ASSERT_MSG(alice_id->flags & PEP_idf_devicegroup, tl_ident_flags_String(alice_id->flags).c_str());
  50.175 +    
  50.176 +    status = myself(session, alice_id2);
  50.177 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  50.178 +    TEST_ASSERT_MSG(!(alice_id2->flags & PEP_idf_devicegroup), tl_ident_flags_String(alice_id2->flags).c_str());
  50.179 +
  50.180 +    status = myself(session, alice_id3);
  50.181 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  50.182 +    TEST_ASSERT_MSG(!(alice_id3->flags & PEP_idf_devicegroup), tl_ident_flags_String(alice_id3->flags).c_str());
  50.183 +
  50.184 +    // Note: this is a shortcut to omit alice_id from ident list
  50.185 +    ids_to_group->ident = alice_id2;
  50.186 +    
  50.187 +    identity_list_add(ids_to_group, alice_id3);
  50.188 +    
  50.189 +    // Add 2 and 3 to device group (hopefully removing alice_id)
  50.190 +    status = enter_device_group(session, ids_to_group);
  50.191 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  50.192 +
  50.193 +    // Is alice_id in? (shouldn't be)
  50.194 +    status = myself(session, alice_id);
  50.195 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  50.196 +    TEST_ASSERT_MSG(!(alice_id->flags & PEP_idf_devicegroup), tl_ident_flags_String(alice_id->flags).c_str());
  50.197 +    
  50.198 +    // are 2 and 3 in? (should be)
  50.199 +    status = myself(session, alice_id2);
  50.200 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  50.201 +    TEST_ASSERT_MSG(alice_id2->flags & PEP_idf_devicegroup, tl_ident_flags_String(alice_id2->flags).c_str());
  50.202 +
  50.203 +    status = myself(session, alice_id3);
  50.204 +    TEST_ASSERT(status == PEP_STATUS_OK);    
  50.205 +    TEST_ASSERT_MSG(alice_id3->flags & PEP_idf_devicegroup, tl_ident_flags_String(alice_id3->flags).c_str());
  50.206 +                        
  50.207 +    free_identity_list(ids_to_group);
  50.208 +    free_identity(alice_id);
  50.209 +}