Browse Source

ENGINE-767: fixed get_identities/update_identity stuff - doouble check more in the morning. Partial test.

test-README.md
parent
commit
956baab8e2
5 changed files with 210 additions and 13 deletions
  1. +1
    -1
      src/keymanagement.c
  2. +6
    -4
      src/message_api.c
  3. +17
    -7
      src/pEpEngine.c
  4. +2
    -1
      src/pEpEngine.h
  5. +184
    -0
      test/src/IdentEncFormatTest.cc

+ 1
- 1
src/keymanagement.c View File

@ -574,6 +574,7 @@ static PEP_STATUS prepare_updated_identity(PEP_SESSION session,
}
transfer_ident_lang_and_flags(return_id, stored_ident);
return_id->enc_format = stored_ident->enc_format;
if (return_id->comm_type == PEP_ct_unknown)
return_id->comm_type = PEP_ct_key_not_found;
@ -2124,4 +2125,3 @@ PEP_STATUS clean_own_key_defaults(PEP_SESSION session) {
}
return status;
}

+ 6
- 4
src/message_api.c View File

@ -2027,14 +2027,16 @@ DYNAMIC_API PEP_STATUS encrypt_message(
if (max_version_major == 1)
force_v_1 = true;
if (enc_format == PEP_enc_none) {
if (enc_format == PEP_enc_auto) {
update_encryption_format(src->to, &enc_format);
if (enc_format == PEP_enc_none && src->cc)
if (enc_format == PEP_enc_auto && src->cc)
update_encryption_format(src->cc, &enc_format);
if (enc_format == PEP_enc_none && src->bcc)
if (enc_format == PEP_enc_auto && src->bcc)
update_encryption_format(src->bcc, &enc_format);
if (enc_format == PEP_enc_auto)
enc_format = PEP_enc_PEP;
}
else {
else if (enc_format != PEP_enc_none) {
status = id_list_set_enc_format(session, src->to, enc_format);
status = ((status != PEP_STATUS_OK || !(src->cc)) ? status : id_list_set_enc_format(session, src->cc, enc_format));
status = ((status != PEP_STATUS_OK || !(src->bcc)) ? status : id_list_set_enc_format(session, src->bcc, enc_format));


+ 17
- 7
src/pEpEngine.c View File

@ -82,7 +82,7 @@ static const char *sql_trustword =
static const char *sql_get_identity =
"select identity.main_key_id, username, comm_type, lang,"
" identity.flags | pgp_keypair.flags,"
" is_own, pEp_version_major, pEp_version_minor"
" is_own, pEp_version_major, pEp_version_minor, enc_format"
" from identity"
" join person on id = identity.user_id"
" left join pgp_keypair on fpr = identity.main_key_id"
@ -100,7 +100,7 @@ static const char *sql_get_identity =
static const char *sql_get_identities_by_main_key_id =
"select address, identity.user_id, username, comm_type, lang,"
" identity.flags | pgp_keypair.flags,"
" is_own, pEp_version_major, pEp_version_minor"
" is_own, pEp_version_major, pEp_version_minor, enc_format"
" from identity"
" join person on id = identity.user_id"
" left join pgp_keypair on fpr = identity.main_key_id"
@ -112,7 +112,7 @@ static const char *sql_get_identities_by_main_key_id =
static const char *sql_get_identity_without_trust_check =
"select identity.main_key_id, username, lang,"
" identity.flags, is_own, pEp_version_major, pEp_version_minor"
" identity.flags, is_own, pEp_version_major, pEp_version_minor, enc_format"
" from identity"
" join person on id = identity.user_id"
" where (case when (address = ?1) then (1)"
@ -126,7 +126,7 @@ static const char *sql_get_identity_without_trust_check =
static const char *sql_get_identities_by_address =
"select user_id, identity.main_key_id, username, lang,"
" identity.flags, is_own, pEp_version_major, pEp_version_minor"
" identity.flags, is_own, pEp_version_major, pEp_version_minor, enc_format"
" from identity"
" join person on id = identity.user_id"
" where (case when (address = ?1) then (1)"
@ -140,7 +140,7 @@ static const char *sql_get_identities_by_address =
static const char *sql_get_identities_by_userid =
"select address, identity.main_key_id, username, comm_type, lang,"
" identity.flags | pgp_keypair.flags,"
" is_own, pEp_version_major, pEp_version_minor"
" is_own, pEp_version_major, pEp_version_minor, enc_format"
" from identity"
" join person on id = identity.user_id"
" left join pgp_keypair on fpr = identity.main_key_id"
@ -2838,7 +2838,8 @@ DYNAMIC_API PEP_STATUS get_identity(
sqlite3_column_int(session->get_identity, 6);
_identity->minor_ver =
sqlite3_column_int(session->get_identity, 7);
_identity->enc_format =
sqlite3_column_int(session->get_identity, 8);
*identity = _identity;
break;
default:
@ -2916,6 +2917,9 @@ PEP_STATUS get_identities_by_userid(
sqlite3_column_int(session->get_identities_by_userid, 7);
ident->minor_ver =
sqlite3_column_int(session->get_identities_by_userid, 8);
ident->enc_format =
sqlite3_column_int(session->get_identities_by_userid, 9);
identity_list_add(*identities, ident);
ident = NULL;
@ -2986,6 +2990,8 @@ PEP_STATUS get_identities_by_main_key_id(
sqlite3_column_int(session->get_identities_by_main_key_id, 7);
ident->minor_ver =
sqlite3_column_int(session->get_identities_by_main_key_id, 8);
ident->enc_format =
sqlite3_column_int(session->get_identities_by_main_key_id, 9);
identity_list_add(*identities, ident);
ident = NULL;
@ -3060,6 +3066,8 @@ PEP_STATUS get_identity_without_trust_check(
sqlite3_column_int(session->get_identity_without_trust_check, 5);
_identity->minor_ver =
sqlite3_column_int(session->get_identity_without_trust_check, 6);
_identity->enc_format =
sqlite3_column_int(session->get_identity_without_trust_check, 7);
*identity = _identity;
break;
@ -3129,7 +3137,9 @@ PEP_STATUS get_identities_by_address(
sqlite3_column_int(session->get_identities_by_address, 6);
ident->minor_ver =
sqlite3_column_int(session->get_identities_by_address, 7);
ident->enc_format =
sqlite3_column_int(session->get_identities_by_address, 8);
if (ident_list)
identity_list_add(ident_list, ident);
else


+ 2
- 1
src/pEpEngine.h View File

@ -161,7 +161,8 @@ typedef enum _PEP_enc_format {
PEP_enc_PGP_MIME, // RFC3156
PEP_enc_PEP, // pEp encryption format
PEP_enc_PGP_MIME_Outlook1, // Message B0rken by Outlook type 1
PEP_enc_inline_EA
PEP_enc_inline_EA,
PEP_enc_auto = 255 // figure out automatically where possible
} PEP_enc_format;


+ 184
- 0
test/src/IdentEncFormatTest.cc View File

@ -0,0 +1,184 @@
#include <stdlib.h>
#include <string>
#include <cstring>
#include "pEpEngine.h"
#include "test_util.h"
#include "TestConstants.h"
#include "Engine.h"
#include <gtest/gtest.h>
namespace {
//The fixture for IdentEncFormatTest
class IdentEncFormatTest : public ::testing::Test {
public:
Engine* engine;
PEP_SESSION session;
protected:
// You can remove any or all of the following functions if its body
// is empty.
IdentEncFormatTest() {
// You can do set-up work for each test here.
test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->GTEST_SUITE_SYM();
test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
}
~IdentEncFormatTest() override {
// You can do clean-up work that doesn't throw exceptions here.
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
void SetUp() override {
// Code here will be called immediately after the constructor (right
// before each test).
// Leave this empty if there are no files to copy to the home directory path
std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
// Get a new test Engine.
engine = new Engine(test_path);
ASSERT_NE(engine, nullptr);
// Ok, let's initialize test directories etc.
engine->prep(NULL, NULL, init_files);
// Ok, try to start this bugger.
engine->start();
ASSERT_NE(engine->session, nullptr);
session = engine->session;
// Engine is up. Keep on truckin'
}
void TearDown() override {
// Code here will be called immediately after each test (right
// before the destructor).
engine->shut_down();
delete engine;
engine = NULL;
session = NULL;
}
const char* alice_filename = "test_keys/alice-no-passwords.pgp";
const char* alice_pub_filename = "test_keys/pub/alice-0x2A649B9F_pub.asc";
const char* carol_filename = "test_keys/carol-subkeys-password-carol.pgp";
const char* alice_fpr = "03AF88F728B8E9AADA7F370BD41801C62A649B9F";
const char* carol_fpr = "A5B3473EA7CBB5DF7A4F595A8883DC4BCD8BAC06";
private:
const char* test_suite_name;
const char* test_name;
string test_path;
// Objects declared here can be used by all tests in the IdentEncFormatTest suite.
};
} // namespace
TEST_F(IdentEncFormatTest, check_ident_enc_format_specified) {
ASSERT_TRUE(slurp_and_import_key(session, carol_filename));
stringlist_t* found_key = NULL;
PEP_STATUS status = find_keys(session, carol_fpr, &found_key);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_NE(found_key, nullptr);
ASSERT_NE(found_key->value, nullptr);
ASSERT_STREQ(found_key->value, carol_fpr);
ASSERT_EQ(found_key->next, nullptr);
const char* my_fpr = carol_fpr;
const char* my_name = "Carol Peril";
const char* my_address = "carol_peril@darthmama.cool";
pEp_identity* my_ident = new_identity(my_address, my_fpr, PEP_OWN_USERID, my_name);
status = set_own_key(session, my_ident, my_fpr);
ASSERT_EQ(status, PEP_STATUS_OK);
// Set up "to"
ASSERT_TRUE(slurp_and_import_key(session, alice_pub_filename));
const char* to_fpr = alice_fpr;
const char* to_name = "Alice Malice";
const char* to_address = "alice_malice@darthmama.cool";
pEp_identity* to_ident = new_identity(to_address, to_fpr, "ALICE", to_name);
status = set_identity(session, to_ident);
ASSERT_EQ(status, PEP_STATUS_OK);
message* msg = new_message(PEP_dir_outgoing);
msg->from = my_ident;
msg->to = new_identity_list(to_ident);
msg->shortmsg = strdup("This is an exciting message from Carol!");
msg->longmsg = strdup("Not\nVery\nExciting\n");
message* enc_msg = NULL;
status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_inline, 0);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_NE(enc_msg, nullptr);
ASSERT_EQ(msg->enc_format, PEP_enc_inline);
free_message(msg);
free_message(enc_msg);
free_stringlist(found_key);
}
TEST_F(IdentEncFormatTest, check_ident_enc_format_one_to_nospec) {
ASSERT_TRUE(slurp_and_import_key(session, carol_filename));
stringlist_t* found_key = NULL;
PEP_STATUS status = find_keys(session, carol_fpr, &found_key);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_NE(found_key, nullptr);
ASSERT_NE(found_key->value, nullptr);
ASSERT_STREQ(found_key->value, carol_fpr);
ASSERT_EQ(found_key->next, nullptr);
const char* my_fpr = carol_fpr;
const char* my_name = "Carol Peril";
const char* my_address = "carol_peril@darthmama.cool";
pEp_identity* my_ident = new_identity(my_address, my_fpr, PEP_OWN_USERID, my_name);
status = set_own_key(session, my_ident, my_fpr);
ASSERT_EQ(status, PEP_STATUS_OK);
// Set up "to"
ASSERT_TRUE(slurp_and_import_key(session, alice_pub_filename));
const char* to_fpr = alice_fpr;
const char* to_name = "Alice Malice";
const char* to_address = "alice_malice@darthmama.cool";
pEp_identity* to_ident = new_identity(to_address, to_fpr, "ALICE", to_name);
status = set_identity(session, to_ident);
ASSERT_EQ(status, PEP_STATUS_OK);
pEp_identity* to_setter = identity_dup(to_ident);
status = set_ident_enc_format(session, to_setter, PEP_enc_inline_EA);
free_identity(to_setter);
ASSERT_EQ(status, PEP_STATUS_OK);
message* msg = new_message(PEP_dir_outgoing);
msg->from = my_ident;
msg->to = new_identity_list(to_ident);
msg->shortmsg = strdup("This is an exciting message from Carol!");
msg->longmsg = strdup("Not\nVery\nExciting\n");
message* enc_msg = NULL;
status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_auto, 0);
ASSERT_EQ(status, PEP_STATUS_OK);
ASSERT_NE(enc_msg, nullptr);
ASSERT_EQ(enc_msg->enc_format, PEP_enc_inline_EA);
free_message(msg);
free_message(enc_msg);
free_stringlist(found_key);
}
TEST_F(IdentEncFormatTest, check_ident_enc_format_multi_to_middle_nospec) {
}
TEST_F(IdentEncFormatTest, check_ident_enc_format_multi_cc_middle_nospec) {
}
TEST_F(IdentEncFormatTest, check_ident_enc_format_multi_bcc_nospec) {
}

Loading…
Cancel
Save