test/src/engine_tests/CaseAndDotAddressTests.cc
author Krista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 29 Jan 2019 19:19:30 +0100
branchENGINE-448
changeset 3254 6e7f6bc9460a
parent 2685 01edd04b3c38
child 3276 c0b3430f1f1d
permissions -rw-r--r--
ENGINE-448: made key removal much less aggressive. NetPGP will still be a problem, but versions built against gpg will now only remove actual keys
krista@1886
     1
// This file is under GNU General Public License 3.0
krista@1886
     2
// see LICENSE.txt
krista@1886
     3
krista@1886
     4
#include <stdlib.h>
krista@1886
     5
#include <string.h>
krista@1886
     6
#include <time.h>
krista@1886
     7
#include "platform.h"
krista@1886
     8
#include <iostream>
krista@1886
     9
#include <fstream>
krista@1886
    10
#include "mime.h"
krista@1886
    11
#include "message_api.h"
krista@1886
    12
#include "test_util.h"
krista@1886
    13
krista@2650
    14
#include "EngineTestSuite.h"
krista@2653
    15
#include "EngineTestSessionSuite.h"
krista@2650
    16
#include "CaseAndDotAddressTests.h"
krista@2650
    17
krista@1886
    18
using namespace std;
krista@1886
    19
krista@2650
    20
CaseAndDotAddressTests::CaseAndDotAddressTests(string suitename, string test_home_dir) : 
krista@2653
    21
    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {            
krista@2685
    22
    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CaseAndDotAddressTests::check_case_and_dot_address"),
krista@2685
    23
                                                                      static_cast<Func>(&CaseAndDotAddressTests::check_case_and_dot_address)));
krista@2650
    24
}
krista@2650
    25
krista@2650
    26
void CaseAndDotAddressTests::check_case_and_dot_address() {
krista@1886
    27
    cout << "\n*** case_and_dot_address_test.cc ***\n\n";
krista@1886
    28
    
krista@2482
    29
    char* user_id = get_new_uuid();
krista@1886
    30
    
krista@1886
    31
    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
krista@1886
    32
krista@1886
    33
    const char* alice_email_case = "pEp.teST.AlICe@pEP-pRoJeCt.ORG";
krista@1886
    34
    const char* alice_email_dot = "pe.p.te.st.a.l.i.ce@pep-project.org";
krista@1886
    35
    const char* alice_email_dotless = "peptestalice@pep-project.org";
krista@1886
    36
    const char* alice_email_case_and_dot = "PE.p.teS.t.ALICE@pep-project.OrG";
krista@1886
    37
krista@1886
    38
    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
krista@3254
    39
    TEST_ASSERT_MSG((statuspub == PEP_KEY_IMPORTED), "statuspub == PEP_STATUS_OK");
krista@1886
    40
krista@2482
    41
    pEp_identity * alice_id = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", user_id, "Alice Test");
krista@2482
    42
krista@2650
    43
    PEP_STATUS status = trust_personal_key(session, alice_id);
krista@2482
    44
krista@2482
    45
    pEp_identity * new_alice_id = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", user_id, "Alice Test");
krista@2308
    46
    status = update_identity(session, new_alice_id);
krista@2669
    47
    TEST_ASSERT_MSG((new_alice_id->fpr), "new_alice_id->fpr");
krista@2669
    48
    TEST_ASSERT_MSG((strcmp(new_alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(new_alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
krista@2308
    49
    free_identity(new_alice_id);
krista@1886
    50
    free_identity(alice_id);
krista@1886
    51
    alice_id = NULL;
krista@2308
    52
    new_alice_id = NULL;
krista@1886
    53
krista@2482
    54
    alice_id = new_identity(alice_email_case, NULL, user_id, "Alice Test");
krista@2482
    55
    status = update_identity(session, alice_id);
krista@2669
    56
    TEST_ASSERT_MSG((alice_id->fpr), "alice_id->fpr");
krista@2481
    57
    cout << "Alice email: " << alice_email_case << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
krista@2669
    58
    TEST_ASSERT_MSG((strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
krista@1886
    59
    free_identity(alice_id);
krista@1886
    60
    alice_id = NULL;
krista@1886
    61
krista@2482
    62
    alice_id = new_identity(alice_email_dot, NULL, user_id, "Alice Test");
krista@2482
    63
    status = update_identity(session, alice_id);
krista@2669
    64
    TEST_ASSERT_MSG((alice_id->fpr), "alice_id->fpr");
krista@2481
    65
    cout << "Alice email: " << alice_email_dot << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
krista@2669
    66
    TEST_ASSERT_MSG((strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
krista@1886
    67
    free_identity(alice_id);
krista@1886
    68
    alice_id = NULL;
krista@1886
    69
krista@2482
    70
    alice_id = new_identity(alice_email_dotless, NULL, user_id, "Alice Test");
krista@2482
    71
    status = update_identity(session, alice_id);
krista@2669
    72
    TEST_ASSERT_MSG((alice_id->fpr), "alice_id->fpr");
krista@2481
    73
    cout << "Alice email: " << alice_email_dotless << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
krista@2669
    74
    TEST_ASSERT_MSG((strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
krista@1886
    75
    free_identity(alice_id);
krista@1886
    76
    alice_id = NULL;
krista@1886
    77
krista@2482
    78
    alice_id = new_identity(alice_email_case_and_dot, NULL, user_id, "Alice Test");
krista@2482
    79
    status = update_identity(session, alice_id);
krista@2669
    80
    TEST_ASSERT_MSG((alice_id->fpr), "alice_id->fpr");
krista@2481
    81
    cout << "Alice email: " << alice_email_case_and_dot << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
krista@2669
    82
    TEST_ASSERT_MSG((strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
krista@1886
    83
    free_identity(alice_id);
krista@1886
    84
    alice_id = NULL;
krista@1886
    85
}