test/trustwords_test.cc
author Edouard Tisserant <edouard@pep-project.org>
Mon, 24 Oct 2016 20:44:48 +0200
changeset 1329 876ad7615d75
parent 1315 d42e1163f3f3
child 1496 eacf1934b6cc
permissions -rw-r--r--
sync : fix encrypted sync messages not being injected when decrypted from non-sync session
     1 #include <iostream>
     2 #include <string>
     3 #include <assert.h>
     4 #include "pEpEngine.h"
     5 #include "message_api.h"
     6 
     7 using namespace std;
     8 
     9 int main() {
    10     cout << "\n*** get_trustwords test ***\n\n";
    11 
    12     PEP_SESSION session;
    13     
    14     cout << "calling init()\n";
    15     PEP_STATUS status1 = init(&session);   
    16     assert(status1 == PEP_STATUS_OK);
    17     assert(session);
    18     cout << "init() completed.\n";
    19         
    20     pEp_identity* identity1  = new_identity(
    21         "leon.schumacher@digitalekho.com",
    22         "8BD08954C74D830EEFFB5DEB2682A17F7C87F73D",
    23         "23",
    24         "Leon Schumacher");
    25     
    26     pEp_identity* identity2 = new_identity(
    27         "krista@kgrothoff.org",
    28         "62D4932086185C15917B72D30571AFBCA5493553",
    29         "blargh",
    30         "Krista Grothoff");
    31     
    32     string fingerprint1 = identity1->fpr;
    33     string fingerprint2 = identity2->fpr;
    34     char* words1;
    35     char* words2;
    36     char* full_wordlist;
    37     size_t wsize1;
    38     size_t wsize2;
    39     size_t wsize_full;
    40     
    41     cout << "\nTest 1: fpr1 > fpr2, short" << endl;
    42     
    43     cout << "\nfinding German trustwords for " << fingerprint1 << "...\n";
    44     trustwords(session, fingerprint1.c_str(), "de", &words1, &wsize1, 5);
    45     assert(words1);
    46     cout << words1 << "\n";
    47 
    48     cout << "\nfinding German trustwords for " << fingerprint2 << "...\n";
    49     trustwords(session, fingerprint2.c_str(), "de", &words2, &wsize2, 5);
    50     assert(words2);
    51     cout << words2 << "\n";
    52 
    53     cout << "\nfinding German trustwords for " << identity1->address << " and " << identity2->address << "...\n";
    54     get_trustwords(session, identity1, identity2, "de", &full_wordlist, &wsize_full, false);
    55     assert(full_wordlist);
    56     cout << full_wordlist << "\n";
    57     
    58     
    59     pEp_free(words1);
    60     pEp_free(words2);
    61     pEp_free(full_wordlist);
    62 
    63     cout << "\nTest 2: fpr1 == fpr1, short" << endl;
    64     
    65     cout << "\nfinding French trustwords for " << fingerprint2 << "...\n";
    66     trustwords(session, fingerprint1.c_str(), "fr", &words1, &wsize1, 5);
    67     assert(words1);
    68     cout << words1 << "\n";
    69         
    70     cout << "\nfinding French trustwords for " << identity2->address << " and " << identity2->address << "...\n";
    71     get_trustwords(session, identity2, identity2, "fr", &full_wordlist, &wsize_full, false);
    72     assert(full_wordlist);
    73     cout << full_wordlist << "\n";
    74 
    75     pEp_free(words1);
    76     pEp_free(full_wordlist);
    77 
    78     cout << "\nTest 3: fpr1 < fpr2, long" << endl;
    79     
    80     cout << "\nfinding English trustwords for " << fingerprint2 << "...\n";
    81     trustwords(session, fingerprint2.c_str(), "en", &words1, &wsize1, 0);
    82     assert(words1);
    83     cout << words1 << "\n";
    84     
    85     cout << "\nfinding English trustwords for " << fingerprint1 << "...\n";
    86     trustwords(session, fingerprint1.c_str(), "en", &words2, &wsize2, 0);
    87     assert(words2);
    88     cout << words2 << "\n";
    89     
    90     cout << "\nfinding English trustwords for " << identity2->address << " and " << identity2->address << "...\n";
    91     get_trustwords(session, identity2, identity1, "en", &full_wordlist, &wsize_full, true);
    92     assert(full_wordlist);
    93     cout << full_wordlist << "\n";
    94     
    95     pEp_free(words1);
    96     pEp_free(words2);
    97     pEp_free(full_wordlist);
    98     
    99     
   100     cout << "\nTest 4: fpr1 < fpr2, leading zeros (fpr1 has more), long" << endl;
   101     
   102     pEp_identity* identity3 = new_identity(
   103         "nobody@kgrothoff.org",
   104         "000F932086185C15917B72D30571AFBCA5493553",
   105         "blargh",
   106         "Krista Grothoff");
   107     
   108     pEp_identity* identity4 = new_identity(
   109         "nobody2@kgrothoff.org",
   110         "001F932086185C15917B72D30571AFBCA5493553",
   111         "blargh",
   112         "Krista Grothoff");
   113     
   114     pEp_identity* identity5 = new_identity(
   115         "nobody3@kgrothoff.org",
   116         "001F732086185C15917B72D30571AFBCA5493553",
   117         "blargh",
   118         "Krista Grothoff");
   119 
   120     string fingerprint3 = identity3->fpr;
   121     string fingerprint4 = identity4->fpr;
   122     string fingerprint5 = identity5->fpr; 
   123         
   124     cout << "\nfinding Catalan trustwords for " << fingerprint3 << "...\n";
   125     trustwords(session, fingerprint3.c_str(), "ca", &words1, &wsize1, 0);
   126     assert(words1);
   127     cout << words1 << "\n";
   128     
   129     cout << "\nfinding Catalan trustwords for " << fingerprint4 << "...\n";
   130     trustwords(session, fingerprint4.c_str(), "ca", &words2, &wsize2, 0);
   131     assert(words2);
   132     cout << words2 << "\n";
   133     
   134     cout << "\nfinding Catalan trustwords for " << identity3->address << " and " << identity4->address << "...\n";
   135     get_trustwords(session, identity3, identity4, "ca", &full_wordlist, &wsize_full, true);
   136     assert(full_wordlist);
   137     cout << full_wordlist << "\n";
   138 
   139     pEp_free(words1);
   140     pEp_free(words2);
   141     pEp_free(full_wordlist);
   142 
   143     cout << "\nTest 5: fpr1 > fpr2, leading zeros (same number), interior digit difference, short" << endl;
   144     
   145     cout << "\nfinding Turkish trustwords for " << fingerprint4 << "...\n";
   146     trustwords(session, fingerprint4.c_str(), "tr", &words1, &wsize1, 5);
   147     assert(words1);
   148     cout << words1 << "\n";
   149     
   150     cout << "\nfinding Turkish trustwords for " << fingerprint5 << "...\n";
   151     trustwords(session, fingerprint5.c_str(), "tr", &words2, &wsize2, 5);
   152     assert(words2);
   153     cout << words2 << "\n";
   154     
   155     cout << "\nfinding Turkish trustwords for " << identity4->address << " and " << identity5->address << "...\n";
   156     get_trustwords(session, identity4, identity5, "tr", &full_wordlist, &wsize_full, false);
   157     assert(full_wordlist);
   158     cout << full_wordlist << "\n";
   159     
   160     pEp_free(words1);
   161     pEp_free(words2);
   162     pEp_free(full_wordlist);
   163 
   164     cout << "\nTest 6: fpr2 is too short" << endl;
   165     
   166     pEp_identity* identity6 = new_identity(
   167         "nobody4@kgrothoff.org",
   168         "01F932086185C15917B72D30571AFBCA5493553",
   169         "blargh",
   170         "Krista Grothoff");
   171     
   172     cout << "\nfinding Turkish trustwords for " << identity5->address << " and " << identity6->address << "...\n";
   173     PEP_STATUS status6 = get_trustwords(session, identity5, identity6, "tr", &full_wordlist, &wsize_full, false);
   174     assert(status6 == PEP_TRUSTWORDS_FPR_WRONG_LENGTH);
   175     cout << "Bad fpr length correctly recognised." << "\n";
   176     
   177     pEp_identity* identity7 = new_identity(
   178         "nobody5@kgrothoff.org",
   179         "F01X932086185C15917B72D30571AFBCA5493553",
   180         "blargh",
   181         "Krista Grothoff");
   182 
   183     cout << "\nTest 7: fpr2 has a non-hex character" << endl;
   184     
   185     cout << "\nfinding Turkish trustwords for " << identity1->address << " and " << identity7->address << "...\n";
   186     PEP_STATUS status7 = get_trustwords(session, identity1, identity7, "tr", &full_wordlist, &wsize_full, true);
   187     assert(status7 == PEP_ILLEGAL_VALUE);
   188     cout << "Illegal digit value correctly recognised." << "\n";
   189     
   190     
   191     free(identity1);
   192     free(identity2);
   193     free(identity3);
   194     free(identity4);
   195     free(identity5);
   196     free(identity6);
   197     free(identity7);
   198     
   199     cout << "calling release()\n";
   200     release(session);
   201     return 0;
   202 }
   203