test/src/KeyResetMessageTest.cc
author Krista 'DarthMama' Bennett <krista@pep.foundation>
Sun, 12 Jan 2020 15:37:56 +0100
branchkrista-local-7-Jan-2020
changeset 4324 820329a83680
parent 4323 28b0e2285aa1
child 4326 4916e99785a0
permissions -rw-r--r--
changed API calls - committing to test on debian, some weird mem stuff still.
krista@2892
     1
// This file is under GNU General Public License 3.0
krista@2892
     2
// see LICENSE.txt
krista@2892
     3
krista@2892
     4
#include <stdlib.h>
krista@2892
     5
#include <string>
krista@2920
     6
#include <vector>
krista@2920
     7
#include <unordered_map>
krista@2917
     8
#include <assert.h>
krista@4117
     9
#include <iostream>
krista@4117
    10
#include <fstream>
krista@2892
    11
krista@2892
    12
#include "pEpEngine.h"
krista@2917
    13
#include "pEp_internal.h"
krista@2924
    14
#include "mime.h"
krista@2933
    15
#include "keymanagement.h"
krista@3507
    16
#include "key_reset.h"
krista@2892
    17
krista@3335
    18
#include "test_util.h"
krista@4021
    19
#include "TestConstants.h"
krista@4016
    20
krista@4016
    21
krista@4016
    22
#include "Engine.h"
krista@2892
    23
krista@4016
    24
#include <gtest/gtest.h>
krista@4016
    25
krista@4020
    26
PEP_STATUS KRMT_message_send_callback(message* msg);
krista@2892
    27
krista@4020
    28
static void* KRMT_fake_this;
krista@2920
    29
krista@4020
    30
//The fixture for KeyResetMessageTest
krista@4020
    31
class KeyResetMessageTest : public ::testing::Test {
krista@4020
    32
    public:
krista@4020
    33
        Engine* engine;
krista@4020
    34
        PEP_SESSION session;
krista@4020
    35
krista@4020
    36
        vector<message*> m_queue;
krista@4016
    37
        
krista@4020
    38
    protected:
krista@4020
    39
                    
krista@4020
    40
        const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
krista@4020
    41
        const char* bob_fpr = "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39";
krista@4020
    42
    
krista@4315
    43
        const char* alice_receive_reset_fpr = "B6C09F07E93CEEC39E5326DF1CCD0383597D2701";
krista@4016
    44
krista@4020
    45
        const string alice_user_id = PEP_OWN_USERID;
krista@4020
    46
        const string bob_user_id = "BobId";
krista@4020
    47
        const string carol_user_id = "carolId";
krista@4020
    48
        const string dave_user_id = "DaveId";
krista@4020
    49
        const string erin_user_id = "ErinErinErin";
krista@4020
    50
        const string fenris_user_id = "BadWolf";
krista@4016
    51
krista@4020
    52
        // You can remove any or all of the following functions if its body
krista@4020
    53
        // is empty.
krista@4020
    54
        KeyResetMessageTest() {
krista@4020
    55
            // You can do set-up work for each test here.
krista@4170
    56
            test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->GTEST_SUITE_SYM();
krista@4020
    57
            test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
krista@4020
    58
            test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
krista@4020
    59
        }
krista@4016
    60
krista@4020
    61
        ~KeyResetMessageTest() override {
krista@4020
    62
            // You can do clean-up work that doesn't throw exceptions here.
krista@4020
    63
        }
krista@4020
    64
krista@4020
    65
        // If the constructor and destructor are not enough for setting up
krista@4020
    66
        // and cleaning up each test, you can define the following methods:
krista@4016
    67
krista@4020
    68
        void SetUp() override {
krista@4020
    69
            // Code here will be called immediately after the constructor (right
krista@4020
    70
            // before each test).
krista@4016
    71
krista@4020
    72
            KRMT_fake_this = (void*)this;
krista@4020
    73
            // Leave this empty if there are no files to copy to the home directory path
krista@4020
    74
            std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
krista@4016
    75
krista@4020
    76
            // Get a new test Engine.
krista@4020
    77
            engine = new Engine(test_path);
krista@4020
    78
            ASSERT_NE(engine, nullptr);
krista@4016
    79
krista@4020
    80
            // Ok, let's initialize test directories etc.
krista@4020
    81
            engine->prep(&KRMT_message_send_callback, NULL, init_files);
krista@4016
    82
krista@4020
    83
            // Ok, try to start this bugger.
krista@4020
    84
            engine->start();
krista@4020
    85
            ASSERT_NE(engine->session, nullptr);
krista@4020
    86
            session = engine->session;
krista@3529
    87
krista@4020
    88
            // Engine is up. Keep on truckin'
krista@4020
    89
            m_queue.clear();
krista@4020
    90
        }
krista@2917
    91
krista@4020
    92
        void TearDown() override {
krista@4020
    93
            // Code here will be called immediately after each test (right
krista@4020
    94
            // before the destructor).
krista@4020
    95
            KRMT_fake_this = NULL;            
krista@4020
    96
            engine->shut_down();
krista@4020
    97
            delete engine;
krista@4020
    98
            engine = NULL;
krista@4020
    99
            session = NULL;
krista@4020
   100
        }
krista@4020
   101
        
krista@4020
   102
        void send_setup() {
krista@4020
   103
            // Setup own identity
krista@4020
   104
            PEP_STATUS status = read_file_and_import_key(session,
krista@4020
   105
                        "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
krista@4020
   106
            assert(status == PEP_KEY_IMPORTED);
krista@4020
   107
            status = set_up_ident_from_scratch(session,
krista@4020
   108
                        "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
krista@4020
   109
                        "pep.test.alice@pep-project.org", alice_fpr,
krista@4020
   110
                        alice_user_id.c_str(), "Alice in Wonderland", NULL, true
krista@4020
   111
                    );
krista@4020
   112
            ASSERT_EQ(status, PEP_STATUS_OK);
krista@4016
   113
krista@4020
   114
            status = set_up_ident_from_scratch(session,
krista@4020
   115
                        "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc",
krista@4020
   116
                        "pep.test.bob@pep-project.org", NULL, bob_user_id.c_str(), "Bob's Burgers",
krista@4020
   117
                        NULL, false
krista@4020
   118
                    );
krista@4020
   119
            ASSERT_EQ(status, PEP_STATUS_OK);
krista@4016
   120
krista@4020
   121
            status = set_up_ident_from_scratch(session,
krista@4020
   122
                        "test_keys/pub/pep-test-carol-0x42A85A42_pub.asc",
krista@4020
   123
                        "pep-test-carol@pep-project.org", NULL, carol_user_id.c_str(), "Carol Burnett",
krista@4020
   124
                        NULL, false
krista@4020
   125
                    );
krista@4020
   126
            ASSERT_EQ(status, PEP_STATUS_OK);
krista@2917
   127
krista@4020
   128
            status = set_up_ident_from_scratch(session,
krista@4020
   129
                        "test_keys/pub/pep-test-dave-0xBB5BCCF6_pub.asc",
krista@4020
   130
                        "pep-test-dave@pep-project.org", NULL, dave_user_id.c_str(),
krista@4020
   131
                        "David Hasselhoff (Germans Love Me)", NULL, false
krista@4020
   132
                    );
krista@4020
   133
            ASSERT_EQ(status, PEP_STATUS_OK);
krista@4016
   134
krista@4020
   135
            status = set_up_ident_from_scratch(session,
krista@4020
   136
                        "test_keys/pub/pep-test-erin-0x9F8D7CBA_pub.asc",
krista@4020
   137
                        "pep-test-erin@pep-project.org", NULL, erin_user_id.c_str(),
krista@4020
   138
                        "Éirinn go Brách", NULL, false
krista@4020
   139
                    );
krista@4020
   140
            ASSERT_EQ(status, PEP_STATUS_OK);
krista@4020
   141
krista@4020
   142
            status = set_up_ident_from_scratch(session,
krista@4020
   143
                        "test_keys/pub/pep.test.fenris-0x4F3D2900_pub.asc",
krista@4020
   144
                        "pep.test.fenris@thisstilldoesntwork.lu", NULL, fenris_user_id.c_str(),
krista@4020
   145
                        "Fenris Leto Hawke", NULL, false
krista@4020
   146
                    );
krista@4020
   147
            ASSERT_EQ(status, PEP_STATUS_OK);
krista@4020
   148
        }
krista@4016
   149
krista@4020
   150
        void receive_setup() {
krista@4020
   151
            PEP_STATUS status = read_file_and_import_key(session,
krista@4020
   152
                        "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");
krista@4020
   153
            assert(status == PEP_KEY_IMPORTED);
krista@4020
   154
            status = set_up_ident_from_scratch(session,
krista@4020
   155
                        "test_keys/priv/pep-test-bob-0xC9C2EE39_priv.asc",
krista@4020
   156
                        "pep.test.bob@pep-project.org", bob_fpr,
krista@4020
   157
                        bob_user_id.c_str(), "Robert Redford", NULL, true
krista@4020
   158
                    );
krista@4020
   159
            ASSERT_EQ(status, PEP_STATUS_OK);
krista@2917
   160
krista@4020
   161
            status = set_up_ident_from_scratch(session,
krista@4020
   162
                        "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc",
krista@4315
   163
                        "pep.test.alice@pep-project.org", NULL, alice_user_id.c_str(), "Alice in Wonderland",
krista@4020
   164
                        NULL, false
krista@4020
   165
                    );
krista@4020
   166
            ASSERT_EQ(status, PEP_STATUS_OK);
krista@4020
   167
        }
krista@4020
   168
        
krista@4020
   169
        void create_msg_for_revoked_key() {
krista@4020
   170
            PEP_STATUS status = set_up_ident_from_scratch(session,
krista@4020
   171
                        "test_keys/pub/pep-test-gabrielle-0xE203586C_pub.asc",
krista@4020
   172
                        "pep-test-gabrielle@pep-project.org", NULL, PEP_OWN_USERID,
krista@4020
   173
                        "Gabi", NULL, false
krista@4020
   174
                    );
krista@4020
   175
            ASSERT_EQ(status, PEP_STATUS_OK);
krista@4020
   176
            status = set_up_ident_from_scratch(session,
krista@4020
   177
                        "test_keys/priv/pep-test-gabrielle-0xE203586C_priv.asc",
krista@4020
   178
                        "pep-test-gabrielle@pep-project.org", NULL, PEP_OWN_USERID,
krista@4020
   179
                        "Gabi", NULL, false
krista@4020
   180
                    );
krista@4020
   181
            ASSERT_EQ(status, PEP_STATUS_OK);
krista@4016
   182
krista@4020
   183
            status = set_up_ident_from_scratch(session,
krista@4020
   184
                        "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc",
krista@4315
   185
                        "pep.test.alice@pep-project.org", NULL, "AliceOther", "Alice in Wonderland",
krista@4020
   186
                        NULL, false
krista@4020
   187
                    );
krista@2917
   188
krista@4020
   189
            pEp_identity* from_ident = new_identity("pep-test-gabrielle@pep-project.org", NULL, PEP_OWN_USERID, NULL);
krista@4020
   190
            status = myself(session, from_ident);
krista@4020
   191
            ASSERT_EQ(status , PEP_STATUS_OK);
krista@4020
   192
            ASSERT_NE(from_ident->fpr, nullptr);
krista@4020
   193
            ASSERT_STRCASEEQ(from_ident->fpr, "906C9B8349954E82C5623C3C8C541BD4E203586C");
krista@4020
   194
            ASSERT_TRUE(from_ident->me);
krista@2917
   195
krista@4020
   196
            // "send" some messages to update the social graph entries
krista@4020
   197
            identity_list* send_idents =
krista@4020
   198
                new_identity_list(
krista@4020
   199
                    new_identity("pep.test.alice@pep-project.org", NULL, "AliceOther", NULL));
krista@4020
   200
            status = update_identity(session, send_idents->ident);
krista@4020
   201
            ASSERT_EQ(status , PEP_STATUS_OK);
krista@4020
   202
            status = set_as_pEp_user(session, send_idents->ident);
krista@4016
   203
krista@4020
   204
            message* outgoing_msg = new_message(PEP_dir_outgoing);
krista@4020
   205
            ASSERT_NE(outgoing_msg, nullptr);
krista@4020
   206
            outgoing_msg->from = from_ident;
krista@4020
   207
            outgoing_msg->to = send_idents;
krista@4020
   208
            outgoing_msg->shortmsg = strdup("Well isn't THIS a useless message...");
krista@4020
   209
            outgoing_msg->longmsg = strdup("Hi Mom...\n");
krista@4020
   210
            outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
krista@4021
   211
            output_stream << "Message created.\n\n";
krista@4021
   212
            output_stream << "Encrypting message as MIME multipart…\n";
krista@4020
   213
            message* enc_outgoing_msg = nullptr;
krista@4021
   214
            output_stream << "Calling encrypt_message()\n";
krista@4020
   215
            status = encrypt_message(session, outgoing_msg, NULL, &enc_outgoing_msg, PEP_enc_PGP_MIME, 0);
krista@4020
   216
            ASSERT_EQ(status , PEP_STATUS_OK);
krista@4020
   217
            ASSERT_NE(enc_outgoing_msg, nullptr);
krista@4021
   218
            output_stream << "Message encrypted.\n";
krista@4020
   219
            char* outstring = NULL;
krista@4020
   220
            mime_encode_message(enc_outgoing_msg, false, &outstring);
krista@4021
   221
            output_stream << outstring << endl;
krista@4020
   222
            free_message(enc_outgoing_msg);
krista@4020
   223
            free(outstring);
krista@4020
   224
        }
krista@2917
   225
krista@4020
   226
    private:
krista@4020
   227
        const char* test_suite_name;
krista@4020
   228
        const char* test_name;
krista@4020
   229
        string test_path;
krista@4020
   230
        // Objects declared here can be used by all tests in the KeyResetMessageTest suite.
krista@2892
   231
krista@4020
   232
};
krista@4016
   233
krista@4020
   234
PEP_STATUS KRMT_message_send_callback(message* msg) {
krista@4020
   235
    ((KeyResetMessageTest*)KRMT_fake_this)->m_queue.push_back(msg);
krista@4020
   236
    return PEP_STATUS_OK;
krista@4020
   237
}
krista@4016
   238
krista@4323
   239
krista@4016
   240
TEST_F(KeyResetMessageTest, check_reset_key_and_notify) {
krista@2917
   241
    send_setup();
krista@4016
   242
krista@2917
   243
    pEp_identity* from_ident = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, NULL);
krista@4016
   244
    PEP_STATUS status = myself(session, from_ident);
krista@4016
   245
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4020
   246
    ASSERT_NE(from_ident->fpr, nullptr);
krista@4020
   247
    ASSERT_STRCASEEQ(from_ident->fpr, alice_fpr);
krista@4020
   248
    ASSERT_TRUE(from_ident->me);
krista@4016
   249
krista@2917
   250
    // "send" some messages to update the social graph entries
krista@4016
   251
    identity_list* send_idents =
krista@2917
   252
        new_identity_list(
krista@4016
   253
            new_identity("pep.test.bob@pep-project.org",
krista@2940
   254
                         NULL, bob_user_id.c_str(), "Bob's Burgers"));
krista@4016
   255
krista@4016
   256
    identity_list_add(send_idents, new_identity("pep-test-carol@pep-project.org", NULL, NULL, NULL));
krista@4016
   257
    identity_list_add(send_idents, new_identity("pep-test-dave@pep-project.org", NULL, NULL, NULL));
krista@4016
   258
    identity_list_add(send_idents, new_identity("pep-test-erin@pep-project.org", NULL, NULL, NULL));
krista@4016
   259
    identity_list_add(send_idents, new_identity("pep.test.fenris@thisstilldoesntwork.lu", NULL, NULL, NULL));
krista@2940
   260
krista@2940
   261
    identity_list* curr_ident;
krista@4016
   262
krista@2940
   263
    for (curr_ident = send_idents; curr_ident && curr_ident->ident; curr_ident = curr_ident->next) {
krista@2940
   264
        status = update_identity(session, curr_ident->ident);
krista@2940
   265
        if (strcmp(curr_ident->ident->user_id, bob_user_id.c_str()) == 0)
krista@2940
   266
            continue;
krista@4016
   267
krista@2956
   268
        status = set_as_pEp_user(session, curr_ident->ident);
krista@4016
   269
        ASSERT_EQ(status , PEP_STATUS_OK);
krista@2940
   270
    }
krista@4016
   271
krista@4021
   272
    output_stream << "Creating outgoing message to update DB" << endl;
krista@2917
   273
    message* outgoing_msg = new_message(PEP_dir_outgoing);
krista@4016
   274
    ASSERT_NE(outgoing_msg, nullptr);
krista@2917
   275
    outgoing_msg->from = from_ident;
krista@2917
   276
    outgoing_msg->to = send_idents;
krista@2917
   277
    outgoing_msg->shortmsg = strdup("Well isn't THIS a useless message...");
krista@2917
   278
    outgoing_msg->longmsg = strdup("Hi Mom...\n");
krista@3335
   279
    // outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
krista@3335
   280
    // that's illegal - VB.
krista@4021
   281
    output_stream << "Message created.\n\n";
krista@4021
   282
    output_stream << "Encrypting message as MIME multipart…\n";
krista@2917
   283
    message* enc_outgoing_msg = nullptr;
krista@4021
   284
    output_stream << "Calling encrypt_message()\n";
krista@2917
   285
    status = encrypt_message(session, outgoing_msg, NULL, &enc_outgoing_msg, PEP_enc_PGP_MIME, 0);
krista@4016
   286
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
   287
    ASSERT_NE(enc_outgoing_msg, nullptr);
krista@4021
   288
    output_stream << "Message encrypted.\n";
krista@4016
   289
krista@4016
   290
    // If this all worked, we should have a list of recent guys in our DB which, when we reset Alice's
krista@2917
   291
    // key, will get sent some nice key reset messages.
krista@2917
   292
    // But... we need to have one look like an older message. So. Time to mess with the DB.
krista@2920
   293
    // Dave is our victim. Because I have a friend called Dave, who is actually a nice dude, but it amuses me.
krista@2933
   294
    // (Note: said friend is NOT David Hasselhoff. To my knowledge. Hi Dave! (Addendum: Dave confirms he is
krista@2933
   295
    // not Hasselhoff. But he wishes he were, sort of.))
krista@2917
   296
    //
krista@2917
   297
    // update identity
krista@2917
   298
    //      set timestamp = 661008730
krista@2917
   299
    //      where address = "pep-test-dave@pep-project.org"
krista@2917
   300
    int int_result = sqlite3_exec(
krista@2917
   301
        session->db,
krista@2917
   302
        "update identity "
krista@2917
   303
        "   set timestamp = 661008730 "
krista@2917
   304
        "   where address = 'pep-test-dave@pep-project.org' ;",
krista@2917
   305
        NULL,
krista@2917
   306
        NULL,
krista@2917
   307
        NULL
krista@2917
   308
    );
krista@4016
   309
    ASSERT_EQ(int_result , SQLITE_OK);
krista@4016
   310
krista@4312
   311
    status = key_reset(session, alice_fpr, from_ident);
krista@4016
   312
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
   313
    ASSERT_GT(m_queue.size(), 0);
krista@2936
   314
    status = myself(session, from_ident);
krista@2936
   315
    string new_fpr = from_ident->fpr;
krista@4016
   316
    ASSERT_STRNE(alice_fpr, new_fpr.c_str());
krista@4016
   317
krista@2920
   318
    unordered_map<string, bool> hashmap;
krista@2920
   319
    hashmap[alice_user_id] = false;
krista@2920
   320
    hashmap[bob_user_id] = false;
krista@2920
   321
    hashmap[carol_user_id] = false;
krista@2920
   322
    hashmap[dave_user_id] = false;
krista@2920
   323
    hashmap[erin_user_id] = false;
krista@2920
   324
    hashmap[fenris_user_id] = false;
krista@4016
   325
krista@2924
   326
    // Number of messages we SHOULD be sending.
krista@4016
   327
    ASSERT_EQ(m_queue.size(), 4);
krista@4016
   328
krista@3335
   329
    for (vector<message*>::iterator it = m_queue.begin(); it != m_queue.end(); it++) {
krista@2920
   330
        message* curr_sent_msg = *it;
krista@4016
   331
        ASSERT_NE(curr_sent_msg, nullptr);
krista@4016
   332
        ASSERT_NE(curr_sent_msg->to, nullptr);
krista@4016
   333
        ASSERT_NE(curr_sent_msg->to->ident, nullptr);
krista@4020
   334
        ASSERT_EQ(curr_sent_msg->to->next, nullptr);
krista@2920
   335
        pEp_identity* to = curr_sent_msg->to->ident;
krista@4016
   336
        ASSERT_NE(to, nullptr);
krista@4016
   337
        ASSERT_NE(to->user_id, nullptr);
krista@4016
   338
krista@2920
   339
        unordered_map<string, bool>::iterator jt = hashmap.find(to->user_id);
krista@4016
   340
krista@4016
   341
        ASSERT_NE(jt, hashmap.end());
krista@4016
   342
        hashmap[jt->first] = true;
krista@2936
   343
krista@2936
   344
        // Uncomment to regenerate received message - remember to update
krista@4016
   345
        // alice_receive_reset_fpr
krista@4315
   346
        if (false) {
krista@4315
   347
            if (strcmp(curr_sent_msg->to->ident->user_id, bob_user_id.c_str()) == 0) {
krista@4315
   348
                ofstream outfile;
krista@4315
   349
                outfile.open("test_files/398_reset_from_alice_to_bob.eml");
krista@4315
   350
                char* bob_msg = NULL;
krista@4315
   351
                mime_encode_message(curr_sent_msg, false, &bob_msg);
krista@4315
   352
                outfile << bob_msg;
krista@4315
   353
                outfile.close();
krista@4315
   354
            }
krista@4315
   355
            else if (strcmp(curr_sent_msg->to->ident->user_id, fenris_user_id.c_str()) == 0) {
krista@4315
   356
                ofstream outfile;
krista@4315
   357
                outfile.open("test_files/398_reset_from_alice_to_fenris.eml");            
krista@4315
   358
                char* fenris_msg = NULL;
krista@4315
   359
                mime_encode_message(curr_sent_msg, false, &fenris_msg);
krista@4315
   360
                outfile << fenris_msg;
krista@4315
   361
                outfile.close();
krista@4315
   362
            }
krista@4315
   363
        }    
krista@2920
   364
    }
krista@4016
   365
krista@2933
   366
    // MESSAGE LIST NOW INVALID.
krista@3335
   367
    m_queue.clear();
krista@4016
   368
krista@2933
   369
    // Make sure we have messages only to desired recips
krista@4016
   370
    ASSERT_FALSE(hashmap[alice_user_id]);
krista@4016
   371
    ASSERT_TRUE(hashmap[bob_user_id]);
krista@4016
   372
    ASSERT_TRUE(hashmap[carol_user_id]);
krista@4016
   373
    ASSERT_FALSE(hashmap[dave_user_id]);
krista@4016
   374
    ASSERT_TRUE(hashmap[erin_user_id]);
krista@4016
   375
    ASSERT_TRUE(hashmap[fenris_user_id]);
krista@4315
   376
    cout << "HEY! reset_fpr is " << new_fpr << endl;    
krista@2917
   377
}
krista@2917
   378
krista@4323
   379
krista@4016
   380
TEST_F(KeyResetMessageTest, check_non_reset_receive_revoked) {
krista@2924
   381
    receive_setup();
krista@2924
   382
    pEp_identity* alice_ident = new_identity("pep.test.alice@pep-project.org", NULL,
krista@2924
   383
                                            alice_user_id.c_str(), NULL);
krista@4016
   384
krista@2924
   385
    PEP_STATUS status = update_identity(session, alice_ident);
krista@4016
   386
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
   387
    ASSERT_STREQ(alice_fpr, alice_ident->fpr);
krista@4016
   388
krista@2924
   389
    string received_mail = slurp("test_files/398_reset_from_alice_to_bob.eml");
krista@2924
   390
    char* decrypted_msg = NULL;
krista@2924
   391
    char* modified_src = NULL;
krista@2924
   392
    stringlist_t* keylist = NULL;
krista@2924
   393
    PEP_rating rating;
krista@2924
   394
    PEP_decrypt_flags_t flags;
krista@2924
   395
    status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(),
krista@2924
   396
                                  &decrypted_msg, &keylist, &rating, &flags, &modified_src);
krista@4016
   397
krista@4016
   398
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
   399
    ASSERT_NE(keylist, nullptr);
krista@2933
   400
    if (keylist) // there's a test option to continue when asserts fail, so...
krista@4020
   401
        ASSERT_STREQ(keylist->value,alice_receive_reset_fpr);
krista@4016
   402
krista@2924
   403
    status = update_identity(session, alice_ident);
krista@4016
   404
    ASSERT_NE(alice_ident->fpr, nullptr);
krista@4020
   405
    ASSERT_STREQ(alice_receive_reset_fpr,alice_ident->fpr);
krista@4016
   406
krista@2933
   407
    keylist = NULL;
krista@2933
   408
krista@4016
   409
    free(keylist);
krista@2940
   410
}
krista@2940
   411
krista@4016
   412
TEST_F(KeyResetMessageTest, check_reset_receive_revoked) {
krista@2940
   413
    PEP_STATUS status = set_up_ident_from_scratch(session,
krista@2940
   414
                "test_keys/pub/pep.test.fenris-0x4F3D2900_pub.asc",
krista@4016
   415
                "pep.test.fenris@thisstilldoesntwork.lu", NULL, fenris_user_id.c_str(),
krista@2940
   416
                "Fenris Leto Hawke", NULL, false
krista@2940
   417
            );
krista@4016
   418
    ASSERT_EQ(status, PEP_STATUS_OK);
krista@2940
   419
    status = set_up_ident_from_scratch(session,
krista@2940
   420
                "test_keys/priv/pep.test.fenris-0x4F3D2900_priv.asc",
krista@4016
   421
                "pep.test.fenris@thisstilldoesntwork.lu", NULL, fenris_user_id.c_str(),
krista@4315
   422
                "Fenris Leto Hawke", NULL, true
krista@2940
   423
            );
krista@4016
   424
    ASSERT_EQ(status, PEP_STATUS_OK);
krista@4016
   425
krista@2940
   426
    status = set_up_ident_from_scratch(session,
krista@2940
   427
                "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc",
krista@4315
   428
                "pep.test.alice@pep-project.org", NULL, "ALICE_IS_NOT_OWN_ID", "Alice in Wonderland",
krista@2940
   429
                NULL, false
krista@2940
   430
            );
krista@4016
   431
    ASSERT_EQ(status, PEP_STATUS_OK);
krista@4016
   432
krista@2940
   433
    pEp_identity* alice_ident = new_identity("pep.test.alice@pep-project.org", NULL,
krista@4315
   434
                                            "ALICE_IS_NOT_OWN_ID", "Alice in Wonderland");
krista@4016
   435
krista@2940
   436
    status = update_identity(session, alice_ident);
krista@4016
   437
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
   438
    ASSERT_STREQ(alice_fpr, alice_ident->fpr);
krista@4016
   439
krista@2940
   440
    string received_mail = slurp("test_files/398_reset_from_alice_to_fenris.eml");
krista@2940
   441
    char* decrypted_msg = NULL;
krista@2940
   442
    char* modified_src = NULL;
krista@2940
   443
    stringlist_t* keylist = NULL;
krista@2940
   444
    PEP_rating rating;
krista@2940
   445
    PEP_decrypt_flags_t flags;
krista@2940
   446
    status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(),
krista@2940
   447
                                  &decrypted_msg, &keylist, &rating, &flags, &modified_src);
krista@4016
   448
krista@4016
   449
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
   450
    ASSERT_NE(keylist, nullptr);
krista@2940
   451
    if (keylist) // there's a test option to continue when asserts fail, so...
krista@4016
   452
        ASSERT_STREQ(keylist->value, alice_receive_reset_fpr);
krista@4016
   453
krista@2940
   454
    status = update_identity(session, alice_ident);
krista@4016
   455
    ASSERT_NE(alice_ident->fpr, nullptr);
krista@4016
   456
    ASSERT_STREQ(alice_receive_reset_fpr, alice_ident->fpr);
krista@4016
   457
krista@2940
   458
    keylist = NULL;
krista@2940
   459
krista@4016
   460
    free(keylist);
krista@2917
   461
}
krista@2917
   462
krista@4323
   463
krista@4016
   464
TEST_F(KeyResetMessageTest, check_receive_message_to_revoked_key_from_unknown) {
krista@4016
   465
    // create_msg_for_revoked_key(); // call to recreate msg
krista@4016
   466
    send_setup();
krista@4016
   467
    pEp_identity* from_ident = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, NULL);
krista@4016
   468
    PEP_STATUS status = myself(session, from_ident);
krista@4016
   469
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4020
   470
    ASSERT_NE(from_ident->fpr, nullptr);
krista@4020
   471
    ASSERT_STRCASEEQ(from_ident->fpr, alice_fpr);
krista@4016
   472
    ASSERT_TRUE(from_ident->me);
krista@4016
   473
krista@4312
   474
    status = key_reset(session, alice_fpr, from_ident);
krista@4016
   475
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
   476
    m_queue.clear();
krista@4016
   477
krista@4016
   478
    string received_mail = slurp("test_files/398_gabrielle_to_alice.eml");
krista@4016
   479
    char* decrypted_msg = NULL;
krista@4016
   480
    char* modified_src = NULL;
krista@4016
   481
    stringlist_t* keylist = NULL;
krista@4016
   482
    PEP_rating rating;
krista@4016
   483
    PEP_decrypt_flags_t flags;
krista@4016
   484
    status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(),
krista@4016
   485
                                  &decrypted_msg, &keylist, &rating, &flags, &modified_src);
krista@4016
   486
    ASSERT_EQ(m_queue.size() , 0);
krista@4016
   487
    free(decrypted_msg);
krista@4016
   488
    free(modified_src);
krista@4016
   489
    free_stringlist(keylist);
krista@4016
   490
    free_identity(from_ident);
krista@4016
   491
}
krista@4016
   492
krista@4323
   493
krista@4016
   494
TEST_F(KeyResetMessageTest, check_receive_message_to_revoked_key_from_contact) {
krista@4016
   495
    // create_msg_for_revoked_key(); // call to recreate msg
krista@4016
   496
    send_setup();
krista@4016
   497
    pEp_identity* from_ident = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, NULL);
krista@4016
   498
    PEP_STATUS status = myself(session, from_ident);
krista@4016
   499
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4019
   500
    ASSERT_NE(from_ident->fpr, nullptr);
krista@4016
   501
    ASSERT_STRCASEEQ(from_ident->fpr, alice_fpr);
krista@4016
   502
    ASSERT_TRUE(from_ident->me);
krista@4016
   503
krista@4016
   504
    // Send Gabrielle a message
krista@4016
   505
    identity_list* send_idents = new_identity_list(new_identity("pep-test-gabrielle@pep-project.org", NULL, "Gabi", "Gabi"));
krista@4021
   506
    output_stream << "Creating outgoing message to update DB" << endl;
krista@2942
   507
    message* outgoing_msg = new_message(PEP_dir_outgoing);
krista@4016
   508
    ASSERT_NE(outgoing_msg, nullptr);
krista@2942
   509
    outgoing_msg->from = from_ident;
krista@2942
   510
    outgoing_msg->to = send_idents;
krista@2942
   511
    outgoing_msg->shortmsg = strdup("Well isn't THIS a useless message...");
krista@2942
   512
    outgoing_msg->longmsg = strdup("Hi Mom...\n");
krista@2942
   513
    outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
krista@4021
   514
    output_stream << "Message created.\n\n";
krista@4021
   515
    output_stream << "Encrypting message as MIME multipart…\n";
krista@2942
   516
    message* enc_outgoing_msg = nullptr;
krista@4021
   517
    output_stream << "Calling encrypt_message()\n";
krista@2942
   518
    status = encrypt_message(session, outgoing_msg, NULL, &enc_outgoing_msg, PEP_enc_PGP_MIME, 0);
krista@4016
   519
    ASSERT_EQ(status , PEP_UNENCRYPTED);
krista@2942
   520
    //
krista@4021
   521
    output_stream << "Message created." << endl;
krista@4016
   522
krista@2942
   523
    // Make the update have occurred earlier, so we don't notify her
krista@2942
   524
    // (We have no key for her yet anyway!)
krista@2942
   525
    int int_result = sqlite3_exec(
krista@2942
   526
        session->db,
krista@2942
   527
        "update identity "
krista@3495
   528
        "   set timestamp = '2018-04-10 16:48:33' "
krista@2942
   529
        "   where address = 'pep-test-gabrielle@pep-project.org' ;",
krista@2942
   530
        NULL,
krista@2942
   531
        NULL,
krista@2942
   532
        NULL
krista@2942
   533
    );
krista@4016
   534
    ASSERT_EQ(int_result , SQLITE_OK);
krista@2942
   535
krista@3173
   536
    // FIXME: longer term we need to fix the test, but the key attached to the message below has expired, so for now, we give her a new key
krista@3173
   537
    slurp_and_import_key(session, "test_keys/pub/pep-test-gabrielle-0xE203586C_pub.asc");
krista@3173
   538
krista@4312
   539
    status = key_reset(session, alice_fpr, from_ident);
krista@4016
   540
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
   541
    ASSERT_EQ(m_queue.size() , 0);
krista@3335
   542
    m_queue.clear();
krista@2942
   543
krista@2942
   544
    // Now we get mail from Gabi, who only has our old key AND has become
krista@2942
   545
    // a pEp user in the meantime...
krista@2942
   546
    string received_mail = slurp("test_files/398_gabrielle_to_alice.eml");
krista@2942
   547
    char* decrypted_msg = NULL;
krista@2942
   548
    char* modified_src = NULL;
krista@2942
   549
    stringlist_t* keylist = NULL;
krista@2942
   550
    PEP_rating rating;
krista@2942
   551
    PEP_decrypt_flags_t flags;
krista@2942
   552
    status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(),
krista@2942
   553
                                  &decrypted_msg, &keylist, &rating, &flags, &modified_src);
krista@4016
   554
krista@4016
   555
    ASSERT_EQ(m_queue.size() , 1);
krista@3335
   556
    vector<message*>::iterator it = m_queue.begin();
krista@2942
   557
    message* reset_msg = *it;
krista@4016
   558
    ASSERT_NE(reset_msg, nullptr);
krista@4016
   559
    ASSERT_NE(reset_msg->from, nullptr);
krista@4016
   560
    ASSERT_NE(reset_msg->to, nullptr);
krista@4016
   561
    ASSERT_NE(reset_msg->to->ident, nullptr);
krista@4016
   562
    ASSERT_STREQ(reset_msg->to->ident->address, "pep-test-gabrielle@pep-project.org");
krista@4016
   563
    ASSERT_STREQ(reset_msg->to->ident->fpr, "906C9B8349954E82C5623C3C8C541BD4E203586C");
krista@4016
   564
    ASSERT_STRNE(reset_msg->from->fpr, alice_fpr);
krista@4016
   565
    ASSERT_NE(keylist, nullptr);
krista@4016
   566
    ASSERT_NE(keylist->value, nullptr);
krista@4016
   567
    ASSERT_STRNE(keylist->value, alice_fpr);
krista@4016
   568
    ASSERT_NE(keylist->next, nullptr);
krista@4016
   569
    if (strcmp(keylist->next->value, "906C9B8349954E82C5623C3C8C541BD4E203586C") != 0) {
krista@4016
   570
        ASSERT_NE(keylist->next->next, nullptr);
krista@4016
   571
        ASSERT_STREQ(keylist->next->value, "906C9B8349954E82C5623C3C8C541BD4E203586C");
krista@4016
   572
    }
krista@2917
   573
}
krista@3174
   574
krista@4323
   575
krista@4016
   576
TEST_F(KeyResetMessageTest, check_multiple_resets_single_key) {
krista@3174
   577
    send_setup();
krista@4016
   578
krista@3174
   579
    pEp_identity* from_ident = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, NULL);
krista@4016
   580
    PEP_STATUS status = myself(session, from_ident);
krista@4016
   581
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4020
   582
    ASSERT_NE(from_ident->fpr, nullptr);
krista@4020
   583
    ASSERT_STRCASEEQ(from_ident->fpr, alice_fpr);
krista@4016
   584
    ASSERT_TRUE(from_ident->me);
krista@3174
   585
krista@4312
   586
    status = key_reset(session, NULL, NULL);
krista@4016
   587
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
   588
krista@4312
   589
    status = key_reset(session, NULL, NULL);
krista@4016
   590
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
   591
krista@3174
   592
    status = myself(session, from_ident);
krista@4016
   593
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
   594
    ASSERT_TRUE(from_ident->fpr != NULL && from_ident->fpr[0] != 0);
krista@3270
   595
}
krista@3507
   596
krista@4323
   597
krista@4016
   598
TEST_F(KeyResetMessageTest, check_reset_ident_uid_only) {
krista@3507
   599
    send_setup(); // lazy
krista@3507
   600
    pEp_identity* bob = new_identity(NULL, NULL, bob_user_id.c_str(), NULL);
krista@3507
   601
krista@3507
   602
    // Ok, let's reset it
krista@3507
   603
    PEP_STATUS status = key_reset_identity(session, bob, NULL);
krista@4016
   604
    ASSERT_EQ(status , PEP_ILLEGAL_VALUE);
krista@3507
   605
}
krista@3507
   606
krista@4323
   607
krista@4016
   608
TEST_F(KeyResetMessageTest, check_reset_ident_address_only) {
krista@3507
   609
    send_setup(); // lazy
krista@3507
   610
    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, NULL, NULL);
krista@3507
   611
krista@3507
   612
    PEP_STATUS status = key_reset_identity(session, bob, NULL);
krista@4016
   613
    ASSERT_EQ(status , PEP_ILLEGAL_VALUE);
krista@3507
   614
}
krista@3507
   615
krista@4323
   616
krista@4016
   617
TEST_F(KeyResetMessageTest, check_reset_ident_null_ident) {
krista@3507
   618
    // Ok, let's reset it
krista@3507
   619
    PEP_STATUS status = key_reset_identity(session, NULL, NULL);
krista@4016
   620
    ASSERT_EQ(status , PEP_ILLEGAL_VALUE);
krista@3507
   621
}
krista@3507
   622
krista@4320
   623
TEST_F(KeyResetMessageTest, check_reset_grouped_own) {
krista@4320
   624
    send_setup(); // lazy
krista@4320
   625
    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", NULL, alice_user_id.c_str(), NULL);
krista@4320
   626
    PEP_STATUS status = myself(session, alice);
krista@4320
   627
krista@4320
   628
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4320
   629
    ASSERT_TRUE(alice->fpr && alice->fpr[0]);
krista@4320
   630
    ASSERT_TRUE(alice->me);
krista@4320
   631
    ASSERT_STREQ(alice->fpr, alice_fpr);
krista@4320
   632
krista@4320
   633
    status = set_identity_flags(session, alice, alice->flags | PEP_idf_devicegroup);
krista@4320
   634
    status = key_reset_identity(session, alice, alice_fpr);
krista@4320
   635
    status = myself(session, alice);
krista@4320
   636
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4320
   637
    char* alice_new_fpr = alice->fpr;
krista@4320
   638
    ASSERT_TRUE(alice_new_fpr && alice_new_fpr[0]);
krista@4320
   639
    ASSERT_STRNE(alice_fpr, alice_new_fpr);
krista@4320
   640
    
krista@4320
   641
    ASSERT_EQ(m_queue.size(), 1);
krista@4321
   642
    
krista@4321
   643
    if (false) {
krista@4321
   644
        ofstream outfile;
krista@4321
   645
        outfile.open("test_mails/check_reset_grouped_own_recv.eml");
krista@4321
   646
        message* curr_sent_msg = m_queue.at(0);
krista@4321
   647
        char* msg_txt = NULL;
krista@4321
   648
        mime_encode_message(curr_sent_msg, false, &msg_txt);
krista@4321
   649
        outfile << msg_txt;
krista@4321
   650
        outfile.close();
krista@4321
   651
    }
krista@4321
   652
}
krista@4320
   653
krista@4321
   654
TEST_F(KeyResetMessageTest, check_reset_grouped_own_recv) {
krista@4321
   655
    send_setup(); // lazy
krista@4321
   656
    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", NULL, alice_user_id.c_str(), NULL);
krista@4321
   657
    PEP_STATUS status = myself(session, alice);
krista@4321
   658
krista@4321
   659
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4321
   660
    ASSERT_TRUE(alice->fpr && alice->fpr[0]);
krista@4321
   661
    ASSERT_TRUE(alice->me);
krista@4321
   662
    ASSERT_STREQ(alice->fpr, alice_fpr);
krista@4321
   663
krista@4321
   664
    status = set_identity_flags(session, alice, alice->flags | PEP_idf_devicegroup);
krista@4321
   665
    ASSERT_EQ(status , PEP_STATUS_OK);    
krista@4321
   666
    status = myself(session, alice);
krista@4321
   667
    ASSERT_EQ(status , PEP_STATUS_OK);    
krista@4321
   668
krista@4321
   669
    string received_mail = slurp("test_mails/check_reset_grouped_own_recv.eml");
krista@4321
   670
    char* decrypted_msg = NULL;
krista@4321
   671
    char* modified_src = NULL;
krista@4321
   672
    stringlist_t* keylist = NULL;
krista@4321
   673
    PEP_rating rating;
krista@4321
   674
    PEP_decrypt_flags_t flags;
krista@4321
   675
    status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(),
krista@4321
   676
                                  &decrypted_msg, &keylist, &rating, &flags, &modified_src);
krista@4321
   677
krista@4321
   678
    status = myself(session, alice);
krista@4321
   679
    ASSERT_EQ(status , PEP_STATUS_OK);                                     
krista@4321
   680
    ASSERT_STRNE(alice->fpr, alice_fpr);
krista@4321
   681
    ASSERT_STREQ(alice->fpr, "6E8AD7C3AB59FFBE62CDC1B5B625A54EB1D486E9");
krista@4321
   682
    
krista@4321
   683
    bool revoked = false;
krista@4321
   684
    status = key_revoked(session, alice_fpr, &revoked);
krista@4321
   685
    ASSERT_EQ(status, PEP_STATUS_OK);
krista@4321
   686
    ASSERT_TRUE(revoked);
krista@4321
   687
                                  
krista@4320
   688
}
krista@4320
   689
krista@4323
   690
TEST_F(KeyResetMessageTest, check_reset_grouped_own_multi_ident_one_fpr) {
krista@4323
   691
    char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
krista@4320
   692
krista@4323
   693
    pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
krista@4323
   694
                                        NULL,
krista@4323
   695
                                        "AlexID",
krista@4323
   696
                                        "Alexander Braithwaite");
krista@4323
   697
krista@4323
   698
    pEp_identity* alex_id2 = new_identity("pep.test.alexander6@darthmama.org",
krista@4323
   699
                                          NULL,
krista@4323
   700
                                          "AlexID",
krista@4323
   701
                                          "Alexander Braithwaite");
krista@4323
   702
    
krista@4323
   703
    pEp_identity* alex_id3 = new_identity("pep.test.alexander6a@darthmama.org",
krista@4323
   704
                                          NULL,
krista@4323
   705
                                          "AlexID",
krista@4323
   706
                                          "Alexander Braithwaite");
krista@4323
   707
krista@4323
   708
    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
krista@4323
   709
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x0019697D_priv.asc");
krista@4323
   710
krista@4323
   711
    alex_id->me = true;
krista@4323
   712
    status = set_own_key(session, alex_id, pubkey1);
krista@4323
   713
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   714
krista@4323
   715
    alex_id2->me = true;
krista@4323
   716
    status = set_own_key(session, alex_id2, pubkey1);
krista@4323
   717
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   718
krista@4323
   719
    alex_id3->me = true;
krista@4323
   720
    status = set_own_key(session, alex_id3, pubkey1);
krista@4323
   721
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   722
        
krista@4323
   723
    status = myself(session, alex_id);
krista@4323
   724
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   725
    ASSERT_STREQ(pubkey1, alex_id->fpr);
krista@4323
   726
    
krista@4323
   727
    status = myself(session, alex_id2);
krista@4323
   728
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   729
    ASSERT_STREQ(pubkey1, alex_id2->fpr);
krista@4323
   730
krista@4323
   731
    status = myself(session, alex_id3);
krista@4323
   732
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   733
    ASSERT_STREQ(pubkey1, alex_id3->fpr);
krista@4323
   734
krista@4324
   735
    status = key_reset_identity(session, alex_id, pubkey1);
krista@4323
   736
krista@4323
   737
    alex_id->fpr = pubkey1;
krista@4323
   738
    status = get_trust(session, alex_id);
krista@4323
   739
    ASSERT_EQ(alex_id->comm_type , PEP_ct_mistrusted);
krista@4323
   740
krista@4323
   741
    bool revoked = false;
krista@4323
   742
    status = key_revoked(session, pubkey1, &revoked);
krista@4323
   743
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   744
    ASSERT_TRUE(revoked);    
krista@4323
   745
    
krista@4323
   746
    status = myself(session, alex_id);
krista@4323
   747
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   748
    ASSERT_STRNE(pubkey1, alex_id->fpr);
krista@4323
   749
    
krista@4323
   750
    status = myself(session, alex_id2);
krista@4323
   751
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   752
    ASSERT_STRNE(pubkey1, alex_id2->fpr);
krista@4323
   753
krista@4323
   754
    status = myself(session, alex_id3);
krista@4323
   755
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   756
    ASSERT_STRNE(pubkey1, alex_id3->fpr);
krista@4323
   757
    
krista@4323
   758
    ASSERT_STRNE(alex_id->fpr, alex_id2->fpr);
krista@4323
   759
    ASSERT_STRNE(alex_id->fpr, alex_id3->fpr);
krista@4323
   760
    ASSERT_STRNE(alex_id2->fpr, alex_id3->fpr);
krista@4323
   761
krista@4323
   762
    free_identity(alex_id);
krista@4323
   763
    free_identity(alex_id2);
krista@4323
   764
    free_identity(alex_id3);    
krista@4323
   765
}
krista@4323
   766
krista@4323
   767
TEST_F(KeyResetMessageTest, check_reset_grouped_own_multiple_keys_multiple_idents_reset_all) {
krista@4323
   768
    char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
krista@4323
   769
    char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
krista@4323
   770
    char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
krista@4323
   771
krista@4323
   772
    pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
krista@4323
   773
                                        NULL,
krista@4323
   774
                                        "AlexID",
krista@4323
   775
                                        "Alexander Braithwaite");
krista@4323
   776
krista@4323
   777
    pEp_identity* alex_id2 = new_identity("pep.test.alexander6@darthmama.org",
krista@4323
   778
                                          NULL,
krista@4323
   779
                                          "AlexID",
krista@4323
   780
                                          "Alexander Braithwaite");
krista@4323
   781
    
krista@4323
   782
    pEp_identity* alex_id3 = new_identity("pep.test.alexander6a@darthmama.org",
krista@4323
   783
                                          NULL,
krista@4323
   784
                                          "AlexID",
krista@4323
   785
                                          "Alexander Braithwaite");
krista@4323
   786
krista@4323
   787
krista@4323
   788
    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
krista@4323
   789
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
krista@4323
   790
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
krista@4323
   791
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x0019697D_priv.asc");
krista@4323
   792
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x503B14D8_priv.asc");
krista@4323
   793
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xA216E95A_priv.asc");
krista@4323
   794
krista@4323
   795
    alex_id->me = true;
krista@4323
   796
    status = set_own_key(session, alex_id, pubkey1);
krista@4323
   797
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   798
krista@4323
   799
    alex_id2->me = true;
krista@4323
   800
    status = set_own_key(session, alex_id2, pubkey2);
krista@4323
   801
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   802
krista@4323
   803
    alex_id3->me = true;
krista@4323
   804
    status = set_own_key(session, alex_id3, pubkey3);
krista@4323
   805
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   806
        
krista@4323
   807
    status = myself(session, alex_id);
krista@4323
   808
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   809
    ASSERT_STREQ(pubkey1, alex_id->fpr);
krista@4323
   810
    
krista@4323
   811
    status = myself(session, alex_id2);
krista@4323
   812
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   813
    ASSERT_STREQ(pubkey2, alex_id2->fpr);
krista@4323
   814
krista@4323
   815
    status = myself(session, alex_id3);
krista@4323
   816
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   817
    ASSERT_STREQ(pubkey3, alex_id3->fpr);
krista@4323
   818
krista@4324
   819
    status = key_reset_all_own_keys(session);
krista@4323
   820
krista@4323
   821
    free(alex_id->fpr);
krista@4323
   822
    alex_id->fpr = pubkey1;
krista@4323
   823
    status = get_trust(session, alex_id);
krista@4323
   824
    ASSERT_EQ(alex_id->comm_type , PEP_ct_mistrusted);
krista@4323
   825
krista@4323
   826
    free(alex_id2->fpr);
krista@4323
   827
    alex_id2->fpr = pubkey2;
krista@4323
   828
    status = get_trust(session, alex_id2);
krista@4323
   829
    ASSERT_EQ(alex_id->comm_type , PEP_ct_mistrusted);
krista@4323
   830
krista@4323
   831
    free(alex_id3->fpr);
krista@4323
   832
    alex_id3->fpr = pubkey3;
krista@4323
   833
    status = get_trust(session, alex_id3);
krista@4323
   834
    ASSERT_EQ(alex_id->comm_type , PEP_ct_mistrusted);
krista@4323
   835
krista@4323
   836
    bool revoked = false;
krista@4323
   837
    status = key_revoked(session, pubkey1, &revoked);
krista@4323
   838
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   839
    ASSERT_TRUE(revoked);    
krista@4323
   840
krista@4323
   841
    revoked = false;
krista@4323
   842
    status = key_revoked(session, pubkey2, &revoked);
krista@4323
   843
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   844
    ASSERT_TRUE(revoked);    
krista@4323
   845
krista@4323
   846
    revoked = false;
krista@4323
   847
    status = key_revoked(session, pubkey3, &revoked);
krista@4323
   848
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   849
    ASSERT_TRUE(revoked);    
krista@4323
   850
    
krista@4323
   851
    status = myself(session, alex_id);
krista@4323
   852
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   853
    ASSERT_STRNE(pubkey1, alex_id->fpr);
krista@4323
   854
    
krista@4323
   855
    status = myself(session, alex_id2);
krista@4323
   856
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   857
    ASSERT_STRNE(pubkey2, alex_id2->fpr);
krista@4323
   858
krista@4323
   859
    status = myself(session, alex_id3);
krista@4323
   860
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   861
    ASSERT_STRNE(pubkey3, alex_id3->fpr);
krista@4323
   862
    
krista@4323
   863
    // Not reaaaally necessary, but...
krista@4323
   864
    ASSERT_STRNE(alex_id->fpr, alex_id2->fpr);
krista@4323
   865
    ASSERT_STRNE(alex_id->fpr, alex_id3->fpr);
krista@4323
   866
    ASSERT_STRNE(alex_id2->fpr, alex_id3->fpr);
krista@4323
   867
krista@4323
   868
    free_identity(alex_id);
krista@4323
   869
    free_identity(alex_id2);
krista@4323
   870
    free_identity(alex_id3);    
krista@4323
   871
}
krista@4323
   872
krista@4323
   873
TEST_F(KeyResetMessageTest, check_reset_grouped_own_multiple_keys_multiple_idents_reset_one) {
krista@4323
   874
    char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
krista@4323
   875
    char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
krista@4323
   876
    char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
krista@4323
   877
krista@4323
   878
    pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
krista@4323
   879
                                        NULL,
krista@4323
   880
                                        "AlexID",
krista@4323
   881
                                        "Alexander Braithwaite");
krista@4323
   882
krista@4323
   883
    pEp_identity* alex_id2 = new_identity("pep.test.alexander6@darthmama.org",
krista@4323
   884
                                          NULL,
krista@4323
   885
                                          "AlexID",
krista@4323
   886
                                          "Alexander Braithwaite");
krista@4323
   887
    
krista@4323
   888
    pEp_identity* alex_id3 = new_identity("pep.test.alexander6a@darthmama.org",
krista@4323
   889
                                          NULL,
krista@4323
   890
                                          "AlexID",
krista@4323
   891
                                          "Alexander Braithwaite");
krista@4323
   892
krista@4323
   893
krista@4323
   894
    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
krista@4323
   895
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
krista@4323
   896
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
krista@4323
   897
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x0019697D_priv.asc");
krista@4323
   898
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x503B14D8_priv.asc");
krista@4323
   899
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xA216E95A_priv.asc");
krista@4323
   900
krista@4323
   901
    alex_id->me = true;
krista@4323
   902
    status = set_own_key(session, alex_id, pubkey1);
krista@4323
   903
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   904
krista@4323
   905
    alex_id2->me = true;
krista@4323
   906
    status = set_own_key(session, alex_id2, pubkey2);
krista@4323
   907
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   908
krista@4323
   909
    alex_id3->me = true;
krista@4323
   910
    status = set_own_key(session, alex_id3, pubkey3);
krista@4323
   911
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   912
        
krista@4323
   913
    status = myself(session, alex_id);
krista@4323
   914
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   915
    ASSERT_STREQ(pubkey1, alex_id->fpr);
krista@4323
   916
    
krista@4323
   917
    status = myself(session, alex_id2);
krista@4323
   918
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   919
    ASSERT_STREQ(pubkey2, alex_id2->fpr);
krista@4323
   920
krista@4323
   921
    status = myself(session, alex_id3);
krista@4323
   922
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   923
    ASSERT_STREQ(pubkey3, alex_id3->fpr);
krista@4323
   924
krista@4324
   925
    status = key_reset_identity(session, alex_id2, alex_id2->fpr);
krista@4323
   926
krista@4323
   927
    free(alex_id->fpr);
krista@4323
   928
    alex_id->fpr = pubkey1;
krista@4323
   929
    status = get_trust(session, alex_id);
krista@4323
   930
    ASSERT_EQ(alex_id->comm_type , PEP_ct_pEp);
krista@4323
   931
krista@4323
   932
    free(alex_id2->fpr);
krista@4323
   933
    alex_id2->fpr = pubkey2;
krista@4323
   934
    status = get_trust(session, alex_id2);
krista@4323
   935
    ASSERT_EQ(alex_id2->comm_type , PEP_ct_mistrusted);
krista@4323
   936
krista@4323
   937
    free(alex_id3->fpr);
krista@4323
   938
    alex_id3->fpr = pubkey3;
krista@4323
   939
    status = get_trust(session, alex_id3);
krista@4323
   940
    ASSERT_EQ(alex_id3->comm_type , PEP_ct_pEp);
krista@4323
   941
krista@4323
   942
    bool revoked = false;
krista@4323
   943
    status = key_revoked(session, pubkey1, &revoked);
krista@4323
   944
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   945
    ASSERT_FALSE(revoked);    
krista@4323
   946
krista@4323
   947
    revoked = false;
krista@4323
   948
    status = key_revoked(session, pubkey2, &revoked);
krista@4323
   949
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   950
    ASSERT_TRUE(revoked);    
krista@4323
   951
krista@4323
   952
    revoked = false;
krista@4323
   953
    status = key_revoked(session, pubkey3, &revoked);
krista@4323
   954
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   955
    ASSERT_FALSE(revoked);    
krista@4323
   956
    
krista@4323
   957
    status = myself(session, alex_id);
krista@4323
   958
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   959
    ASSERT_STREQ(pubkey1, alex_id->fpr);
krista@4323
   960
    
krista@4323
   961
    status = myself(session, alex_id2);
krista@4323
   962
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   963
    ASSERT_STRNE(pubkey2, alex_id2->fpr);
krista@4323
   964
krista@4323
   965
    status = myself(session, alex_id3);
krista@4323
   966
    ASSERT_EQ(status, PEP_STATUS_OK);    
krista@4323
   967
    ASSERT_STREQ(pubkey3, alex_id3->fpr);
krista@4323
   968
    
krista@4323
   969
    // Not reaaaally necessary, but...
krista@4323
   970
    ASSERT_STRNE(alex_id->fpr, alex_id2->fpr);
krista@4323
   971
    ASSERT_STRNE(alex_id->fpr, alex_id3->fpr);
krista@4323
   972
    ASSERT_STRNE(alex_id2->fpr, alex_id3->fpr);
krista@4323
   973
krista@4323
   974
    free_identity(alex_id);
krista@4323
   975
    free_identity(alex_id2);
krista@4323
   976
    free_identity(alex_id3);    
krista@4323
   977
}
krista@4323
   978
krista@4323
   979
krista@4016
   980
TEST_F(KeyResetMessageTest, check_reset_ident_other_pub_fpr) {
krista@3507
   981
    send_setup(); // lazy
krista@3507
   982
    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, bob_user_id.c_str(), NULL);
krista@3507
   983
    PEP_STATUS status = update_identity(session, bob);
krista@4016
   984
krista@4016
   985
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
   986
    ASSERT_TRUE(bob->fpr && bob->fpr[0]);
krista@3507
   987
    status = set_as_pEp_user(session, bob);
krista@3507
   988
    status = trust_personal_key(session, bob);
krista@3507
   989
krista@3507
   990
    status = update_identity(session, bob);
krista@4016
   991
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
   992
    ASSERT_EQ(bob->comm_type , PEP_ct_pEp);
krista@3507
   993
krista@3507
   994
    // Ok, let's reset it
krista@3507
   995
    status = key_reset_identity(session, bob, bob->fpr);
krista@3507
   996
    status = update_identity(session, bob);
krista@4016
   997
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
   998
    ASSERT_EQ(bob->comm_type , PEP_ct_key_not_found);
krista@4016
   999
    ASSERT_TRUE(!(bob->fpr) || !(bob->fpr[0]));
krista@3507
  1000
    // TODO: import key, verify PEP_ct_OpenPGP_unconfirmed
krista@3507
  1001
}
krista@3507
  1002
krista@4323
  1003
krista@3507
  1004
// Corner case?
krista@4016
  1005
TEST_F(KeyResetMessageTest, check_reset_ident_other_priv_fpr) {
krista@3507
  1006
    send_setup(); // lazy
krista@3507
  1007
    // Also import Bob's private key, because that dude is a fool.
krista@3507
  1008
    PEP_STATUS status = read_file_and_import_key(session, "test_keys/priv/pep-test-bob-0xC9C2EE39_priv.asc");
krista@3507
  1009
    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, bob_user_id.c_str(), NULL);
krista@3507
  1010
    status = update_identity(session, bob);
krista@3507
  1011
krista@4016
  1012
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
  1013
    ASSERT_TRUE(bob->fpr && bob->fpr[0]);
krista@4016
  1014
    ASSERT_FALSE(bob->me);
krista@4016
  1015
krista@3507
  1016
    status = set_as_pEp_user(session, bob);
krista@3507
  1017
    status = trust_personal_key(session, bob);
krista@3507
  1018
krista@3507
  1019
    status = update_identity(session, bob);
krista@4016
  1020
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
  1021
    ASSERT_EQ(bob->comm_type , PEP_ct_pEp);
krista@4016
  1022
    ASSERT_FALSE(bob->me);
krista@3507
  1023
krista@3507
  1024
    // Ok, let's reset it
krista@3507
  1025
    status = key_reset_identity(session, bob, bob->fpr);
krista@3507
  1026
    status = update_identity(session, bob);
krista@4016
  1027
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
  1028
    ASSERT_EQ(bob->comm_type , PEP_ct_key_not_found);
krista@4016
  1029
    ASSERT_TRUE(!(bob->fpr) || !(bob->fpr[0]));
krista@3507
  1030
krista@3507
  1031
    // TODO: import key, verify PEP_ct_OpenPGP_unconfirmed
krista@3507
  1032
}
krista@3507
  1033
krista@4323
  1034
krista@4016
  1035
TEST_F(KeyResetMessageTest, check_reset_ident_other_pub_no_fpr) {
krista@3507
  1036
    send_setup(); // lazy
krista@3507
  1037
    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, bob_user_id.c_str(), NULL);
krista@3507
  1038
    PEP_STATUS status = update_identity(session, bob);
krista@4016
  1039
krista@4016
  1040
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
  1041
    ASSERT_TRUE(bob->fpr && bob->fpr[0]);
krista@3507
  1042
    status = set_as_pEp_user(session, bob);
krista@3507
  1043
    status = trust_personal_key(session, bob);
krista@3507
  1044
krista@3507
  1045
    status = update_identity(session, bob);
krista@4016
  1046
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
  1047
    ASSERT_EQ(bob->comm_type , PEP_ct_pEp);
krista@3507
  1048
    free(bob->fpr);
krista@3507
  1049
    bob->fpr = NULL;
krista@3507
  1050
krista@3507
  1051
    // Ok, let's reset it
krista@3507
  1052
    status = key_reset_identity(session, bob, NULL);
krista@3507
  1053
    status = update_identity(session, bob);
krista@4016
  1054
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
  1055
    ASSERT_EQ(bob->comm_type , PEP_ct_key_not_found);
krista@4016
  1056
    ASSERT_TRUE(!(bob->fpr) || !(bob->fpr[0]));
krista@3507
  1057
krista@3507
  1058
    // TODO: import key, verify PEP_ct_OpenPGP_unconfirmed
krista@3507
  1059
}
krista@3507
  1060
//    const char* bob_fpr = "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39";
krista@3507
  1061
// TODO: multiplr keys above
krista@3507
  1062
krista@4323
  1063
krista@4016
  1064
TEST_F(KeyResetMessageTest, check_reset_ident_other_priv_no_fpr) {
krista@3507
  1065
    send_setup(); // lazy
krista@3507
  1066
    // Also import Bob's private key, because that dude is a fool.
krista@3507
  1067
    PEP_STATUS status = read_file_and_import_key(session, "test_keys/priv/pep-test-bob-0xC9C2EE39_priv.asc");
krista@3507
  1068
    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, bob_user_id.c_str(), NULL);
krista@3507
  1069
    status = update_identity(session, bob);
krista@4016
  1070
krista@4016
  1071
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
  1072
    ASSERT_TRUE(bob->fpr && bob->fpr[0]);
krista@3507
  1073
    status = set_as_pEp_user(session, bob);
krista@3507
  1074
    status = trust_personal_key(session, bob);
krista@4016
  1075
krista@3507
  1076
    status = update_identity(session, bob);
krista@4016
  1077
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
  1078
    ASSERT_EQ(bob->comm_type , PEP_ct_pEp);
krista@4016
  1079
    ASSERT_FALSE(bob->me);
krista@3507
  1080
    free(bob->fpr);
krista@3507
  1081
    bob->fpr = NULL;
krista@3507
  1082
krista@3507
  1083
    // Ok, let's reset it
krista@3507
  1084
    status = key_reset_identity(session, bob, NULL);
krista@3507
  1085
    status = update_identity(session, bob);
krista@4016
  1086
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
  1087
    ASSERT_EQ(bob->comm_type , PEP_ct_key_not_found);
krista@4016
  1088
    ASSERT_TRUE(!(bob->fpr) || !(bob->fpr[0]));
krista@4016
  1089
    ASSERT_FALSE(bob->me);
krista@3507
  1090
krista@3507
  1091
    // TODO: import key, verify PEP_ct_OpenPGP_unconfirmed
krista@3507
  1092
}
krista@3507
  1093
krista@4323
  1094
krista@4016
  1095
TEST_F(KeyResetMessageTest, check_reset_ident_own_pub_fpr) {
krista@3507
  1096
    send_setup(); // lazy
krista@3507
  1097
    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", NULL, alice_user_id.c_str(), NULL);
krista@3507
  1098
    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander-0x26B54E4E_pub.asc");
krista@4016
  1099
krista@3507
  1100
    // hacky
krista@3507
  1101
    alice->fpr = strdup("3AD9F60FAEB22675DB873A1362D6981326B54E4E");
krista@3507
  1102
    status = set_pgp_keypair(session, alice->fpr);
krista@4016
  1103
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@3507
  1104
    alice->comm_type = PEP_ct_OpenPGP;
krista@3507
  1105
    status = set_trust(session, alice);
krista@4016
  1106
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
  1107
krista@3507
  1108
    // Ok, let's reset it
krista@3507
  1109
    status = key_reset_identity(session, alice, alice->fpr);
krista@3507
  1110
    status = myself(session, alice);
krista@4016
  1111
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@3507
  1112
krista@4016
  1113
    ASSERT_TRUE(alice->me);
krista@4016
  1114
    ASSERT_NE(alice->fpr, nullptr);
krista@4016
  1115
    ASSERT_STREQ(alice->fpr, alice_fpr);
krista@4016
  1116
    ASSERT_EQ(alice->comm_type , PEP_ct_pEp);
krista@3507
  1117
krista@3507
  1118
    free(alice->fpr);
krista@3507
  1119
    alice->fpr = strdup("3AD9F60FAEB22675DB873A1362D6981326B54E4E");
krista@3507
  1120
    status = get_trust(session, alice);
krista@4016
  1121
    ASSERT_EQ(status , PEP_CANNOT_FIND_IDENTITY);
krista@3507
  1122
}
krista@3507
  1123
krista@4323
  1124
krista@4016
  1125
TEST_F(KeyResetMessageTest, check_reset_ident_own_priv_fpr) {
krista@3507
  1126
    send_setup(); // lazy
krista@3507
  1127
    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", NULL, alice_user_id.c_str(), NULL);
krista@3507
  1128
    PEP_STATUS status = myself(session, alice);
krista@3507
  1129
krista@4016
  1130
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
  1131
    ASSERT_TRUE(alice->fpr && alice->fpr[0]);
krista@4016
  1132
    ASSERT_TRUE(alice->me);
krista@4016
  1133
    ASSERT_STREQ(alice->fpr, alice_fpr);
krista@4016
  1134
krista@3507
  1135
    status = key_reset_identity(session, alice, alice_fpr);
krista@3507
  1136
    status = myself(session, alice);
krista@4016
  1137
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@3507
  1138
    char* alice_new_fpr = alice->fpr;
krista@4016
  1139
    ASSERT_TRUE(alice_new_fpr && alice_new_fpr[0]);
krista@4016
  1140
    ASSERT_STRNE(alice_fpr, alice_new_fpr);
krista@3507
  1141
}
krista@3507
  1142
krista@4323
  1143
krista@4016
  1144
TEST_F(KeyResetMessageTest, check_reset_ident_own_priv_no_fpr) {
krista@3507
  1145
    send_setup(); // lazy
krista@3507
  1146
    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", NULL, alice_user_id.c_str(), NULL);
krista@3507
  1147
    PEP_STATUS status = myself(session, alice);
krista@3507
  1148
krista@4016
  1149
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4016
  1150
    ASSERT_TRUE(alice->fpr && alice->fpr[0]);
krista@4016
  1151
    ASSERT_TRUE(alice->me);
krista@4016
  1152
    ASSERT_STREQ(alice->fpr, alice_fpr);
krista@3507
  1153
    free(alice->fpr);
krista@3507
  1154
    alice->fpr = NULL;
krista@3507
  1155
    status = key_reset_identity(session, alice, NULL);
krista@3507
  1156
    status = myself(session, alice);
krista@4016
  1157
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@3507
  1158
    char* alice_new_fpr = alice->fpr;
krista@4016
  1159
    ASSERT_TRUE(alice_new_fpr && alice_new_fpr[0]);
krista@4016
  1160
    ASSERT_STRNE(alice_fpr, alice_new_fpr);
krista@3507
  1161
}
krista@3529
  1162
krista@4323
  1163
krista@4016
  1164
TEST_F(KeyResetMessageTest, check_reset_user_other_no_fpr) {
krista@3529
  1165
      char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
krista@3529
  1166
      char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
krista@3529
  1167
      char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
krista@3529
  1168
      char* pubkey4 = strdup("B4CE2F6947B6947C500F0687AEFDE530BDA17020");
krista@3529
  1169
krista@3529
  1170
      pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
krista@3529
  1171
                                            NULL,
krista@3529
  1172
                                            "AlexID",
krista@3529
  1173
                                            "Alexander Braithwaite");
krista@3529
  1174
krista@4016
  1175
/*
krista@3529
  1176
test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc
krista@3529
  1177
test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc
krista@3529
  1178
test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc
krista@3529
  1179
test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc
krista@3529
  1180
*/
krista@3529
  1181
    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
krista@3529
  1182
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
krista@3529
  1183
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
krista@3529
  1184
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc");
krista@3529
  1185
krista@3529
  1186
    alex_id->fpr = pubkey1;
krista@3529
  1187
    status = trust_personal_key(session, alex_id);
krista@3529
  1188
    alex_id->fpr = pubkey3;
krista@3529
  1189
    status = trust_personal_key(session, alex_id);
krista@3529
  1190
    status = set_as_pEp_user(session, alex_id);
krista@3529
  1191
    alex_id->fpr = pubkey4;
krista@3529
  1192
    status = trust_personal_key(session, alex_id);
krista@3529
  1193
krista@3529
  1194
    status = key_reset_user(session, alex_id->user_id, NULL);
krista@3529
  1195
krista@3529
  1196
    stringlist_t* keylist = NULL;
krista@3529
  1197
krista@3529
  1198
    alex_id->fpr = pubkey1;
krista@3529
  1199
    status = get_trust(session, alex_id);
krista@4016
  1200
    ASSERT_EQ(alex_id->comm_type , PEP_ct_unknown);
krista@3529
  1201
    status = find_keys(session, pubkey1, &keylist);
krista@4016
  1202
    ASSERT_TRUE(status == PEP_GET_KEY_FAILED || !keylist || EMPTYSTR(keylist->value));
krista@3529
  1203
krista@3529
  1204
    alex_id->fpr = pubkey2;
krista@3529
  1205
    status = get_trust(session, alex_id);
krista@4016
  1206
    ASSERT_EQ(alex_id->comm_type , PEP_ct_unknown);
krista@3529
  1207
    status = find_keys(session, pubkey2, &keylist);
krista@4016
  1208
    ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
krista@3529
  1209
krista@3529
  1210
    alex_id->fpr = pubkey3;
krista@3529
  1211
    status = get_trust(session, alex_id);
krista@4016
  1212
    ASSERT_EQ(alex_id->comm_type , PEP_ct_unknown);
krista@3529
  1213
    status = find_keys(session, pubkey3, &keylist);
krista@4016
  1214
    ASSERT_TRUE(status == PEP_GET_KEY_FAILED || !keylist || EMPTYSTR(keylist->value));
krista@3529
  1215
krista@3529
  1216
    alex_id->fpr = pubkey4;
krista@4016
  1217
    status = get_trust(session, alex_id);
krista@4016
  1218
    ASSERT_EQ(alex_id->comm_type , PEP_ct_unknown);
krista@3529
  1219
    status = find_keys(session, pubkey4, &keylist);
krista@4016
  1220
    ASSERT_TRUE(status == PEP_GET_KEY_FAILED || !keylist || EMPTYSTR(keylist->value));
krista@3529
  1221
krista@3529
  1222
}
krista@3529
  1223
krista@4323
  1224
krista@4016
  1225
TEST_F(KeyResetMessageTest, check_reset_user_other_fpr) {
krista@3529
  1226
      char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
krista@3529
  1227
      char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
krista@3529
  1228
      char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
krista@3529
  1229
      char* pubkey4 = strdup("B4CE2F6947B6947C500F0687AEFDE530BDA17020");
krista@3529
  1230
krista@3529
  1231
      pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
krista@3529
  1232
                                            NULL,
krista@3529
  1233
                                            "AlexID",
krista@3529
  1234
                                            "Alexander Braithwaite");
krista@3529
  1235
krista@4016
  1236
/*
krista@3529
  1237
test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc
krista@3529
  1238
test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc
krista@3529
  1239
test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc
krista@3529
  1240
test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc
krista@3529
  1241
*/
krista@3529
  1242
    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
krista@3529
  1243
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
krista@3529
  1244
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
krista@3529
  1245
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc");
krista@3529
  1246
krista@3529
  1247
    alex_id->fpr = pubkey1;
krista@3529
  1248
    status = trust_personal_key(session, alex_id);
krista@3529
  1249
    alex_id->fpr = pubkey3;
krista@3529
  1250
    status = trust_personal_key(session, alex_id);
krista@3529
  1251
    status = set_as_pEp_user(session, alex_id);
krista@3529
  1252
    alex_id->fpr = pubkey4;
krista@3529
  1253
    status = trust_personal_key(session, alex_id);
krista@3529
  1254
krista@3529
  1255
    status = key_reset_user(session, alex_id->user_id, pubkey3);
krista@3529
  1256
krista@3529
  1257
    stringlist_t* keylist = NULL;
krista@3529
  1258
krista@3529
  1259
    alex_id->fpr = pubkey1;
krista@3529
  1260
    status = get_trust(session, alex_id);
krista@4016
  1261
    ASSERT_EQ(alex_id->comm_type , PEP_ct_pEp);
krista@3529
  1262
    status = find_keys(session, pubkey1, &keylist);
krista@4016
  1263
    ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
krista@3529
  1264
krista@3529
  1265
    free_stringlist(keylist);
krista@3529
  1266
    keylist = NULL;
krista@4016
  1267
krista@3529
  1268
    alex_id->fpr = pubkey2;
krista@3529
  1269
    status = get_trust(session, alex_id);
krista@4016
  1270
    ASSERT_EQ(alex_id->comm_type , PEP_ct_unknown);
krista@3529
  1271
    status = find_keys(session, pubkey2, &keylist);
krista@4016
  1272
    ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
krista@3529
  1273
krista@3529
  1274
    alex_id->fpr = pubkey3;
krista@3529
  1275
    status = get_trust(session, alex_id);
krista@4016
  1276
    ASSERT_EQ(alex_id->comm_type , PEP_ct_unknown);
krista@3529
  1277
    status = find_keys(session, pubkey3, &keylist);
krista@4016
  1278
    ASSERT_TRUE(status == PEP_GET_KEY_FAILED || !keylist || EMPTYSTR(keylist->value));
krista@3529
  1279
krista@3529
  1280
    alex_id->fpr = pubkey4;
krista@4016
  1281
    status = get_trust(session, alex_id);
krista@4016
  1282
    ASSERT_EQ(alex_id->comm_type , PEP_ct_pEp);
krista@3529
  1283
    status = find_keys(session, pubkey4, &keylist);
krista@4016
  1284
    ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
krista@3529
  1285
krista@3529
  1286
    // next line is for readability.
krista@3529
  1287
    alex_id->fpr = NULL;
krista@3529
  1288
    free_stringlist(keylist);
krista@3529
  1289
    free(pubkey1);
krista@3529
  1290
    free(pubkey2);
krista@3529
  1291
    free(pubkey3);
krista@3529
  1292
    free(pubkey4);
krista@3529
  1293
    free_identity(alex_id);
krista@3529
  1294
}
krista@3529
  1295
krista@4323
  1296
krista@4016
  1297
TEST_F(KeyResetMessageTest, check_reset_user_own_fpr) {
krista@3529
  1298
      char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
krista@3529
  1299
      char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
krista@3529
  1300
      char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
krista@3529
  1301
      char* pubkey4 = strdup("B4CE2F6947B6947C500F0687AEFDE530BDA17020");
krista@3529
  1302
krista@3529
  1303
      pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
krista@3529
  1304
                                            NULL,
krista@3529
  1305
                                            "AlexID",
krista@3529
  1306
                                            "Alexander Braithwaite");
krista@3529
  1307
krista@4016
  1308
/*
krista@3529
  1309
test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc
krista@3529
  1310
test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc
krista@3529
  1311
test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc
krista@3529
  1312
test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc
krista@3529
  1313
*/
krista@3529
  1314
    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
krista@3529
  1315
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
krista@3529
  1316
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
krista@3529
  1317
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc");
krista@3529
  1318
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x0019697D_priv.asc");
krista@3529
  1319
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x503B14D8_priv.asc");
krista@3529
  1320
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xA216E95A_priv.asc");
krista@3529
  1321
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xBDA17020_priv.asc");
krista@3529
  1322
krista@3529
  1323
    alex_id->me = true;
krista@3529
  1324
    status = set_own_key(session, alex_id, pubkey1);
krista@4316
  1325
    status = set_own_key(session, alex_id, pubkey4);
krista@3529
  1326
    status = set_own_key(session, alex_id, pubkey3);
krista@4316
  1327
    
krista@4316
  1328
    status = myself(session, alex_id);
krista@3529
  1329
krista@3529
  1330
    status = key_reset_user(session, alex_id->user_id, pubkey3);
krista@3529
  1331
krista@3529
  1332
    alex_id->fpr = pubkey1;
krista@3529
  1333
    status = get_trust(session, alex_id);
krista@4016
  1334
    ASSERT_EQ(alex_id->comm_type , PEP_ct_pEp);
krista@4016
  1335
krista@3529
  1336
    alex_id->fpr = pubkey2;
krista@3529
  1337
    status = get_trust(session, alex_id);
krista@4016
  1338
    ASSERT_EQ(alex_id->comm_type , PEP_ct_unknown);
krista@3529
  1339
krista@3529
  1340
    stringlist_t* keylist = NULL;
krista@4016
  1341
krista@3529
  1342
    alex_id->fpr = pubkey3;
krista@3529
  1343
    status = get_trust(session, alex_id);
krista@4016
  1344
    ASSERT_EQ(alex_id->comm_type , PEP_ct_mistrusted);
krista@3529
  1345
    status = find_keys(session, pubkey4, &keylist);
krista@4016
  1346
    ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
krista@3529
  1347
krista@3529
  1348
    free_stringlist(keylist);
krista@3529
  1349
    keylist = NULL;
krista@4016
  1350
krista@3529
  1351
    alex_id->fpr = pubkey4;
krista@4016
  1352
    status = get_trust(session, alex_id);
krista@4016
  1353
    ASSERT_EQ(alex_id->comm_type , PEP_ct_pEp);
krista@3529
  1354
krista@3529
  1355
    // next line is for readability.
krista@3529
  1356
    alex_id->fpr = NULL;
krista@3529
  1357
    free_stringlist(keylist);
krista@3529
  1358
    free(pubkey1);
krista@3529
  1359
    free(pubkey2);
krista@3529
  1360
    free(pubkey3);
krista@3529
  1361
    free(pubkey4);
krista@3529
  1362
    free_identity(alex_id);
krista@3529
  1363
}
krista@3529
  1364
krista@4323
  1365
krista@4016
  1366
TEST_F(KeyResetMessageTest, check_reset_user_no_fpr) {
krista@3529
  1367
      char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
krista@3529
  1368
      char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
krista@3529
  1369
      char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
krista@3529
  1370
      char* pubkey4 = strdup("B4CE2F6947B6947C500F0687AEFDE530BDA17020");
krista@3529
  1371
krista@3529
  1372
      pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
krista@3529
  1373
                                            NULL,
krista@3529
  1374
                                            "AlexID",
krista@3529
  1375
                                            "Alexander Braithwaite");
krista@3529
  1376
krista@4016
  1377
/*
krista@3529
  1378
test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc
krista@3529
  1379
test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc
krista@3529
  1380
test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc
krista@3529
  1381
test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc
krista@3529
  1382
*/
krista@3529
  1383
    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
krista@3529
  1384
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
krista@3529
  1385
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
krista@3529
  1386
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc");
krista@3529
  1387
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x0019697D_priv.asc");
krista@3529
  1388
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x503B14D8_priv.asc");
krista@3529
  1389
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xA216E95A_priv.asc");
krista@3529
  1390
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xBDA17020_priv.asc");
krista@3529
  1391
krista@3529
  1392
    alex_id->me = true;
krista@3529
  1393
    status = set_own_key(session, alex_id, pubkey1);
krista@3529
  1394
    status = set_own_key(session, alex_id, pubkey3);
krista@3529
  1395
    status = set_own_key(session, alex_id, pubkey4);
krista@3529
  1396
krista@3529
  1397
    status = key_reset_user(session, alex_id->user_id, NULL);
krista@4016
  1398
krista@4016
  1399
    ASSERT_EQ(status , PEP_ILLEGAL_VALUE);
krista@3529
  1400
krista@3529
  1401
    free(pubkey1);
krista@3529
  1402
    free(pubkey2);
krista@3529
  1403
    free(pubkey3);
krista@3529
  1404
    free(pubkey4);
krista@3529
  1405
    free_identity(alex_id);
krista@3529
  1406
}
krista@3529
  1407
krista@4323
  1408
krista@4016
  1409
TEST_F(KeyResetMessageTest, check_reset_all_own_keys) {
krista@4316
  1410
    char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
krista@4316
  1411
    char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
krista@4316
  1412
    char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
krista@4316
  1413
    char* pubkey4 = strdup("B4CE2F6947B6947C500F0687AEFDE530BDA17020");
krista@3529
  1414
krista@4316
  1415
    pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
krista@4316
  1416
                                         NULL,
krista@4316
  1417
                                         "AlexID",
krista@4316
  1418
                                         "Alexander Braithwaite");
krista@3529
  1419
krista@4316
  1420
    pEp_identity* alex_id2 = new_identity("pep.test.alexander6@darthmama.org",
krista@4316
  1421
                                          NULL,
krista@4316
  1422
                                          "AlexID",
krista@4316
  1423
                                          "Alexander Braithwaite");
krista@4316
  1424
krista@4316
  1425
krista@3529
  1426
    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
krista@3529
  1427
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
krista@3529
  1428
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
krista@3529
  1429
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc");
krista@3529
  1430
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x0019697D_priv.asc");
krista@3529
  1431
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0x503B14D8_priv.asc");
krista@3529
  1432
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xA216E95A_priv.asc");
krista@3529
  1433
    status = read_file_and_import_key(session, "test_keys/priv/pep.test.alexander6-0xBDA17020_priv.asc");
krista@3529
  1434
krista@3529
  1435
    alex_id->me = true;
krista@4316
  1436
    status = set_own_key(session, alex_id, pubkey3);
krista@4316
  1437
    status = myself(session, alex_id);
krista@3529
  1438
    status = set_own_key(session, alex_id, pubkey1);
krista@4316
  1439
    status = myself(session, alex_id);
krista@4316
  1440
    
krista@4316
  1441
    alex_id2->me = true;
krista@4316
  1442
    status = set_own_key(session, alex_id2, pubkey4);
krista@4316
  1443
    status = myself(session, alex_id2);
krista@3529
  1444
krista@3529
  1445
    status = key_reset_all_own_keys(session);
krista@3529
  1446
krista@3529
  1447
    stringlist_t* keylist = NULL;
krista@3529
  1448
krista@3529
  1449
    alex_id->fpr = pubkey1;
krista@3529
  1450
    status = get_trust(session, alex_id);
krista@4016
  1451
    ASSERT_EQ(alex_id->comm_type , PEP_ct_mistrusted);
krista@3529
  1452
    status = find_keys(session, pubkey1, &keylist);
krista@4016
  1453
    ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
krista@4016
  1454
krista@3529
  1455
    free_stringlist(keylist);
krista@3529
  1456
    keylist = NULL;
krista@4016
  1457
krista@3529
  1458
    alex_id->fpr = pubkey2;
krista@3529
  1459
    status = get_trust(session, alex_id);
krista@4016
  1460
    ASSERT_EQ(alex_id->comm_type , PEP_ct_unknown);
krista@3529
  1461
    status = find_keys(session, pubkey2, &keylist);
krista@4016
  1462
    ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
krista@3529
  1463
krista@3529
  1464
    free_stringlist(keylist);
krista@3529
  1465
    keylist = NULL;
krista@3529
  1466
krista@3529
  1467
    alex_id->fpr = pubkey3;
krista@3529
  1468
    status = get_trust(session, alex_id);
krista@4316
  1469
    ASSERT_EQ(alex_id->comm_type , PEP_ct_pEp);
krista@3529
  1470
    status = find_keys(session, pubkey3, &keylist);
krista@4016
  1471
    ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
krista@3529
  1472
krista@3529
  1473
    free_stringlist(keylist);
krista@3529
  1474
    keylist = NULL;
krista@3529
  1475
krista@4316
  1476
    alex_id2->fpr = pubkey4;
krista@4316
  1477
    status = get_trust(session, alex_id2);
krista@4316
  1478
    ASSERT_EQ(alex_id2->comm_type , PEP_ct_mistrusted);
krista@3529
  1479
    status = find_keys(session, pubkey4, &keylist);
krista@4016
  1480
    ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
krista@3529
  1481
krista@3529
  1482
    free_stringlist(keylist);
krista@3529
  1483
    keylist = NULL;
krista@3529
  1484
krista@3529
  1485
    alex_id->fpr = NULL;
krista@3529
  1486
    status = myself(session, alex_id);
krista@4016
  1487
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@3529
  1488
krista@4016
  1489
    ASSERT_NE(alex_id->fpr, nullptr);
krista@4021
  1490
    output_stream << "alex_id->fpr is " << alex_id->fpr << endl;
krista@4016
  1491
    ASSERT_STRNE(alex_id->fpr, pubkey1);
krista@4016
  1492
    ASSERT_STRNE(alex_id->fpr, pubkey2);
krista@4016
  1493
    ASSERT_STRNE(alex_id->fpr, pubkey3);
krista@4016
  1494
    ASSERT_STRNE(alex_id->fpr, pubkey4);
krista@4016
  1495
    ASSERT_EQ(alex_id->comm_type , PEP_ct_pEp);
krista@4016
  1496
krista@4316
  1497
    alex_id2->fpr = NULL;
krista@4316
  1498
    status = myself(session, alex_id2);
krista@4316
  1499
    ASSERT_EQ(status , PEP_STATUS_OK);
krista@4316
  1500
    ASSERT_STRNE(alex_id2->fpr, pubkey1);
krista@4316
  1501
    ASSERT_STRNE(alex_id2->fpr, pubkey2);
krista@4316
  1502
    ASSERT_STRNE(alex_id2->fpr, pubkey3);
krista@4316
  1503
    ASSERT_STRNE(alex_id2->fpr, pubkey4);
krista@4316
  1504
krista@3529
  1505
    free(pubkey1);
krista@3529
  1506
    free(pubkey2);
krista@3529
  1507
    free(pubkey3);
krista@3529
  1508
    free(pubkey4);
krista@3529
  1509
    free_identity(alex_id);
krista@3529
  1510
}
krista@3529
  1511
krista@4323
  1512
krista@4016
  1513
TEST_F(KeyResetMessageTest, check_reset_all_own_no_own) {
krista@3529
  1514
      char* pubkey1 = strdup("74D79B4496E289BD8A71B70BA8E2C4530019697D");
krista@3529
  1515
      char* pubkey2 = strdup("2E21325D202A44BFD9C607FCF095B202503B14D8");
krista@3529
  1516
      char* pubkey3 = strdup("3C1E713D8519D7F907E3142D179EAA24A216E95A");
krista@3529
  1517
      char* pubkey4 = strdup("B4CE2F6947B6947C500F0687AEFDE530BDA17020");
krista@3529
  1518
krista@3529
  1519
      pEp_identity* alex_id = new_identity("pep.test.alexander@darthmama.org",
krista@3529
  1520
                                            NULL,
krista@3529
  1521
                                            "AlexID",
krista@3529
  1522
                                            "Alexander Braithwaite");
krista@3529
  1523
krista@4016
  1524
/*
krista@3529
  1525
test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc
krista@3529
  1526
test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc
krista@3529
  1527
test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc
krista@3529
  1528
test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc
krista@3529
  1529
*/
krista@3529
  1530
    PEP_STATUS status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
krista@3529
  1531
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
krista@3529
  1532
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
krista@3529
  1533
    status = read_file_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xBDA17020_pub.asc");
krista@3529
  1534
krista@3529
  1535
    alex_id->fpr = pubkey1;
krista@3529
  1536
    status = trust_personal_key(session, alex_id);
krista@3529
  1537
    alex_id->fpr = pubkey3;
krista@3529
  1538
    status = trust_personal_key(session, alex_id);
krista@3529
  1539
    alex_id->fpr = pubkey4;
krista@3529
  1540
    status = trust_personal_key(session, alex_id);
krista@3529
  1541
krista@3529
  1542
    status = key_reset_all_own_keys(session);
krista@4016
  1543
    ASSERT_EQ(status , PEP_CANNOT_FIND_IDENTITY);
krista@3529
  1544
krista@3529
  1545
    stringlist_t* keylist = NULL;
krista@3529
  1546
krista@3529
  1547
    alex_id->fpr = pubkey1;
krista@3529
  1548
    status = get_trust(session, alex_id);
krista@4016
  1549
    ASSERT_EQ(alex_id->comm_type , PEP_ct_OpenPGP);
krista@3529
  1550
    status = find_keys(session, pubkey1, &keylist);
krista@4016
  1551
    ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
krista@3529
  1552
krista@3529
  1553
    free_stringlist(keylist);
krista@4117
  1554
        keylist = NULL;
krista@4016
  1555
krista@3529
  1556
    alex_id->fpr = pubkey2;
krista@3529
  1557
    status = get_trust(session, alex_id);
krista@4016
  1558
    ASSERT_EQ(alex_id->comm_type , PEP_ct_unknown);
krista@3529
  1559
    status = find_keys(session, pubkey2, &keylist);
krista@4016
  1560
    ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
krista@3529
  1561
krista@3529
  1562
    alex_id->fpr = pubkey3;
krista@3529
  1563
    status = get_trust(session, alex_id);
krista@4016
  1564
    ASSERT_EQ(alex_id->comm_type , PEP_ct_OpenPGP);
krista@3529
  1565
    status = find_keys(session, pubkey3, &keylist);
krista@4016
  1566
    ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
krista@3529
  1567
krista@3529
  1568
    alex_id->fpr = pubkey4;
krista@4016
  1569
    status = get_trust(session, alex_id);
krista@4016
  1570
    ASSERT_EQ(alex_id->comm_type , PEP_ct_OpenPGP);
krista@3529
  1571
    status = find_keys(session, pubkey4, &keylist);
krista@4016
  1572
    ASSERT_TRUE(status == PEP_STATUS_OK && keylist && !EMPTYSTR(keylist->value));
krista@3529
  1573
krista@3529
  1574
    // next line is for readability.
krista@3529
  1575
    alex_id->fpr = NULL;
krista@3529
  1576
    free_stringlist(keylist);
krista@3529
  1577
    free(pubkey1);
krista@3529
  1578
    free(pubkey2);
krista@3529
  1579
    free(pubkey3);
krista@3529
  1580
    free(pubkey4);
krista@3529
  1581
    free_identity(alex_id);
krista@3529
  1582
krista@3529
  1583
}
krista@4117
  1584
krista@4117
  1585
// TEST_F(KeyResetMessageTest, check_reset_mistrust_next_msg_have_mailed) {
krista@4117
  1586
// 
krista@4117
  1587
// }
krista@4117
  1588
krista@4117
  1589
TEST_F(KeyResetMessageTest, not_a_test) {
krista@4117
  1590
    pEp_identity* bob = NULL;
krista@4117
  1591
    PEP_STATUS status = set_up_preset(session, BOB,
krista@4117
  1592
                                      true, true, true, true, true, &bob);
krista@4117
  1593
                                                                
krista@4117
  1594
    const char* carol_fpr = "8DD4F5827B45839E9ACCA94687BDDFFB42A85A42";                                                                
krista@4117
  1595
    slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");    
krista@4117
  1596
    slurp_and_import_key(session, "test_keys/pub/pep-test-carol-0x42A85A42_pub.asc");
krista@4117
  1597
                                      
krista@4117
  1598
    pEp_identity* carol = new_identity("pep-test-carol@pep-project.org", carol_fpr, carol_user_id.c_str(), "Christmas Carol");
krista@4117
  1599
    status = update_identity(session, carol);
krista@4117
  1600
    
krista@4117
  1601
    message* bob_msg = new_message(PEP_dir_outgoing);
krista@4117
  1602
    bob_msg->from = identity_dup(bob);
krista@4117
  1603
    bob_msg->to = new_identity_list(carol);
krista@4117
  1604
    bob_msg->shortmsg = strdup("Engine bugs suck\n");
krista@4117
  1605
    bob_msg->longmsg = strdup("Everything is the engine's fault.\n");
krista@4117
  1606
    
krista@4117
  1607
    char* enc_msg_str = NULL;
krista@4117
  1608
    message* enc_msg = NULL;
krista@4117
  1609
    
krista@4117
  1610
    status = encrypt_message(session, bob_msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
krista@4117
  1611
    ASSERT_EQ(status, PEP_STATUS_OK);
krista@4117
  1612
    status = mime_encode_message(enc_msg, false, &enc_msg_str);
krista@4117
  1613
    
krista@4117
  1614
    ofstream myfile;
krista@4117
  1615
    myfile.open("test_mails/ENGINE-654_bob_mail.eml");
krista@4117
  1616
    myfile << enc_msg_str;
krista@4117
  1617
    myfile.close();      
krista@4117
  1618
}
krista@4117
  1619
krista@4323
  1620
krista@4234
  1621
TEST_F(KeyResetMessageTest, check_no_reset_message_to_self) {
krista@4234
  1622
    pEp_identity* bob = NULL;
krista@4234
  1623
    PEP_STATUS status = set_up_preset(session, BOB,
krista@4234
  1624
                                      true, true, true, true, true, &bob);
krista@4234
  1625
                                                                
krista@4234
  1626
    slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");    
krista@4234
  1627
                                          
krista@4234
  1628
    message* bob_msg = new_message(PEP_dir_outgoing);
krista@4234
  1629
    bob_msg->from = identity_dup(bob);
krista@4234
  1630
    bob_msg->to = new_identity_list(identity_dup(bob));
krista@4234
  1631
    bob_msg->shortmsg = strdup("Engine bugs suck\n");
krista@4234
  1632
    bob_msg->longmsg = strdup("Everything is the engine's fault.\n");
krista@4234
  1633
    
krista@4234
  1634
    message* enc_msg = NULL;
krista@4234
  1635
    
krista@4234
  1636
    status = encrypt_message(session, bob_msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
krista@4234
  1637
    ASSERT_EQ(status, PEP_STATUS_OK);
krista@4234
  1638
krista@4234
  1639
    key_reset_all_own_keys(session);
krista@4234
  1640
    
krista@4234
  1641
    message* dec_msg = NULL;
krista@4234
  1642
    stringlist_t* keylist = NULL;
krista@4234
  1643
    PEP_rating rating;
krista@4234
  1644
    PEP_decrypt_flags_t flags = 0;
krista@4234
  1645
    
krista@4234
  1646
    status = decrypt_message(session, enc_msg, &dec_msg, &keylist, &rating, &flags);
krista@4234
  1647
    ASSERT_EQ(m_queue.size(), 0);
krista@4234
  1648
    ASSERT_EQ(status, PEP_VERIFY_SIGNER_KEY_REVOKED);
krista@4234
  1649
}
krista@4234
  1650
krista@4323
  1651
krista@4117
  1652
TEST_F(KeyResetMessageTest, check_reset_mistrust_next_msg_have_not_mailed) {
krista@4117
  1653
    pEp_identity* carol = NULL;
krista@4117
  1654
    PEP_STATUS status = set_up_preset(session, CAROL,
krista@4117
  1655
                                      true, true, true, true, true, &carol);
krista@4117
  1656
                                      
krista@4117
  1657
    status = myself(session, carol);
krista@4117
  1658
    ASSERT_STREQ(carol->fpr, "8DD4F5827B45839E9ACCA94687BDDFFB42A85A42");                                  
krista@4117
  1659
krista@4117
  1660
    slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");                                      
krista@4117
  1661
    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", bob_fpr, NULL, "Bob's Burgers");
krista@4117
  1662
    status = update_identity(session, bob);
krista@4117
  1663
    
krista@4117
  1664
    status = key_mistrusted(session, bob);
krista@4117
  1665
    ASSERT_EQ(status, PEP_STATUS_OK);
krista@4120
  1666
//    ASSERT_EQ(bob->fpr, nullptr);
krista@4117
  1667
    
krista@4117
  1668
    string mail_from_bob = slurp("test_mails/ENGINE-654_bob_mail.eml");
krista@4120
  1669
    // 
krista@4120
  1670
    // // Ok, so let's see if the thing is mistrusted
krista@4117
  1671
    message* bob_enc_msg = NULL;
krista@4120
  1672
    // 
krista@4120
  1673
    // mime_decode_message(mail_from_bob.c_str(), mail_from_bob.size(), &bob_enc_msg);
krista@4120
  1674
    // 
krista@4117
  1675
    message* bob_dec_msg = NULL;
krista@4117
  1676
    stringlist_t* keylist = NULL;
krista@4117
  1677
    PEP_rating rating;
krista@4117
  1678
    PEP_decrypt_flags_t flags = 0;
krista@4120
  1679
    // 
krista@4120
  1680
    // status = decrypt_message(session, bob_enc_msg, &bob_dec_msg, &keylist, &rating, &flags);
krista@4120
  1681
    // ASSERT_EQ(status, PEP_STATUS_OK);
krista@4120
  1682
    // ASSERT_EQ(rating, PEP_rating_mistrust);
krista@4120
  1683
    // 
krista@4120
  1684
    // free_message(bob_enc_msg);
krista@4120
  1685
    // free_message(bob_dec_msg);
krista@4117
  1686
    
krista@4120
  1687
    free(bob->fpr);
krista@4120
  1688
    bob->fpr = NULL;
krista@4117
  1689
    
krista@4117
  1690
    status = key_reset_identity(session, bob, NULL);
krista@4117
  1691
    ASSERT_EQ(status, PEP_STATUS_OK);
krista@4120
  1692
krista@4120
  1693
    // status = identity_rating(session, bob, &rating);
krista@4120
  1694
    // status = update_identity(session, bob);
krista@4117
  1695
    status = identity_rating(session, bob, &rating);
krista@4117
  1696
    ASSERT_EQ(rating, PEP_rating_have_no_key);
krista@4117
  1697
    //update_identity(session, bob);
krista@4117
  1698
            //    ASSERT_EQ(bob->fpr, nullptr);
krista@4117
  1699
krista@4117
  1700
    mime_decode_message(mail_from_bob.c_str(), mail_from_bob.size(), &bob_enc_msg);
krista@4117
  1701
    
krista@4117
  1702
    bob_dec_msg = NULL;
krista@4117
  1703
    free_stringlist(keylist);
krista@4117
  1704
    keylist = NULL;
krista@4117
  1705
    flags = 0;
krista@4117
  1706
    
krista@4117
  1707
    status = decrypt_message(session, bob_enc_msg, &bob_dec_msg, &keylist, &rating, &flags);
krista@4117
  1708
    ASSERT_EQ(status, PEP_STATUS_OK);
krista@4117
  1709
    ASSERT_EQ(rating, PEP_rating_reliable);
krista@4117
  1710
    
krista@4117
  1711
}
krista@4312
  1712
/*
krista@4246
  1713
TEST_F(KeyResetMessageTest, check_reset_own_with_revocations) {
krista@4246
  1714
    pEp_identity* id1 = new_identity("krista-not-real@darthmama.org", NULL, PEP_OWN_USERID, "Krista at Home");    
krista@4246
  1715
    PEP_STATUS status = myself(session, id1);
krista@4246
  1716
    pEp_identity* id2 = NULL;
krista@4246
  1717
    status = set_up_preset(session, ALICE, true, true, false, false, false, &id2);
krista@4246
  1718
    pEp_identity* id3 = new_identity("krista-not-real@angryshark.eu", NULL, PEP_OWN_USERID, "Krista at Shark");
krista@4246
  1719
    status = myself(session, id3);
krista@4246
  1720
    pEp_identity* id4 = NULL;    
krista@4246
  1721
    status = set_up_preset(session, BOB, true, false, false, false, false, &id4);
krista@4246
  1722
    pEp_identity* id5 = new_identity("krista-not-real@pep.foundation", NULL, PEP_OWN_USERID, "Krista at Work");
krista@4246
  1723
    status = myself(session, id5);
krista@4246
  1724
    pEp_identity* id6 = new_identity("grrrr-not-real@angryshark.eu", NULL, PEP_OWN_USERID, "GRRRR is a Shark");
krista@4246
  1725
    status = myself(session, id6);
krista@4246
  1726
    pEp_identity* id7 = NULL;
krista@4246
  1727
    status = set_up_preset(session, CAROL, true, false, true, false, false, &id7);
krista@4246
  1728
    pEp_identity* id8 = NULL;    
krista@4246
  1729
    status = set_up_preset(session, DAVE, true, true, true, false, false, &id8);
krista@4246
  1730
krista@4246
  1731
    identity_list* own_identities = NULL;
krista@4246
  1732
    stringlist_t* revocations = NULL;
krista@4246
  1733
    stringlist_t* keys = NULL;
krista@4246
  1734
    
krista@4246
  1735
    stringlist_t* first_keylist = new_stringlist(NULL);
krista@4246
  1736
    stringlist_add(first_keylist, strdup(id1->fpr));
krista@4246
  1737
    stringlist_add(first_keylist, strdup(id3->fpr));
krista@4246
  1738
    stringlist_add(first_keylist, strdup(id5->fpr));
krista@4246
  1739
    stringlist_add(first_keylist, strdup(id6->fpr));
krista@4246
  1740
    
krista@4246
  1741
    status = key_reset_own_and_deliver_revocations(session, 
krista@4246
  1742
                                                   &own_identities, 
krista@4246
  1743
                                                   &revocations, 
krista@4246
  1744
                                                   &keys);
krista@4246
  1745
                                                                                                      
krista@4246
  1746
    ASSERT_EQ(status, PEP_STATUS_OK);
krista@4246
  1747
    ASSERT_NE(own_identities, nullptr);
krista@4246
  1748
    ASSERT_NE(revocations, nullptr);
krista@4246
  1749
    ASSERT_NE(keys, nullptr);
krista@4246
  1750
krista@4246
  1751
    int i = 0;
krista@4246
  1752
    identity_list* curr_ident = own_identities;
krista@4246
  1753
    stringlist_t* second_keylist = new_stringlist(NULL);
krista@4246
  1754
    
krista@4246
  1755
    for (i = 0; i < 4 && curr_ident; i++, curr_ident = curr_ident->next) {
krista@4246
  1756
        ASSERT_NE(curr_ident->ident, nullptr);
krista@4246
  1757
        ASSERT_NE(curr_ident->ident->fpr, nullptr);        
krista@4246
  1758
        stringlist_t* found = stringlist_search(first_keylist, curr_ident->ident->fpr);
krista@4246
  1759
        ASSERT_EQ(found, nullptr);
krista@4246
  1760
        PEP_comm_type ct = PEP_ct_unknown;
krista@4246
  1761
        status = get_key_rating(session, curr_ident->ident->fpr, &ct);
krista@4246
  1762
        ASSERT_EQ(ct, PEP_ct_OpenPGP_unconfirmed);    
krista@4246
  1763
        stringlist_add(second_keylist, strdup(curr_ident->ident->fpr));            
krista@4246
  1764
    }
krista@4246
  1765
    ASSERT_EQ(i, 4);
krista@4246
  1766
    ASSERT_EQ(curr_ident, nullptr);
krista@4246
  1767
    
krista@4246
  1768
    stringlist_t* curr_key = first_keylist;
krista@4246
  1769
    for (i = 0; i < 4; i++, curr_key = curr_key->next) {
krista@4246
  1770
        PEP_comm_type ct = PEP_ct_unknown;
krista@4246
  1771
        status = get_key_rating(session, curr_key->value, &ct);
krista@4246
  1772
        ASSERT_EQ(ct, PEP_ct_key_revoked);
krista@4246
  1773
    }
krista@4246
  1774
    
krista@4246
  1775
    // Ok, now we're going to delete all the keys, and then try to reimport.
krista@4246
  1776
    curr_key = first_keylist;
krista@4246
  1777
    for (i = 0; i < 4; curr_key = curr_key->next, i++) {
krista@4246
  1778
        status = delete_keypair(session, curr_key->value);
krista@4246
  1779
        ASSERT_EQ(status, PEP_STATUS_OK);
krista@4246
  1780
    }
krista@4246
  1781
    ASSERT_EQ(i, 4);
krista@4246
  1782
    ASSERT_EQ(curr_key, nullptr);
krista@4246
  1783
    
krista@4246
  1784
    curr_key = second_keylist;
krista@4246
  1785
    for (i = 0; i < 4; curr_key = curr_key->next, i++) {
krista@4246
  1786
        status = delete_keypair(session, curr_key->value);
krista@4246
  1787
        ASSERT_EQ(status, PEP_STATUS_OK);
krista@4246
  1788
    }
krista@4246
  1789
    ASSERT_EQ(i, 4);
krista@4246
  1790
    ASSERT_EQ(curr_key, nullptr);
krista@4246
  1791
    
krista@4246
  1792
    // Make sure we can't find them
krista@4246
  1793
    curr_key = first_keylist;
krista@4246
  1794
    for (i = 0; i < 4; curr_key = curr_key->next, i++) {
krista@4246
  1795
        PEP_comm_type ct = PEP_ct_unknown;
krista@4246
  1796
        status = get_key_rating(session, curr_key->value, &ct);
krista@4246
  1797
        ASSERT_EQ(status, PEP_KEY_NOT_FOUND);    
krista@4246
  1798
    }
krista@4246
  1799
    curr_key = second_keylist;
krista@4246
  1800
    for (i = 0; i < 4; curr_key = curr_key->next, i++) {
krista@4246
  1801
        PEP_comm_type ct = PEP_ct_unknown;
krista@4246
  1802
        status = get_key_rating(session, curr_key->value, &ct);
krista@4246
  1803
        ASSERT_EQ(status, PEP_KEY_NOT_FOUND);
krista@4246
  1804
    }
krista@4246
  1805
    
krista@4246
  1806
    
krista@4246
  1807
    // Reimport
krista@4246
  1808
    curr_key = revocations;
krista@4246
  1809
    for (i = 0; i < 4; curr_key = curr_key->next, i++) {
krista@4246
  1810
        status = import_key(session, curr_key->value, strlen(curr_key->value), NULL);
krista@4246
  1811
        ASSERT_EQ(status, PEP_KEY_IMPORTED);
krista@4246
  1812
    }
krista@4246
  1813
    ASSERT_EQ(i, 4);
krista@4246
  1814
    ASSERT_EQ(curr_key, nullptr);
krista@4246
  1815
    
krista@4246
  1816
    curr_key = keys;
krista@4246
  1817
    for (i = 0; i < 4; curr_key = curr_key->next, i++) {
krista@4246
  1818
        status = import_key(session, curr_key->value, strlen(curr_key->value), NULL);
krista@4246
  1819
        ASSERT_EQ(status, PEP_KEY_IMPORTED);
krista@4246
  1820
    }
krista@4246
  1821
    ASSERT_EQ(i, 4);
krista@4246
  1822
    ASSERT_EQ(curr_key, nullptr);
krista@4246
  1823
    
krista@4246
  1824
    // Check the revoked keys to be sure they are revoked
krista@4246
  1825
    curr_key = first_keylist;
krista@4246
  1826
    for (i = 0; i < 4; curr_key = curr_key->next, i++) {
krista@4246
  1827
        PEP_comm_type ct = PEP_ct_unknown;
krista@4246
  1828
        status = get_key_rating(session, curr_key->value, &ct);
krista@4246
  1829
        ASSERT_EQ(ct, PEP_ct_key_revoked);
krista@4246
  1830
        ASSERT_EQ(status, PEP_STATUS_OK);
krista@4246
  1831
    }
krista@4246
  1832
    // Check the imported keys to be sure they are OK
krista@4246
  1833
    curr_key = second_keylist;
krista@4246
  1834
    for (i = 0; i < 4; curr_key = curr_key->next, i++) {
krista@4246
  1835
        PEP_comm_type ct = PEP_ct_unknown;
krista@4246
  1836
        status = get_key_rating(session, curr_key->value, &ct);
krista@4246
  1837
        ASSERT_EQ(ct, PEP_ct_OpenPGP_unconfirmed);
krista@4246
  1838
        ASSERT_EQ(status, PEP_STATUS_OK);
krista@4246
  1839
    }
krista@4246
  1840
}
krista@4312
  1841
*/
krista@4315
  1842
krista@4323
  1843
vb@4274
  1844
TEST_F(KeyResetMessageTest, codec_test) {
vb@4274
  1845
    // create input values
vb@4274
  1846
vb@4276
  1847
    pEp_identity *ident1 = new_identity("alice@pep-project.org", "FEDCBA9876543210", "42", "Alice Miller");
vb@4274
  1848
    ASSERT_NE(ident1, nullptr);
vb@4276
  1849
    const char *key1 = "0123456789ABCDEF";
vb@4274
  1850
    keyreset_command *cmd1 = new_keyreset_command(ident1, key1);
vb@4274
  1851
    ASSERT_NE(cmd1, nullptr);
vb@4274
  1852
vb@4274
  1853
    keyreset_command_list *il = new_keyreset_command_list(cmd1);
vb@4274
  1854
    ASSERT_NE(il, nullptr);
vb@4274
  1855
vb@4277
  1856
    pEp_identity *ident2 = new_identity("alice@peptest.ch", "0123456789abcdef", "42", "Alice Miller");
vb@4274
  1857
    ASSERT_NE(ident2, nullptr);
vb@4277
  1858
    const char *key2 = "fedcba9876543210";
vb@4274
  1859
    keyreset_command *cmd2 = new_keyreset_command(ident2, key2);
vb@4274
  1860
    ASSERT_NE(cmd2, nullptr);
vb@4274
  1861
vb@4274
  1862
    keyreset_command_list *_il = keyreset_command_list_add(il, cmd2);
vb@4274
  1863
    ASSERT_NE(_il, nullptr);
vb@4274
  1864
vb@4274
  1865
    // check created struct
vb@4274
  1866
vb@4274
  1867
    ASSERT_NE(il->command, nullptr);
vb@4274
  1868
    ASSERT_NE(il->command->ident, nullptr);
vb@4274
  1869
    ASSERT_NE(il->command->new_key, nullptr);
vb@4274
  1870
vb@4274
  1871
    ASSERT_STREQ(il->command->ident->address, ident1->address);
vb@4276
  1872
    ASSERT_STREQ(il->command->ident->fpr, ident1->fpr);
vb@4274
  1873
    ASSERT_STREQ(il->command->ident->user_id, ident1->user_id);
vb@4274
  1874
    ASSERT_STREQ(il->command->ident->username, ident1->username);
vb@4274
  1875
    ASSERT_STREQ(il->command->new_key, key1);
vb@4274
  1876
vb@4274
  1877
    ASSERT_NE(il->next, nullptr);
vb@4274
  1878
    ASSERT_NE(il->next->command, nullptr);
vb@4274
  1879
    ASSERT_NE(il->next->command->ident, nullptr);
vb@4274
  1880
    ASSERT_NE(il->next->command->new_key, nullptr);
vb@4274
  1881
vb@4274
  1882
    ASSERT_STREQ(il->next->command->ident->address, ident2->address);
vb@4277
  1883
    ASSERT_STRCASEEQ(il->next->command->ident->fpr, ident2->fpr);
vb@4274
  1884
    ASSERT_STREQ(il->next->command->ident->user_id, ident2->user_id);
vb@4274
  1885
    ASSERT_STREQ(il->next->command->ident->username, ident2->username);
vb@4277
  1886
    ASSERT_STRCASEEQ(il->next->command->new_key, key2);
vb@4274
  1887
vb@4274
  1888
    ASSERT_EQ(il->next->next, nullptr);
vb@4274
  1889
vb@4274
  1890
    // encode
vb@4274
  1891
 
vb@4274
  1892
    char *cmds = nullptr;
vb@4274
  1893
    size_t size = 0;
vb@4274
  1894
    PEP_STATUS status = key_reset_commands_to_PER(il, &cmds, &size);
vb@4274
  1895
    ASSERT_EQ(status, PEP_STATUS_OK);
vb@4274
  1896
    ASSERT_NE(cmds, nullptr);
vb@4274
  1897
    ASSERT_NE(size, 0);
vb@4274
  1898
vb@4274
  1899
    // decode
vb@4274
  1900
    
vb@4274
  1901
    keyreset_command_list *ol = nullptr;
vb@4274
  1902
    status = PER_to_key_reset_commands(cmds, size, &ol);
vb@4274
  1903
    ASSERT_EQ(status, PEP_STATUS_OK);
vb@4274
  1904
    ASSERT_NE(ol, nullptr);
vb@4274
  1905
vb@4274
  1906
    // compare
vb@4274
  1907
vb@4274
  1908
    ASSERT_NE(ol->command, nullptr);
vb@4274
  1909
    ASSERT_NE(ol->command->ident, nullptr);
vb@4274
  1910
    ASSERT_NE(ol->command->new_key, nullptr);
vb@4274
  1911
vb@4274
  1912
    ASSERT_STREQ(ol->command->ident->address, ident1->address);
vb@4276
  1913
    ASSERT_STREQ(ol->command->ident->fpr, ident1->fpr);
vb@4274
  1914
    ASSERT_STREQ(ol->command->ident->user_id, ident1->user_id);
vb@4274
  1915
    ASSERT_STREQ(ol->command->ident->username, ident1->username);
vb@4274
  1916
    ASSERT_STREQ(ol->command->new_key, key1);
vb@4274
  1917
vb@4274
  1918
    ASSERT_NE(ol->next, nullptr);
vb@4274
  1919
    ASSERT_NE(ol->next->command, nullptr);
vb@4274
  1920
    ASSERT_NE(ol->next->command->ident, nullptr);
vb@4274
  1921
    ASSERT_NE(ol->next->command->new_key, nullptr);
vb@4274
  1922
vb@4274
  1923
    ASSERT_STREQ(ol->next->command->ident->address, ident2->address);
vb@4277
  1924
    ASSERT_STRCASEEQ(ol->next->command->ident->fpr, ident2->fpr);
vb@4274
  1925
    ASSERT_STREQ(ol->next->command->ident->user_id, ident2->user_id);
vb@4274
  1926
    ASSERT_STREQ(ol->next->command->ident->username, ident2->username);
vb@4277
  1927
    ASSERT_STRCASEEQ(ol->next->command->new_key, key2);
vb@4274
  1928
vb@4274
  1929
    ASSERT_EQ(ol->next->next, nullptr);
vb@4274
  1930
vb@4274
  1931
    // free
vb@4274
  1932
vb@4274
  1933
    free_keyreset_command_list(ol);
vb@4274
  1934
    free(cmds);
vb@4274
  1935
vb@4274
  1936
    free_identity(ident1);
vb@4274
  1937
    free_identity(ident2);
vb@4274
  1938
    free_keyreset_command_list(il);
vb@4274
  1939
}