fix: Datetime mangling for Android phones #564 (#602)

This commit is contained in:
James Read 2025-06-06 21:41:54 +01:00 committed by GitHub
parent 224d7f40ed
commit 18c5599704
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 67 additions and 0 deletions

View File

@ -213,3 +213,32 @@ func typeSafetyCheckUrl(value string) error {
return err
}
func mangleInvalidArgumentValues(req *ExecutionRequest) {
mangleInvalidDatetimeValues(req)
}
func mangleInvalidDatetimeValues(req *ExecutionRequest) {
for _, arg := range req.Action.Arguments {
if arg.Type == "datetime" {
value, exists := req.Arguments[arg.Name]
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")
}
}
}
}

View File

@ -402,6 +402,8 @@ func stepParseArgs(req *ExecutionRequest) bool {
req.Arguments["ot_executionTrackingId"] = req.TrackingID
req.Arguments["ot_username"] = req.AuthenticatedUser.Username
mangleInvalidArgumentValues(req)
req.finalParsedCommand, err = parseActionArguments(req.Arguments, req.Action, req.EntityPrefix)
if err != nil {

View File

@ -129,6 +129,7 @@ func TestGetLogsLessThanPageSize(t *testing.T) {
Title: "blat",
Shell: "date",
})
cfg.Sanitize()
assert.Equal(t, int64(10), cfg.LogHistoryPageSize, "Logs page size should be 10")
@ -226,3 +227,38 @@ func TestUnusedArgumentStillPassesTypeSafetyCheck(t *testing.T) {
assert.Equal(t, "", out)
assert.NotNil(t, err)
}
// https://github.com/OliveTin/OliveTin/issues/564
func TestMangleInvalidArgumentValues(t *testing.T) {
e, cfg := testingExecutor()
a1 := &config.Action{
Title: "Validate my date without seconds because I am from an Android phone",
Shell: "echo 'The date is: {{ date }}'",
Arguments: []config.ActionArgument{
{
Name: "date",
Type: "datetime",
},
},
}
cfg.Actions = append(cfg.Actions, a1)
cfg.Sanitize()
req := ExecutionRequest{
Action: a1,
AuthenticatedUser: acl.UserFromSystem(cfg, "testuser"),
Cfg: cfg,
Arguments: map[string]string{
"date": "1990-01-10T12:00", // Invalid format, should be without seconds
},
}
wg, _ := e.ExecRequest(&req)
wg.Wait()
assert.NotNil(t, req.logEntry, "Log entry should not be nil")
assert.Equal(t, req.logEntry.Output, "The date is: 1990-01-10T12:00:00\n", "Date should be mangled to a valid format")
}