|
| 1 | +#!/usr/bin/env bats |
| 2 | +# |
| 3 | +# Copyright 2024 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 | +load 'utils/_helpers' |
| 27 | + |
| 28 | +# We are using "haproxy_config_setup" here because we need the files |
| 29 | +# from data/container. HAProxy will actually load those PEM files when |
| 30 | +# checking if the configuration is valid. |
| 31 | + |
| 32 | +@test "crt_store: all tests (>=3.0)" { |
| 33 | + haproxy_version_ge "3.0" || skip |
| 34 | + |
| 35 | + debug "crt_store: create a new section" |
| 36 | + resource_post "$_CRT_STORE_PATH" "data/new_store.json" "force_reload=true" |
| 37 | + assert_equal "$SC" "201" |
| 38 | + |
| 39 | + debug "crt_store: get a section" |
| 40 | + resource_get "$_CRT_STORE_PATH/$_STORE_NAME" |
| 41 | + assert_equal "$SC" "200" |
| 42 | + assert_equal "$_STORE_NAME" "$(get_json_path "$BODY" .name)" |
| 43 | + assert_equal "/secure/certs" "$(get_json_path "$BODY" .crt_base)" |
| 44 | + assert_equal "/secure/keys" "$(get_json_path "$BODY" .key_base)" |
| 45 | + |
| 46 | + debug "crt_store: edit a section" |
| 47 | + resource_put "$_CRT_STORE_PATH/$_STORE_NAME" "data/edit_store.json" "force_reload=true" |
| 48 | + assert_equal "$SC" "200" |
| 49 | + resource_get "$_CRT_STORE_PATH/$_STORE_NAME" |
| 50 | + assert_equal "/sec" "$(get_json_path "$BODY" .key_base)" |
| 51 | + |
| 52 | + debug "crt_store: get a list of sections" |
| 53 | + resource_get "$_CRT_STORE_PATH" |
| 54 | + assert_equal "$SC" "200" |
| 55 | + assert_equal "$_STORE_NAME" "$(get_json_path "$BODY" .[0].name)" |
| 56 | + |
| 57 | + debug "crt_store: add load entries" |
| 58 | + resource_post "$_CRT_LOAD_PATH" "data/post_entry1.json" "crt_store=$_STORE_NAME" |
| 59 | + assert_equal "$SC" "202" |
| 60 | + resource_post "$_CRT_LOAD_PATH" "data/post_entry2.json" "crt_store=$_STORE_NAME" |
| 61 | + assert_equal "$SC" "202" |
| 62 | + |
| 63 | + debug "crt_store: get a load entry" |
| 64 | + resource_get "$_CRT_LOAD_PATH/c1.pem" "crt_store=$_STORE_NAME" |
| 65 | + assert_equal "$SC" "200" |
| 66 | + assert_equal "c1.pem" "$(get_json_path "$BODY" .certificate)" |
| 67 | + assert_equal "k1.pem" "$(get_json_path "$BODY" .key)" |
| 68 | + assert_equal "disabled" "$(get_json_path "$BODY" .ocsp_update)" |
| 69 | + |
| 70 | + debug "crt_store: get all load entries" |
| 71 | + resource_get "$_CRT_LOAD_PATH" "crt_store=$_STORE_NAME" |
| 72 | + assert_equal "$SC" "200" |
| 73 | + assert_equal "2" "$(get_json_path "$BODY" '.|length')" |
| 74 | + assert_equal "c1.pem" "$(get_json_path "$BODY" .[0].certificate)" |
| 75 | + assert_equal "c2.pem" "$(get_json_path "$BODY" .[1].certificate)" |
| 76 | + |
| 77 | + debug "crt_store: modify a load entry" |
| 78 | + resource_put "$_CRT_LOAD_PATH/c2.pem" "data/put_entry.json" \ |
| 79 | + "crt_store=$_STORE_NAME" "force_reload=true" |
| 80 | + assert_equal "$SC" "202" |
| 81 | + resource_get "$_CRT_LOAD_PATH/c2.pem" "crt_store=$_STORE_NAME" |
| 82 | + assert_equal "c2.pem" "$(get_json_path "$BODY" .certificate)" |
| 83 | + assert_equal "disabled" "$(get_json_path "$BODY" .ocsp_update)" |
| 84 | + assert_equal "example.com" "$(get_json_path "$BODY" .alias)" |
| 85 | + |
| 86 | + debug "crt_store: delete a load entry" |
| 87 | + resource_delete "$_CRT_LOAD_PATH/c1.pem" "crt_store=$_STORE_NAME" "force_reload=true" |
| 88 | + assert_equal "$SC" "202" |
| 89 | + resource_delete "$_CRT_LOAD_PATH/c2.pem" "crt_store=$_STORE_NAME" "force_reload=true" |
| 90 | + assert_equal "$SC" "202" |
| 91 | + resource_get "$_CRT_LOAD_PATH/c2.pem" "crt_store=$_STORE_NAME" |
| 92 | + assert_equal "$SC" "404" |
| 93 | + |
| 94 | + debug "crt_store: delete a section" |
| 95 | + resource_delete "$_CRT_STORE_PATH/$_STORE_NAME" "force_reload=true" |
| 96 | + assert_equal "$SC" "204" |
| 97 | + resource_get "$_CRT_STORE_PATH/$_STORE_NAME" |
| 98 | + assert_equal "$SC" "404" |
| 99 | +} |
0 commit comments