2018-05-23 21:44:41 +00:00
|
|
|
package set
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent"
|
|
|
|
"github.com/hashicorp/consul/agent/connect/ca"
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2018-08-06 23:46:09 +00:00
|
|
|
"github.com/hashicorp/consul/testrpc"
|
2018-05-23 21:44:41 +00:00
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConnectCASetConfigCommand_noTabs(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
if strings.ContainsRune(New(cli.NewMockUi()).Help(), '\t') {
|
|
|
|
t.Fatal("help has tabs")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConnectCASetConfigCommand(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
2020-03-31 19:59:56 +00:00
|
|
|
a := agent.NewTestAgent(t, ``)
|
2018-05-23 21:44:41 +00:00
|
|
|
defer a.Shutdown()
|
|
|
|
|
2018-09-04 11:31:51 +00:00
|
|
|
testrpc.WaitForTestAgent(t, a.RPC, "dc1")
|
2018-05-23 21:44:41 +00:00
|
|
|
ui := cli.NewMockUi()
|
|
|
|
c := New(ui)
|
|
|
|
args := []string{
|
|
|
|
"-http-addr=" + a.HTTPAddr(),
|
|
|
|
"-config-file=test-fixtures/ca_config.json",
|
|
|
|
}
|
|
|
|
|
|
|
|
code := c.Run(args)
|
|
|
|
if code != 0 {
|
|
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
req := structs.DCSpecificRequest{
|
|
|
|
Datacenter: "dc1",
|
|
|
|
}
|
|
|
|
var reply structs.CAConfiguration
|
|
|
|
require.NoError(a.RPC("ConnectCA.ConfigurationGet", &req, &reply))
|
|
|
|
require.Equal("consul", reply.Provider)
|
|
|
|
|
|
|
|
parsed, err := ca.ParseConsulCAConfig(reply.Config)
|
|
|
|
require.NoError(err)
|
|
|
|
require.Equal(24*time.Hour, parsed.RotationPeriod)
|
2020-02-10 23:05:49 +00:00
|
|
|
require.Equal(288*time.Hour, parsed.IntermediateCertTTL)
|
2018-05-23 21:44:41 +00:00
|
|
|
}
|