2023-03-28 22:48:58 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 22:48:58 +00:00
|
|
|
|
2023-02-07 19:13:19 +00:00
|
|
|
package upgrade
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
libassert "github.com/hashicorp/consul/test/integration/consul-container/libs/assert"
|
|
|
|
libcluster "github.com/hashicorp/consul/test/integration/consul-container/libs/cluster"
|
|
|
|
libtopology "github.com/hashicorp/consul/test/integration/consul-container/libs/topology"
|
|
|
|
"github.com/hashicorp/consul/test/integration/consul-container/libs/utils"
|
|
|
|
)
|
|
|
|
|
2023-03-30 20:07:16 +00:00
|
|
|
// TestACL_NodeToken test verifies the following after upgrade
|
2023-02-07 19:13:19 +00:00
|
|
|
// 1. Upgraded agent can inherit the persistend token and join the cluster
|
|
|
|
// 2. Agent token prior to upgrade is still valid after upgrade
|
2023-03-30 20:07:16 +00:00
|
|
|
func TestACL_NodeToken(t *testing.T) {
|
2023-02-07 19:13:19 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2023-03-30 20:07:16 +00:00
|
|
|
// NOTE: Disable auto.encrypt due to its conflict with ACL token during bootstrap
|
|
|
|
cluster, _, _ := libtopology.NewCluster(t, &libtopology.ClusterConfig{
|
|
|
|
NumServers: 1,
|
|
|
|
NumClients: 1,
|
|
|
|
BuildOpts: &libcluster.BuildOptions{
|
|
|
|
Datacenter: "dc1",
|
2023-05-08 16:02:31 +00:00
|
|
|
ConsulImageName: utils.GetLatestImageName(),
|
2023-03-30 20:07:16 +00:00
|
|
|
ConsulVersion: utils.LatestVersion,
|
|
|
|
InjectAutoEncryption: false,
|
|
|
|
ACLEnabled: true,
|
|
|
|
},
|
|
|
|
ApplyDefaultProxySettings: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
agentToken, err := cluster.CreateAgentToken("dc1",
|
|
|
|
cluster.Agents[1].GetAgentName())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-05-08 16:02:31 +00:00
|
|
|
err = cluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), utils.TargetVersion)
|
2023-03-30 20:07:16 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Post upgrade validation: agent token can be used to query the node
|
|
|
|
// Assert consul catalog nodes -token e3dc19d9-658d-a430-bcf4-7302efa397fc
|
|
|
|
client, err := cluster.Agents[1].NewClient(agentToken, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
libassert.CatalogNodeExists(t, client, cluster.Agents[1].GetAgentName())
|
2023-02-07 19:13:19 +00:00
|
|
|
}
|