mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-06 14:47:01 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package http
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hashicorp/vault/api"
|
|
"github.com/hashicorp/vault/vault"
|
|
)
|
|
|
|
func TestSysMountConfig(t *testing.T) {
|
|
core, _, token := vault.TestCoreUnsealed(t)
|
|
ln, addr := TestServer(t, core)
|
|
defer ln.Close()
|
|
|
|
config := api.DefaultConfig()
|
|
config.Address = addr
|
|
|
|
client, err := api.NewClient(config)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
client.SetToken(token)
|
|
|
|
// Set up a test mount
|
|
path, err := testMount(client)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer client.Sys().Unmount(path)
|
|
|
|
// Get config info for this mount
|
|
mountConfig, err := client.Sys().MountConfig(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
expectedDefaultTTL := 2764800
|
|
if mountConfig.DefaultLeaseTTL != expectedDefaultTTL {
|
|
t.Fatalf("Expected default lease TTL: %d, got %d",
|
|
expectedDefaultTTL, mountConfig.DefaultLeaseTTL)
|
|
}
|
|
|
|
expectedMaxTTL := 2764800
|
|
if mountConfig.MaxLeaseTTL != expectedMaxTTL {
|
|
t.Fatalf("Expected default lease TTL: %d, got %d",
|
|
expectedMaxTTL, mountConfig.MaxLeaseTTL)
|
|
}
|
|
|
|
if mountConfig.ForceNoCache {
|
|
t.Fatal("did not expect force cache")
|
|
}
|
|
}
|
|
|
|
// testMount sets up a test mount of a kv backend w/ a random path; caller
|
|
// is responsible for unmounting
|
|
func testMount(client *api.Client) (string, error) {
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
randInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
|
|
path := fmt.Sprintf("testmount-%d", randInt)
|
|
err := client.Sys().Mount(path, &api.MountInput{Type: "kv"})
|
|
return path, err
|
|
}
|