Skip to content

Commit

Permalink
chore: sync some commits (keploy#1687)
Browse files Browse the repository at this point in the history
Signed-off-by: gouravkrosx <gouravgreatkr@gmail.com>
  • Loading branch information
gouravkrosx authored Mar 13, 2024
1 parent 93d2476 commit 7febf76
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
5 changes: 2 additions & 3 deletions pkg/core/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ func (a *App) run(ctx context.Context) models.AppError {
username := os.Getenv("SUDO_USER")
cmd := exec.CommandContext(ctx, "sh", "-c", a.cmd)
if username != "" {
// print all environment variables
a.logger.Debug("env inherited from the cmd", zap.Any("env", os.Environ()))
// Run the command as the user who invoked sudo to preserve the user environment variables and PATH
cmd = exec.CommandContext(ctx, "sudo", "-E", "-u", os.Getenv("SUDO_USER"), "env", "PATH="+os.Getenv("PATH"), "sh", "-c", a.cmd)
}
Expand All @@ -460,9 +462,6 @@ func (a *App) run(ctx context.Context) models.AppError {
Setpgid: true,
}

// Explicitly set the environment for cmd
cmd.Env = os.Environ()

// Set the output of the command
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down
9 changes: 5 additions & 4 deletions pkg/core/hooks/conn/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ func capture(_ context.Context, logger *zap.Logger, t chan *models.TestCase, req
Timestamp: reqTimeTest,
},
HTTPResp: models.HTTPResp{
StatusCode: resp.StatusCode,
Header: pkg.ToYamlHTTPHeader(resp.Header),
Body: string(respBody),
Timestamp: resTimeTest,
StatusCode: resp.StatusCode,
Header: pkg.ToYamlHTTPHeader(resp.Header),
Body: string(respBody),
Timestamp: resTimeTest,
StatusMessage: http.StatusText(resp.StatusCode),
},
Noise: map[string][]string{},
// Mocks: mocks,
Expand Down
13 changes: 9 additions & 4 deletions pkg/core/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,15 @@ func (p *Proxy) handleConnection(ctx context.Context, srcConn net.Conn) error {
}

addr := fmt.Sprintf("%v:%v", dstURL, destInfo.Port)
dstConn, err = tls.Dial("tcp", addr, cfg)
if err != nil {
utils.LogError(logger, err, "failed to dial the conn to destination server", zap.Any("proxy port", p.Port), zap.Any("server address", dstAddr))
return err
if rule.Mode != models.MODE_TEST {
dialer := &net.Dialer{
Timeout: 1 * time.Second,
}
dstConn, err = tls.DialWithDialer(dialer, "tcp", addr, cfg)
if err != nil {
utils.LogError(logger, err, "failed to dial the conn to destination server", zap.Any("proxy port", p.Port), zap.Any("server address", dstAddr))
return err
}
}

dstCfg.TLSCfg = cfg
Expand Down
5 changes: 3 additions & 2 deletions pkg/service/replay/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -411,8 +412,8 @@ func (r *replayer) RunTestSet(ctx context.Context, testSetID string, testRunID s
Binary: testCase.HTTPResp.Binary,
Timestamp: testCase.HTTPResp.Timestamp,
},
TestCasePath: r.config.Path,
MockPath: r.config.Path,
TestCasePath: filepath.Join(r.config.Path, testSetID),
MockPath: filepath.Join(r.config.Path, testSetID, "mocks.yaml"),
Noise: testCase.Noise,
Result: *testResult,
}
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ type TestFlags struct {
func getAlias(ctx context.Context, logger *zap.Logger) (string, error) {
// Get the name of the operating system.
osName := runtime.GOOS
//TODO: configure the hardcoded port mapping
//TODO: configure the hardcoded port mapping & check if (/.keploy-config:/root/.keploy-config) can be removed from all the aliases
switch osName {
case "linux":
alias := "sudo docker run --pull always --name keploy-v2 -e BINARY_TO_DOCKER=true -p 16789:16789 --privileged --pid=host -it -v " + os.Getenv("PWD") + ":" + os.Getenv("PWD") + " -w " + os.Getenv("PWD") + " -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock -v " + os.Getenv("HOME") + "/.keploy-config:/root/.keploy-config -v " + os.Getenv("HOME") + "/.keploy:/root/.keploy --rm ghcr.io/keploy/keploy "
Expand Down

0 comments on commit 7febf76

Please sign in to comment.