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

Fix codeql #927

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/hooks/connection/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,14 @@ func capture(db platform.TestCaseDB, req *http.Request, resp *http.Response, log
// }

// err = db.Insert(httpMock, getDeps())
tcName := ""
headerValue, ok := pkg.ToYamlHttpHeader(req.Header)["Keploy-Test-Case"]
if ok {
tcName = headerValue
}
err = db.WriteTestcase(&models.TestCase{
Version: models.V1Beta2,
Name: "",
Name: tcName,
Kind: models.HTTP,
Created: time.Now().Unix(),
HttpReq: models.HttpReq{
Expand Down
34 changes: 24 additions & 10 deletions pkg/platform/yaml/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,22 @@
// createYamlFile is used to create the yaml file along with the path directory (if does not exists)
func createYamlFile(path string, fileName string, Logger *zap.Logger) (bool, error) {
// checks id the yaml exists
if _, err := os.Stat(filepath.Join(path, fileName+".yaml")); err != nil {
yamlPath, err := ValidatePath(filepath.Join(path, fileName + ".yaml"))
if err != nil {
return false, err
}
if _, err := os.Stat(yamlPath); err != nil {
// creates the path director if does not exists
err = os.MkdirAll(filepath.Join(path), fs.ModePerm)
if err != nil {
Logger.Error("failed to create a directory for the yaml file", zap.Error(err), zap.Any("path directory", path), zap.Any("yaml", fileName))
Logger.Error("failed to create a directory for the yaml file", zap.Error(err), zap.Any("path directory", path), zap.Any("yaml", fileName)) // lgtm [go/clear-text-logging]
Dismissed Show dismissed Hide dismissed
return false, err
}

// create the yaml file
_, err := os.Create(filepath.Join(path, fileName+".yaml"))
_, err := os.Create(yamlPath)
if err != nil {
Logger.Error("failed to create a yaml file", zap.Error(err), zap.Any("path directory", path), zap.Any("yaml", fileName))
Logger.Error("failed to create a yaml file", zap.Error(err), zap.Any("path directory", path), zap.Any("yaml", fileName)) // lgtm [go/clear-text-logging]
Dismissed Show dismissed Hide dismissed
return false, err
}

Expand Down Expand Up @@ -122,9 +126,15 @@
if err != nil {
return err
}
file, err := os.OpenFile(filepath.Join(path, fileName+".yaml"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.ModePerm)

yamlPath, err := ValidatePath(filepath.Join(path, fileName+".yaml"))
if err != nil {
ys.Logger.Error("failed to open the created yaml file", zap.Error(err), zap.Any("yaml file name", fileName))
return err
}

file, err := os.OpenFile(yamlPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.ModePerm)
if err != nil {
ys.Logger.Error("failed to open the created yaml file", zap.Error(err), zap.Any("yaml file name", fileName)) // lgtm [go/clear-text-logging]

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

Sensitive data returned by HTTP request headers
flows to a logging call.
return err
}

Expand All @@ -134,14 +144,14 @@
}
d, err := yamlLib.Marshal(&doc)
if err != nil {
ys.Logger.Error("failed to marshal the recorded calls into yaml", zap.Error(err), zap.Any("yaml file name", fileName))
ys.Logger.Error("failed to marshal the recorded calls into yaml", zap.Error(err), zap.Any("yaml file name", fileName)) // lgtm [go/clear-text-logging]
Dismissed Show dismissed Hide dismissed
return err
}
data = append(data, d...)

_, err = file.Write(data)
if err != nil {
ys.Logger.Error("failed to write the yaml document", zap.Error(err), zap.Any("yaml file name", fileName))
ys.Logger.Error("failed to write the yaml document", zap.Error(err), zap.Any("yaml file name", fileName)) // lgtm [go/clear-text-logging]

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

Sensitive data returned by HTTP request headers
flows to a logging call.
return err
}
defer file.Close()
Expand All @@ -159,7 +169,11 @@
if err != nil {
return err
}
tcsName = fmt.Sprintf("test-%v", lastIndx)
if tc.Name == "" {
tcsName = fmt.Sprintf("test-%v", lastIndx)
} else {
tcsName = tc.Name
}
} else {
tcsName = ys.TcsName
}
Expand All @@ -178,7 +192,7 @@
ys.Logger.Error("failed to write testcase yaml file", zap.Error(err))
return err
}
ys.Logger.Info("🟠 Keploy has captured test cases for the user's application.", zap.String("path", ys.TcsPath), zap.String("testcase name", tcsName))
ys.Logger.Info("🟠 Keploy has captured test cases for the user's application.", zap.String("path", ys.TcsPath), zap.String("testcase name", tcsName)) // lgtm [go/clear-text-logging]
Dismissed Show dismissed Hide dismissed

// write the mock yamls
// mockName := fmt.Sprintf("mock-%v", lastIndx)
Expand Down