ENGINE-247: Initial commit - tests need to be cleaned up and are failing for weird reasons. ENGINE-247
authorKrista Bennett <krista@pep-project.org>
Mon, 11 Sep 2017 14:49:57 +0200
branchENGINE-247
changeset 2045162803eb47e0
parent 2040 3a83ac7f8f32
child 2046 deec7a422249
ENGINE-247: Initial commit - tests need to be cleaned up and are failing for weird reasons.
src/message_api.c
src/mime.c
src/pEp_internal.h
test/pEp_subject_received_test.cc
     1.1 --- a/src/message_api.c	Wed Sep 06 14:23:44 2017 +0200
     1.2 +++ b/src/message_api.c	Mon Sep 11 14:49:57 2017 +0200
     1.3 @@ -103,9 +103,12 @@
     1.4  static char * combine_short_and_long(const char *shortmsg, const char *longmsg)
     1.5  {
     1.6      assert(shortmsg);
     1.7 -    assert(strcmp(shortmsg, "pEp") != 0);
     1.8 -
     1.9 -    if (!shortmsg || strcmp(shortmsg, "pEp") == 0) {
    1.10 +    
    1.11 +    unsigned char pepstr[] = PEP_SUBJ_STRING;
    1.12 +    assert(strcmp(shortmsg, "pEp") != 0 && _unsigned_signed_strcmp(pepstr, shortmsg, PEP_SUBJ_BYTELEN) != 0); 
    1.13 +    
    1.14 +    if (!shortmsg || strcmp(shortmsg, "pEp") == 0 || 
    1.15 +                     _unsigned_signed_strcmp(pepstr, shortmsg, PEP_SUBJ_BYTELEN) == 0) {
    1.16          if (!longmsg) {
    1.17              return NULL;
    1.18          }
    1.19 @@ -370,8 +373,10 @@
    1.20      size_t csize;
    1.21      assert(dst->longmsg == NULL);
    1.22      dst->enc_format = PEP_enc_PGP_MIME;
    1.23 -
    1.24 -    if (src->shortmsg && strcmp(src->shortmsg, "pEp") != 0) {
    1.25 +    unsigned char pepstr[] = PEP_SUBJ_STRING;
    1.26 +
    1.27 +    if (src->shortmsg && strcmp(src->shortmsg, "pEp") != 0 
    1.28 +                      && _unsigned_signed_strcmp(pepstr, src->shortmsg, PEP_SUBJ_BYTELEN) != 0) {
    1.29          if (session->unencrypted_subject) {
    1.30              dst->shortmsg = strdup(src->shortmsg);
    1.31              assert(dst->shortmsg);
    1.32 @@ -390,7 +395,7 @@
    1.33          ptext = src->longmsg;
    1.34      }
    1.35      else {
    1.36 -        ptext = "pEp";
    1.37 +        ptext = (char*)pepstr;
    1.38      }
    1.39  
    1.40      message *_src = calloc(1, sizeof(message));
    1.41 @@ -471,7 +476,8 @@
    1.42      size_t csize;
    1.43      char *ptext = NULL;
    1.44      bool free_ptext = false;
    1.45 -
    1.46 +    unsigned char pepstr[] = PEP_SUBJ_STRING;
    1.47 +    
    1.48      assert(dst->longmsg == NULL);
    1.49      assert(dst->attachments == NULL);
    1.50  
    1.51 @@ -479,7 +485,8 @@
    1.52  
    1.53      bool nosign = (flags & PEP_encrypt_flag_force_unsigned);
    1.54  
    1.55 -    if (src->shortmsg && src->shortmsg[0] && strcmp(src->shortmsg, "pEp") != 0) {
    1.56 +    if (src->shortmsg && src->shortmsg[0] && strcmp(src->shortmsg, "pEp") != 0 && 
    1.57 +        _unsigned_signed_strcmp(pepstr, src->shortmsg, PEP_SUBJ_BYTELEN) != 0) {
    1.58          if (session->unencrypted_subject) {
    1.59              dst->shortmsg = strdup(src->shortmsg);
    1.60              assert(dst->shortmsg);
    1.61 @@ -1284,7 +1291,7 @@
    1.62      free_stringlist(keys);
    1.63  
    1.64      if (msg && msg->shortmsg == NULL) {
    1.65 -        msg->shortmsg = strdup("pEp");
    1.66 +        msg->shortmsg = _pep_subj_copy();
    1.67          assert(msg->shortmsg);
    1.68          if (msg->shortmsg == NULL)
    1.69              goto enomem;
    1.70 @@ -1395,7 +1402,7 @@
    1.71          goto pep_error;
    1.72  
    1.73       if (msg && msg->shortmsg == NULL) {
    1.74 -         msg->shortmsg = strdup("pEp");
    1.75 +         msg->shortmsg = _pep_subj_copy();
    1.76           assert(msg->shortmsg);
    1.77           if (msg->shortmsg == NULL)
    1.78               goto enomem;
    1.79 @@ -1680,6 +1687,7 @@
    1.80      char *ptext = NULL;
    1.81      size_t psize;
    1.82      stringlist_t *_keylist = NULL;
    1.83 +    unsigned char pepstr[] = PEP_SUBJ_STRING;
    1.84  
    1.85      assert(session);
    1.86      assert(src);
    1.87 @@ -1970,7 +1978,8 @@
    1.88                      GOTO(pep_error);
    1.89                  }
    1.90  
    1.91 -                if (src->shortmsg == NULL || strcmp(src->shortmsg, "pEp") == 0)
    1.92 +                if (src->shortmsg == NULL || strcmp(src->shortmsg, "pEp") == 0 ||
    1.93 +                    _unsigned_signed_strcmp(pepstr, src->shortmsg, PEP_SUBJ_BYTELEN) == 0)
    1.94                  {
    1.95                      char * shortmsg;
    1.96                      char * longmsg;
     2.1 --- a/src/mime.c	Wed Sep 06 14:23:44 2017 +0200
     2.2 +++ b/src/mime.c	Mon Sep 11 14:49:57 2017 +0200
     2.3 @@ -418,7 +418,8 @@
     2.4      struct mailimf_fields * fields = NULL;
     2.5      int r;
     2.6      clist * fields_list = NULL;
     2.7 -    char *subject = msg->shortmsg ? msg->shortmsg : "pEp";
     2.8 +    unsigned char pepstr[] = PEP_SUBJ_STRING; // unsigned due to UTF-8 byte fun
     2.9 +    char *subject = msg->shortmsg ? msg->shortmsg : (char*)pepstr;
    2.10  
    2.11      assert(msg);
    2.12      assert(msg->from);
     3.1 --- a/src/pEp_internal.h	Wed Sep 06 14:23:44 2017 +0200
     3.2 +++ b/src/pEp_internal.h	Mon Sep 11 14:49:57 2017 +0200
     3.3 @@ -31,6 +31,12 @@
     3.4  #endif
     3.5  #define CRASHDUMP_MAX_LINES 32767
     3.6  
     3.7 +// p≡p full string, NUL-terminated
     3.8 +#ifndef PEP_SUBJ_STRING
     3.9 +#define PEP_SUBJ_STRING {0x70,0xE2,0x89,0xA1,0x70,0x00}
    3.10 +#define PEP_SUBJ_BYTELEN 5
    3.11 +#endif
    3.12 +
    3.13  #include "platform.h"
    3.14  
    3.15  #ifdef WIN32
    3.16 @@ -324,6 +330,24 @@
    3.17      return identity->user_id && strcmp(identity->user_id, PEP_OWN_USERID) == 0;
    3.18  }
    3.19  
    3.20 +// size is the length of the bytestr that's coming in. This is really only intended
    3.21 +// for comparing two full strings. If charstr's length is different from bytestr_size,
    3.22 +// we'll return a non-zero value.
    3.23 +static inline int _unsigned_signed_strcmp(const unsigned char* bytestr, const char* charstr, int bytestr_size) {
    3.24 +    int charstr_len = strlen(charstr);
    3.25 +    if (charstr_len != bytestr_size)
    3.26 +        return -1; // we don't actually care except that it's non-zero
    3.27 +    return memcmp(bytestr, charstr, bytestr_size);
    3.28 +}
    3.29 +
    3.30 +// This is just a horrible example of C type madness. UTF-8 made me do it.
    3.31 +static inline char* _pep_subj_copy() {
    3.32 +    unsigned char pepstr[] = PEP_SUBJ_STRING;
    3.33 +    void* retval = calloc(1, sizeof(unsigned char)*PEP_SUBJ_BYTELEN + 1);
    3.34 +    memcpy(retval, pepstr, PEP_SUBJ_BYTELEN);
    3.35 +    return (char*)retval;
    3.36 +}
    3.37 +
    3.38  #ifdef DEBUG_ERRORSTACK
    3.39      PEP_STATUS session_add_error(PEP_SESSION session, const char* file, unsigned line, PEP_STATUS status);
    3.40      #define ADD_TO_LOG(status)   session_add_error(session, __FILE__, __LINE__, (status))
     4.1 --- a/test/pEp_subject_received_test.cc	Wed Sep 06 14:23:44 2017 +0200
     4.2 +++ b/test/pEp_subject_received_test.cc	Mon Sep 11 14:49:57 2017 +0200
     4.3 @@ -14,7 +14,7 @@
     4.4  
     4.5  int main(int argc, char** argv) {
     4.6  
     4.7 -    cout << "\n*** check that pEp subject is handled properly in received mails ***\n\n";
     4.8 +    cout << "\n*** check that p≡p subject is handled properly in received mails ***\n\n";
     4.9  
    4.10      PEP_SESSION session;
    4.11      
    4.12 @@ -119,6 +119,7 @@
    4.13      
    4.14      cout << "-----------------------------------------------------------------------" << endl;
    4.15      cout << "Test 3: Encrypted mail, pEp as actual subject, no subject in body text." << endl;
    4.16 +    cout << "FIXME: need tp make new encrypted mail for this." << endl;
    4.17      cout << "-----------------------------------------------------------------------" << endl;
    4.18  
    4.19      msg_ptr = nullptr;
    4.20 @@ -151,6 +152,7 @@
    4.21  
    4.22      cout << "-----------------------------------------------------------------------" << endl;
    4.23      cout << "Test 4: Encrypted mail, pEp as actual subject, pEp subject in body text." << endl;
    4.24 +    cout << "FIXME: need tp make new encrypted mail for this." << endl;
    4.25      cout << "-----------------------------------------------------------------------" << endl;
    4.26  
    4.27      msg_ptr = nullptr;
    4.28 @@ -183,6 +185,7 @@
    4.29  
    4.30      cout << "-------------------------------------------------------------------------" << endl;
    4.31      cout << "Test 5: Unencrypted variant where pEp in the subject line is the subject." << endl;
    4.32 +    cout << "FIXME: need tp make new mail for this." << endl;
    4.33      cout << "-------------------------------------------------------------------------" << endl;
    4.34  
    4.35      msg_ptr = nullptr;