Agent/Proxy : Properly passes env variables to child

This commit is contained in:
MagnumOpus21 2018-07-05 22:04:29 -04:00
parent f92e5b1121
commit 6cecf2961d
2 changed files with 41 additions and 1 deletions

View File

@ -432,7 +432,7 @@ func (m *Manager) newProxy(mp *local.ManagedProxy) (Proxy, error) {
if err := m.configureLogDir(id, &cmd); err != nil {
return nil, fmt.Errorf("error configuring proxy logs: %s", err)
}
cmd.Env = os.Environ()
// Build the daemon structure
proxy.Command = &cmd
proxy.ProxyID = id

View File

@ -261,6 +261,46 @@ func TestManagerRun_daemonPid(t *testing.T) {
require.NotEmpty(pidRaw)
}
// Test to check if the parent and the child processes
// have the same environmental variables
func TestEnvironproxy(t *testing.T) {
t.Parallel()
require := require.New(t)
state := local.TestState(t)
m, closer := testManager(t)
defer closer()
m.State = state
defer m.Kill()
// Add the proxy
td, closer := testTempDir(t)
defer closer()
path := filepath.Join(td, "env-variables")
d := &Daemon{
Command: helperProcess("parent", path),
Logger: testLogger,
}
var currentEnviron []string
currentEnviron = os.Environ()
// Environmental variable of the helper
if err := d.Start(); err != nil {
t.Error("Daemon failed to start")
defer d.Stop()
envProcess := d.Command.Env
var envData []byte
for _, data := range envProcess {
envData = append(envData, []byte(data)...)
envData = append(envData, []byte("\n")...)
}
t.Logf("Env Data:%s", envProcess)
//Get the parent environmental variables in a file
require.Equal(currentEnviron, envProcess)
}
}
// Test the Snapshot/Restore works.
func TestManagerRun_snapshotRestore(t *testing.T) {
t.Parallel()