|
| 1 | +#!/usr/bin/env bats |
| 2 | +# |
| 3 | +# Copyright 2025 HAProxy Technologies |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http:#www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +load '../../libs/dataplaneapi' |
| 19 | +load '../../libs/debug' |
| 20 | +load '../../libs/get_json_path' |
| 21 | +load '../../libs/haproxy_config_setup' |
| 22 | +load '../../libs/haproxy_version' |
| 23 | +load '../../libs/resource_client' |
| 24 | +load '../../libs/version' |
| 25 | + |
| 26 | +_ACME_PATH="/services/haproxy/configuration/acme" |
| 27 | +_ACME_NAME="letsencrypt" |
| 28 | + |
| 29 | +@test "acme: all tests (>=3.2)" { |
| 30 | + haproxy_version_ge "3.2" || skip |
| 31 | + |
| 32 | + resource_post "$_ACME_PATH" "data/new_acme.json" "force_reload=true" |
| 33 | + assert_equal "$SC" "201" |
| 34 | + |
| 35 | + resource_get "$_ACME_PATH/$_ACME_NAME" |
| 36 | + assert_equal "$SC" "200" |
| 37 | + assert_equal "$(get_json_path "$BODY" .name)" "$_ACME_NAME" |
| 38 | + assert_equal "$(get_json_path "$BODY" .contact)" "[email protected]" |
| 39 | + assert_equal "$(get_json_path "$BODY" .directory)" "https://acme-staging-v02.api.letsencrypt.org/directory" |
| 40 | + |
| 41 | + resource_put "$_ACME_PATH/$_ACME_NAME" "data/edit_acme.json" "force_reload=true" |
| 42 | + assert_equal "$SC" "200" |
| 43 | + resource_get "$_ACME_PATH/$_ACME_NAME" |
| 44 | + assert_equal "$(get_json_path "$BODY" .directory)" "https://acme-v02.api.letsencrypt.org/directory" |
| 45 | + assert_equal "$(get_json_path "$BODY" .keytype)" "RSA" |
| 46 | + assert_equal "$(get_json_path "$BODY" .bits)" 4096 |
| 47 | + |
| 48 | + resource_get "$_ACME_PATH" |
| 49 | + assert_equal "$SC" "200" |
| 50 | + assert_equal "$(get_json_path "$BODY" '.|length')" 1 |
| 51 | + assert_equal "$(get_json_path "$BODY" .[0].name)" "$_ACME_NAME" |
| 52 | + |
| 53 | + # back to the original |
| 54 | + resource_put "$_ACME_PATH/$_ACME_NAME" "data/new_acme.json" "force_reload=true" |
| 55 | + assert_equal "$SC" "200" |
| 56 | + resource_get "$_ACME_PATH/$_ACME_NAME" |
| 57 | + assert_equal "$(get_json_path "$BODY" .directory)" "https://acme-staging-v02.api.letsencrypt.org/directory" |
| 58 | + assert_equal "$(get_json_path "$BODY" .keytype)" null |
| 59 | + assert_equal "$(get_json_path "$BODY" .bits)" null |
| 60 | + |
| 61 | + resource_delete "$_ACME_PATH/$_ACME_NAME" "force_reload=true" |
| 62 | + assert_equal "$SC" "204" |
| 63 | + resource_get "$_ACME_PATH/$_ACME_NAME" |
| 64 | + assert_equal "$SC" "404" |
| 65 | +} |
0 commit comments