backport of commit d5f4243c9efe3970ccf0c6227c27bb2c03f02a31 (#23162)

Co-authored-by: Hamid Ghaf <83242695+hghaf099@users.noreply.github.com>
This commit is contained in:
hc-github-team-secure-vault-core 2023-09-19 12:03:52 -04:00 committed by GitHub
parent 9da2fc4b8b
commit e5bee669e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 19 deletions

View File

@ -376,14 +376,14 @@ listener "tcp" {
cmd.client = serverClient cmd.client = serverClient
cmd.startedCh = make(chan struct{}) cmd.startedCh = make(chan struct{})
var output string
var code int
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
wg.Add(1) wg.Add(1)
go func() { go func() {
code := cmd.Run([]string{"-config", configPath}) code = cmd.Run([]string{"-config", configPath})
if code != 0 { if code != 0 {
t.Errorf("non-zero return code when running agent: %d", code) output = ui.ErrorWriter.String() + ui.OutputWriter.String()
t.Logf("STDOUT from agent:\n%s", ui.OutputWriter.String())
t.Logf("STDERR from agent:\n%s", ui.ErrorWriter.String())
} }
wg.Done() wg.Done()
}() }()
@ -398,6 +398,9 @@ listener "tcp" {
defer func() { defer func() {
cmd.ShutdownCh <- struct{}{} cmd.ShutdownCh <- struct{}{}
wg.Wait() wg.Wait()
if code != 0 {
t.Fatalf("got a non-zero exit status: %d, stdout/stderr: %s", code, output)
}
}() }()
//---------------------------------------------------- //----------------------------------------------------
@ -2624,14 +2627,14 @@ listener "tcp" {
cmd.client = serverClient cmd.client = serverClient
cmd.startedCh = make(chan struct{}) cmd.startedCh = make(chan struct{})
var output string
var code int
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
wg.Add(1) wg.Add(1)
go func() { go func() {
code := cmd.Run([]string{"-config", configPath}) code = cmd.Run([]string{"-config", configPath})
if code != 0 { if code != 0 {
t.Errorf("non-zero return code when running agent: %d", code) output = ui.ErrorWriter.String() + ui.OutputWriter.String()
t.Logf("STDOUT from agent:\n%s", ui.OutputWriter.String())
t.Logf("STDERR from agent:\n%s", ui.ErrorWriter.String())
} }
wg.Done() wg.Done()
}() }()
@ -2646,6 +2649,9 @@ listener "tcp" {
defer func() { defer func() {
cmd.ShutdownCh <- struct{}{} cmd.ShutdownCh <- struct{}{}
wg.Wait() wg.Wait()
if code != 0 {
t.Fatalf("got a non-zero exit status: %d, stdout/stderr: %s", code, output)
}
}() }()
conf := api.DefaultConfig() conf := api.DefaultConfig()
@ -2939,12 +2945,13 @@ func TestAgent_Config_ReloadTls(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace) logger := logging.NewVaultLogger(hclog.Trace)
ui, cmd := testAgentCommand(t, logger) ui, cmd := testAgentCommand(t, logger)
var output string
var code int
wg.Add(1) wg.Add(1)
args := []string{"-config", configFile.Name()} args := []string{"-config", configFile.Name()}
go func() { go func() {
if code := cmd.Run(args); code != 0 { if code = cmd.Run(args); code != 0 {
output := ui.ErrorWriter.String() + ui.OutputWriter.String() output = ui.ErrorWriter.String() + ui.OutputWriter.String()
t.Errorf("got a non-zero exit status: %s", output)
} }
wg.Done() wg.Done()
}() }()
@ -3011,8 +3018,11 @@ func TestAgent_Config_ReloadTls(t *testing.T) {
// Shut down // Shut down
cmd.ShutdownCh <- struct{}{} cmd.ShutdownCh <- struct{}{}
wg.Wait() wg.Wait()
if code != 0 {
t.Fatalf("got a non-zero exit status: %d, stdout/stderr: %s", code, output)
}
} }
// TestAgent_NonTLSListener_SIGHUP tests giving a SIGHUP signal to a listener // TestAgent_NonTLSListener_SIGHUP tests giving a SIGHUP signal to a listener
@ -3056,12 +3066,13 @@ vault {
cmd.startedCh = make(chan struct{}) cmd.startedCh = make(chan struct{})
var output string
var code int
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
wg.Add(1) wg.Add(1)
go func() { go func() {
if code := cmd.Run([]string{"-config", configPath}); code != 0 { if code = cmd.Run([]string{"-config", configPath}); code != 0 {
output := ui.ErrorWriter.String() + ui.OutputWriter.String() output = ui.ErrorWriter.String() + ui.OutputWriter.String()
t.Errorf("got a non-zero exit status: %s", output)
} }
wg.Done() wg.Done()
}() }()
@ -3082,6 +3093,10 @@ vault {
close(cmd.ShutdownCh) close(cmd.ShutdownCh)
wg.Wait() wg.Wait()
if code != 0 {
t.Fatalf("got a non-zero exit status: %d, stdout/stderr: %s", code, output)
}
} }
// Get a randomly assigned port and then free it again before returning it. // Get a randomly assigned port and then free it again before returning it.

View File

@ -1193,12 +1193,13 @@ func TestProxy_Config_ReloadTls(t *testing.T) {
logger := logging.NewVaultLogger(hclog.Trace) logger := logging.NewVaultLogger(hclog.Trace)
ui, cmd := testProxyCommand(t, logger) ui, cmd := testProxyCommand(t, logger)
var output string
var code int
wg.Add(1) wg.Add(1)
args := []string{"-config", configFile.Name()} args := []string{"-config", configFile.Name()}
go func() { go func() {
if code := cmd.Run(args); code != 0 { if code = cmd.Run(args); code != 0 {
output := ui.ErrorWriter.String() + ui.OutputWriter.String() output = ui.ErrorWriter.String() + ui.OutputWriter.String()
t.Errorf("got a non-zero exit status: %s", output)
} }
wg.Done() wg.Done()
}() }()
@ -1265,6 +1266,9 @@ func TestProxy_Config_ReloadTls(t *testing.T) {
// Shut down // Shut down
cmd.ShutdownCh <- struct{}{} cmd.ShutdownCh <- struct{}{}
wg.Wait() wg.Wait()
if code != 0 {
t.Fatalf("got a non-zero exit status: %d, stdout/stderr: %s", code, output)
}
} }