You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
2.2 KiB

  1. #!/bin/bash
  2. exname=$(basename $0)
  3. prefix_cmd="
  4. . /etc/shlib
  5. include common
  6. include parse
  7. . ../lib/common
  8. "
  9. # mock
  10. relation-get() {
  11. local key="$1"
  12. echo "$CFG" | shyaml get-value "$key" 2>/dev/null
  13. }
  14. export -f relation-get
  15. cfg-get-value() {
  16. local key="$1"
  17. shyaml get-value "$key" 2>/dev/null
  18. }
  19. export -f cfg-get-value
  20. get_service_relations() {
  21. printf "%s\0" "${RELATIONS[@]}"
  22. }
  23. export -f get_service_relations
  24. merge_yaml_str() {
  25. printf "<merge_yaml_str("
  26. printf "'%s', " "$@"
  27. printf ")>"
  28. }
  29. export -f merge_yaml_str
  30. export state_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX)
  31. trap "rm -rf \"$state_tmpdir\"" EXIT
  32. ##
  33. ## Tests
  34. ##
  35. try "
  36. ssl_get_plugin_fun '
  37. domain: www.example.com
  38. '"
  39. is errlvl 1
  40. is err 'Error: No ssl options available.
  41. '
  42. is out ''
  43. try "
  44. set -o pipefail
  45. ssl_get_plugin_fun '
  46. domain: www.example.com
  47. ssl: true
  48. ' | tr '\0' ':'
  49. "
  50. is errlvl 0
  51. is err ''
  52. is out reg '^ssl_fallback:'
  53. try "
  54. ssl_get_plugin_fun '
  55. domain: www.example.com
  56. ssl:
  57. - a
  58. - b
  59. '
  60. "
  61. is errlvl 1
  62. is err part 'please provide a string or a struct'
  63. is out ''
  64. try "
  65. ssl_get_plugin_fun '
  66. domain: www.example.com
  67. ssl:
  68. - a
  69. - b
  70. '
  71. "
  72. is errlvl 1
  73. is err part 'please provide a string or a struct'
  74. is out ''
  75. try "
  76. ssl_get_plugin_fun '
  77. domain: www.example.com
  78. ssl: xxx
  79. '
  80. "
  81. is errlvl 1
  82. is err part 'no corresponding services declared in cert-provider'
  83. is out ''
  84. try "
  85. RELATIONS=(cert-provider xxx mycfg True)
  86. ssl_get_plugin_fun '
  87. domain: www.example.com
  88. ssl: xxx
  89. ' | tr '\0' ':'
  90. "
  91. noerror
  92. is out "ssl_plugin_cert-provider:xxx:<merge_yaml_str('mycfg', '', )>:"
  93. try "
  94. RELATIONS=(
  95. cert-provider xxx mycfgxxx True
  96. cert-provider yyy mycfgyyy True
  97. )
  98. ssl_get_plugin_fun '
  99. domain: www.example.com
  100. ssl: yyy
  101. ' | tr '\0' ':'
  102. "
  103. noerror
  104. is out "ssl_plugin_cert-provider:yyy:<merge_yaml_str('mycfgyyy', '', )>:"
  105. try "
  106. RELATIONS=(
  107. cert-provider xxx mycfgxxx True
  108. cert-provider yyy mycfgyyy True
  109. )
  110. ssl_get_plugin_fun '
  111. domain: www.example.com
  112. ssl:
  113. cert: a
  114. ' | tr '\0' '|'
  115. "
  116. noerror
  117. is out "ssl_fallback||cert: a|"
  118. try "
  119. RELATIONS=(
  120. cert-provider xxx mycfgxxx True
  121. cert-provider yyy mycfgyyy True
  122. )
  123. ssl_get_plugin_fun '
  124. domain: www.example.com
  125. ssl:
  126. popo: a
  127. '
  128. "
  129. is errlvl 1
  130. is err part 'no corresponding services declared in cert-provider'
  131. is out ''