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
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include <stdlib.h>
     5 #include <string.h>
     6 #include <time.h>
     7 #include "platform.h"
     8 #include <iostream>
     9 #include <fstream>
    10 #include "mime.h"
    11 #include "message_api.h"
    12 #include "test_util.h"
    13 
    14 #include "EngineTestSuite.h"
    15 #include "EngineTestSessionSuite.h"
    16 #include "CaseAndDotAddressTests.h"
    17 
    18 using namespace std;
    19 
    20 CaseAndDotAddressTests::CaseAndDotAddressTests(string suitename, string test_home_dir) : 
    21     EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {            
    22     add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CaseAndDotAddressTests::check_case_and_dot_address"),
    23                                                                       static_cast<Func>(&CaseAndDotAddressTests::check_case_and_dot_address)));
    24 }
    25 
    26 void CaseAndDotAddressTests::check_case_and_dot_address() {
    27     cout << "\n*** case_and_dot_address_test.cc ***\n\n";
    28     
    29     char* user_id = get_new_uuid();
    30     
    31     const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    32 
    33     const char* alice_email_case = "pEp.teST.AlICe@pEP-pRoJeCt.ORG";
    34     const char* alice_email_dot = "pe.p.te.st.a.l.i.ce@pep-project.org";
    35     const char* alice_email_dotless = "peptestalice@pep-project.org";
    36     const char* alice_email_case_and_dot = "PE.p.teS.t.ALICE@pep-project.OrG";
    37 
    38     PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
    39     TEST_ASSERT_MSG((statuspub == PEP_KEY_IMPORTED), "statuspub == PEP_STATUS_OK");
    40 
    41     pEp_identity * alice_id = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", user_id, "Alice Test");
    42 
    43     PEP_STATUS status = trust_personal_key(session, alice_id);
    44 
    45     pEp_identity * new_alice_id = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", user_id, "Alice Test");
    46     status = update_identity(session, new_alice_id);
    47     TEST_ASSERT_MSG((new_alice_id->fpr), "new_alice_id->fpr");
    48     TEST_ASSERT_MSG((strcmp(new_alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(new_alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
    49     free_identity(new_alice_id);
    50     free_identity(alice_id);
    51     alice_id = NULL;
    52     new_alice_id = NULL;
    53 
    54     alice_id = new_identity(alice_email_case, NULL, user_id, "Alice Test");
    55     status = update_identity(session, alice_id);
    56     TEST_ASSERT_MSG((alice_id->fpr), "alice_id->fpr");
    57     cout << "Alice email: " << alice_email_case << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
    58     TEST_ASSERT_MSG((strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
    59     free_identity(alice_id);
    60     alice_id = NULL;
    61 
    62     alice_id = new_identity(alice_email_dot, NULL, user_id, "Alice Test");
    63     status = update_identity(session, alice_id);
    64     TEST_ASSERT_MSG((alice_id->fpr), "alice_id->fpr");
    65     cout << "Alice email: " << alice_email_dot << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
    66     TEST_ASSERT_MSG((strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
    67     free_identity(alice_id);
    68     alice_id = NULL;
    69 
    70     alice_id = new_identity(alice_email_dotless, NULL, user_id, "Alice Test");
    71     status = update_identity(session, alice_id);
    72     TEST_ASSERT_MSG((alice_id->fpr), "alice_id->fpr");
    73     cout << "Alice email: " << alice_email_dotless << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
    74     TEST_ASSERT_MSG((strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
    75     free_identity(alice_id);
    76     alice_id = NULL;
    77 
    78     alice_id = new_identity(alice_email_case_and_dot, NULL, user_id, "Alice Test");
    79     status = update_identity(session, alice_id);
    80     TEST_ASSERT_MSG((alice_id->fpr), "alice_id->fpr");
    81     cout << "Alice email: " << alice_email_case_and_dot << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
    82     TEST_ASSERT_MSG((strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0), "strcmp(alice_id->fpr, \"4ABE3AAF59AC32CFE4F86500A9411D176FF00E97\") == 0");
    83     free_identity(alice_id);
    84     alice_id = NULL;
    85 }