• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at https://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22 #include "curlcheck.h"
23 
24 #include "tool_getparam.h"
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 
30 #include "memdebug.h" /* LAST include file */
31 
unit_setup(void)32 static CURLcode unit_setup(void)
33 {
34   return CURLE_OK;
35 }
36 
unit_stop(void)37 static void unit_stop(void)
38 {
39 
40 }
41 
42 UNITTEST_START
43 
44   const char *values[] = {
45     /* -E parameter */        /* exp. cert name */  /* exp. passphrase */
46     "foo:bar:baz",            "foo",                "bar:baz",
47     "foo\\:bar:baz",          "foo:bar",            "baz",
48     "foo\\\\:bar:baz",        "foo\\",              "bar:baz",
49     "foo:bar\\:baz",          "foo",                "bar\\:baz",
50     "foo:bar\\\\:baz",        "foo",                "bar\\\\:baz",
51     "foo\\bar\\baz",          "foo\\bar\\baz",      NULL,
52     "foo\\\\bar\\\\baz",      "foo\\bar\\baz",      NULL,
53     "foo\\",                  "foo\\",              NULL,
54     "foo\\\\",                "foo\\",              NULL,
55     "foo:bar\\",              "foo",                "bar\\",
56     "foo:bar\\\\",            "foo",                "bar\\\\",
57     "foo:bar:",               "foo",                "bar:",
58     "foo\\::bar\\:",          "foo:",               "bar\\:",
59     "pkcs11:foobar",          "pkcs11:foobar",      NULL,
60     "PKCS11:foobar",          "PKCS11:foobar",      NULL,
61     "PkCs11:foobar",          "PkCs11:foobar",      NULL,
62 #ifdef WIN32
63     "c:\\foo:bar:baz",        "c:\\foo",            "bar:baz",
64     "c:\\foo\\:bar:baz",      "c:\\foo:bar",        "baz",
65     "c:\\foo\\\\:bar:baz",    "c:\\foo\\",          "bar:baz",
66     "c:\\foo:bar\\:baz",      "c:\\foo",            "bar\\:baz",
67     "c:\\foo:bar\\\\:baz",    "c:\\foo",            "bar\\\\:baz",
68     "c:\\foo\\bar\\baz",      "c:\\foo\\bar\\baz",  NULL,
69     "c:\\foo\\\\bar\\\\baz",  "c:\\foo\\bar\\baz",  NULL,
70     "c:\\foo\\",              "c:\\foo\\",          NULL,
71     "c:\\foo\\\\",            "c:\\foo\\",          NULL,
72     "c:\\foo:bar\\",          "c:\\foo",            "bar\\",
73     "c:\\foo:bar\\\\",        "c:\\foo",            "bar\\\\",
74     "c:\\foo:bar:",           "c:\\foo",            "bar:",
75     "c:\\foo\\::bar\\:",      "c:\\foo:",           "bar\\:",
76 #endif
77     NULL,                     NULL,                 NULL,
78   };
79   const char **p;
80   char *certname, *passphrase;
81   for(p = values; *p; p += 3) {
82     parse_cert_parameter(p[0], &certname, &passphrase);
83     if(p[1]) {
84       if(certname) {
85         if(strcmp(p[1], certname)) {
86           printf("expected certname '%s' but got '%s' "
87               "for -E param '%s'\n", p[1], certname, p[0]);
88           fail("assertion failure");
89         }
90       }
91       else {
92         printf("expected certname '%s' but got NULL "
93             "for -E param '%s'\n", p[1], p[0]);
94         fail("assertion failure");
95       }
96     }
97     else {
98       if(certname) {
99         printf("expected certname NULL but got '%s' "
100             "for -E param '%s'\n", certname, p[0]);
101         fail("assertion failure");
102       }
103     }
104     if(p[2]) {
105       if(passphrase) {
106         if(strcmp(p[2], passphrase)) {
107           printf("expected passphrase '%s' but got '%s'"
108               "for -E param '%s'\n", p[2], passphrase, p[0]);
109           fail("assertion failure");
110         }
111       }
112       else {
113         printf("expected passphrase '%s' but got NULL "
114             "for -E param '%s'\n", p[2], p[0]);
115         fail("assertion failure");
116       }
117     }
118     else {
119       if(passphrase) {
120         printf("expected passphrase NULL but got '%s' "
121             "for -E param '%s'\n", passphrase, p[0]);
122         fail("assertion failure");
123       }
124     }
125     if(certname) free(certname);
126     if(passphrase) free(passphrase);
127   }
128 
129 UNITTEST_STOP
130