113498266Sopenharmony_ci/***************************************************************************
213498266Sopenharmony_ci *                                  _   _ ____  _
313498266Sopenharmony_ci *  Project                     ___| | | |  _ \| |
413498266Sopenharmony_ci *                             / __| | | | |_) | |
513498266Sopenharmony_ci *                            | (__| |_| |  _ <| |___
613498266Sopenharmony_ci *                             \___|\___/|_| \_\_____|
713498266Sopenharmony_ci *
813498266Sopenharmony_ci * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
913498266Sopenharmony_ci *
1013498266Sopenharmony_ci * This software is licensed as described in the file COPYING, which
1113498266Sopenharmony_ci * you should have received as part of this distribution. The terms
1213498266Sopenharmony_ci * are also available at https://curl.se/docs/copyright.html.
1313498266Sopenharmony_ci *
1413498266Sopenharmony_ci * You may opt to use, copy, modify, merge, publish, distribute and/or sell
1513498266Sopenharmony_ci * copies of the Software, and permit persons to whom the Software is
1613498266Sopenharmony_ci * furnished to do so, under the terms of the COPYING file.
1713498266Sopenharmony_ci *
1813498266Sopenharmony_ci * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1913498266Sopenharmony_ci * KIND, either express or implied.
2013498266Sopenharmony_ci *
2113498266Sopenharmony_ci * SPDX-License-Identifier: curl
2213498266Sopenharmony_ci *
2313498266Sopenharmony_ci ***************************************************************************/
2413498266Sopenharmony_ci#include "curlcheck.h"
2513498266Sopenharmony_ci
2613498266Sopenharmony_ci#include "tool_getparam.h"
2713498266Sopenharmony_ci
2813498266Sopenharmony_ci#include <stdio.h>
2913498266Sopenharmony_ci#include <stdlib.h>
3013498266Sopenharmony_ci#include <string.h>
3113498266Sopenharmony_ci
3213498266Sopenharmony_ci#include "memdebug.h" /* LAST include file */
3313498266Sopenharmony_ci
3413498266Sopenharmony_cistatic CURLcode unit_setup(void)
3513498266Sopenharmony_ci{
3613498266Sopenharmony_ci  return CURLE_OK;
3713498266Sopenharmony_ci}
3813498266Sopenharmony_ci
3913498266Sopenharmony_cistatic void unit_stop(void)
4013498266Sopenharmony_ci{
4113498266Sopenharmony_ci
4213498266Sopenharmony_ci}
4313498266Sopenharmony_ci
4413498266Sopenharmony_ciUNITTEST_START
4513498266Sopenharmony_ci
4613498266Sopenharmony_ci  const char *values[] = {
4713498266Sopenharmony_ci    /* -E parameter */        /* exp. cert name */  /* exp. passphrase */
4813498266Sopenharmony_ci    "foo:bar:baz",            "foo",                "bar:baz",
4913498266Sopenharmony_ci    "foo\\:bar:baz",          "foo:bar",            "baz",
5013498266Sopenharmony_ci    "foo\\\\:bar:baz",        "foo\\",              "bar:baz",
5113498266Sopenharmony_ci    "foo:bar\\:baz",          "foo",                "bar\\:baz",
5213498266Sopenharmony_ci    "foo:bar\\\\:baz",        "foo",                "bar\\\\:baz",
5313498266Sopenharmony_ci    "foo\\bar\\baz",          "foo\\bar\\baz",      NULL,
5413498266Sopenharmony_ci    "foo\\\\bar\\\\baz",      "foo\\bar\\baz",      NULL,
5513498266Sopenharmony_ci    "foo\\",                  "foo\\",              NULL,
5613498266Sopenharmony_ci    "foo\\\\",                "foo\\",              NULL,
5713498266Sopenharmony_ci    "foo:bar\\",              "foo",                "bar\\",
5813498266Sopenharmony_ci    "foo:bar\\\\",            "foo",                "bar\\\\",
5913498266Sopenharmony_ci    "foo:bar:",               "foo",                "bar:",
6013498266Sopenharmony_ci    "foo\\::bar\\:",          "foo:",               "bar\\:",
6113498266Sopenharmony_ci    "pkcs11:foobar",          "pkcs11:foobar",      NULL,
6213498266Sopenharmony_ci    "PKCS11:foobar",          "PKCS11:foobar",      NULL,
6313498266Sopenharmony_ci    "PkCs11:foobar",          "PkCs11:foobar",      NULL,
6413498266Sopenharmony_ci#ifdef _WIN32
6513498266Sopenharmony_ci    "c:\\foo:bar:baz",        "c:\\foo",            "bar:baz",
6613498266Sopenharmony_ci    "c:\\foo\\:bar:baz",      "c:\\foo:bar",        "baz",
6713498266Sopenharmony_ci    "c:\\foo\\\\:bar:baz",    "c:\\foo\\",          "bar:baz",
6813498266Sopenharmony_ci    "c:\\foo:bar\\:baz",      "c:\\foo",            "bar\\:baz",
6913498266Sopenharmony_ci    "c:\\foo:bar\\\\:baz",    "c:\\foo",            "bar\\\\:baz",
7013498266Sopenharmony_ci    "c:\\foo\\bar\\baz",      "c:\\foo\\bar\\baz",  NULL,
7113498266Sopenharmony_ci    "c:\\foo\\\\bar\\\\baz",  "c:\\foo\\bar\\baz",  NULL,
7213498266Sopenharmony_ci    "c:\\foo\\",              "c:\\foo\\",          NULL,
7313498266Sopenharmony_ci    "c:\\foo\\\\",            "c:\\foo\\",          NULL,
7413498266Sopenharmony_ci    "c:\\foo:bar\\",          "c:\\foo",            "bar\\",
7513498266Sopenharmony_ci    "c:\\foo:bar\\\\",        "c:\\foo",            "bar\\\\",
7613498266Sopenharmony_ci    "c:\\foo:bar:",           "c:\\foo",            "bar:",
7713498266Sopenharmony_ci    "c:\\foo\\::bar\\:",      "c:\\foo:",           "bar\\:",
7813498266Sopenharmony_ci#endif
7913498266Sopenharmony_ci    NULL,                     NULL,                 NULL,
8013498266Sopenharmony_ci  };
8113498266Sopenharmony_ci  const char **p;
8213498266Sopenharmony_ci  char *certname, *passphrase;
8313498266Sopenharmony_ci  for(p = values; *p; p += 3) {
8413498266Sopenharmony_ci    parse_cert_parameter(p[0], &certname, &passphrase);
8513498266Sopenharmony_ci    if(p[1]) {
8613498266Sopenharmony_ci      if(certname) {
8713498266Sopenharmony_ci        if(strcmp(p[1], certname)) {
8813498266Sopenharmony_ci          printf("expected certname '%s' but got '%s' "
8913498266Sopenharmony_ci              "for -E param '%s'\n", p[1], certname, p[0]);
9013498266Sopenharmony_ci          fail("assertion failure");
9113498266Sopenharmony_ci        }
9213498266Sopenharmony_ci      }
9313498266Sopenharmony_ci      else {
9413498266Sopenharmony_ci        printf("expected certname '%s' but got NULL "
9513498266Sopenharmony_ci            "for -E param '%s'\n", p[1], p[0]);
9613498266Sopenharmony_ci        fail("assertion failure");
9713498266Sopenharmony_ci      }
9813498266Sopenharmony_ci    }
9913498266Sopenharmony_ci    else {
10013498266Sopenharmony_ci      if(certname) {
10113498266Sopenharmony_ci        printf("expected certname NULL but got '%s' "
10213498266Sopenharmony_ci            "for -E param '%s'\n", certname, p[0]);
10313498266Sopenharmony_ci        fail("assertion failure");
10413498266Sopenharmony_ci      }
10513498266Sopenharmony_ci    }
10613498266Sopenharmony_ci    if(p[2]) {
10713498266Sopenharmony_ci      if(passphrase) {
10813498266Sopenharmony_ci        if(strcmp(p[2], passphrase)) {
10913498266Sopenharmony_ci          printf("expected passphrase '%s' but got '%s'"
11013498266Sopenharmony_ci              "for -E param '%s'\n", p[2], passphrase, p[0]);
11113498266Sopenharmony_ci          fail("assertion failure");
11213498266Sopenharmony_ci        }
11313498266Sopenharmony_ci      }
11413498266Sopenharmony_ci      else {
11513498266Sopenharmony_ci        printf("expected passphrase '%s' but got NULL "
11613498266Sopenharmony_ci            "for -E param '%s'\n", p[2], p[0]);
11713498266Sopenharmony_ci        fail("assertion failure");
11813498266Sopenharmony_ci      }
11913498266Sopenharmony_ci    }
12013498266Sopenharmony_ci    else {
12113498266Sopenharmony_ci      if(passphrase) {
12213498266Sopenharmony_ci        printf("expected passphrase NULL but got '%s' "
12313498266Sopenharmony_ci            "for -E param '%s'\n", passphrase, p[0]);
12413498266Sopenharmony_ci        fail("assertion failure");
12513498266Sopenharmony_ci      }
12613498266Sopenharmony_ci    }
12713498266Sopenharmony_ci    if(certname)
12813498266Sopenharmony_ci      free(certname);
12913498266Sopenharmony_ci    if(passphrase)
13013498266Sopenharmony_ci      free(passphrase);
13113498266Sopenharmony_ci  }
13213498266Sopenharmony_ci
13313498266Sopenharmony_ciUNITTEST_STOP
134