fix: gofmt/gocylo leftover from old PR (#610)
This commit is contained in:
parent
1ffdd93ddf
commit
e38361f3d7
|
|
@ -81,6 +81,7 @@ func parseActionArguments(values map[string]string, action *config.Action, entit
|
||||||
return parsedShellCommand, nil
|
return parsedShellCommand, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//gocyclo:ignore
|
||||||
func redactShellCommand(shellCommand string, arguments []config.ActionArgument, argumentValues map[string]string) string {
|
func redactShellCommand(shellCommand string, arguments []config.ActionArgument, argumentValues map[string]string) string {
|
||||||
for _, arg := range arguments {
|
for _, arg := range arguments {
|
||||||
if arg.Type == "password" {
|
if arg.Type == "password" {
|
||||||
|
|
@ -92,7 +93,7 @@ func redactShellCommand(shellCommand string, arguments []config.ActionArgument,
|
||||||
}
|
}
|
||||||
|
|
||||||
if argValue == "" {
|
if argValue == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
shellCommand = strings.ReplaceAll(shellCommand, argValue, "<redacted>")
|
shellCommand = strings.ReplaceAll(shellCommand, argValue, "<redacted>")
|
||||||
|
|
@ -237,30 +238,29 @@ func typeSafetyCheckUrl(value string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func mangleInvalidArgumentValues(req *ExecutionRequest) {
|
func mangleInvalidArgumentValues(req *ExecutionRequest) {
|
||||||
mangleInvalidDatetimeValues(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
func mangleInvalidDatetimeValues(req *ExecutionRequest) {
|
|
||||||
for _, arg := range req.Action.Arguments {
|
for _, arg := range req.Action.Arguments {
|
||||||
if arg.Type == "datetime" {
|
if arg.Type == "datetime" {
|
||||||
value, exists := req.Arguments[arg.Name]
|
mangleInvalidDatetimeValues(req, &arg)
|
||||||
|
|
||||||
if !exists || value == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
timestamp, err := time.Parse("2006-01-02T15:04", value)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
log.WithFields(log.Fields {
|
|
||||||
"arg": arg.Name,
|
|
||||||
"value": value,
|
|
||||||
"actionTitle": req.Action.Title,
|
|
||||||
}).Warnf("Mangled invalid datetime value without seconds to :00 seconds, this issue is commonly caused by Android browsers.")
|
|
||||||
|
|
||||||
req.Arguments[arg.Name] = timestamp.Format("2006-01-02T15:04:05")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mangleInvalidDatetimeValues(req *ExecutionRequest, arg *config.ActionArgument) {
|
||||||
|
value, exists := req.Arguments[arg.Name]
|
||||||
|
|
||||||
|
if !exists || value == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
timestamp, err := time.Parse("2006-01-02T15:04", value)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"arg": arg.Name,
|
||||||
|
"value": value,
|
||||||
|
"actionTitle": req.Action.Title,
|
||||||
|
}).Warnf("Mangled invalid datetime value without seconds to :00 seconds, this issue is commonly caused by Android browsers.")
|
||||||
|
|
||||||
|
req.Arguments[arg.Name] = timestamp.Format("2006-01-02T15:04:05")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ func TestRedactShellCommand(t *testing.T) {
|
||||||
|
|
||||||
values := map[string]string{
|
values := map[string]string{
|
||||||
"personName": "Fred",
|
"personName": "Fred",
|
||||||
"password": "toomanysecrets",
|
"password": "toomanysecrets",
|
||||||
}
|
}
|
||||||
|
|
||||||
res := redactShellCommand(cmd, args, values)
|
res := redactShellCommand(cmd, args, values)
|
||||||
|
|
|
||||||
|
|
@ -247,11 +247,11 @@ func TestMangleInvalidArgumentValues(t *testing.T) {
|
||||||
cfg.Sanitize()
|
cfg.Sanitize()
|
||||||
|
|
||||||
req := ExecutionRequest{
|
req := ExecutionRequest{
|
||||||
Action: a1,
|
Action: a1,
|
||||||
AuthenticatedUser: acl.UserFromSystem(cfg, "testuser"),
|
AuthenticatedUser: acl.UserFromSystem(cfg, "testuser"),
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
Arguments: map[string]string{
|
Arguments: map[string]string{
|
||||||
"date": "1990-01-10T12:00", // Invalid format, should be without seconds
|
"date": "1990-01-10T12:00", // Invalid format, should be without seconds
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue