fork 0k-charms
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.

162 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 ''
  41. is out ''
  42. try "
  43. set -o pipefail
  44. ssl_get_plugin_fun '
  45. domain: www.example.com
  46. ssl: true
  47. ' | tr '\0' ':'
  48. "
  49. is errlvl 0
  50. is err ''
  51. is out reg '^ssl_fallback:'
  52. try "
  53. ssl_get_plugin_fun '
  54. domain: www.example.com
  55. ssl:
  56. - a
  57. - b
  58. '
  59. "
  60. is errlvl 1
  61. is err part 'please provide a string or a struct'
  62. is out ''
  63. try "
  64. ssl_get_plugin_fun '
  65. domain: www.example.com
  66. ssl:
  67. - a
  68. - b
  69. '
  70. "
  71. is errlvl 1
  72. is err part 'please provide a string or a struct'
  73. is out ''
  74. try "
  75. ssl_get_plugin_fun '
  76. domain: www.example.com
  77. ssl: xxx
  78. '
  79. "
  80. is errlvl 1
  81. is err part 'no corresponding services declared in cert-provider'
  82. is out ''
  83. try "
  84. RELATIONS=(cert-provider xxx mycfg True)
  85. ssl_get_plugin_fun '
  86. domain: www.example.com
  87. ssl: xxx
  88. ' | tr '\0' ':'
  89. "
  90. noerror
  91. is out "ssl_plugin_cert-provider:xxx:<merge_yaml_str('mycfg', '', )>:"
  92. try "
  93. RELATIONS=(
  94. cert-provider xxx mycfgxxx True
  95. cert-provider yyy mycfgyyy True
  96. )
  97. ssl_get_plugin_fun '
  98. domain: www.example.com
  99. ssl: yyy
  100. ' | tr '\0' ':'
  101. "
  102. noerror
  103. is out "ssl_plugin_cert-provider:yyy:<merge_yaml_str('mycfgyyy', '', )>:"
  104. try "
  105. RELATIONS=(
  106. cert-provider xxx mycfgxxx True
  107. cert-provider yyy mycfgyyy True
  108. )
  109. ssl_get_plugin_fun '
  110. domain: www.example.com
  111. ssl:
  112. cert: a
  113. ' | tr '\0' '|'
  114. "
  115. noerror
  116. is out "ssl_fallback||cert: a|"
  117. try "
  118. RELATIONS=(
  119. cert-provider xxx mycfgxxx True
  120. cert-provider yyy mycfgyyy True
  121. )
  122. ssl_get_plugin_fun '
  123. domain: www.example.com
  124. ssl:
  125. popo: a
  126. '
  127. "
  128. is errlvl 1
  129. is err part 'no corresponding services declared in cert-provider'
  130. is out ''