2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2017-02-24 19:23:15 +00:00
|
|
|
package http
|
2016-02-02 23:11:05 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2017-02-24 19:23:15 +00:00
|
|
|
"github.com/hashicorp/vault/api"
|
2016-02-02 23:11:05 +00:00
|
|
|
"github.com/hashicorp/vault/vault"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSysMountConfig(t *testing.T) {
|
|
|
|
core, _, token := vault.TestCoreUnsealed(t)
|
2017-02-24 19:23:15 +00:00
|
|
|
ln, addr := TestServer(t, core)
|
2016-02-02 23:11:05 +00:00
|
|
|
defer ln.Close()
|
|
|
|
|
2017-02-24 19:23:15 +00:00
|
|
|
config := api.DefaultConfig()
|
2016-02-02 23:11:05 +00:00
|
|
|
config.Address = addr
|
|
|
|
|
2017-02-24 19:23:15 +00:00
|
|
|
client, err := api.NewClient(config)
|
2016-02-02 23:11:05 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
client.SetToken(token)
|
|
|
|
|
|
|
|
// Set up a test mount
|
|
|
|
path, err := testMount(client)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-04-07 19:12:58 +00:00
|
|
|
defer client.Sys().Unmount(path)
|
2016-02-02 23:11:05 +00:00
|
|
|
|
|
|
|
// Get config info for this mount
|
2022-04-07 19:12:58 +00:00
|
|
|
mountConfig, err := client.Sys().MountConfig(path)
|
2016-02-02 23:11:05 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-09-28 22:32:49 +00:00
|
|
|
expectedDefaultTTL := 2764800
|
2016-02-02 23:11:05 +00:00
|
|
|
if mountConfig.DefaultLeaseTTL != expectedDefaultTTL {
|
|
|
|
t.Fatalf("Expected default lease TTL: %d, got %d",
|
|
|
|
expectedDefaultTTL, mountConfig.DefaultLeaseTTL)
|
|
|
|
}
|
|
|
|
|
2016-09-28 22:32:49 +00:00
|
|
|
expectedMaxTTL := 2764800
|
2016-02-02 23:11:05 +00:00
|
|
|
if mountConfig.MaxLeaseTTL != expectedMaxTTL {
|
|
|
|
t.Fatalf("Expected default lease TTL: %d, got %d",
|
|
|
|
expectedMaxTTL, mountConfig.MaxLeaseTTL)
|
|
|
|
}
|
2017-03-08 14:20:09 +00:00
|
|
|
|
2022-02-18 14:35:53 +00:00
|
|
|
if mountConfig.ForceNoCache {
|
|
|
|
t.Fatal("did not expect force cache")
|
2017-03-08 14:20:09 +00:00
|
|
|
}
|
2016-02-02 23:11:05 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 13:02:29 +00:00
|
|
|
// testMount sets up a test mount of a kv backend w/ a random path; caller
|
2016-02-02 23:11:05 +00:00
|
|
|
// is responsible for unmounting
|
2017-02-24 19:23:15 +00:00
|
|
|
func testMount(client *api.Client) (string, error) {
|
2016-02-02 23:11:05 +00:00
|
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
|
|
randInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
|
|
|
|
path := fmt.Sprintf("testmount-%d", randInt)
|
2022-04-07 19:12:58 +00:00
|
|
|
err := client.Sys().Mount(path, &api.MountInput{Type: "kv"})
|
2016-02-02 23:11:05 +00:00
|
|
|
return path, err
|
|
|
|
}
|