ENGINE-533 (ENGINE-531), ENGINE-348: Fixed bugs with identity flags sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Fri, 29 Mar 2019 16:31:16 +0100
branchsync
changeset 342209bec729847d
parent 3421 d7fc3647f02b
child 3425 495866c118e7
ENGINE-533 (ENGINE-531), ENGINE-348: Fixed bugs with identity flags
src/keymanagement.c
src/pEpEngine.c
test/include/EnterLeaveDeviceGroupTests.h
test/include/locked_queue.hh
test/include/test_util.h
test/src/SuiteMaker.cc
test/src/engine_tests/EnterLeaveDeviceGroupTests.cc
test/src/util/test_util.cc
     1.1 --- a/src/keymanagement.c	Fri Mar 29 14:07:40 2019 +0100
     1.2 +++ b/src/keymanagement.c	Fri Mar 29 16:31:16 2019 +0100
     1.3 @@ -1124,36 +1124,40 @@
     1.4      }
     1.5  
     1.6      // check stored identity
     1.7 -    if (stored_identity && !EMPTYSTR(stored_identity->fpr)) {
     1.8 -        // Fall back / retrieve
     1.9 -        status = validate_fpr(session, stored_identity, false, true);
    1.10 -        if (status == PEP_OUT_OF_MEMORY)
    1.11 -            goto pEp_free;
    1.12 -        if (status == PEP_STATUS_OK) {
    1.13 -            if (stored_identity->comm_type >= PEP_ct_strong_but_unconfirmed) {
    1.14 -                identity->fpr = strdup(stored_identity->fpr);
    1.15 -                assert(identity->fpr);
    1.16 -                if (!identity->fpr) {
    1.17 -                    status = PEP_OUT_OF_MEMORY;
    1.18 -                    goto pEp_free;
    1.19 -                }
    1.20 -                valid_key_found = true;            
    1.21 -            }
    1.22 -            else {
    1.23 -                bool revoked = false;
    1.24 -                status = key_revoked(session, stored_identity->fpr, &revoked);
    1.25 -                if (status)
    1.26 -                    goto pEp_free;
    1.27 -                if (revoked) {
    1.28 -                    revoked_fpr = strdup(stored_identity->fpr);
    1.29 -                    assert(revoked_fpr);
    1.30 -                    if (!revoked_fpr) {
    1.31 +    if (stored_identity) {
    1.32 +        if (!EMPTYSTR(stored_identity->fpr)) {
    1.33 +            // Fall back / retrieve
    1.34 +            status = validate_fpr(session, stored_identity, false, true);
    1.35 +            if (status == PEP_OUT_OF_MEMORY)
    1.36 +                goto pEp_free;
    1.37 +            if (status == PEP_STATUS_OK) {
    1.38 +                if (stored_identity->comm_type >= PEP_ct_strong_but_unconfirmed) {
    1.39 +                    identity->fpr = strdup(stored_identity->fpr);
    1.40 +                    assert(identity->fpr);
    1.41 +                    if (!identity->fpr) {
    1.42                          status = PEP_OUT_OF_MEMORY;
    1.43                          goto pEp_free;
    1.44                      }
    1.45 +                    valid_key_found = true;            
    1.46 +                }
    1.47 +                else {
    1.48 +                    bool revoked = false;
    1.49 +                    status = key_revoked(session, stored_identity->fpr, &revoked);
    1.50 +                    if (status)
    1.51 +                        goto pEp_free;
    1.52 +                    if (revoked) {
    1.53 +                        revoked_fpr = strdup(stored_identity->fpr);
    1.54 +                        assert(revoked_fpr);
    1.55 +                        if (!revoked_fpr) {
    1.56 +                            status = PEP_OUT_OF_MEMORY;
    1.57 +                            goto pEp_free;
    1.58 +                        }
    1.59 +                    }
    1.60                  }
    1.61              }
    1.62          }
    1.63 +        // reconcile language, flags
    1.64 +        transfer_ident_lang_and_flags(identity, stored_identity);
    1.65      }
    1.66      
    1.67      // Nothing left to do but generate a key
     2.1 --- a/src/pEpEngine.c	Fri Mar 29 14:07:40 2019 +0100
     2.2 +++ b/src/pEpEngine.c	Fri Mar 29 16:31:16 2019 +0100
     2.3 @@ -271,7 +271,7 @@
     2.4          
     2.5  static const char *sql_set_identity_flags = 
     2.6      "update identity set flags = "
     2.7 -    "    ((?1 & 255) | (select flags from identity"
     2.8 +    "    ((?1 & 65535) | (select flags from identity"
     2.9      "                    where (case when (address = ?2) then (1)"
    2.10      "                                when (lower(address) = lower(?2)) then (1)"
    2.11      "                                when (replace(lower(address),'.','') = replace(lower(?2),'.','')) then (1)"
    2.12 @@ -287,7 +287,7 @@
    2.13  
    2.14  static const char *sql_unset_identity_flags = 
    2.15      "update identity set flags = "
    2.16 -    "    ( ~(?1 & 255) & (select flags from identity"
    2.17 +    "    ( ~(?1 & 65535) & (select flags from identity"
    2.18      "                    where (case when (address = ?2) then (1)"
    2.19      "                                when (lower(address) = lower(?2)) then (1)"
    2.20      "                                when (replace(lower(address),'.','') = replace(lower(?2),'.','')) then (1)"
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/include/EnterLeaveDeviceGroupTests.h	Fri Mar 29 16:31:16 2019 +0100
     3.3 @@ -0,0 +1,28 @@
     3.4 +// This file is under GNU General Public License 3.0
     3.5 +// see LICENSE.txt
     3.6 +
     3.7 +#ifndef ENTER_LEAVE_DEVICE_GROUP_H
     3.8 +#define ENTER_LEAVE_DEVICE_GROUP_H
     3.9 +
    3.10 +#include <string>
    3.11 +#include "EngineTestIndividualSuite.h"
    3.12 +
    3.13 +using namespace std;
    3.14 +
    3.15 +class EnterLeaveDeviceGroupTests : public EngineTestIndividualSuite {
    3.16 +    public:
    3.17 +        EnterLeaveDeviceGroupTests(string test_suite, string test_home_dir);
    3.18 +    private:
    3.19 +        void check_enter_device_group_no_own();    
    3.20 +        void check_enter_device_group_one_own_empty();    
    3.21 +        void check_enter_device_group_one_own_one();    
    3.22 +        void check_enter_device_group_one_own_many();    
    3.23 +        void check_enter_device_group_one_own_single_not_me();    
    3.24 +        void check_enter_device_group_one_own_single_many_w_not_me();    
    3.25 +        void check_enter_device_group_many_empty();    
    3.26 +        void check_enter_device_group_many_own_one();    
    3.27 +        void check_enter_device_group_many_own_many();    
    3.28 +        void check_enter_device_group_many_own_many_w_not_me();    
    3.29 +};
    3.30 +
    3.31 +#endif
     4.1 --- a/test/include/locked_queue.hh	Fri Mar 29 14:07:40 2019 +0100
     4.2 +++ b/test/include/locked_queue.hh	Fri Mar 29 16:31:16 2019 +0100
     4.3 @@ -58,4 +58,4 @@
     4.4              return _q.empty();
     4.5          }
     4.6      };
     4.7 -};
     4.8 +}
     5.1 --- a/test/include/test_util.h	Fri Mar 29 14:07:40 2019 +0100
     5.2 +++ b/test/include/test_util.h	Fri Mar 29 16:31:16 2019 +0100
     5.3 @@ -44,6 +44,8 @@
     5.4  // Returns the string value of the input status enum value. 
     5.5  const char* tl_status_string(PEP_STATUS status);
     5.6  
     5.7 +std::string tl_ident_flags_String(identity_flags_t fl);
     5.8 +
     5.9  // Grabs a new uuid for your randomish string needs.
    5.10  char* get_new_uuid();
    5.11  
     6.1 --- a/test/src/SuiteMaker.cc	Fri Mar 29 14:07:40 2019 +0100
     6.2 +++ b/test/src/SuiteMaker.cc	Fri Mar 29 16:31:16 2019 +0100
     6.3 @@ -32,6 +32,7 @@
     6.4  #include "EncryptMissingPrivateKeyTests.h"
     6.5  #include "CaseAndDotAddressTests.h"
     6.6  #include "UserIDAliasTests.h"
     6.7 +#include "EnterLeaveDeviceGroupTests.h"
     6.8  #include "SignOnlyTests.h"
     6.9  #include "BCCTests.h"
    6.10  #include "Engine358Tests.h"
    6.11 @@ -85,6 +86,7 @@
    6.12      "EncryptMissingPrivateKeyTests",
    6.13      "CaseAndDotAddressTests",
    6.14      "UserIDAliasTests",
    6.15 +    "EnterLeaveDeviceGroupTests",
    6.16      "SignOnlyTests",
    6.17      "BCCTests",
    6.18      "Engine358Tests",
    6.19 @@ -118,7 +120,7 @@
    6.20  };
    6.21  
    6.22  // This file is generated, so magic constants are ok.
    6.23 -int SuiteMaker::num_suites = 50;
    6.24 +int SuiteMaker::num_suites = 51;
    6.25  
    6.26  void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
    6.27      if (strcmp(test_class_name, "MimeTests") == 0)
    6.28 @@ -161,6 +163,8 @@
    6.29          *test_suite = new CaseAndDotAddressTests(test_class_name, test_home);
    6.30      else if (strcmp(test_class_name, "UserIDAliasTests") == 0)
    6.31          *test_suite = new UserIDAliasTests(test_class_name, test_home);
    6.32 +    else if (strcmp(test_class_name, "EnterLeaveDeviceGroupTests") == 0)
    6.33 +        *test_suite = new EnterLeaveDeviceGroupTests(test_class_name, test_home);
    6.34      else if (strcmp(test_class_name, "SignOnlyTests") == 0)
    6.35          *test_suite = new SignOnlyTests(test_class_name, test_home);
    6.36      else if (strcmp(test_class_name, "BCCTests") == 0)
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/src/engine_tests/EnterLeaveDeviceGroupTests.cc	Fri Mar 29 16:31:16 2019 +0100
     7.3 @@ -0,0 +1,113 @@
     7.4 +// This file is under GNU General Public License 3.0
     7.5 +// see LICENSE.txt
     7.6 +
     7.7 +#include <stdlib.h>
     7.8 +#include <string>
     7.9 +#include <cstring>
    7.10 +
    7.11 +#include "pEpEngine.h"
    7.12 +
    7.13 +#include "test_util.h"
    7.14 +#include "sync_api.h"
    7.15 +#include <cpptest.h>
    7.16 +#include "EngineTestIndividualSuite.h"
    7.17 +#include "EnterLeaveDeviceGroupTests.h"
    7.18 +
    7.19 +using namespace std;
    7.20 +
    7.21 +EnterLeaveDeviceGroupTests::EnterLeaveDeviceGroupTests(string suitename, string test_home_dir) :
    7.22 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
    7.23 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_no_own"),
    7.24 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_no_own)));
    7.25 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_empty"),
    7.26 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_empty)));
    7.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_one"),
    7.28 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_one)));
    7.29 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_many"),
    7.30 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_many)));
    7.31 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_not_me"),
    7.32 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_not_me)));
    7.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"),
    7.34 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_many_w_not_me)));
    7.35 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_many_empty"),
    7.36 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_many_empty)));
    7.37 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_one"),
    7.38 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_one)));
    7.39 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many"),
    7.40 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many)));
    7.41 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many_w_not_me"),
    7.42 +                                                                      static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many_w_not_me)));
    7.43 +}
    7.44 +
    7.45 +void EnterLeaveDeviceGroupTests::check_enter_device_group_no_own() {    
    7.46 +    pEp_identity* alice_id = NULL;
    7.47 +    PEP_STATUS status = set_up_ident_from_scratch(session,
    7.48 +                                "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
    7.49 +                                "pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", 
    7.50 +                                "ALICE", "Alice in Wonderland", &alice_id, false
    7.51 +                        );
    7.52 +                        
    7.53 +    TEST_ASSERT(status == PEP_STATUS_OK);
    7.54 +    status = enter_device_group(session, NULL);
    7.55 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    7.56 +    
    7.57 +    status = update_identity(session, alice_id);
    7.58 +    TEST_ASSERT(!(alice_id->flags & PEP_idf_devicegroup));
    7.59 +
    7.60 +    TEST_ASSERT(true);
    7.61 +}
    7.62 +
    7.63 +void EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_empty() {    
    7.64 +    pEp_identity* alice_id = NULL;
    7.65 +    PEP_STATUS status = set_up_ident_from_scratch(session,
    7.66 +                                "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
    7.67 +                                "pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", 
    7.68 +                                "ALICE", "Alice in Wonderland", &alice_id, true
    7.69 +                        );    
    7.70 +
    7.71 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    7.72 +    status = myself(session, alice_id);
    7.73 +
    7.74 +    TEST_ASSERT(alice_id->me);
    7.75 +    TEST_ASSERT(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
    7.76 +    status = enter_device_group(session, NULL);
    7.77 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    7.78 +    
    7.79 +    status = myself(session, alice_id);
    7.80 +    TEST_ASSERT(status == PEP_STATUS_OK);    
    7.81 +    TEST_ASSERT_MSG(alice_id->flags & PEP_idf_devicegroup, tl_ident_flags_String(alice_id->flags).c_str());
    7.82 +                        
    7.83 +    TEST_ASSERT(true);
    7.84 +}
    7.85 +
    7.86 +void EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_one() {    
    7.87 +    TEST_ASSERT(true);
    7.88 +}
    7.89 +
    7.90 +void EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_many() {    
    7.91 +    TEST_ASSERT(true);
    7.92 +}
    7.93 +
    7.94 +void EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_not_me() {    
    7.95 +    TEST_ASSERT(true);
    7.96 +}
    7.97 +
    7.98 +void EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_many_w_not_me() {    
    7.99 +    TEST_ASSERT(true);
   7.100 +}
   7.101 +
   7.102 +void EnterLeaveDeviceGroupTests::check_enter_device_group_many_empty() {    
   7.103 +    TEST_ASSERT(true);
   7.104 +}
   7.105 +
   7.106 +void EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_one() {    
   7.107 +    TEST_ASSERT(true);
   7.108 +}
   7.109 +
   7.110 +void EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many() {    
   7.111 +    TEST_ASSERT(true);
   7.112 +}
   7.113 +
   7.114 +void EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many_w_not_me() {    
   7.115 +    TEST_ASSERT(true);
   7.116 +}
     8.1 --- a/test/src/util/test_util.cc	Fri Mar 29 14:07:40 2019 +0100
     8.2 +++ b/test/src/util/test_util.cc	Fri Mar 29 16:31:16 2019 +0100
     8.3 @@ -381,6 +381,18 @@
     8.4      }
     8.5  }
     8.6  
     8.7 +std::string tl_ident_flags_String(identity_flags_t fl) {
     8.8 +    std::string retval;
     8.9 +    if (fl & PEP_idf_not_for_sync)   // don't use this identity for sync
    8.10 +        retval += " PEP_idf_not_for_sync";
    8.11 +    if (fl & PEP_idf_list)           // identity of list of persons
    8.12 +        retval += " PEP_idf_list";
    8.13 +    if (fl & PEP_idf_devicegroup)
    8.14 +        retval += "PEP_idf_devicegroup";
    8.15 +    if (retval.empty())
    8.16 +        return std::string("PEP_idf_OMGWTFBBQ");
    8.17 +    return retval;
    8.18 +}
    8.19  bool slurp_and_import_key(PEP_SESSION session, const char* key_filename) {
    8.20      std::string keyfile = slurp(key_filename);
    8.21      if (import_key(session, keyfile.c_str(), keyfile.size(), NULL) != PEP_TEST_KEY_IMPORT_SUCCESS)