unit1394.c 4.6 KB

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