test/test_util.cc
author Krista Bennett <krista@pep-project.org>
Thu, 01 Jun 2017 19:52:13 +0200
branchENGINE-209
changeset 1812 925ad845e3ec
parent 1656 ea7d229bed3f
child 2282 eed4a7047201
permissions -rw-r--r--
ENGINE-209: externally revoked and added keys should now be handled correctly in the database.
     1 #include "pEpEngine_test.h"
     2 #include "pEpEngine.h"
     3 #include "message_api.h"
     4 #include <fstream>
     5 #include <sstream>
     6 #include <stdexcept>
     7 
     8 std::string slurp(const std::string& filename)
     9 {
    10 	std::ifstream input(filename.c_str());
    11 	if(!input)
    12 	{
    13 		throw std::runtime_error("Cannot read file \"" + filename + "\"! ");
    14 	}
    15 	
    16 	std::stringstream sstr;
    17 	sstr << input.rdbuf();
    18 	return sstr.str();
    19 }
    20 
    21 const char* tl_status_string(PEP_STATUS status) {
    22     switch (status) {
    23         case PEP_STATUS_OK:
    24             return "PEP_STATUS_OK";
    25         case PEP_INIT_CANNOT_LOAD_GPGME:
    26             return "PEP_INIT_CANNOT_LOAD_GPGME";
    27         case PEP_INIT_GPGME_INIT_FAILED:
    28             return "PEP_INIT_GPGME_INIT_FAILED";
    29         case PEP_INIT_NO_GPG_HOME:
    30             return "PEP_INIT_NO_GPG_HOME";
    31         case PEP_INIT_NETPGP_INIT_FAILED:
    32             return "PEP_INIT_NETPGP_INIT_FAILED";
    33         case PEP_INIT_SQLITE3_WITHOUT_MUTEX:
    34             return "PEP_INIT_SQLITE3_WITHOUT_MUTEX";
    35         case PEP_INIT_CANNOT_OPEN_DB:
    36             return "PEP_INIT_CANNOT_OPEN_DB";
    37         case PEP_INIT_CANNOT_OPEN_SYSTEM_DB:
    38             return "PEP_INIT_CANNOT_OPEN_SYSTEM_DB";
    39         case PEP_KEY_NOT_FOUND:
    40             return "PEP_KEY_NOT_FOUND";
    41         case PEP_KEY_HAS_AMBIG_NAME:
    42             return "PEP_KEY_HAS_AMBIG_NAME";
    43         case PEP_GET_KEY_FAILED:
    44             return "PEP_GET_KEY_FAILED";
    45         case PEP_CANNOT_EXPORT_KEY:
    46             return "PEP_CANNOT_EXPORT_KEY";
    47         case PEP_CANNOT_EDIT_KEY:
    48             return "PEP_CANNOT_EDIT_KEY";
    49         case PEP_CANNOT_FIND_IDENTITY:
    50             return "PEP_CANNOT_FIND_IDENTITY";
    51         case PEP_CANNOT_SET_PERSON:
    52             return "PEP_CANNOT_SET_PERSON";
    53         case PEP_CANNOT_SET_PGP_KEYPAIR:
    54             return "PEP_CANNOT_SET_PGP_KEYPAIR";
    55         case PEP_CANNOT_SET_IDENTITY:
    56             return "PEP_CANNOT_SET_IDENTITY";
    57         case PEP_CANNOT_SET_TRUST:
    58             return "PEP_CANNOT_SET_TRUST";
    59         case PEP_KEY_BLACKLISTED:
    60             return "PEP_KEY_BLACKLISTED";
    61         case PEP_UNENCRYPTED:
    62             return "PEP_UNENCRYPTED";
    63         case PEP_VERIFIED:
    64             return "PEP_VERIFIED";
    65         case PEP_DECRYPTED:
    66             return "PEP_DECRYPTED";
    67         case PEP_DECRYPTED_AND_VERIFIED:
    68             return "PEP_DECRYPTED_AND_VERIFIED";
    69         case PEP_DECRYPT_WRONG_FORMAT:
    70             return "PEP_DECRYPT_WRONG_FORMAT";
    71         case PEP_DECRYPT_NO_KEY:
    72             return "PEP_DECRYPT_NO_KEY";
    73         case PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH:
    74             return "PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH";
    75         case PEP_VERIFY_NO_KEY:
    76             return "PEP_VERIFY_NO_KEY";
    77         case PEP_VERIFIED_AND_TRUSTED:
    78             return "PEP_VERIFIED_AND_TRUSTED";
    79         case PEP_CANNOT_DECRYPT_UNKNOWN:
    80             return "PEP_CANNOT_DECRYPT_UNKNOWN";
    81         case PEP_TRUSTWORD_NOT_FOUND:
    82             return "PEP_TRUSTWORD_NOT_FOUND";
    83         case PEP_TRUSTWORDS_FPR_WRONG_LENGTH:
    84             return "PEP_TRUSTWORDS_FPR_WRONG_LENGTH";
    85         case PEP_CANNOT_CREATE_KEY:
    86             return "PEP_CANNOT_CREATE_KEY";
    87         case PEP_CANNOT_SEND_KEY:
    88             return "PEP_CANNOT_SEND_KEY";
    89         case PEP_PHRASE_NOT_FOUND:
    90             return "PEP_PHRASE_NOT_FOUND";
    91         case PEP_SEND_FUNCTION_NOT_REGISTERED:
    92             return "PEP_SEND_FUNCTION_NOT_REGISTERED";
    93         case PEP_CONTRAINTS_VIOLATED:
    94             return "PEP_CONTRAINTS_VIOLATED";
    95         case PEP_CANNOT_ENCODE:
    96             return "PEP_CANNOT_ENCODE";
    97         case PEP_SYNC_NO_NOTIFY_CALLBACK:
    98             return "PEP_SYNC_NO_NOTIFY_CALLBACK";
    99         case PEP_SYNC_ILLEGAL_MESSAGE:
   100             return "PEP_SYNC_ILLEGAL_MESSAGE";
   101         case PEP_SYNC_NO_INJECT_CALLBACK:
   102             return "PEP_SYNC_NO_INJECT_CALLBACK";
   103         case PEP_SEQUENCE_VIOLATED:
   104             return "PEP_SEQUENCE_VIOLATED";
   105         case PEP_CANNOT_INCREASE_SEQUENCE:
   106             return "PEP_CANNOT_INCREASE_SEQUENCE";
   107         case PEP_CANNOT_SET_SEQUENCE_VALUE:
   108             return "PEP_CANNOT_SET_SEQUENCE_VALUE";
   109         case PEP_OWN_SEQUENCE:
   110             return "PEP_OWN_SEQUENCE";
   111         case PEP_SYNC_STATEMACHINE_ERROR:
   112             return "PEP_SYNC_STATEMACHINE_ERROR";
   113         case PEP_SYNC_NO_TRUST:
   114             return "PEP_SYNC_NO_TRUST";
   115         case PEP_STATEMACHINE_INVALID_STATE:
   116             return "PEP_STATEMACHINE_INVALID_STATE";
   117         case PEP_STATEMACHINE_INVALID_EVENT:
   118             return "PEP_STATEMACHINE_INVALID_EVENT";
   119         case PEP_STATEMACHINE_INVALID_CONDITION:
   120             return "PEP_STATEMACHINE_INVALID_CONDITION";
   121         case PEP_STATEMACHINE_INVALID_ACTION:
   122             return "PEP_STATEMACHINE_INVALID_ACTION";
   123         case PEP_STATEMACHINE_INHIBITED_EVENT:
   124             return "PEP_STATEMACHINE_INHIBITED_EVENT";
   125         case PEP_COMMIT_FAILED:
   126             return "PEP_COMMIT_FAILED";
   127         case PEP_MESSAGE_CONSUME:
   128             return "PEP_MESSAGE_CONSUME";
   129         case PEP_MESSAGE_IGNORE:
   130             return "PEP_MESSAGE_IGNORE";
   131         case PEP_RECORD_NOT_FOUND:
   132             return "PEP_RECORD_NOT_FOUND";
   133         case PEP_CANNOT_CREATE_TEMP_FILE:
   134             return "PEP_CANNOT_CREATE_TEMP_FILE";
   135         case PEP_ILLEGAL_VALUE:
   136             return "PEP_ILLEGAL_VALUE";
   137         case PEP_BUFFER_TOO_SMALL:
   138             return "PEP_BUFFER_TOO_SMALL";
   139         case PEP_OUT_OF_MEMORY:
   140             return "PEP_OUT_OF_MEMORY";
   141         case PEP_UNKNOWN_ERROR:
   142             return "PEP_UNKNOWN_ERROR";
   143         default:
   144             return "PEP_STATUS_OMGWTFBBQ - This means you're using a status the test lib doesn't know about!";
   145     }
   146 }
   147 const char* tl_rating_string(PEP_rating rating) {
   148     switch (rating) {
   149         case PEP_rating_undefined:
   150             return "PEP_rating_undefined";
   151         case PEP_rating_cannot_decrypt:
   152             return "PEP_rating_cannot_decrypt";
   153         case PEP_rating_have_no_key:
   154             return "PEP_rating_have_no_key";
   155         case PEP_rating_unencrypted:
   156             return "PEP_rating_unencrypted";
   157         case PEP_rating_unencrypted_for_some:
   158             return "PEP_rating_unencrypted_for_some";
   159         case PEP_rating_unreliable:
   160             return "PEP_rating_unreliable";
   161         case PEP_rating_reliable:
   162             return "PEP_rating_reliable";
   163         case PEP_rating_trusted:
   164             return "PEP_rating_trusted";
   165         case PEP_rating_trusted_and_anonymized:
   166             return "PEP_rating_trusted_and_anonymized";
   167         case PEP_rating_fully_anonymous:
   168             return "PEP_rating_fully_anonymous";
   169         case PEP_rating_mistrust:
   170             return "PEP_rating_mistrust";
   171         case PEP_rating_b0rken:
   172             return "PEP_rating_b0rken";
   173         case PEP_rating_under_attack:
   174             return "PEP_rating_under_attack";
   175         default:
   176             return "PEP_rating_OMGWTFBBQ - in other words, INVALID RATING VALUE!!!\n\nSomething bad is going on here, or a new rating value has been added to the enum and not the test function.";
   177     }
   178 }
   179 
   180 const char* tl_ct_string(PEP_comm_type ct) {
   181     switch (ct) {
   182         case PEP_ct_unknown:
   183             return "PEP_ct_unknown";
   184         case PEP_ct_no_encryption:
   185             return "PEP_ct_no_encryption";
   186         case PEP_ct_no_encrypted_channel:
   187             return "PEP_ct_no_encrypted_channel";
   188         case PEP_ct_key_not_found:
   189             return "PEP_ct_key_not_found";
   190         case PEP_ct_key_expired:
   191             return "PEP_ct_key_expired";
   192         case PEP_ct_key_revoked:
   193             return "PEP_ct_key_revoked";
   194         case PEP_ct_key_b0rken:
   195             return "PEP_ct_key_b0rken";
   196         case PEP_ct_my_key_not_included:
   197             return "PEP_ct_my_key_not_included";
   198         case PEP_ct_security_by_obscurity:
   199             return "PEP_ct_security_by_obscurity";
   200         case PEP_ct_b0rken_crypto:
   201             return "PEP_ct_b0rken_crypto";
   202         case PEP_ct_key_too_short:
   203             return "PEP_ct_key_too_short";
   204         case PEP_ct_compromized:
   205             return "PEP_ct_compromized";
   206         case PEP_ct_mistrusted:
   207             return "PEP_ct_mistrusted";
   208         case PEP_ct_unconfirmed_encryption:
   209             return "PEP_ct_unconfirmed_encryption";
   210         case PEP_ct_OpenPGP_weak_unconfirmed:
   211             return "PEP_ct_OpenPGP_weak_unconfirmed";
   212         case PEP_ct_to_be_checked:
   213             return "PEP_ct_to_be_checked";
   214         case PEP_ct_SMIME_unconfirmed:
   215             return "PEP_ct_SMIME_unconfirmed";
   216         case PEP_ct_CMS_unconfirmed:
   217             return "PEP_ct_CMS_unconfirmed";
   218         case PEP_ct_strong_but_unconfirmed:
   219             return "PEP_ct_strong_but_unconfirmed";
   220         case PEP_ct_OpenPGP_unconfirmed:
   221             return "PEP_ct_OpenPGP_unconfirmed";
   222         case PEP_ct_OTR_unconfirmed:
   223             return "PEP_ct_OTR_unconfirmed";
   224         case PEP_ct_unconfirmed_enc_anon:
   225             return "PEP_ct_unconfirmed_enc_anon";
   226         case PEP_ct_pEp_unconfirmed:
   227             return "PEP_ct_pEp_unconfirmed";
   228         case PEP_ct_confirmed:
   229             return "PEP_ct_pEp_confirmed";
   230         case PEP_ct_confirmed_encryption:
   231             return "PEP_ct_confirmed_encryption";
   232         case PEP_ct_OpenPGP_weak:
   233             return "PEP_ct_OpenPGP_weak";
   234         case PEP_ct_to_be_checked_confirmed:
   235             return "PEP_ct_to_be_checked_confirmed";
   236         case PEP_ct_SMIME:
   237             return "PEP_ct_SMIME";
   238         case PEP_ct_CMS:
   239             return "PEP_ct_CMS";
   240         case PEP_ct_strong_encryption:
   241             return "PEP_ct_strong_encryption";
   242         case PEP_ct_OpenPGP:
   243             return "PEP_ct_OpenPGP";
   244         case PEP_ct_OTR:
   245             return "PEP_ct_OTR";
   246         case PEP_ct_confirmed_enc_anon:
   247             return "PEP_ct_confirmed_enc_anon";
   248         case PEP_ct_pEp:
   249             return "PEP_ct_pEp";
   250         default:
   251             return "PEP_ct_OMGWTFBBQ\n\nIn other words, comm type is invalid. Either something's corrupt or a new ct value has been added to the enum but not to the test function.";
   252     }
   253 }