Stop passing in loggers to clusters explicitly (#21999)

This commit is contained in:
Nick Cabatoff
2023-07-24 10:51:02 -04:00
committed by GitHub
parent dc06bb9496
commit c14c2cf6bd
32 changed files with 33 additions and 199 deletions

View File

@@ -8,10 +8,8 @@ import (
"testing"
"time"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/api"
vaulthttp "github.com/hashicorp/vault/http"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault"
)
@@ -104,9 +102,7 @@ func TestBackend_E2E_Initialize(t *testing.T) {
func setupAwsTestCluster(t *testing.T, _ context.Context) *vault.TestCluster {
// create a cluster with the aws auth backend built-in
logger := logging.NewVaultLogger(hclog.Trace)
coreConfig := &vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"aws": Factory,
},

View File

@@ -27,25 +27,21 @@ import (
"testing"
"time"
"github.com/hashicorp/go-sockaddr"
"github.com/go-test/deep"
"golang.org/x/net/http2"
cleanhttp "github.com/hashicorp/go-cleanhttp"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/api"
vaulthttp "github.com/hashicorp/vault/http"
rootcerts "github.com/hashicorp/go-rootcerts"
"github.com/hashicorp/go-sockaddr"
"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/builtin/logical/pki"
logicaltest "github.com/hashicorp/vault/helper/testhelpers/logical"
vaulthttp "github.com/hashicorp/vault/http"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/helper/certutil"
"github.com/hashicorp/vault/sdk/helper/tokenutil"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault"
"github.com/mitchellh/mapstructure"
"golang.org/x/net/http2"
)
const (
@@ -253,9 +249,6 @@ func connectionState(serverCAPath, serverCertPath, serverKeyPath, clientCertPath
func TestBackend_PermittedDNSDomainsIntermediateCA(t *testing.T) {
// Enable PKI secret engine and Cert auth method
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: log.NewNullLogger(),
CredentialBackends: map[string]logical.Factory{
"cert": Factory,
},
@@ -479,9 +472,6 @@ func TestBackend_PermittedDNSDomainsIntermediateCA(t *testing.T) {
func TestBackend_MetadataBasedACLPolicy(t *testing.T) {
// Start cluster with cert auth method enabled
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: log.NewNullLogger(),
CredentialBackends: map[string]logical.Factory{
"cert": Factory,
},

View File

@@ -15,7 +15,6 @@ import (
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/providers"
"github.com/aliyun/alibaba-cloud-sdk-go/services/sts"
hclog "github.com/hashicorp/go-hclog"
uuid "github.com/hashicorp/go-uuid"
vaultalicloud "github.com/hashicorp/vault-plugin-auth-alicloud"
"github.com/hashicorp/vault/api"
@@ -25,7 +24,6 @@ import (
"github.com/hashicorp/vault/command/agentproxyshared/sink/file"
"github.com/hashicorp/vault/helper/testhelpers"
vaulthttp "github.com/hashicorp/vault/http"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault"
)
@@ -49,9 +47,7 @@ func TestAliCloudEndToEnd(t *testing.T) {
}
testhelpers.SkipUnlessEnvVarsSet(t, credNames)
logger := logging.NewVaultLogger(hclog.Trace)
coreConfig := &vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"alicloud": vaultalicloud.Factory,
},
@@ -91,7 +87,7 @@ func TestAliCloudEndToEnd(t *testing.T) {
}()
am, err := agentalicloud.NewAliCloudAuthMethod(&auth.AuthConfig{
Logger: logger.Named("auth.alicloud"),
Logger: cluster.Logger.Named("auth.alicloud"),
MountPath: "auth/alicloud",
Config: map[string]interface{}{
"role": "test",
@@ -104,7 +100,7 @@ func TestAliCloudEndToEnd(t *testing.T) {
}
ahConfig := &auth.AuthHandlerConfig{
Logger: logger.Named("auth.handler"),
Logger: cluster.Logger.Named("auth.handler"),
Client: client,
}
@@ -133,7 +129,7 @@ func TestAliCloudEndToEnd(t *testing.T) {
t.Logf("output: %s", tokenSinkFileName)
config := &sink.SinkConfig{
Logger: logger.Named("sink.file"),
Logger: cluster.Logger.Named("sink.file"),
Config: map[string]interface{}{
"path": tokenSinkFileName,
},
@@ -147,7 +143,7 @@ func TestAliCloudEndToEnd(t *testing.T) {
config.Sink = fs
ss := sink.NewSinkServer(&sink.SinkServerConfig{
Logger: logger.Named("sink.server"),
Logger: cluster.Logger.Named("sink.server"),
Client: client,
})
go func() {

View File

@@ -72,7 +72,6 @@ func testAppRoleEndToEnd(t *testing.T, removeSecretIDFile bool, bindSecretID boo
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: log.NewNullLogger(),
CredentialBackends: map[string]logical.Factory{
"approle": credAppRole.Factory,
},
@@ -411,9 +410,6 @@ func TestAppRoleLongRoleName(t *testing.T) {
approleName := strings.Repeat("a", 5000)
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: log.NewNullLogger(),
CredentialBackends: map[string]logical.Factory{
"approle": credAppRole.Factory,
},
@@ -477,9 +473,6 @@ func testAppRoleWithWrapping(t *testing.T, bindSecretID bool, secretIDLess bool,
var err error
logger := logging.NewVaultLogger(log.Trace)
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: log.NewNullLogger(),
CredentialBackends: map[string]logical.Factory{
"approle": credAppRole.Factory,
},

View File

@@ -26,7 +26,6 @@ import (
func TestTokenPreload_UsingAutoAuth(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
coreConfig := &vault.CoreConfig{
Logger: logger,
LogicalBackends: map[string]logical.Factory{
"kv": vault.LeasedPassthroughBackendFactory,
},

View File

@@ -61,7 +61,6 @@ func TestAWSEndToEnd(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
coreConfig := &vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"aws": vaultaws.Factory,
},

View File

@@ -45,9 +45,6 @@ func TestCache_UsingAutoAuthToken(t *testing.T) {
var err error
logger := logging.NewVaultLogger(log.Trace)
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: log.NewNullLogger(),
LogicalBackends: map[string]logical.Factory{
"kv": vault.LeasedPassthroughBackendFactory,
},

View File

@@ -66,7 +66,6 @@ func TestCertEndToEnd(t *testing.T) {
func testCertEndToEnd(t *testing.T, withCertRoleName, ahWrapping bool) {
logger := logging.NewVaultLogger(hclog.Trace)
coreConfig := &vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"cert": vaultcert.Factory,
},
@@ -306,7 +305,6 @@ func testCertEndToEnd(t *testing.T, withCertRoleName, ahWrapping bool) {
func TestCertEndToEnd_CertsInConfig(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
coreConfig := &vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"cert": vaultcert.Factory,
},

View File

@@ -29,9 +29,6 @@ func TestCFEndToEnd(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: hclog.NewNullLogger(),
CredentialBackends: map[string]logical.Factory{
"cf": credCF.Factory,
},

View File

@@ -55,7 +55,6 @@ func TestJWTEndToEnd(t *testing.T) {
func testJWTEndToEnd(t *testing.T, ahWrapping, useSymlink, removeJWTAfterReading bool) {
logger := logging.NewVaultLogger(hclog.Trace)
coreConfig := &vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"jwt": vaultjwt.Factory,
},

View File

@@ -59,7 +59,6 @@ func TestOCIEndToEnd(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
coreConfig := &vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"oci": vaultoci.Factory,
},

View File

@@ -21,15 +21,8 @@ import (
)
func TestTokenFileEndToEnd(t *testing.T) {
var err error
logger := logging.NewVaultLogger(log.Trace)
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: log.NewNullLogger(),
}
cluster := vault.NewTestCluster(t, coreConfig, &vault.TestClusterOptions{
cluster := vault.NewTestCluster(t, nil, &vault.TestClusterOptions{
HandlerFunc: vaulthttp.Handler,
})

View File

@@ -107,7 +107,6 @@ func TestAgent_ExitAfterAuth(t *testing.T) {
func testAgentExitAfterAuth(t *testing.T, viaFlag bool) {
logger := logging.NewVaultLogger(hclog.Trace)
coreConfig := &vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"jwt": vaultjwt.Factory,
},
@@ -311,7 +310,6 @@ func TestAgent_RequireRequestHeader(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
cluster := vault.NewTestCluster(t,
&vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"approle": credAppRole.Factory,
},
@@ -528,7 +526,6 @@ func TestAgent_Template_UserAgent(t *testing.T) {
var h userAgentHandler
cluster := vault.NewTestCluster(t,
&vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"approle": credAppRole.Factory,
},
@@ -776,7 +773,6 @@ func TestAgent_Template_Basic(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
cluster := vault.NewTestCluster(t,
&vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"approle": credAppRole.Factory,
},
@@ -1079,7 +1075,6 @@ func TestAgent_Template_ExitCounter(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
cluster := vault.NewTestCluster(t,
&vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"approle": credAppRole.Factory,
},
@@ -1436,7 +1431,6 @@ func TestAgent_Template_Retry(t *testing.T) {
var h handler
cluster := vault.NewTestCluster(t,
&vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"approle": credAppRole.Factory,
},
@@ -1724,7 +1718,6 @@ func TestAgent_AutoAuth_UserAgent(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
var h userAgentHandler
cluster := vault.NewTestCluster(t, &vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"approle": credAppRole.Factory,
},
@@ -2168,7 +2161,6 @@ func TestAgent_ApiProxy_Retry(t *testing.T) {
var h handler
cluster := vault.NewTestCluster(t,
&vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"approle": credAppRole.Factory,
},
@@ -2320,7 +2312,6 @@ func TestAgent_TemplateConfig_ExitOnRetryFailure(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
cluster := vault.NewTestCluster(t,
&vault.CoreConfig{
// Logger: logger,
CredentialBackends: map[string]logical.Factory{
"approle": credAppRole.Factory,
},
@@ -2623,11 +2614,7 @@ func TestAgent_Metrics(t *testing.T) {
//----------------------------------------------------
// Start a vault server
logger := logging.NewVaultLogger(hclog.Trace)
cluster := vault.NewTestCluster(t,
&vault.CoreConfig{
Logger: logger,
},
cluster := vault.NewTestCluster(t, nil,
&vault.TestClusterOptions{
HandlerFunc: vaulthttp.Handler,
})
@@ -2650,7 +2637,7 @@ listener "tcp" {
defer os.Remove(configPath)
// Start the agent
ui, cmd := testAgentCommand(t, logger)
ui, cmd := testAgentCommand(t, logging.NewVaultLogger(hclog.Trace))
cmd.client = serverClient
cmd.startedCh = make(chan struct{})

View File

@@ -58,9 +58,7 @@ func (u *userpassTestMethod) Shutdown() {
}
func TestAuthHandler(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
coreConfig := &vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"userpass": userpass.Factory,
},
@@ -77,7 +75,7 @@ func TestAuthHandler(t *testing.T) {
ctx, cancelFunc := context.WithCancel(context.Background())
ah := NewAuthHandler(&AuthHandlerConfig{
Logger: logger.Named("auth.handler"),
Logger: logging.NewVaultLogger(hclog.Trace).Named("auth.handler"),
Client: client,
})

View File

@@ -12,18 +12,16 @@ import (
"testing"
"time"
"github.com/hashicorp/vault/helper/useragent"
"github.com/hashicorp/vault/builtin/credential/userpass"
vaulthttp "github.com/hashicorp/vault/http"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/builtin/credential/userpass"
"github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/helper/useragent"
vaulthttp "github.com/hashicorp/vault/http"
"github.com/hashicorp/vault/sdk/helper/jsonutil"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault"
)
const policyAdmin = `
@@ -188,15 +186,9 @@ func setupClusterAndAgentCommon(ctx context.Context, t *testing.T, coreConfig *v
ctx = context.Background()
}
// Handle sane defaults
if coreConfig == nil {
coreConfig = &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: logging.NewVaultLogger(hclog.Trace),
}
coreConfig = &vault.CoreConfig{}
}
// Always set up the userpass backend since we use that to generate an admin
// token for the client that will make proxied requests to through the agent.
if coreConfig.CredentialBackends == nil || coreConfig.CredentialBackends["userpass"] == nil {
@@ -257,7 +249,7 @@ func setupClusterAndAgentCommon(ctx context.Context, t *testing.T, coreConfig *v
t.Fatal(err)
}
apiProxyLogger := logging.NewVaultLogger(hclog.Trace).Named("apiproxy")
apiProxyLogger := cluster.Logger.Named("apiproxy")
// Create the API proxier
apiProxy, err := NewAPIProxy(&APIProxyConfig{
@@ -275,7 +267,7 @@ func setupClusterAndAgentCommon(ctx context.Context, t *testing.T, coreConfig *v
var leaseCache *LeaseCache
if useCache {
cacheLogger := logging.NewVaultLogger(hclog.Trace).Named("cache")
cacheLogger := cluster.Logger.Named("cache")
// Create the lease cache proxier and set its underlying proxier to
// the API proxier.

View File

@@ -202,9 +202,6 @@ func TestCache_AutoAuthClientTokenProxyStripping(t *testing.T) {
func TestCache_ConcurrentRequests(t *testing.T) {
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: hclog.NewNullLogger(),
LogicalBackends: map[string]logical.Factory{
"kv": vault.LeasedPassthroughBackendFactory,
},
@@ -247,9 +244,6 @@ func TestCache_ConcurrentRequests(t *testing.T) {
func TestCache_TokenRevocations_RevokeOrphan(t *testing.T) {
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: hclog.NewNullLogger(),
LogicalBackends: map[string]logical.Factory{
"kv": vault.LeasedPassthroughBackendFactory,
},
@@ -348,9 +342,6 @@ func TestCache_TokenRevocations_RevokeOrphan(t *testing.T) {
func TestCache_TokenRevocations_LeafLevelToken(t *testing.T) {
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: hclog.NewNullLogger(),
LogicalBackends: map[string]logical.Factory{
"kv": vault.LeasedPassthroughBackendFactory,
},
@@ -448,9 +439,6 @@ func TestCache_TokenRevocations_LeafLevelToken(t *testing.T) {
func TestCache_TokenRevocations_IntermediateLevelToken(t *testing.T) {
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: hclog.NewNullLogger(),
LogicalBackends: map[string]logical.Factory{
"kv": vault.LeasedPassthroughBackendFactory,
},
@@ -546,9 +534,6 @@ func TestCache_TokenRevocations_IntermediateLevelToken(t *testing.T) {
func TestCache_TokenRevocations_TopLevelToken(t *testing.T) {
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: hclog.NewNullLogger(),
LogicalBackends: map[string]logical.Factory{
"kv": vault.LeasedPassthroughBackendFactory,
},
@@ -641,9 +626,6 @@ func TestCache_TokenRevocations_TopLevelToken(t *testing.T) {
func TestCache_TokenRevocations_Shutdown(t *testing.T) {
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: hclog.NewNullLogger(),
LogicalBackends: map[string]logical.Factory{
"kv": vault.LeasedPassthroughBackendFactory,
},
@@ -731,9 +713,6 @@ func TestCache_TokenRevocations_Shutdown(t *testing.T) {
func TestCache_TokenRevocations_BaseContextCancellation(t *testing.T) {
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: hclog.NewNullLogger(),
LogicalBackends: map[string]logical.Factory{
"kv": vault.LeasedPassthroughBackendFactory,
},
@@ -822,9 +801,6 @@ func TestCache_TokenRevocations_BaseContextCancellation(t *testing.T) {
func TestCache_NonCacheable(t *testing.T) {
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: hclog.NewNullLogger(),
LogicalBackends: map[string]logical.Factory{
"kv": kv.Factory,
},
@@ -930,9 +906,6 @@ func TestCache_Caching_AuthResponse(t *testing.T) {
func TestCache_Caching_LeaseResponse(t *testing.T) {
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: hclog.NewNullLogger(),
LogicalBackends: map[string]logical.Factory{
"kv": vault.LeasedPassthroughBackendFactory,
},
@@ -1032,9 +1005,6 @@ func TestCache_Caching_CacheClear(t *testing.T) {
func testCachingCacheClearCommon(t *testing.T, clearType string) {
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: hclog.NewNullLogger(),
LogicalBackends: map[string]logical.Factory{
"kv": vault.LeasedPassthroughBackendFactory,
},

View File

@@ -8,7 +8,6 @@ import (
"sync"
"testing"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/api"
auth "github.com/hashicorp/vault/api/auth/approle"
credAppRole "github.com/hashicorp/vault/builtin/credential/approle"
@@ -20,9 +19,6 @@ import (
func TestAppRole_Integ_ConcurrentLogins(t *testing.T) {
var err error
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: log.NewNullLogger(),
CredentialBackends: map[string]logical.Factory{
"approle": credAppRole.Factory,
},

View File

@@ -21,7 +21,6 @@ import (
"github.com/hashicorp/vault/builtin/logical/transit"
"github.com/hashicorp/vault/helper/benchhelpers"
"github.com/hashicorp/vault/helper/builtinplugins"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/sdk/physical/inmem"
"github.com/hashicorp/vault/vault"
@@ -126,9 +125,6 @@ func testVaultServerAllBackends(tb testing.TB) (*api.Client, func()) {
tb.Helper()
client, _, closer := testVaultServerCoreConfig(tb, &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: defaultVaultLogger,
CredentialBackends: credentialBackends,
AuditBackends: auditBackends,
LogicalBackends: logicalBackends,
@@ -156,16 +152,8 @@ func testVaultServerUnseal(tb testing.TB) (*api.Client, []string, func()) {
func testVaultServerUnsealWithKVVersionWithSeal(tb testing.TB, kvVersion string, seal vault.Seal) (*api.Client, []string, func()) {
tb.Helper()
logger := log.NewInterceptLogger(&log.LoggerOptions{
Output: log.DefaultOutput,
Level: log.Debug,
JSONFormat: logging.ParseEnvLogFormat() == logging.JSONFormat,
})
return testVaultServerCoreConfigWithOpts(tb, &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: logger,
CredentialBackends: defaultVaultCredentialBackends,
AuditBackends: defaultVaultAuditBackends,
LogicalBackends: defaultVaultLogicalBackends,
@@ -185,9 +173,6 @@ func testVaultServerPluginDir(tb testing.TB, pluginDir string) (*api.Client, []s
tb.Helper()
return testVaultServerCoreConfig(tb, &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: defaultVaultLogger,
CredentialBackends: defaultVaultCredentialBackends,
AuditBackends: defaultVaultAuditBackends,
LogicalBackends: defaultVaultLogicalBackends,
@@ -251,8 +236,6 @@ func testVaultServerUninit(tb testing.TB) (*api.Client, func()) {
core, err := vault.NewCore(&vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: defaultVaultLogger,
Physical: inm,
CredentialBackends: defaultVaultCredentialBackends,
AuditBackends: defaultVaultAuditBackends,

View File

@@ -65,7 +65,6 @@ func TestProxy_ExitAfterAuth(t *testing.T) {
func testProxyExitAfterAuth(t *testing.T, viaFlag bool) {
logger := logging.NewVaultLogger(hclog.Trace)
coreConfig := &vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"jwt": vaultjwt.Factory,
},
@@ -249,7 +248,6 @@ func TestProxy_AutoAuth_UserAgent(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace)
var h userAgentHandler
cluster := vault.NewTestCluster(t, &vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"approle": credAppRole.Factory,
},
@@ -696,7 +694,6 @@ func TestProxy_ApiProxy_Retry(t *testing.T) {
var h handler
cluster := vault.NewTestCluster(t,
&vault.CoreConfig{
Logger: logger,
CredentialBackends: map[string]logical.Factory{
"approle": credAppRole.Factory,
},
@@ -844,10 +841,7 @@ vault {
func TestProxy_Metrics(t *testing.T) {
// Start a vault server
logger := logging.NewVaultLogger(hclog.Trace)
cluster := vault.NewTestCluster(t,
&vault.CoreConfig{
Logger: logger,
},
cluster := vault.NewTestCluster(t, nil,
&vault.TestClusterOptions{
HandlerFunc: vaulthttp.Handler,
})

View File

@@ -3,13 +3,11 @@ package builtinplugins
import (
"testing"
"github.com/hashicorp/go-hclog"
logicalKv "github.com/hashicorp/vault-plugin-secrets-kv"
"github.com/hashicorp/vault/api"
logicalDb "github.com/hashicorp/vault/builtin/logical/database"
vaulthttp "github.com/hashicorp/vault/http"
"github.com/hashicorp/vault/sdk/helper/consts"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault"
)
@@ -41,7 +39,6 @@ func TestBuiltinPluginsWork(t *testing.T) {
// builtinplugins.Registry, so we need to add it here to be able to test it!
"database": logicalDb.Factory,
},
Logger: logging.NewVaultLogger(hclog.Trace),
PendingRemovalMountsAllowed: true,
},
&vault.TestClusterOptions{

View File

@@ -7,13 +7,12 @@ import (
"path"
"strconv"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/builtin/logical/transit"
"github.com/hashicorp/vault/helper/testhelpers/corehelpers"
"github.com/hashicorp/vault/helper/testhelpers/teststorage"
"github.com/hashicorp/vault/http"
"github.com/hashicorp/vault/internalshared/configutil"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault"
"github.com/hashicorp/vault/vault/seal"
@@ -33,7 +32,7 @@ func NewTransitSealServer(t testing.T, idx int) *TransitSealServer {
opts := &vault.TestClusterOptions{
NumCores: 1,
HandlerFunc: http.Handler,
Logger: logging.NewVaultLogger(hclog.Trace).Named(t.Name()).Named("transit-seal" + strconv.Itoa(idx)),
Logger: corehelpers.NewTestLogger(t).Named("transit-seal" + strconv.Itoa(idx)),
}
teststorage.InmemBackendSetup(conf, opts)
cluster := vault.NewTestCluster(t, conf, opts)

View File

@@ -45,7 +45,6 @@ func getPluginClusterAndCore(t testing.TB, logger log.Logger) (*vault.TestCluste
cluster := vault.NewTestCluster(benchhelpers.TBtoT(t), coreConfig, &vault.TestClusterOptions{
HandlerFunc: Handler,
Logger: logger.Named("testclusteroptions"),
})
cluster.Start()

View File

@@ -10,9 +10,8 @@ import (
"strconv"
"testing"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/builtin/logical/transit"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/helper/testhelpers/corehelpers"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault"
"github.com/hashicorp/vault/vault/seal"
@@ -169,7 +168,7 @@ func TestSysInit_Put_ValidateParams_AutoUnseal(t *testing.T) {
opts := &vault.TestClusterOptions{
NumCores: 1,
HandlerFunc: Handler,
Logger: logging.NewVaultLogger(hclog.Trace).Named(t.Name()).Named("transit-seal" + strconv.Itoa(0)),
Logger: corehelpers.NewTestLogger(t).Named("transit-seal" + strconv.Itoa(0)),
}
cluster := vault.NewTestCluster(t, conf, opts)
cluster.Start()

View File

@@ -12,7 +12,6 @@ import (
"testing"
"time"
log "github.com/hashicorp/go-hclog"
ldapcred "github.com/hashicorp/vault/builtin/credential/ldap"
"github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/sdk/framework"
@@ -38,11 +37,7 @@ rule "charset" {
)
func TestIdentity_BackendTemplating(t *testing.T) {
var err error
coreConfig := &CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: log.NewNullLogger(),
CredentialBackends: map[string]logical.Factory{
"ldap": ldapcred.Factory,
},
@@ -178,11 +173,7 @@ func TestIdentity_BackendTemplating(t *testing.T) {
}
func TestDynamicSystemView_GeneratePasswordFromPolicy_successful(t *testing.T) {
var err error
coreConfig := &CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: log.NewNullLogger(),
CredentialBackends: map[string]logical.Factory{},
}
@@ -201,7 +192,7 @@ func TestDynamicSystemView_GeneratePasswordFromPolicy_successful(t *testing.T) {
req.ClientToken = cluster.RootToken
req.Data["policy"] = b64Policy
_, err = core.HandleRequest(namespace.RootContext(nil), req)
_, err := core.HandleRequest(namespace.RootContext(nil), req)
if err != nil {
t.Fatalf("err: %v", err)
}

View File

@@ -14,7 +14,6 @@ import (
"strings"
"testing"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/helper/testhelpers/corehelpers"
"github.com/hashicorp/vault/helper/testhelpers/pluginhelpers"
@@ -67,9 +66,6 @@ func TestCore_EnableExternalPlugin(t *testing.T) {
} {
t.Run(name, func(t *testing.T) {
coreConfig := &CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: log.NewNullLogger(),
CredentialBackends: map[string]logical.Factory{},
}

View File

@@ -7,7 +7,6 @@ import (
"encoding/base64"
"testing"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/audit"
auditFile "github.com/hashicorp/vault/builtin/audit/file"
@@ -37,9 +36,6 @@ func testVaultServerUnseal(t testing.TB) (*api.Client, []string, func()) {
t.Helper()
return testVaultServerCoreConfig(t, &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: log.NewNullLogger(),
CredentialBackends: map[string]logical.Factory{
"userpass": credUserpass.Factory,
},

View File

@@ -8,7 +8,6 @@ import (
"strings"
"testing"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/helper/builtinplugins"
"github.com/hashicorp/vault/sdk/helper/jsonutil"
@@ -22,11 +21,8 @@ func TestSudoPaths(t *testing.T) {
t.Parallel()
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
EnableRaw: true,
EnableIntrospection: true,
Logger: log.NewNullLogger(),
BuiltinRegistry: builtinplugins.Registry,
}
client, _, closer := testVaultServerCoreConfig(t, coreConfig)

View File

@@ -6,7 +6,6 @@ package misc
import (
"testing"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/api"
vaulthttp "github.com/hashicorp/vault/http"
"github.com/hashicorp/vault/sdk/logical"
@@ -16,13 +15,11 @@ import (
// Tests the regression in
// https://github.com/hashicorp/vault/pull/6920
func TestRecoverFromPanic(t *testing.T) {
logger := hclog.New(nil)
coreConfig := &vault.CoreConfig{
LogicalBackends: map[string]logical.Factory{
"noop": vault.NoopBackendFactory,
},
EnableRaw: true,
Logger: logger,
}
cluster := vault.NewTestCluster(t, coreConfig, &vault.TestClusterOptions{
HandlerFunc: vaulthttp.Handler,

View File

@@ -8,18 +8,16 @@ import (
"testing"
"github.com/go-test/deep"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/helper/testhelpers"
"github.com/hashicorp/vault/helper/testhelpers/corehelpers"
"github.com/hashicorp/vault/http"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/sdk/physical/inmem"
"github.com/hashicorp/vault/vault"
"go.uber.org/atomic"
)
func TestRecovery(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Debug).Named(t.Name())
inm, err := inmem.NewTransactionalInmemHA(nil, logger)
inm, err := inmem.NewTransactionalInmemHA(nil, corehelpers.NewTestLogger(t))
if err != nil {
t.Fatal(err)
}
@@ -30,7 +28,6 @@ func TestRecovery(t *testing.T) {
{
conf := vault.CoreConfig{
Physical: inm,
Logger: logger,
}
opts := vault.TestClusterOptions{
HandlerFunc: http.Handler,
@@ -73,7 +70,6 @@ func TestRecovery(t *testing.T) {
var tokenRef atomic.String
conf := vault.CoreConfig{
Physical: inm,
Logger: logger,
RecoveryMode: true,
}
opts := vault.TestClusterOptions{
@@ -117,7 +113,6 @@ func TestRecovery(t *testing.T) {
// Now go back to regular mode and verify that our changes are present
conf := vault.CoreConfig{
Physical: inm,
Logger: logger,
}
opts := vault.TestClusterOptions{
HandlerFunc: http.Handler,

View File

@@ -7,15 +7,13 @@ import (
"testing"
"time"
"github.com/hashicorp/vault/helper/testhelpers/minimal"
"github.com/go-test/deep"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-secure-stdlib/strutil"
"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/builtin/credential/ldap"
credUserpass "github.com/hashicorp/vault/builtin/credential/userpass"
ldaphelper "github.com/hashicorp/vault/helper/testhelpers/ldap"
"github.com/hashicorp/vault/helper/testhelpers/minimal"
vaulthttp "github.com/hashicorp/vault/http"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault"
@@ -24,9 +22,6 @@ import (
func TestPolicy_NoDefaultPolicy(t *testing.T) {
var err error
coreConfig := &vault.CoreConfig{
DisableMlock: true,
DisableCache: true,
Logger: hclog.NewNullLogger(),
CredentialBackends: map[string]logical.Factory{
"ldap": ldap.Factory,
},

View File

@@ -9,15 +9,15 @@ import (
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/helper/testhelpers"
"github.com/hashicorp/vault/helper/testhelpers/corehelpers"
"github.com/hashicorp/vault/helper/testhelpers/teststorage"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/vault"
)
type testFunc func(t *testing.T, logger hclog.Logger, storage teststorage.ReusableStorage, basePort int)
func testVariousBackends(t *testing.T, tf testFunc, basePort int, includeRaft bool) {
logger := logging.NewVaultLogger(hclog.Trace).Named(t.Name())
logger := corehelpers.NewTestLogger(t)
t.Run("inmem", func(t *testing.T) {
t.Parallel()

View File

@@ -8,20 +8,18 @@ package vault
import (
"bytes"
"context"
"sync"
"testing"
proto "github.com/golang/protobuf/proto"
log "github.com/hashicorp/go-hclog"
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
"github.com/hashicorp/vault/helper/testhelpers/corehelpers"
"github.com/hashicorp/vault/sdk/physical"
"github.com/hashicorp/vault/sdk/physical/inmem"
)
func TestSealUnwrapper(t *testing.T) {
logger := log.New(&log.LoggerOptions{
Mutex: &sync.Mutex{},
})
logger := corehelpers.NewTestLogger(t)
// Test without transactions
phys, err := inmem.NewInmemHA(nil, logger)