xref: /curl/tests/unit/unit1394.c (revision e9a7d4a1)
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 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.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  * SPDX-License-Identifier: curl
22  *
23  ***************************************************************************/
24 #include "curlcheck.h"
25 
26 #include "tool_getparam.h"
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 
32 #include "memdebug.h" /* LAST include file */
33 
unit_setup(void)34 static CURLcode unit_setup(void)
35 {
36   return CURLE_OK;
37 }
38 
unit_stop(void)39 static void unit_stop(void)
40 {
41 
42 }
43 
44 UNITTEST_START
45 
46   const char *values[] = {
47     /* -E parameter */        /* exp. cert name */  /* exp. passphrase */
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",
52     "foo:bar\\\\:baz",        "foo",                "bar\\\\:baz",
53     "foo\\bar\\baz",          "foo\\bar\\baz",      NULL,
54     "foo\\\\bar\\\\baz",      "foo\\bar\\baz",      NULL,
55     "foo\\",                  "foo\\",              NULL,
56     "foo\\\\",                "foo\\",              NULL,
57     "foo:bar\\",              "foo",                "bar\\",
58     "foo:bar\\\\",            "foo",                "bar\\\\",
59     "foo:bar:",               "foo",                "bar:",
60     "foo\\::bar\\:",          "foo:",               "bar\\:",
61     "pkcs11:foobar",          "pkcs11:foobar",      NULL,
62     "PKCS11:foobar",          "PKCS11:foobar",      NULL,
63     "PkCs11:foobar",          "PkCs11:foobar",      NULL,
64 #ifdef _WIN32
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",
69     "c:\\foo:bar\\\\:baz",    "c:\\foo",            "bar\\\\:baz",
70     "c:\\foo\\bar\\baz",      "c:\\foo\\bar\\baz",  NULL,
71     "c:\\foo\\\\bar\\\\baz",  "c:\\foo\\bar\\baz",  NULL,
72     "c:\\foo\\",              "c:\\foo\\",          NULL,
73     "c:\\foo\\\\",            "c:\\foo\\",          NULL,
74     "c:\\foo:bar\\",          "c:\\foo",            "bar\\",
75     "c:\\foo:bar\\\\",        "c:\\foo",            "bar\\\\",
76     "c:\\foo:bar:",           "c:\\foo",            "bar:",
77     "c:\\foo\\::bar\\:",      "c:\\foo:",           "bar\\:",
78 #endif
79     NULL,                     NULL,                 NULL,
80   };
81   const char **p;
82   char *certname, *passphrase;
83   for(p = values; *p; p += 3) {
84     parse_cert_parameter(p[0], &certname, &passphrase);
85     if(p[1]) {
86       if(certname) {
87         if(strcmp(p[1], certname)) {
88           printf("expected certname '%s' but got '%s' "
89               "for -E param '%s'\n", p[1], certname, p[0]);
90           fail("assertion failure");
91         }
92       }
93       else {
94         printf("expected certname '%s' but got NULL "
95             "for -E param '%s'\n", p[1], p[0]);
96         fail("assertion failure");
97       }
98     }
99     else {
100       if(certname) {
101         printf("expected certname NULL but got '%s' "
102             "for -E param '%s'\n", certname, p[0]);
103         fail("assertion failure");
104       }
105     }
106     if(p[2]) {
107       if(passphrase) {
108         if(strcmp(p[2], passphrase)) {
109           printf("expected passphrase '%s' but got '%s'"
110               "for -E param '%s'\n", p[2], passphrase, p[0]);
111           fail("assertion failure");
112         }
113       }
114       else {
115         printf("expected passphrase '%s' but got NULL "
116             "for -E param '%s'\n", p[2], p[0]);
117         fail("assertion failure");
118       }
119     }
120     else {
121       if(passphrase) {
122         printf("expected passphrase NULL but got '%s' "
123             "for -E param '%s'\n", passphrase, p[0]);
124         fail("assertion failure");
125       }
126     }
127     if(certname)
128       free(certname);
129     if(passphrase)
130       free(passphrase);
131   }
132 
133 UNITTEST_STOP
134