138 lines
1.8 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. export state_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX)
  25. trap "rm -rf \"$state_tmpdir\"" EXIT
  26. ##
  27. ## Tests
  28. ##
  29. try "
  30. __vhost_cfg_normalize_protocol '
  31. protocol: both
  32. '"
  33. noerror
  34. is out ',http,https,'
  35. try "
  36. __vhost_cfg_normalize_protocol '
  37. protocol: http
  38. '"
  39. noerror
  40. is out ',http,'
  41. try "
  42. __vhost_cfg_normalize_protocol '
  43. protocol: https
  44. '"
  45. noerror
  46. is out ',https,'
  47. try "
  48. __vhost_cfg_normalize_protocol '
  49. protocol: ssl
  50. '"
  51. noerror
  52. is out ',https,'
  53. ##
  54. ## auto
  55. ##
  56. try "
  57. __vhost_cfg_normalize_protocol '
  58. protocol: auto
  59. '"
  60. noerror
  61. is out ',http,'
  62. try "
  63. __vhost_cfg_normalize_protocol '
  64. '"
  65. noerror
  66. is out ',http,'
  67. try "
  68. __vhost_cfg_normalize_protocol '
  69. ssl: false
  70. '"
  71. noerror
  72. is out ',http,'
  73. try "
  74. __vhost_cfg_normalize_protocol '
  75. ssl: null
  76. '"
  77. noerror
  78. is out ',http,'
  79. try "
  80. __vhost_cfg_normalize_protocol '
  81. ssl: true
  82. '"
  83. noerror
  84. is out ',http,https,'
  85. ## This case is special, we have values, but we don't know
  86. ## how if there are any plugin that can use it. For this
  87. ## function's responsibility, we are wanting 'ssl'.
  88. try "
  89. __vhost_cfg_normalize_protocol '
  90. ssl: xxx
  91. '"
  92. noerror
  93. is out ',http,https,'
  94. try "
  95. RELATIONS=(cert-provider foo a True)
  96. __vhost_cfg_normalize_protocol '
  97. '" "no ssl, but with cert-provider"
  98. noerror
  99. is out ',http,https,'
  100. try "
  101. RELATIONS=(cert-provider foo a True)
  102. __vhost_cfg_normalize_protocol '
  103. ssl: false
  104. '" "with explicit ssl disable, but with cert-provider"
  105. noerror
  106. is out ',http,'