Browse Source

ENGINE-533 (ENGINE-531), ENGINE-348: Fixed bugs with identity flags

pEpMIME_windows
parent
commit
f60686fb61
8 changed files with 191 additions and 28 deletions
  1. +28
    -24
      src/keymanagement.c
  2. +2
    -2
      src/pEpEngine.c
  3. +28
    -0
      test/include/EnterLeaveDeviceGroupTests.h
  4. +1
    -1
      test/include/locked_queue.hh
  5. +2
    -0
      test/include/test_util.h
  6. +5
    -1
      test/src/SuiteMaker.cc
  7. +113
    -0
      test/src/engine_tests/EnterLeaveDeviceGroupTests.cc
  8. +12
    -0
      test/src/util/test_util.cc

+ 28
- 24
src/keymanagement.c View File

@ -1124,36 +1124,40 @@ PEP_STATUS _myself(PEP_SESSION session,
}
// check stored identity
if (stored_identity && !EMPTYSTR(stored_identity->fpr)) {
// Fall back / retrieve
status = validate_fpr(session, stored_identity, false, true);
if (status == PEP_OUT_OF_MEMORY)
goto pEp_free;
if (status == PEP_STATUS_OK) {
if (stored_identity->comm_type >= PEP_ct_strong_but_unconfirmed) {
identity->fpr = strdup(stored_identity->fpr);
assert(identity->fpr);
if (!identity->fpr) {
status = PEP_OUT_OF_MEMORY;
goto pEp_free;
}
valid_key_found = true;
}
else {
bool revoked = false;
status = key_revoked(session, stored_identity->fpr, &revoked);
if (status)
goto pEp_free;
if (revoked) {
revoked_fpr = strdup(stored_identity->fpr);
assert(revoked_fpr);
if (!revoked_fpr) {
if (stored_identity) {
if (!EMPTYSTR(stored_identity->fpr)) {
// Fall back / retrieve
status = validate_fpr(session, stored_identity, false, true);
if (status == PEP_OUT_OF_MEMORY)
goto pEp_free;
if (status == PEP_STATUS_OK) {
if (stored_identity->comm_type >= PEP_ct_strong_but_unconfirmed) {
identity->fpr = strdup(stored_identity->fpr);
assert(identity->fpr);
if (!identity->fpr) {
status = PEP_OUT_OF_MEMORY;
goto pEp_free;
}
valid_key_found = true;
}
else {
bool revoked = false;
status = key_revoked(session, stored_identity->fpr, &revoked);
if (status)
goto pEp_free;
if (revoked) {
revoked_fpr = strdup(stored_identity->fpr);
assert(revoked_fpr);
if (!revoked_fpr) {
status = PEP_OUT_OF_MEMORY;
goto pEp_free;
}
}
}
}
}
// reconcile language, flags
transfer_ident_lang_and_flags(identity, stored_identity);
}
// Nothing left to do but generate a key


+ 2
- 2
src/pEpEngine.c View File

@ -271,7 +271,7 @@ static const char* sql_update_identity_entry =
static const char *sql_set_identity_flags =
"update identity set flags = "
" ((?1 & 255) | (select flags from identity"
" ((?1 & 65535) | (select flags from identity"
" where (case when (address = ?2) then (1)"
" when (lower(address) = lower(?2)) then (1)"
" when (replace(lower(address),'.','') = replace(lower(?2),'.','')) then (1)"
@ -287,7 +287,7 @@ static const char *sql_set_identity_flags =
static const char *sql_unset_identity_flags =
"update identity set flags = "
" ( ~(?1 & 255) & (select flags from identity"
" ( ~(?1 & 65535) & (select flags from identity"
" where (case when (address = ?2) then (1)"
" when (lower(address) = lower(?2)) then (1)"
" when (replace(lower(address),'.','') = replace(lower(?2),'.','')) then (1)"


+ 28
- 0
test/include/EnterLeaveDeviceGroupTests.h View File

@ -0,0 +1,28 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef ENTER_LEAVE_DEVICE_GROUP_H
#define ENTER_LEAVE_DEVICE_GROUP_H
#include <string>
#include "EngineTestIndividualSuite.h"
using namespace std;
class EnterLeaveDeviceGroupTests : public EngineTestIndividualSuite {
public:
EnterLeaveDeviceGroupTests(string test_suite, string test_home_dir);
private:
void check_enter_device_group_no_own();
void check_enter_device_group_one_own_empty();
void check_enter_device_group_one_own_one();
void check_enter_device_group_one_own_many();
void check_enter_device_group_one_own_single_not_me();
void check_enter_device_group_one_own_single_many_w_not_me();
void check_enter_device_group_many_empty();
void check_enter_device_group_many_own_one();
void check_enter_device_group_many_own_many();
void check_enter_device_group_many_own_many_w_not_me();
};
#endif

+ 1
- 1
test/include/locked_queue.hh View File

@ -58,4 +58,4 @@ namespace utility
return _q.empty();
}
};
};
}

+ 2
- 0
test/include/test_util.h View File

@ -44,6 +44,8 @@ const char* tl_ct_string(PEP_comm_type ct);
// Returns the string value of the input status enum value.
const char* tl_status_string(PEP_STATUS status);
std::string tl_ident_flags_String(identity_flags_t fl);
// Grabs a new uuid for your randomish string needs.
char* get_new_uuid();


+ 5
- 1
test/src/SuiteMaker.cc View File

@ -32,6 +32,7 @@
#include "EncryptMissingPrivateKeyTests.h"
#include "CaseAndDotAddressTests.h"
#include "UserIDAliasTests.h"
#include "EnterLeaveDeviceGroupTests.h"
#include "SignOnlyTests.h"
#include "BCCTests.h"
#include "Engine358Tests.h"
@ -85,6 +86,7 @@ const char* SuiteMaker::all_suites[] = {
"EncryptMissingPrivateKeyTests",
"CaseAndDotAddressTests",
"UserIDAliasTests",
"EnterLeaveDeviceGroupTests",
"SignOnlyTests",
"BCCTests",
"Engine358Tests",
@ -118,7 +120,7 @@ const char* SuiteMaker::all_suites[] = {
};
// This file is generated, so magic constants are ok.
int SuiteMaker::num_suites = 50;
int SuiteMaker::num_suites = 51;
void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
if (strcmp(test_class_name, "MimeTests") == 0)
@ -161,6 +163,8 @@ void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_
*test_suite = new CaseAndDotAddressTests(test_class_name, test_home);
else if (strcmp(test_class_name, "UserIDAliasTests") == 0)
*test_suite = new UserIDAliasTests(test_class_name, test_home);
else if (strcmp(test_class_name, "EnterLeaveDeviceGroupTests") == 0)
*test_suite = new EnterLeaveDeviceGroupTests(test_class_name, test_home);
else if (strcmp(test_class_name, "SignOnlyTests") == 0)
*test_suite = new SignOnlyTests(test_class_name, test_home);
else if (strcmp(test_class_name, "BCCTests") == 0)


+ 113
- 0
test/src/engine_tests/EnterLeaveDeviceGroupTests.cc View File

@ -0,0 +1,113 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include <stdlib.h>
#include <string>
#include <cstring>
#include "pEpEngine.h"
#include "test_util.h"
#include "sync_api.h"
#include <cpptest.h>
#include "EngineTestIndividualSuite.h"
#include "EnterLeaveDeviceGroupTests.h"
using namespace std;
EnterLeaveDeviceGroupTests::EnterLeaveDeviceGroupTests(string suitename, string test_home_dir) :
EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_no_own"),
static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_no_own)));
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_empty"),
static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_empty)));
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_one"),
static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_one)));
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_many"),
static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_many)));
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_not_me"),
static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_not_me)));
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_many_w_not_me"),
static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_many_w_not_me)));
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_many_empty"),
static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_many_empty)));
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_one"),
static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_one)));
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many"),
static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many)));
add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many_w_not_me"),
static_cast<Func>(&EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many_w_not_me)));
}
void EnterLeaveDeviceGroupTests::check_enter_device_group_no_own() {
pEp_identity* alice_id = NULL;
PEP_STATUS status = set_up_ident_from_scratch(session,
"test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
"pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97",
"ALICE", "Alice in Wonderland", &alice_id, false
);
TEST_ASSERT(status == PEP_STATUS_OK);
status = enter_device_group(session, NULL);
TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
status = update_identity(session, alice_id);
TEST_ASSERT(!(alice_id->flags & PEP_idf_devicegroup));
TEST_ASSERT(true);
}
void EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_empty() {
pEp_identity* alice_id = NULL;
PEP_STATUS status = set_up_ident_from_scratch(session,
"test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
"pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97",
"ALICE", "Alice in Wonderland", &alice_id, true
);
TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
status = myself(session, alice_id);
TEST_ASSERT(alice_id->me);
TEST_ASSERT(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
status = enter_device_group(session, NULL);
TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
status = myself(session, alice_id);
TEST_ASSERT(status == PEP_STATUS_OK);
TEST_ASSERT_MSG(alice_id->flags & PEP_idf_devicegroup, tl_ident_flags_String(alice_id->flags).c_str());
TEST_ASSERT(true);
}
void EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_one() {
TEST_ASSERT(true);
}
void EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_many() {
TEST_ASSERT(true);
}
void EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_not_me() {
TEST_ASSERT(true);
}
void EnterLeaveDeviceGroupTests::check_enter_device_group_one_own_single_many_w_not_me() {
TEST_ASSERT(true);
}
void EnterLeaveDeviceGroupTests::check_enter_device_group_many_empty() {
TEST_ASSERT(true);
}
void EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_one() {
TEST_ASSERT(true);
}
void EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many() {
TEST_ASSERT(true);
}
void EnterLeaveDeviceGroupTests::check_enter_device_group_many_own_many_w_not_me() {
TEST_ASSERT(true);
}

+ 12
- 0
test/src/util/test_util.cc View File

@ -381,6 +381,18 @@ const char* tl_ct_string(PEP_comm_type ct) {
}
}
std::string tl_ident_flags_String(identity_flags_t fl) {
std::string retval;
if (fl & PEP_idf_not_for_sync) // don't use this identity for sync
retval += " PEP_idf_not_for_sync";
if (fl & PEP_idf_list) // identity of list of persons
retval += " PEP_idf_list";
if (fl & PEP_idf_devicegroup)
retval += "PEP_idf_devicegroup";
if (retval.empty())
return std::string("PEP_idf_OMGWTFBBQ");
return retval;
}
bool slurp_and_import_key(PEP_SESSION session, const char* key_filename) {
std::string keyfile = slurp(key_filename);
if (import_key(session, keyfile.c_str(), keyfile.size(), NULL) != PEP_TEST_KEY_IMPORT_SUCCESS)


Loading…
Cancel
Save