|
19 | 19 | package ql |
20 | 20 |
|
21 | 21 | import ( |
22 | | - "github.com/magiconair/properties/assert" |
| 22 | + "github.com/stretchr/testify/require" |
23 | 23 | "testing" |
24 | 24 | ) |
25 | 25 |
|
26 | 26 | func TestParseError(t *testing.T) { |
27 | | - err := newParseError("[", []string{"("}, 10, "ps.name in ['svchost.exe', 'cmd.exe')") |
28 | | - expected := "\nps.name in ['svchost.exe', 'cmd.exe')\n" + |
29 | | - " ^ expected (" |
30 | | - assert.Equal(t, expected, err.Error()) |
| 27 | + expr := `kevt.name in ('RegCreateKey', 'RegDeleteKey', 'RegSetValue', 'RegDeleteValue') |
| 28 | + and |
| 29 | + registry.key.name icontains |
| 30 | + ( |
| 31 | + CurrentVersion\\Run', |
| 32 | + 'Policies\\Explorer\\Run', |
| 33 | + 'Group Policy\\Scripts', |
| 34 | + 'Windows\\System\\Scripts', |
| 35 | + 'CurrentVersion\\Windows\\Load', |
| 36 | + 'CurrentVersion\\Windows\\Run', |
| 37 | + 'CurrentVersion\\Winlogon\\Shell', |
| 38 | + 'CurrentVersion\\Winlogon\\System', |
| 39 | + 'UserInitMprLogonScript' |
| 40 | + ) |
| 41 | + or |
| 42 | + registry.key.name istartswith |
| 43 | + ( |
| 44 | + 'HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\Notify', |
| 45 | + 'HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\Shell', |
| 46 | + 'HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\Userinit', |
| 47 | + 'HKEY_LOCAL_MACHINE\\Software\\WOW6432Node\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32', |
| 48 | + 'HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\BootExecute', |
| 49 | + 'HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug' |
| 50 | + ) |
| 51 | + or |
| 52 | + registry.key.name iendswith |
| 53 | + ( |
| 54 | + 'user shell folders\\startup' |
| 55 | + )` |
| 56 | + expected := `kevt.name in ('RegCreateKey', 'RegDeleteKey', 'RegSetValue', 'RegDeleteValue') |
| 57 | + and |
| 58 | + registry.key.name icontains |
| 59 | + ( |
| 60 | + CurrentVersion\\Run', |
| 61 | +╭─────────────^ |
| 62 | +| |
| 63 | +| 'Policies\\Explorer\\Run', |
| 64 | +| 'Group Policy\\Scripts', |
| 65 | +| 'Windows\\System\\Scripts', |
| 66 | +| 'CurrentVersion\\Windows\\Load', |
| 67 | +| 'CurrentVersion\\Windows\\Run', |
| 68 | +| 'CurrentVersion\\Winlogon\\Shell', |
| 69 | +| 'CurrentVersion\\Winlogon\\System', |
| 70 | +| 'UserInitMprLogonScript' |
| 71 | +| ) |
| 72 | +| or |
| 73 | +| registry.key.name istartswith |
| 74 | +| ( |
| 75 | +| 'HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\Notify', |
| 76 | +| 'HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\Shell', |
| 77 | +| 'HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\Userinit', |
| 78 | +| 'HKEY_LOCAL_MACHINE\\Software\\WOW6432Node\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32', |
| 79 | +| 'HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\BootExecute', |
| 80 | +| 'HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug' |
| 81 | +| ) |
| 82 | +| or |
| 83 | +| registry.key.name iendswith |
| 84 | +| ( |
| 85 | +| 'user shell folders\\startup' |
| 86 | +| ) |
| 87 | +| |
| 88 | +╰─────────────────── expected field, string, number, bool, ip, function, pattern binding` |
| 89 | + |
| 90 | + e := newParseError("[", []string{"field, string, number, bool, ip, function, pattern binding"}, 142, expr) |
| 91 | + require.Equal(t, expected, e.Error()) |
| 92 | + |
| 93 | + expr = `ps.name = 'cmd.exe' aand ps.cmdline contains 'ss'` |
| 94 | + e = newParseError("[", []string{"operator"}, 20, expr) |
| 95 | + |
| 96 | + expected1 := `ps.name = 'cmd.exe' aand ps.cmdline contains 'ss' |
| 97 | +╭────────────────────^ |
| 98 | +| |
| 99 | +| |
| 100 | +╰─────────────────── expected operator` |
| 101 | + |
| 102 | + require.Equal(t, expected1, e.Error()) |
31 | 103 | } |
0 commit comments