Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
Requires backport of testing infrastructure.
  • Loading branch information
efd6 committed Feb 16, 2023
1 parent 9cc651c commit ff8305a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
26 changes: 16 additions & 10 deletions winlogbeat/sys/winevent/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"time"

"github.com/stretchr/testify/assert"

"github.com/elastic/beats/v7/libbeat/common"
)

const (
Expand Down Expand Up @@ -160,9 +162,10 @@ Datos de usuario:</Message>
func TestXML(t *testing.T) {
allXMLTimeCreated, _ := time.Parse(time.RFC3339Nano, "2016-01-28T20:33:27.990735300Z")

var tests = []struct {
xml string
event Event
tests := []struct {
xml string
event Event
mapstr common.MapStr
}{
{
xml: allXML,
Expand Down Expand Up @@ -279,14 +282,14 @@ func TestXML(t *testing.T) {
RenderErrorCode: 0x3a9d,
RenderErrorDataItemName: "shellId",
},
mapstr: mapstr.M{
mapstr: common.MapStr{
"activity_id": "{BE97B1E6-710B-47D7-8941-50AB2A2C757F}",
"channel": "Microsoft-Windows-WinRM/Operational",
"computer_name": "vagrant-2012-r2",
"error": mapstr.M{
"error": common.MapStr{
"code": uint32(0x3a9d),
},
"event_data": mapstr.M{
"event_data": common.MapStr{
"Aplicación host": "C:\\WINDOWS\\System32\\WindowsPowerShell\\V1.0\\PowerShell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -Command exit 1",
"Binary": "770069006E006C006F00670062006500610074002F0034000000",
"Gravedad": "Informational",
Expand All @@ -308,9 +311,9 @@ func TestXML(t *testing.T) {
"message": "CommandInvocation(Get-Date): \"Get-Date\"\n\n\nContexto:\n Gravedad = Informational\n Nombre de host = ConsoleHost\n Versión de host = 5.1.19041.1320\n Id. de host = 56995afd-2444-424e-871c-4c5513731a3b\n Aplicación host = C:\\WINDOWS\\System32\\WindowsPowerShell\\V1.0\\PowerShell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -Command exit 1\n Versión del motor = 5.1.19041.1320\n Id. de espacio de ejecución = 91bb420c-d23e-4926-912b-6d11190df3fb\n Id. de canalización = 1\n Nombre de comando = Get-Date\n Tipo de comando = Cmdlet\n Nombre de script = C:\\WINDOWS\\Administrador\\service-1\\exec\\Invoke.ps1\n Ruta de acceso de comando =\n Número de secuencia = 4174\n Usuario = GENTE\\persona\n Usuario conectado =\n Id. de shell = Microsoft.PowerShell\n\n\nDatos de usuario:",
"opcode": "Para usar cuando la operación solo está ejecutando un método.",
"outcome": "success",
"process": mapstr.M{
"process": common.MapStr{
"pid": uint32(0x398),
"thread": mapstr.M{
"thread": common.MapStr{
"id": uint32(0x480),
},
},
Expand All @@ -320,10 +323,10 @@ func TestXML(t *testing.T) {
"related_activity_id": "{EDAD163F-52D0-4E89-BEF8-0500EC6F08AF}",
"task": "Request handling",
"time_created": allXMLTimeCreated,
"user": mapstr.M{
"user": common.MapStr{
"identifier": "S-1-5-21-4564564786-2382305473-342768465-7452",
},
"user_data": mapstr.M{
"user_data": common.MapStr{
"ServerName": "\\\\VAGRANT-2012-R2",
"UserName": "vagrant",
"xml_name": "EventXML",
Expand Down Expand Up @@ -362,6 +365,9 @@ func TestXML(t *testing.T) {
continue
}
assert.Equal(t, test.event, event)
if test.mapstr != nil {
assert.Equal(t, test.mapstr, event.Fields())
}

if testing.Verbose() {
json, err := json.MarshalIndent(event, "", " ")
Expand Down
15 changes: 2 additions & 13 deletions winlogbeat/sys/winevent/maputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ func AddPairs(m common.MapStr, key string, pairs []KeyValue) common.MapStr {
return nil
}

<<<<<<< HEAD
h := make(common.MapStr, len(pairs))
=======
// Explicitly use the unnamed type to prevent accidental use
// of mapstr.M path look-up methods.
// of common.MapStr path look-up methods.
h := make(map[string]interface{}, len(pairs))

>>>>>>> ab589cebe2 (winlogbeat/sys/winevent: do not interpret dots as JSON path separators (#34549))
for i, kv := range pairs {
// Ignore empty values.
if kv.Value == "" {
Expand All @@ -68,15 +64,8 @@ func AddPairs(m common.MapStr, key string, pairs []KeyValue) common.MapStr {
}

// Do not overwrite.
<<<<<<< HEAD
_, err := h.GetValue(k)
if err == common.ErrKeyNotFound {
_, _ = h.Put(k, sys.RemoveWindowsLineEndings(kv.Value))
} else {
=======
_, exists := h[k]
if exists {
>>>>>>> ab589cebe2 (winlogbeat/sys/winevent: do not interpret dots as JSON path separators (#34549))
debugf("Dropping key/value (k=%s, v=%s) pair because key already "+
"exists. event=%+v", k, kv.Value, m)
} else {
Expand All @@ -88,7 +77,7 @@ func AddPairs(m common.MapStr, key string, pairs []KeyValue) common.MapStr {
return nil
}

_, _ = m.Put(key, mapstr.M(h))
_, _ = m.Put(key, common.MapStr(h))

return h
}
Expand Down

0 comments on commit ff8305a

Please sign in to comment.