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