mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-07 15:17:03 +02:00
* Fix "t.Fatal from a non-test goroutine" errors in cache_test.go - t.Fatal(f) should not be called within a Go routine based on it's documentation and only from the main test's thread. - In 1.24 this seems to cause build failures * Address all "non-constant format string errors" from go vet - Within 1.24 these now cause test builds to fail …" from go vet
112 lines
3.8 KiB
Go
112 lines
3.8 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package server
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/go-test/deep"
|
|
)
|
|
|
|
var defaultCustomHeaders = map[string]string{
|
|
"Strict-Transport-Security": "max-age=1; domains",
|
|
"Content-Security-Policy": "default-src 'others'",
|
|
"X-Vault-Ignored": "ignored",
|
|
"X-Custom-Header": "Custom header value default",
|
|
}
|
|
|
|
var customHeaders307 = map[string]string{
|
|
"X-Custom-Header": "Custom header value 307",
|
|
}
|
|
|
|
var customHeader3xx = map[string]string{
|
|
"X-Vault-Ignored-3xx": "Ignored 3xx",
|
|
"X-Custom-Header": "Custom header value 3xx",
|
|
}
|
|
|
|
var customHeaders200 = map[string]string{
|
|
"Someheader-200": "200",
|
|
"X-Custom-Header": "Custom header value 200",
|
|
}
|
|
|
|
var customHeader2xx = map[string]string{
|
|
"X-Custom-Header": "Custom header value 2xx",
|
|
}
|
|
|
|
var customHeader400 = map[string]string{
|
|
"Someheader-400": "400",
|
|
}
|
|
|
|
var defaultCustomHeadersMultiListener = map[string]string{
|
|
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
|
|
"Content-Security-Policy": "default-src 'others'",
|
|
"X-Vault-Ignored": "ignored",
|
|
"X-Custom-Header": "Custom header value default",
|
|
}
|
|
|
|
var defaultSTS = map[string]string{
|
|
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
|
|
}
|
|
|
|
func TestCustomResponseHeadersConfigs(t *testing.T) {
|
|
expectedCustomResponseHeader := map[string]map[string]string{
|
|
"default": defaultCustomHeaders,
|
|
"307": customHeaders307,
|
|
"3xx": customHeader3xx,
|
|
"200": customHeaders200,
|
|
"2xx": customHeader2xx,
|
|
"400": customHeader400,
|
|
}
|
|
|
|
config, err := LoadConfigFile("./test-fixtures/config_custom_response_headers_1.hcl")
|
|
if err != nil {
|
|
t.Fatalf("Error encountered when loading config %+v", err)
|
|
}
|
|
if diff := deep.Equal(expectedCustomResponseHeader, config.Listeners[0].CustomResponseHeaders); diff != nil {
|
|
t.Fatalf("parsed custom headers do not match the expected ones, difference: %v", diff)
|
|
}
|
|
}
|
|
|
|
func TestCustomResponseHeadersConfigsMultipleListeners(t *testing.T) {
|
|
expectedCustomResponseHeader := map[string]map[string]string{
|
|
"default": defaultCustomHeadersMultiListener,
|
|
"307": customHeaders307,
|
|
"3xx": customHeader3xx,
|
|
"200": customHeaders200,
|
|
"2xx": customHeader2xx,
|
|
"400": customHeader400,
|
|
}
|
|
|
|
config, err := LoadConfigFile("./test-fixtures/config_custom_response_headers_multiple_listeners.hcl")
|
|
if err != nil {
|
|
t.Fatalf("Error encountered when loading config %+v", err)
|
|
}
|
|
if diff := deep.Equal(expectedCustomResponseHeader, config.Listeners[0].CustomResponseHeaders); diff != nil {
|
|
t.Fatalf("parsed custom headers do not match the expected ones, difference: %v", diff)
|
|
}
|
|
|
|
if diff := deep.Equal(expectedCustomResponseHeader, config.Listeners[1].CustomResponseHeaders); diff == nil {
|
|
t.Fatalf("parsed custom headers do not match the expected ones, difference: %v", diff)
|
|
}
|
|
if diff := deep.Equal(expectedCustomResponseHeader["default"], config.Listeners[1].CustomResponseHeaders["default"]); diff != nil {
|
|
t.Fatalf("parsed custom headers do not match the expected ones, difference: %v", diff)
|
|
}
|
|
|
|
if diff := deep.Equal(expectedCustomResponseHeader, config.Listeners[2].CustomResponseHeaders); diff == nil {
|
|
t.Fatalf("parsed custom headers do not match the expected ones, difference: %v", diff)
|
|
}
|
|
|
|
if diff := deep.Equal(defaultSTS, config.Listeners[2].CustomResponseHeaders["default"]); diff != nil {
|
|
t.Fatalf("parsed custom headers do not match the expected ones, difference: %v", diff)
|
|
}
|
|
|
|
if diff := deep.Equal(expectedCustomResponseHeader, config.Listeners[3].CustomResponseHeaders); diff == nil {
|
|
t.Fatalf("parsed custom headers do not match the expected ones, difference: %v", diff)
|
|
}
|
|
|
|
if diff := deep.Equal(defaultSTS, config.Listeners[3].CustomResponseHeaders["default"]); diff != nil {
|
|
t.Fatalf("parsed custom headers do not match the expected ones, difference: %v", diff)
|
|
}
|
|
}
|