Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: sync some commits #1687

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading