more fixes, more tests sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 30 Apr 2019 17:25:11 +0200
branchsync
changeset 358660a1999238bb
parent 3585 0c76403338c8
child 3587 28eaa98bc5b0
more fixes, more tests
src/keymanagement.c
test/src/engine_tests/OwnKeysRetrieveTests.cc
     1.1 --- a/src/keymanagement.c	Tue Apr 30 16:48:03 2019 +0200
     1.2 +++ b/src/keymanagement.c	Tue Apr 30 17:25:11 2019 +0200
     1.3 @@ -1796,9 +1796,11 @@
     1.4                  contains_priv_key(session, _kl->value, &has_private);
     1.5                  if (!has_private) {
     1.6                      stringlist_t* _kl_tmp = _kl;
     1.7 -                    if (_kl_prev) {
     1.8 +                    if (_kl_prev)
     1.9                          _kl_prev->next = _kl->next;
    1.10 -                    }
    1.11 +                    else 
    1.12 +                        _keylist = _kl->next;
    1.13 +                        
    1.14                      _kl = _kl->next;
    1.15                      
    1.16                      _kl_tmp->next = NULL;
     2.1 --- a/test/src/engine_tests/OwnKeysRetrieveTests.cc	Tue Apr 30 16:48:03 2019 +0200
     2.2 +++ b/test/src/engine_tests/OwnKeysRetrieveTests.cc	Tue Apr 30 17:25:11 2019 +0200
     2.3 @@ -81,11 +81,6 @@
     2.4      free(me_bob);
     2.5      me_bob = NULL;
     2.6      TEST_ASSERT(status == PEP_STATUS_OK);
     2.7 -    status = get_identity(session, "pep.test.bob@pep-project.org", PEP_OWN_USERID, &me_bob);
     2.8 -    TEST_ASSERT(status == PEP_STATUS_OK);
     2.9 -    
    2.10 -    free(me_bob);
    2.11 -    me_bob = NULL;
    2.12      
    2.13      // Setup own identity
    2.14      status = read_file_and_import_key(session,
    2.15 @@ -204,7 +199,146 @@
    2.16  }
    2.17  
    2.18  void OwnKeysRetrieveTests::check_own_keys_retrieve_multiple_private_and_pub() {
    2.19 -    TEST_ASSERT(true);
    2.20 +    // Setup own identity
    2.21 +    PEP_STATUS status = read_file_and_import_key(session,
    2.22 +                "test_keys/pub/pep.test.alexander0-0x3B7302DB_pub.asc");
    2.23 +    TEST_ASSERT(status == PEP_KEY_IMPORTED);
    2.24 +    status = set_up_ident_from_scratch(session,
    2.25 +                "test_keys/priv/pep.test.alexander0-0x3B7302DB_priv.asc",
    2.26 +                "pep.test.xander@pep-project.org", "F4598A17D4690EB3B5B0F6A344F04E963B7302DB", 
    2.27 +                PEP_OWN_USERID, "Xander in Wonderland", NULL, true
    2.28 +            );
    2.29 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    2.30 +
    2.31 +    // Own pub key
    2.32 +    TEST_ASSERT_MSG(slurp_and_import_key(session, "test_keys/pub/pep.test.alexander5-0x0773CD29_pub.asc"),
    2.33 +                    "Unable to import test_keys/pub/pep.test.alexander5-0x0773CD29_pub.asc");
    2.34 +    
    2.35 +    // Make it an own identity in the DB
    2.36 +    pEp_identity* me_pub = new_identity("pep.test.xander@pep-project.org", "58BCC2BF2AE1E3C4FBEAB89AD7838ACA0773CD29", PEP_OWN_USERID, NULL);
    2.37 +    me_pub->comm_type = PEP_ct_pEp;
    2.38 +    status = set_trust(session, me_pub);
    2.39 +    TEST_ASSERT(status == PEP_STATUS_OK);    
    2.40 +    free_identity(me_pub);
    2.41 +    me_pub = NULL;
    2.42 +
    2.43 +    // Setup own identity
    2.44 +    status = read_file_and_import_key(session,
    2.45 +                "test_keys/pub/pep.test.alexander1-0x541260F6_pub.asc");
    2.46 +    TEST_ASSERT(status == PEP_KEY_IMPORTED);
    2.47 +    status = set_up_ident_from_scratch(session,
    2.48 +                "test_keys/priv/pep.test.alexander1-0x541260F6_priv.asc",
    2.49 +                "pep.test.xander@pep-project.org", "59AF4C51492283522F6904531C09730A541260F6", 
    2.50 +                PEP_OWN_USERID, "Xander2", NULL, true
    2.51 +            );
    2.52 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    2.53 +
    2.54 +    // Own pub key
    2.55 +    TEST_ASSERT_MSG(slurp_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc"),
    2.56 +                    "Unable to import test_keys/pub/pep.test.alexander6-0x0019697D_pub.asc");
    2.57 +    
    2.58 +    // Make it an own identity in the DB
    2.59 +    me_pub = new_identity("pep.test.xander@pep-project.org", "74D79B4496E289BD8A71B70BA8E2C4530019697D", PEP_OWN_USERID, NULL);
    2.60 +    me_pub->comm_type = PEP_ct_pEp;
    2.61 +    status = set_trust(session, me_pub);
    2.62 +    TEST_ASSERT(status == PEP_STATUS_OK);    
    2.63 +    free_identity(me_pub);
    2.64 +    me_pub = NULL;
    2.65 +
    2.66 +
    2.67 +    // Setup own identity
    2.68 +    status = read_file_and_import_key(session,
    2.69 +                "test_keys/pub/pep.test.alexander2-0xA6512F30_pub.asc");
    2.70 +    TEST_ASSERT(status == PEP_KEY_IMPORTED);
    2.71 +    status = set_up_ident_from_scratch(session,
    2.72 +                "test_keys/priv/pep.test.alexander2-0xA6512F30_priv.asc",
    2.73 +                "pep.test.xander.work@pep-project.org", "46A994F19077C05610870273C4B8AB0BA6512F30", 
    2.74 +                PEP_OWN_USERID, "Xander3", NULL, true
    2.75 +            );
    2.76 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    2.77 +
    2.78 +    // Own pub key
    2.79 +    TEST_ASSERT_MSG(slurp_and_import_key(session, "test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc"),
    2.80 +                    "Unable to import test_keys/pub/pep.test.alexander6-0x503B14D8_pub.asc");
    2.81 +    
    2.82 +    // Make it an own identity in the DB
    2.83 +    me_pub = new_identity("pep.test.xander@pep-project.org", "2E21325D202A44BFD9C607FCF095B202503B14D8", PEP_OWN_USERID, NULL);
    2.84 +    me_pub->comm_type = PEP_ct_pEp;
    2.85 +    status = set_trust(session, me_pub);
    2.86 +    TEST_ASSERT(status == PEP_STATUS_OK);    
    2.87 +    free_identity(me_pub);
    2.88 +    me_pub = NULL;
    2.89 +
    2.90 +
    2.91 +    // Setup own identity
    2.92 +    status = read_file_and_import_key(session,
    2.93 +                "test_keys/pub/pep.test.alexander3-0x724B3975_pub.asc");
    2.94 +    TEST_ASSERT(status == PEP_KEY_IMPORTED);
    2.95 +    status = set_up_ident_from_scratch(session,
    2.96 +                "test_keys/priv/pep.test.alexander3-0x724B3975_priv.asc",
    2.97 +                "pep.test.xander@pep-project.org", "5F7076BBD92E14EA49F0DF7C2CE49419724B3975", 
    2.98 +                PEP_OWN_USERID, "Xander4", NULL, true
    2.99 +            );
   2.100 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   2.101 +
   2.102 +    // Own pub key
   2.103 +    TEST_ASSERT_MSG(slurp_and_import_key(session, "test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc"),
   2.104 +                    "Unable to import test_keys/pub/pep.test.alexander6-0xA216E95A_pub.asc");
   2.105 +    
   2.106 +    // Make it an own identity in the DB
   2.107 +    me_pub = new_identity("pep.test.xander@pep-project.org", "3C1E713D8519D7F907E3142D179EAA24A216E95A", PEP_OWN_USERID, NULL);
   2.108 +    me_pub->comm_type = PEP_ct_pEp;
   2.109 +    status = set_trust(session, me_pub);
   2.110 +    TEST_ASSERT(status == PEP_STATUS_OK);    
   2.111 +    free_identity(me_pub);
   2.112 +    me_pub = NULL;
   2.113 +
   2.114 +    // Setup own identity
   2.115 +    status = read_file_and_import_key(session,
   2.116 +                "test_keys/pub/pep.test.alexander4-0x844B9DCF_pub.asc");
   2.117 +    TEST_ASSERT(status == PEP_KEY_IMPORTED);
   2.118 +    status = set_up_ident_from_scratch(session,
   2.119 +                "test_keys/priv/pep.test.alexander4-0x844B9DCF_priv.asc",
   2.120 +                "pep.test.xander.home@pep-project.org", "E95FFF95B8E2FDD4A12C3374395F1485844B9DCF", 
   2.121 +                PEP_OWN_USERID, "Xander in Wonderland Again", NULL, true
   2.122 +            );
   2.123 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   2.124 +    
   2.125 +    // Ok, see if we get it back.
   2.126 +    stringlist_t* keylist = NULL;
   2.127 +    
   2.128 +    status = _own_keys_retrieve(session, &keylist, 0, true);
   2.129 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   2.130 +    TEST_ASSERT(keylist);
   2.131 +
   2.132 +    int fpr_count = 0;
   2.133 +
   2.134 +    const char* fpr_list[5];
   2.135 +    
   2.136 +    bool* found_list = (bool*)calloc(5, sizeof(bool));
   2.137 +    fpr_list[0] = "F4598A17D4690EB3B5B0F6A344F04E963B7302DB"; 
   2.138 +    fpr_list[1] = "59AF4C51492283522F6904531C09730A541260F6"; 
   2.139 +    fpr_list[2] = "46A994F19077C05610870273C4B8AB0BA6512F30"; 
   2.140 +    fpr_list[3] = "5F7076BBD92E14EA49F0DF7C2CE49419724B3975"; 
   2.141 +    fpr_list[4] = "E95FFF95B8E2FDD4A12C3374395F1485844B9DCF"; 
   2.142 +     
   2.143 +    for (stringlist_t* _kl = keylist; _kl; _kl = _kl->next) {
   2.144 +        TEST_ASSERT(_kl->value);
   2.145 +        fpr_count++;
   2.146 +        
   2.147 +        for (int j = 0; j < 5; j++) {
   2.148 +            if (strcmp(_kl->value, fpr_list[j]) == 0) {
   2.149 +                found_list[j] = true;
   2.150 +                break;
   2.151 +            }
   2.152 +        }
   2.153 +    }
   2.154 +    TEST_ASSERT_MSG(fpr_count == 5, "Returned keylist does not have the correct number of keys.");
   2.155 +    for (int j = 0; j < 5; j++) {
   2.156 +        TEST_ASSERT_MSG(found_list[j], (string(fpr_list[j]) + " was not found.").c_str());
   2.157 +    }    
   2.158 +    free(found_list);
   2.159 +    free_stringlist(keylist);
   2.160  }
   2.161  
   2.162  void OwnKeysRetrieveTests::check_own_keys_retrieve_multi_pub_only() {