2022-01-05 18:02:03 +00:00
|
|
|
//go:build !race
|
2021-03-29 21:22:32 +00:00
|
|
|
|
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2021-04-29 18:32:41 +00:00
|
|
|
"context"
|
|
|
|
"fmt"
|
2021-05-22 02:21:11 +00:00
|
|
|
"io/ioutil"
|
2021-06-24 16:56:38 +00:00
|
|
|
"os"
|
2021-03-29 21:22:32 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2022-04-07 19:15:05 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/consts"
|
2021-04-29 18:32:41 +00:00
|
|
|
"github.com/hashicorp/vault/vault/diagnose"
|
2021-03-29 21:22:32 +00:00
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
|
2021-04-29 18:32:41 +00:00
|
|
|
func testOperatorDiagnoseCommand(tb testing.TB) *OperatorDiagnoseCommand {
|
2021-03-29 21:22:32 +00:00
|
|
|
tb.Helper()
|
|
|
|
|
|
|
|
ui := cli.NewMockUi()
|
2021-04-29 18:32:41 +00:00
|
|
|
return &OperatorDiagnoseCommand{
|
2021-05-22 02:21:11 +00:00
|
|
|
diagnose: diagnose.New(ioutil.Discard),
|
2021-03-29 21:22:32 +00:00
|
|
|
BaseCommand: &BaseCommand{
|
|
|
|
UI: ui,
|
|
|
|
},
|
2021-05-02 20:33:13 +00:00
|
|
|
skipEndEnd: true,
|
2021-03-29 21:22:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOperatorDiagnoseCommand_Run(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
cases := []struct {
|
2021-04-29 18:32:41 +00:00
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
expected []*diagnose.Result
|
2021-03-29 21:22:32 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"diagnose_ok",
|
|
|
|
[]string{
|
2021-04-06 23:40:43 +00:00
|
|
|
"-config", "./server/test-fixtures/config_diagnose_ok.hcl",
|
2021-03-29 21:22:32 +00:00
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
[]*diagnose.Result{
|
2021-06-01 17:43:51 +00:00
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Parse Configuration",
|
2021-06-01 17:43:51 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Start Listeners",
|
2021-06-01 17:43:51 +00:00
|
|
|
Status: diagnose.WarningStatus,
|
|
|
|
Children: []*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Create Listeners",
|
2021-06-01 17:43:51 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Listener TLS",
|
2021-06-01 17:43:51 +00:00
|
|
|
Status: diagnose.WarningStatus,
|
|
|
|
Warnings: []string{
|
2021-07-11 22:44:19 +00:00
|
|
|
"TLS is disabled in a listener config stanza.",
|
2021-06-01 17:43:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Storage",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
Children: []*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Create Storage Backend",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Consul TLS",
|
2021-07-07 18:35:25 +00:00
|
|
|
Status: diagnose.SkippedStatus,
|
2021-05-25 22:23:20 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Consul Direct Storage Access",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
},
|
|
|
|
},
|
2021-06-10 19:29:32 +00:00
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Service Discovery",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
Children: []*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Consul Service Discovery TLS",
|
2021-07-07 18:35:25 +00:00
|
|
|
Status: diagnose.SkippedStatus,
|
2021-06-10 19:29:32 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Consul Direct Service Discovery",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Create Vault Server Configuration Seals",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Create Core Configuration",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
Children: []*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Initialize Randomness for Core",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "HA Storage",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
Children: []*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Create HA Storage Backend",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check HA Consul Direct Storage Access",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Consul TLS",
|
2021-07-07 18:35:25 +00:00
|
|
|
Status: diagnose.SkippedStatus,
|
2021-06-10 19:29:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Determine Redirect Address",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Cluster Address",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Core Creation",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Start Listeners",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.WarningStatus,
|
|
|
|
Children: []*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Create Listeners",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Listener TLS",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.WarningStatus,
|
|
|
|
Warnings: []string{
|
2021-07-11 22:44:19 +00:00
|
|
|
"TLS is disabled in a listener config stanza.",
|
2021-06-10 19:29:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-07-12 20:22:56 +00:00
|
|
|
Name: "Check Autounseal Encryption",
|
|
|
|
Status: diagnose.SkippedStatus,
|
|
|
|
Message: "Skipping barrier encryption",
|
2021-06-10 19:29:32 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Server Before Runtime",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Finalize Shamir Seal",
|
2021-06-10 19:29:32 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
},
|
2021-03-29 21:22:32 +00:00
|
|
|
},
|
2021-06-17 17:04:21 +00:00
|
|
|
{
|
|
|
|
"diagnose_raft_problems",
|
|
|
|
[]string{
|
|
|
|
"-config", "./server/test-fixtures/config_raft.hcl",
|
|
|
|
},
|
|
|
|
[]*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Storage",
|
2021-06-24 16:56:38 +00:00
|
|
|
Status: diagnose.WarningStatus,
|
2021-06-17 17:04:21 +00:00
|
|
|
Children: []*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Create Storage Backend",
|
2021-06-24 16:56:38 +00:00
|
|
|
Status: diagnose.OkStatus,
|
2021-06-17 17:04:21 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Raft Folder Permissions",
|
2021-06-17 17:04:21 +00:00
|
|
|
Status: diagnose.WarningStatus,
|
|
|
|
Message: "too many permissions",
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check For Raft Quorum",
|
2021-06-24 16:56:38 +00:00
|
|
|
Status: diagnose.WarningStatus,
|
2021-07-11 22:44:19 +00:00
|
|
|
Message: "0 voters found",
|
2021-06-17 17:04:21 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-29 21:22:32 +00:00
|
|
|
{
|
|
|
|
"diagnose_invalid_storage",
|
|
|
|
[]string{
|
|
|
|
"-config", "./server/test-fixtures/nostore_config.hcl",
|
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
[]*diagnose.Result{
|
2021-05-25 22:23:20 +00:00
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Storage",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.ErrorStatus,
|
2021-07-11 22:44:19 +00:00
|
|
|
Message: "No storage stanza in Vault server configuration.",
|
2021-05-25 22:23:20 +00:00
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
},
|
2021-03-29 21:22:32 +00:00
|
|
|
},
|
2021-04-06 23:40:43 +00:00
|
|
|
{
|
|
|
|
"diagnose_listener_config_ok",
|
|
|
|
[]string{
|
|
|
|
"-config", "./server/test-fixtures/tls_config_ok.hcl",
|
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
[]*diagnose.Result{
|
2021-05-25 22:23:20 +00:00
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Start Listeners",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
Children: []*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Create Listeners",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Listener TLS",
|
2021-05-27 17:17:52 +00:00
|
|
|
Status: diagnose.OkStatus,
|
2021-05-25 22:23:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
},
|
2021-04-06 23:40:43 +00:00
|
|
|
},
|
2021-04-28 15:55:18 +00:00
|
|
|
{
|
|
|
|
"diagnose_invalid_https_storage",
|
|
|
|
[]string{
|
|
|
|
"-config", "./server/test-fixtures/config_bad_https_storage.hcl",
|
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
[]*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Storage",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.ErrorStatus,
|
|
|
|
Children: []*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Create Storage Backend",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Consul TLS",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.ErrorStatus,
|
2021-06-15 16:53:29 +00:00
|
|
|
Message: "certificate has expired or is not yet valid",
|
|
|
|
Warnings: []string{
|
|
|
|
"expired or near expiry",
|
|
|
|
},
|
2021-05-25 22:23:20 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Consul Direct Storage Access",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
},
|
2021-04-28 15:55:18 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"diagnose_invalid_https_hastorage",
|
|
|
|
[]string{
|
|
|
|
"-config", "./server/test-fixtures/config_diagnose_hastorage_bad_https.hcl",
|
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
[]*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Storage",
|
2021-04-29 18:32:41 +00:00
|
|
|
Status: diagnose.WarningStatus,
|
2021-05-25 22:23:20 +00:00
|
|
|
Children: []*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Create Storage Backend",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Consul TLS",
|
2021-07-07 18:35:25 +00:00
|
|
|
Status: diagnose.SkippedStatus,
|
2021-05-25 22:23:20 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Consul Direct Storage Access",
|
2021-05-27 17:17:52 +00:00
|
|
|
Status: diagnose.WarningStatus,
|
2021-07-11 22:44:19 +00:00
|
|
|
Advice: "We recommend connecting to a local agent.",
|
2021-05-27 17:17:52 +00:00
|
|
|
Warnings: []string{
|
2021-07-11 22:44:19 +00:00
|
|
|
"Vault storage is directly connected to a Consul server.",
|
2021-05-27 17:17:52 +00:00
|
|
|
},
|
2021-05-25 22:23:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "HA Storage",
|
2021-04-29 18:32:41 +00:00
|
|
|
Status: diagnose.ErrorStatus,
|
2021-05-25 22:23:20 +00:00
|
|
|
Children: []*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Create HA Storage Backend",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check HA Consul Direct Storage Access",
|
2021-05-27 17:17:52 +00:00
|
|
|
Status: diagnose.WarningStatus,
|
2021-07-11 22:44:19 +00:00
|
|
|
Advice: "We recommend connecting to a local agent.",
|
2021-05-27 17:17:52 +00:00
|
|
|
Warnings: []string{
|
2021-07-11 22:44:19 +00:00
|
|
|
"Vault storage is directly connected to a Consul server.",
|
2021-05-27 17:17:52 +00:00
|
|
|
},
|
2021-05-25 22:23:20 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Consul TLS",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.ErrorStatus,
|
2021-06-15 16:53:29 +00:00
|
|
|
Message: "certificate has expired or is not yet valid",
|
|
|
|
Warnings: []string{
|
|
|
|
"expired or near expiry",
|
|
|
|
},
|
2021-05-25 22:23:20 +00:00
|
|
|
},
|
2021-05-02 23:21:06 +00:00
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
},
|
2021-05-27 17:17:52 +00:00
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Cluster Address",
|
2021-05-27 17:17:52 +00:00
|
|
|
Status: diagnose.ErrorStatus,
|
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
},
|
2021-04-28 15:55:18 +00:00
|
|
|
},
|
2021-06-24 22:30:42 +00:00
|
|
|
{
|
|
|
|
"diagnose_seal_transit_tls_check_fail",
|
|
|
|
[]string{
|
2021-07-11 22:44:19 +00:00
|
|
|
"-config", "./server/test-fixtures/diagnose_seal_transit_tls_check.hcl",
|
2021-06-24 22:30:42 +00:00
|
|
|
},
|
|
|
|
[]*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Transit Seal TLS",
|
|
|
|
Status: diagnose.WarningStatus,
|
|
|
|
Warnings: []string{
|
|
|
|
"Found at least one intermediate certificate in the CA certificate file.",
|
|
|
|
},
|
2021-06-24 22:30:42 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-04-28 15:55:18 +00:00
|
|
|
{
|
|
|
|
"diagnose_invalid_https_sr",
|
|
|
|
[]string{
|
|
|
|
"-config", "./server/test-fixtures/diagnose_bad_https_consul_sr.hcl",
|
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
[]*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Service Discovery",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.ErrorStatus,
|
|
|
|
Children: []*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Consul Service Discovery TLS",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.ErrorStatus,
|
2021-06-15 16:53:29 +00:00
|
|
|
Message: "certificate has expired or is not yet valid",
|
|
|
|
Warnings: []string{
|
|
|
|
"expired or near expiry",
|
|
|
|
},
|
2021-05-25 22:23:20 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Consul Direct Service Discovery",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.WarningStatus,
|
|
|
|
Warnings: []string{
|
|
|
|
diagnose.DirAccessErr,
|
|
|
|
},
|
|
|
|
},
|
2021-05-02 23:21:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"diagnose_direct_storage_access",
|
|
|
|
[]string{
|
|
|
|
"-config", "./server/test-fixtures/diagnose_ok_storage_direct_access.hcl",
|
|
|
|
},
|
|
|
|
[]*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Storage",
|
2021-05-02 23:21:06 +00:00
|
|
|
Status: diagnose.WarningStatus,
|
2021-05-25 22:23:20 +00:00
|
|
|
Children: []*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Create Storage Backend",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.OkStatus,
|
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Consul TLS",
|
2021-07-07 18:35:25 +00:00
|
|
|
Status: diagnose.SkippedStatus,
|
2021-05-25 22:23:20 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Consul Direct Storage Access",
|
2021-05-25 22:23:20 +00:00
|
|
|
Status: diagnose.WarningStatus,
|
|
|
|
Warnings: []string{
|
|
|
|
diagnose.DirAccessErr,
|
|
|
|
},
|
|
|
|
},
|
2021-05-02 23:21:06 +00:00
|
|
|
},
|
|
|
|
},
|
2021-04-29 18:32:41 +00:00
|
|
|
},
|
2021-04-28 15:55:18 +00:00
|
|
|
},
|
2021-06-24 16:56:38 +00:00
|
|
|
{
|
|
|
|
"diagnose_raft_no_folder_backend",
|
|
|
|
[]string{
|
|
|
|
"-config", "./server/test-fixtures/diagnose_raft_no_bolt_folder.hcl",
|
|
|
|
},
|
|
|
|
[]*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Check Storage",
|
2021-06-24 16:56:38 +00:00
|
|
|
Status: diagnose.ErrorStatus,
|
|
|
|
Message: "Diagnose could not initialize storage backend.",
|
|
|
|
Children: []*diagnose.Result{
|
|
|
|
{
|
2021-07-11 22:44:19 +00:00
|
|
|
Name: "Create Storage Backend",
|
2021-06-24 16:56:38 +00:00
|
|
|
Status: diagnose.ErrorStatus,
|
|
|
|
Message: "no such file or directory",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-20 21:47:59 +00:00
|
|
|
{
|
|
|
|
"diagnose_telemetry_partial_circonus",
|
|
|
|
[]string{
|
|
|
|
"-config", "./server/test-fixtures/diagnose_bad_telemetry1.hcl",
|
|
|
|
},
|
|
|
|
[]*diagnose.Result{
|
|
|
|
{
|
|
|
|
Name: "Check Telemetry",
|
|
|
|
Status: diagnose.ErrorStatus,
|
|
|
|
Message: "incomplete Circonus telemetry configuration, missing circonus_api_url",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"diagnose_telemetry_partial_dogstats",
|
|
|
|
[]string{
|
|
|
|
"-config", "./server/test-fixtures/diagnose_bad_telemetry2.hcl",
|
|
|
|
},
|
|
|
|
[]*diagnose.Result{
|
|
|
|
{
|
|
|
|
Name: "Check Telemetry",
|
|
|
|
Status: diagnose.ErrorStatus,
|
|
|
|
Message: "incomplete DogStatsD telemetry configuration, missing dogstatsd_addr, while dogstatsd_tags specified",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"diagnose_telemetry_partial_stackdriver",
|
|
|
|
[]string{
|
|
|
|
"-config", "./server/test-fixtures/diagnose_bad_telemetry3.hcl",
|
|
|
|
},
|
|
|
|
[]*diagnose.Result{
|
|
|
|
{
|
|
|
|
Name: "Check Telemetry",
|
|
|
|
Status: diagnose.ErrorStatus,
|
|
|
|
Message: "incomplete Stackdriver telemetry configuration, missing stackdriver_project_id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"diagnose_telemetry_default",
|
|
|
|
[]string{
|
|
|
|
"-config", "./server/test-fixtures/config4.hcl",
|
|
|
|
},
|
|
|
|
[]*diagnose.Result{
|
|
|
|
{
|
|
|
|
Name: "Check Telemetry",
|
|
|
|
Status: diagnose.WarningStatus,
|
|
|
|
Warnings: []string{"Telemetry is using default configuration"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-29 21:22:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("validations", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
tc := tc
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
client, closer := testVaultServer(t)
|
|
|
|
defer closer()
|
2022-04-07 19:15:05 +00:00
|
|
|
os.Setenv(consts.VaultDisableFilePermissionsCheckEnv, "true")
|
2021-04-29 18:32:41 +00:00
|
|
|
cmd := testOperatorDiagnoseCommand(t)
|
2021-03-29 21:22:32 +00:00
|
|
|
cmd.client = client
|
|
|
|
|
2021-04-29 18:32:41 +00:00
|
|
|
cmd.Run(tc.args)
|
|
|
|
result := cmd.diagnose.Finalize(context.Background())
|
2021-03-29 21:22:32 +00:00
|
|
|
|
2021-05-27 17:17:52 +00:00
|
|
|
if err := compareResults(tc.expected, result.Children); err != nil {
|
|
|
|
t.Fatalf("Did not find expected test results: %v", err)
|
2021-03-29 21:22:32 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-04-29 18:32:41 +00:00
|
|
|
|
2021-05-27 17:17:52 +00:00
|
|
|
func compareResults(expected []*diagnose.Result, actual []*diagnose.Result) error {
|
|
|
|
for _, exp := range expected {
|
|
|
|
found := false
|
|
|
|
// Check them all so we don't have to be order specific
|
|
|
|
for _, act := range actual {
|
2021-06-17 17:04:21 +00:00
|
|
|
fmt.Printf("%+v", act)
|
2021-05-27 17:17:52 +00:00
|
|
|
if exp.Name == act.Name {
|
|
|
|
found = true
|
|
|
|
if err := compareResult(exp, act); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
return fmt.Errorf("could not find expected test result: %s", exp.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func compareResult(exp *diagnose.Result, act *diagnose.Result) error {
|
2021-04-29 18:32:41 +00:00
|
|
|
if exp.Name != act.Name {
|
|
|
|
return fmt.Errorf("names mismatch: %s vs %s", exp.Name, act.Name)
|
|
|
|
}
|
|
|
|
if exp.Status != act.Status {
|
2021-05-02 20:33:13 +00:00
|
|
|
if act.Status != diagnose.OkStatus {
|
|
|
|
return fmt.Errorf("section %s, status mismatch: %s vs %s, got error %s", exp.Name, exp.Status, act.Status, act.Message)
|
|
|
|
}
|
2021-04-29 18:32:41 +00:00
|
|
|
return fmt.Errorf("section %s, status mismatch: %s vs %s", exp.Name, exp.Status, act.Status)
|
|
|
|
}
|
|
|
|
if exp.Message != "" && exp.Message != act.Message && !strings.Contains(act.Message, exp.Message) {
|
|
|
|
return fmt.Errorf("section %s, message not found: %s in %s", exp.Name, exp.Message, act.Message)
|
|
|
|
}
|
2021-07-11 22:44:19 +00:00
|
|
|
if exp.Advice != "" && exp.Advice != act.Advice && !strings.Contains(act.Advice, exp.Advice) {
|
|
|
|
return fmt.Errorf("section %s, advice not found: %s in %s", exp.Name, exp.Advice, act.Advice)
|
|
|
|
}
|
2021-04-29 18:32:41 +00:00
|
|
|
if len(exp.Warnings) != len(act.Warnings) {
|
|
|
|
return fmt.Errorf("section %s, warning count mismatch: %d vs %d", exp.Name, len(exp.Warnings), len(act.Warnings))
|
|
|
|
}
|
|
|
|
for j := range exp.Warnings {
|
|
|
|
if !strings.Contains(act.Warnings[j], exp.Warnings[j]) {
|
|
|
|
return fmt.Errorf("section %s, warning message not found: %s in %s", exp.Name, exp.Warnings[j], act.Warnings[j])
|
|
|
|
}
|
|
|
|
}
|
2021-06-02 17:17:52 +00:00
|
|
|
if len(exp.Children) > len(act.Children) {
|
2021-05-25 22:23:20 +00:00
|
|
|
errStrings := []string{}
|
|
|
|
for _, c := range act.Children {
|
|
|
|
errStrings = append(errStrings, fmt.Sprintf("%+v", c))
|
|
|
|
}
|
|
|
|
return fmt.Errorf(strings.Join(errStrings, ","))
|
2021-04-29 18:32:41 +00:00
|
|
|
}
|
2021-05-27 17:17:52 +00:00
|
|
|
|
2021-06-01 17:43:51 +00:00
|
|
|
if len(exp.Children) > 0 {
|
|
|
|
return compareResults(exp.Children, act.Children)
|
|
|
|
}
|
|
|
|
|
2021-06-24 16:56:38 +00:00
|
|
|
// Remove raft file if it exists
|
|
|
|
os.Remove("./server/test-fixtures/vault.db")
|
|
|
|
os.RemoveAll("./server/test-fixtures/raft")
|
|
|
|
|
2021-04-29 18:32:41 +00:00
|
|
|
return nil
|
|
|
|
}
|