Browse Source

Fix er up. Now works with explicitly-set versions on identities. Now to check the imports...

ENGINE-641
parent
commit
f87a7dc6c8
5 changed files with 132 additions and 23 deletions
  1. +4
    -1
      src/keymanagement.c
  2. +10
    -1
      src/message.c
  3. +14
    -6
      src/pEpEngine.c
  4. +98
    -11
      test/src/engine_tests/Message2_1Tests.cc
  5. +6
    -4
      test/src/util/test_util.cc

+ 4
- 1
src/keymanagement.c View File

@ -525,6 +525,9 @@ static PEP_STATUS prepare_updated_identity(PEP_SESSION session,
return_id->me = stored_ident->me;
return_id->major_ver = stored_ident->major_ver;
return_id->minor_ver = stored_ident->minor_ver;
// FIXME: Do we ALWAYS do this? We probably should...
if (EMPTYSTR(return_id->user_id)) {
free(return_id->user_id);
@ -557,7 +560,7 @@ static PEP_STATUS prepare_updated_identity(PEP_SESSION session,
}
transfer_ident_lang_and_flags(return_id, stored_ident);
if (return_id->comm_type == PEP_ct_unknown)
return_id->comm_type = PEP_ct_key_not_found;


+ 10
- 1
src/message.c View File

@ -44,6 +44,7 @@ DYNAMIC_API void free_message(message *msg)
free_stringlist(msg->keywords);
free(msg->comments);
free_stringpair_list(msg->opt_fields);
free(msg->_sender_fpr);
free(msg);
}
}
@ -185,6 +186,12 @@ DYNAMIC_API message * message_dup(const message *src)
goto enomem;
}
if (src->_sender_fpr) {
msg->_sender_fpr = strdup(src->_sender_fpr);
if (msg->_sender_fpr == NULL)
goto enomem;
}
msg->enc_format = src->enc_format;
return msg;
@ -218,13 +225,15 @@ DYNAMIC_API void message_transfer(message* dst, message *src)
free(dst->longmsg);
free(dst->longmsg_formatted);
free(dst->comments);
free(dst->_sender_fpr);
dst->id = src->id;
dst->shortmsg = src->shortmsg;
dst->longmsg = src->longmsg;
dst->longmsg_formatted = src->longmsg_formatted;
dst->comments = src->comments;
dst->_sender_fpr = src->_sender_fpr;
src->id = src->shortmsg = src->longmsg = src->longmsg_formatted = NULL;
src->comments = NULL;
src->comments = src->_sender_fpr = NULL;
/* bloblists */
free_bloblist(dst->attachments);


+ 14
- 6
src/pEpEngine.c View File

@ -2379,6 +2379,8 @@ pEp_identity *identity_dup(const pEp_identity *src)
dup->lang[2] = 0;
dup->flags = src->flags;
dup->me = src->me;
dup->major_ver = src->major_ver;
dup->minor_ver = src->minor_ver;
return dup;
}
@ -2651,9 +2653,9 @@ PEP_STATUS get_identities_by_userid(
ident->me = (unsigned int)
sqlite3_column_int(session->get_identities_by_userid, 6);
ident->major_ver =
sqlite3_column_int(session->get_identities_by_userid, 6);
ident->minor_ver =
sqlite3_column_int(session->get_identities_by_userid, 7);
ident->minor_ver =
sqlite3_column_int(session->get_identities_by_userid, 8);
identity_list_add(*identities, ident);
ident = NULL;
@ -2795,9 +2797,9 @@ PEP_STATUS get_identity_without_trust_check(
_identity->me = (unsigned int)
sqlite3_column_int(session->get_identity_without_trust_check, 4);
_identity->major_ver =
sqlite3_column_int(session->get_identity_without_trust_check, 6);
sqlite3_column_int(session->get_identity_without_trust_check, 5);
_identity->minor_ver =
sqlite3_column_int(session->get_identity_without_trust_check, 7);
sqlite3_column_int(session->get_identity_without_trust_check, 6);
*identity = _identity;
break;
@ -3206,6 +3208,12 @@ DYNAMIC_API PEP_STATUS set_identity(
}
}
status = set_pEp_version(session, ident_copy, ident_copy->major_ver, ident_copy->minor_ver);
if (status != PEP_STATUS_OK) {
sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
goto pEp_free;
}
result = sqlite3_exec(session->db, "COMMIT ;", NULL, NULL, NULL);
if (result == SQLITE_OK)
status = PEP_STATUS_OK;
@ -4450,8 +4458,8 @@ DYNAMIC_API PEP_STATUS generate_keypair(
identity->username))
return PEP_ILLEGAL_VALUE;
const char* saved_username = NULL;
const char* at = NULL;
char* saved_username = NULL;
char* at = NULL;
size_t uname_len = strlen(identity->username);
if (uname_len > 0)


+ 98
- 11
test/src/engine_tests/Message2_1Tests.cc View File

@ -57,7 +57,7 @@ bool Message2_1Tests::verify_message_version_produced(message* enc_msg, unsigned
*maj_inout = 2;
*min_inout = 0;
}
else if (strstr(ptext, "X-pEp-Wrapped-Message-Info: INNER") != NULL && strstr(ptext, "forwarded=no") != NULL) {
else if (strstr(ptext, "X-pEp-Wrapped-Message-Info: INNER") != NULL && strstr(ptext, "forwarded=\"no\"") != NULL) {
*maj_inout = 2;
*min_inout = 1;
}
@ -84,15 +84,6 @@ bool Message2_1Tests::verify_message_version_produced(message* enc_msg, unsigned
}
}
/* PEP_STATUS set_up_preset(PEP_SESSION session,
pEp_test_ident_preset preset_name,
bool set_ident,
bool set_pep,
bool trust,
bool set_own,
bool setup_private,
pEp_identity** ident) {
*/
void Message2_1Tests::check_message2_1_recip_2_0() {
pEp_identity* alice = NULL;
@ -142,8 +133,63 @@ void Message2_1Tests::check_message2_1_recip_2_0() {
TEST_ASSERT(true);
}
/* PEP_STATUS set_up_preset(PEP_SESSION session,
pEp_test_ident_preset preset_name,
bool set_ident,
bool set_pep,
bool trust,
bool set_own,
bool setup_private,
pEp_identity** ident) {
*/
void Message2_1Tests::check_message2_1_recip_OpenPGP() {
// set recip to 1.0
pEp_identity* alice = NULL;
pEp_identity* carol = NULL;
PEP_STATUS status = set_up_preset(session, ALICE,
true, true, true, true, true, &alice);
TEST_ASSERT(status == PEP_STATUS_OK);
TEST_ASSERT(alice);
status = set_up_preset(session, CAROL,
false, false, false, false, false, &carol);
TEST_ASSERT(status == PEP_STATUS_OK);
TEST_ASSERT(carol);
status = update_identity(session, carol);
TEST_ASSERT(status == PEP_STATUS_OK);
TEST_ASSERT(carol->major_ver < 2);
TEST_ASSERT(carol->minor_ver == 0);
// generate message
pEp_identity* carol_to = new_identity(carol->address, NULL, NULL, NULL);
message* msg = new_message(PEP_dir_outgoing);
msg->from = alice;
msg->to = new_identity_list(carol_to);
msg->shortmsg = strdup("Boom shaka laka");
msg->longmsg = strdup("Don't you get sick of these?");
message* enc_msg = NULL;
status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
TEST_ASSERT(status == PEP_STATUS_OK);
// ensure sent message is in 1.0 format
unsigned int major = 1;
unsigned int minor = 0;
TEST_ASSERT_MSG(verify_message_version_produced(enc_msg, &major, &minor),
(to_string(major) + "." + to_string(minor)).c_str());
free_identity(carol);
free_message(msg);
free_message(enc_msg);
TEST_ASSERT(true);
// generate message
@ -155,11 +201,52 @@ void Message2_1Tests::check_message2_1_recip_OpenPGP() {
void Message2_1Tests::check_message2_1_recip_2_1() {
// set recip to 2.1
pEp_identity* alice = NULL;
pEp_identity* carol = NULL;
PEP_STATUS status = set_up_preset(session, ALICE,
true, true, true, true, true, &alice);
TEST_ASSERT(status == PEP_STATUS_OK);
TEST_ASSERT(alice);
status = set_up_preset(session, CAROL,
true, true, false, false, false, &carol);
TEST_ASSERT(status == PEP_STATUS_OK);
TEST_ASSERT(carol);
status = set_pEp_version(session, carol, 2, 1);
// default should be 2.1 after setting pep status
status = update_identity(session, carol);
TEST_ASSERT(status == PEP_STATUS_OK);
TEST_ASSERT(carol->major_ver == 2);
TEST_ASSERT(carol->minor_ver == 1);
// generate message
pEp_identity* carol_to = new_identity(carol->address, NULL, NULL, NULL);
// ensure sent message is in 2.1 format
message* msg = new_message(PEP_dir_outgoing);
msg->from = alice;
msg->to = new_identity_list(carol_to);
msg->shortmsg = strdup("Boom shaka laka");
msg->longmsg = strdup("Don't you get sick of these?");
message* enc_msg = NULL;
status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
TEST_ASSERT(status == PEP_STATUS_OK);
// ensure sent message is in 2.0 format
unsigned int major = 2;
unsigned int minor = 1;
TEST_ASSERT_MSG(verify_message_version_produced(enc_msg, &major, &minor),
(to_string(major) + "." + to_string(minor)).c_str());
free_identity(carol);
free_message(msg);
free_message(enc_msg);
TEST_ASSERT(true);
}


+ 6
- 4
test/src/util/test_util.cc View File

@ -914,7 +914,11 @@ PEP_STATUS set_up_preset(PEP_SESSION session,
retval = new_identity(email, NULL, user_id, name);
if (!retval)
return PEP_OUT_OF_MEMORY;
// honestly probably happens anyway
if (set_ident && status == PEP_STATUS_OK)
status = set_identity(session, retval);
if (set_own) {
retval->me = true;
status = set_own_key(session, retval, fpr);
@ -922,6 +926,7 @@ PEP_STATUS set_up_preset(PEP_SESSION session,
if (set_pep && status == PEP_STATUS_OK)
status = set_as_pEp_user(session, retval);
if (trust && status == PEP_STATUS_OK) {
if (!retval->me)
status = update_identity(session, retval);
@ -931,9 +936,6 @@ PEP_STATUS set_up_preset(PEP_SESSION session,
}
}
// honestly probably happens anyway
if (set_ident && status == PEP_STATUS_OK)
status = set_identity(session, retval);
if (ident)
*ident = retval;


Loading…
Cancel
Save