synapse 2.154.1__py311-none-any.whl → 2.156.0__py311-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of synapse might be problematic. Click here for more details.

Files changed (74) hide show
  1. synapse/cmds/cortex.py +2 -14
  2. synapse/common.py +13 -36
  3. synapse/cortex.py +15 -508
  4. synapse/lib/ast.py +215 -22
  5. synapse/lib/cell.py +35 -8
  6. synapse/lib/certdir.py +11 -0
  7. synapse/lib/cmdr.py +0 -5
  8. synapse/lib/gis.py +2 -2
  9. synapse/lib/httpapi.py +14 -43
  10. synapse/lib/layer.py +64 -201
  11. synapse/lib/lmdbslab.py +11 -0
  12. synapse/lib/node.py +1 -3
  13. synapse/lib/parser.py +10 -0
  14. synapse/lib/slabseqn.py +2 -1
  15. synapse/lib/snap.py +121 -21
  16. synapse/lib/spooled.py +9 -0
  17. synapse/lib/storm.lark +23 -6
  18. synapse/lib/storm.py +16 -339
  19. synapse/lib/storm_format.py +5 -0
  20. synapse/lib/stormhttp.py +10 -1
  21. synapse/lib/stormlib/gen.py +1 -2
  22. synapse/lib/stormlib/gis.py +41 -0
  23. synapse/lib/stormlib/graph.py +2 -1
  24. synapse/lib/stormlib/stats.py +21 -2
  25. synapse/lib/stormlib/storm.py +16 -1
  26. synapse/lib/stormtypes.py +244 -16
  27. synapse/lib/types.py +16 -2
  28. synapse/lib/version.py +2 -2
  29. synapse/lib/view.py +118 -25
  30. synapse/models/base.py +2 -2
  31. synapse/models/inet.py +60 -30
  32. synapse/models/infotech.py +130 -8
  33. synapse/models/orgs.py +3 -0
  34. synapse/models/proj.py +3 -0
  35. synapse/models/risk.py +24 -6
  36. synapse/models/syn.py +0 -38
  37. synapse/tests/test_cmds_cortex.py +1 -1
  38. synapse/tests/test_cortex.py +70 -338
  39. synapse/tests/test_lib_agenda.py +19 -54
  40. synapse/tests/test_lib_aha.py +97 -0
  41. synapse/tests/test_lib_ast.py +596 -0
  42. synapse/tests/test_lib_grammar.py +30 -10
  43. synapse/tests/test_lib_httpapi.py +33 -49
  44. synapse/tests/test_lib_layer.py +19 -234
  45. synapse/tests/test_lib_lmdbslab.py +22 -0
  46. synapse/tests/test_lib_snap.py +9 -0
  47. synapse/tests/test_lib_spooled.py +4 -0
  48. synapse/tests/test_lib_storm.py +16 -309
  49. synapse/tests/test_lib_stormlib_gis.py +21 -0
  50. synapse/tests/test_lib_stormlib_stats.py +107 -20
  51. synapse/tests/test_lib_stormlib_storm.py +25 -0
  52. synapse/tests/test_lib_stormtypes.py +253 -8
  53. synapse/tests/test_lib_types.py +40 -0
  54. synapse/tests/test_lib_view.py +6 -13
  55. synapse/tests/test_model_base.py +1 -1
  56. synapse/tests/test_model_inet.py +15 -0
  57. synapse/tests/test_model_infotech.py +110 -0
  58. synapse/tests/test_model_orgs.py +10 -0
  59. synapse/tests/test_model_person.py +0 -3
  60. synapse/tests/test_model_proj.py +2 -1
  61. synapse/tests/test_model_risk.py +24 -0
  62. synapse/tests/test_model_syn.py +20 -34
  63. synapse/tests/test_tools_csvtool.py +2 -1
  64. synapse/tests/test_tools_feed.py +4 -30
  65. synapse/tools/csvtool.py +2 -1
  66. {synapse-2.154.1.dist-info → synapse-2.156.0.dist-info}/METADATA +9 -9
  67. {synapse-2.154.1.dist-info → synapse-2.156.0.dist-info}/RECORD +70 -72
  68. {synapse-2.154.1.dist-info → synapse-2.156.0.dist-info}/WHEEL +1 -1
  69. synapse/cmds/cron.py +0 -726
  70. synapse/cmds/trigger.py +0 -319
  71. synapse/tests/test_cmds_cron.py +0 -453
  72. synapse/tests/test_cmds_trigger.py +0 -176
  73. {synapse-2.154.1.dist-info → synapse-2.156.0.dist-info}/LICENSE +0 -0
  74. {synapse-2.154.1.dist-info → synapse-2.156.0.dist-info}/top_level.txt +0 -0
@@ -1,453 +0,0 @@
1
- import asyncio
2
- import logging
3
- import datetime
4
- from datetime import timezone as tz
5
- from unittest import mock
6
-
7
- import synapse.lib.cmdr as s_cmdr
8
- import synapse.lib.provenance as s_provenance
9
-
10
- import synapse.tests.utils as s_t_utils
11
-
12
- MINSECS = 60
13
- HOURSECS = 60 * MINSECS
14
- DAYSECS = 24 * HOURSECS
15
-
16
- logger = logging.getLogger(__name__)
17
-
18
- class CmdCronTest(s_t_utils.SynTest):
19
-
20
- async def test_cron(self):
21
- MONO_DELT = 1543827303.0
22
- unixtime = datetime.datetime(year=2018, month=12, day=5, hour=7, minute=0, tzinfo=tz.utc).timestamp()
23
- s_provenance.reset()
24
-
25
- def timetime():
26
- return unixtime
27
-
28
- def looptime():
29
- return unixtime - MONO_DELT
30
-
31
- loop = asyncio.get_running_loop()
32
-
33
- with mock.patch.object(loop, 'time', looptime), mock.patch('time.time', timetime):
34
- async with self.getTestCoreAndProxy() as (realcore, core):
35
-
36
- outp = self.getTestOutp()
37
- async with await s_cmdr.getItemCmdr(core, outp=outp) as cmdr:
38
-
39
- # Various silliness
40
-
41
- await cmdr.runCmdLine('cron')
42
- self.true(outp.expect('Manages cron jobs in a cortex'))
43
- await cmdr.runCmdLine('cron timemachine')
44
- self.true(outp.expect('invalid choice'))
45
-
46
- await cmdr.runCmdLine('cron list')
47
- self.true(outp.expect('No cron jobs found'))
48
-
49
- await cmdr.runCmdLine('cron ls')
50
- self.true(outp.expect('No cron jobs found'))
51
-
52
- outp.clear()
53
-
54
- await cmdr.runCmdLine("cron add -M+1,beeroclock {[graph:node='*' :type=m1]}")
55
- self.true(outp.expect('failed to parse parameter'))
56
-
57
- await cmdr.runCmdLine("cron add -m nosuchmonth -d=-2 {#foo}")
58
- self.true(outp.expect('failed to parse fixed parameter'))
59
-
60
- outp.clear()
61
- await cmdr.runCmdLine("cron add -m 8nosuchmonth -d=-2 {#foo}")
62
- self.true(outp.expect('failed to parse fixed parameter'))
63
-
64
- await cmdr.runCmdLine("cron add -d Mon -m +3 {#foo}")
65
- self.true(outp.expect('provide a recurrence value with day of week'))
66
-
67
- await cmdr.runCmdLine("cron add -dMon -m June {#foo}")
68
- self.true(outp.expect('fix month or year with day of week'))
69
-
70
- await cmdr.runCmdLine("cron add -dMon -m +3 -y +2 {#foo}")
71
- self.true(outp.expect('more than 1 recurrence'))
72
-
73
- await cmdr.runCmdLine("cron add --year=2019 {#foo}")
74
- self.true(outp.expect('year may not be a fixed value'))
75
-
76
- await cmdr.runCmdLine("cron add {#foo}")
77
- self.true(outp.expect('must provide at least one optional'))
78
-
79
- await cmdr.runCmdLine("cron add -H3 -M +4 {#foo}")
80
- self.true(outp.expect('fixed unit may not be larger'))
81
-
82
- outp.clear()
83
- await cmdr.runCmdLine('cron add -d Tuesday,1 {#foo}')
84
- self.true(outp.expect('failed to parse day value'))
85
-
86
- outp.clear()
87
- await cmdr.runCmdLine('cron add -d Fri,3 {#foo}')
88
- self.true(outp.expect('failed to parse day value'))
89
-
90
- outp.clear()
91
- await cmdr.runCmdLine('cron add }')
92
- self.true(outp.expect('BadSyntax'))
93
-
94
- # add a mechanism on which we can wait...
95
- await realcore.nodes('$lib.queue.add(foo)')
96
-
97
- async def getNextFoo():
98
- return await asyncio.wait_for(realcore.callStorm('''
99
- $foo = $lib.queue.get(foo)
100
- ($offs, $retn) = $foo.get()
101
- $foo.cull($offs)
102
- return($retn)
103
- '''), timeout=5)
104
-
105
- ##################
106
- # Start simple: add a cron job that creates a node every minute
107
- outp.clear()
108
- await cmdr.runCmdLine("cron add -M +1 {$lib.queue.get(foo).put(bar)}")
109
- self.true(outp.expect('Created cron job'))
110
- guid = outp.mesgs[-1].strip().rsplit(' ', 1)[-1]
111
-
112
- unixtime += 60
113
- self.eq('bar', await getNextFoo())
114
-
115
- await cmdr.runCmdLine('cron list')
116
- self.true(outp.expect('(bar)'))
117
-
118
- # Make sure it ran
119
- await cmdr.runCmdLine(f"cron mod {guid[:6]} {{$lib.queue.get(foo).put(baz)}}")
120
- self.true(outp.expect('Modified cron job'))
121
- await cmdr.runCmdLine(f"cron edit xxx {{[graph:node='*' :type=m2]}}")
122
- self.true(outp.expect('does not match'))
123
-
124
- # Make sure the old one didn't run and the new query ran
125
- unixtime += 60
126
- self.eq('baz', await getNextFoo())
127
-
128
- outp.clear()
129
-
130
- # Delete the job
131
- await cmdr.runCmdLine(f"cron del {guid}")
132
- self.true(outp.expect('Deleted cron job'))
133
- await cmdr.runCmdLine(f"cron del xxx")
134
- self.true(outp.expect('does not match'))
135
- await cmdr.runCmdLine(f"cron rm xxx")
136
- self.true(outp.expect('does not match'))
137
-
138
- # Make sure deleted job didn't run
139
- unixtime += 60
140
- await asyncio.sleep(0)
141
- self.eq(0, await realcore.callStorm('return($lib.queue.get(foo).size())'))
142
-
143
- # Test fixed minute, i.e. every hour at 17 past
144
- unixtime = datetime.datetime(year=2018, month=12, day=5, hour=7, minute=10,
145
- tzinfo=tz.utc).timestamp()
146
- await cmdr.runCmdLine("cron add -M 17 {$lib.queue.get(foo).put(faz)}")
147
- guid = outp.mesgs[-1].strip().rsplit(' ', 1)[-1]
148
-
149
- unixtime += 7 * MINSECS
150
-
151
- self.eq('faz', await getNextFoo())
152
- await cmdr.runCmdLine(f"cron del {guid}")
153
-
154
- ##################
155
-
156
- # Test day increment
157
- await cmdr.runCmdLine("cron add -d +2 {$lib.queue.get(foo).put(d1)}")
158
- self.true(outp.expect('Created cron job'))
159
- guid1 = outp.mesgs[-1].strip().rsplit(' ', 1)[-1]
160
-
161
- unixtime += DAYSECS
162
-
163
- # Make sure it *didn't* run
164
- await asyncio.sleep(0)
165
- self.eq(0, await realcore.callStorm('return($lib.queue.get(foo).size())'))
166
-
167
- unixtime += DAYSECS
168
-
169
- self.eq('d1', await getNextFoo())
170
-
171
- unixtime += DAYSECS * 2
172
-
173
- outp.clear()
174
- self.eq('d1', await getNextFoo())
175
- await cmdr.runCmdLine(f"cron del {guid1}")
176
- outp.expect('Deleted cron job')
177
-
178
- ##################
179
-
180
- # Test fixed day of week: every Monday and Thursday at 3am
181
- unixtime = datetime.datetime(year=2018, month=12, day=11, hour=7, minute=10,
182
- tzinfo=tz.utc).timestamp() # A Tuesday
183
-
184
- outp.clear()
185
- await cmdr.runCmdLine("cron add -H 3 -d Mon,Thursday {$lib.queue.get(foo).put(d2)}")
186
- self.true(outp.expect('Created cron job'))
187
-
188
- guid2 = outp.mesgs[-1].strip().rsplit(' ', 1)[-1]
189
- unixtime = datetime.datetime(year=2018, month=12, day=12, hour=3, minute=10,
190
- tzinfo=tz.utc).timestamp() # Now Wednesday
191
-
192
- outp.clear()
193
- await cmdr.runCmdLine(f'cron stat {guid2}')
194
- self.true(outp.expect('last start time: Never'))
195
-
196
- unixtime = datetime.datetime(year=2018, month=12, day=13, hour=3, minute=10,
197
- tzinfo=tz.utc).timestamp() # Now Thursday
198
-
199
- self.eq('d2', await getNextFoo())
200
-
201
- outp.clear()
202
- await cmdr.runCmdLine(f'cron stat {guid2}')
203
- self.true(outp.expect('last start time: 2018'))
204
- self.true(outp.expect('dayofweek 0'))
205
-
206
- outp.clear()
207
- await cmdr.runCmdLine(f"cron del {guid2}")
208
- outp.expect('Deleted cron job')
209
-
210
- await cmdr.runCmdLine("cron add -H 3 -d Noday {[graph:node='*' :type=d2]}")
211
- self.true(outp.expect('failed to parse day value "Noday"'))
212
-
213
- ##################
214
-
215
- # Test fixed day of month: second-to-last day of month
216
- await cmdr.runCmdLine("cron add -d-2 -mDec {$lib.queue.get(foo).put(d3)}")
217
- guid = outp.mesgs[-1].strip().rsplit(' ', 1)[-1]
218
-
219
- unixtime = datetime.datetime(year=2018, month=12, day=29, hour=0, minute=0,
220
- tzinfo=tz.utc).timestamp() # Now Thursday
221
-
222
- unixtime += DAYSECS
223
-
224
- self.eq('d3', await getNextFoo())
225
-
226
- outp.clear()
227
- await cmdr.runCmdLine(f"cron del {guid}")
228
- outp.expect('Deleted cron job')
229
-
230
- ##################
231
-
232
- # Test month increment
233
-
234
- outp.clear()
235
- await cmdr.runCmdLine("cron add -m +2 -d=4 {$lib.queue.get(foo).put(month1)}")
236
- guid = outp.mesgs[-1].strip().rsplit(' ', 1)[-1]
237
- self.true(outp.expect('Created cron job'))
238
-
239
- unixtime = datetime.datetime(year=2019, month=2, day=4, hour=0, minute=0,
240
- tzinfo=tz.utc).timestamp() # Now Thursday
241
-
242
- self.eq('month1', await getNextFoo())
243
-
244
- outp.clear()
245
- await cmdr.runCmdLine(f"cron del {guid}")
246
- outp.expect('Deleted cron job')
247
-
248
- ##################
249
-
250
- # Test year increment
251
-
252
- outp.clear()
253
- await cmdr.runCmdLine("cron add -y +2 {$lib.queue.get(foo).put(year1)}")
254
- guid2 = outp.mesgs[-1].strip().rsplit(' ', 1)[-1]
255
- self.true(outp.expect('Created cron job'))
256
-
257
- unixtime = datetime.datetime(year=2021, month=1, day=1, hour=0, minute=0,
258
- tzinfo=tz.utc).timestamp() + 1 # Now Thursday
259
- self.eq('year1', await getNextFoo())
260
-
261
- outp.clear()
262
- await cmdr.runCmdLine(f'cron stat {guid2[:6]}')
263
- self.true(outp.expect("{'month': 1, 'hour': 0, 'minute': 0, 'dayofmonth': 1}"))
264
-
265
- outp.clear()
266
- await cmdr.runCmdLine(f"cron del {guid2}")
267
- outp.expect('Deleted cron job')
268
-
269
- # Make sure second-to-last day works for February
270
- outp.clear()
271
- await cmdr.runCmdLine("cron add -m February -d=-2 {$lib.queue.get(foo).put(year2)}")
272
- self.true(outp.expect('Created cron job'))
273
-
274
- unixtime = datetime.datetime(year=2021, month=2, day=27, hour=0, minute=0,
275
- tzinfo=tz.utc).timestamp() + 1 # Now Thursday
276
-
277
- self.eq('year2', await getNextFoo())
278
-
279
- ##################
280
-
281
- # Test 'at' command
282
- outp.clear()
283
- await cmdr.runCmdLine('at')
284
- self.true(outp.expect('Adds a non-recurring'))
285
-
286
- await cmdr.runCmdLine('at --not-a-real-flag')
287
- self.true(outp.expect('the following arguments'))
288
-
289
- await cmdr.runCmdLine('at {#foo}')
290
- self.true(outp.expect('at least'))
291
-
292
- await cmdr.runCmdLine('at +1 {foo:bar}')
293
- self.true(outp.expect('missing unit'))
294
-
295
- await cmdr.runCmdLine('at +1parsec {#woot}')
296
- self.true(outp.expect('Trouble parsing'))
297
-
298
- await cmdr.runCmdLine('at +1day')
299
- self.true(outp.expect('one requirement must'))
300
-
301
- await cmdr.runCmdLine("at +5 minutes {$lib.queue.get(foo).put(at1)}")
302
-
303
- unixtime += 5 * MINSECS
304
-
305
- self.eq('at1', await getNextFoo())
306
-
307
- await cmdr.runCmdLine("at +1 day +7 days {$lib.queue.get(foo).put(at2)}")
308
- guid = outp.mesgs[-1].strip().rsplit(' ', 1)[-1]
309
-
310
- unixtime += DAYSECS
311
-
312
- self.eq('at2', await getNextFoo())
313
-
314
- unixtime += 6 * DAYSECS + 1
315
-
316
- self.eq('at2', await getNextFoo())
317
-
318
- await cmdr.runCmdLine("at 202104170415 {$lib.queue.get(foo).put(at3)}")
319
-
320
- unixtime = datetime.datetime(year=2021, month=4, day=17, hour=4, minute=15,
321
- tzinfo=tz.utc).timestamp() + 1 # Now Thursday
322
-
323
- self.eq('at3', await getNextFoo())
324
- outp.clear()
325
-
326
- ##################
327
-
328
- # Test 'stat' command
329
- await cmdr.runCmdLine(f'cron stat xxx')
330
- self.true(outp.expect('provided iden does not match any'))
331
-
332
- await cmdr.runCmdLine(f'cron stat {guid[:6]}')
333
- self.true(outp.expect('last result: finished successfully with 0 nodes'))
334
- self.true(outp.expect('entries: <None>'))
335
-
336
- ##################
337
-
338
- # Test 'enable' 'disable' commands
339
- await cmdr.runCmdLine(f'cron enable xxx')
340
- self.true(outp.expect('provided iden does not match any'))
341
- outp.clear()
342
-
343
- await cmdr.runCmdLine(f'cron disable xxx')
344
- self.true(outp.expect('provided iden does not match any'))
345
- outp.clear()
346
-
347
- await cmdr.runCmdLine(f'cron disable {guid[:6]}')
348
- await cmdr.runCmdLine(f'cron stat {guid[:6]}')
349
- self.true(outp.expect(f'enabled: N'))
350
- outp.clear()
351
- await cmdr.runCmdLine(f'cron enable {guid[:6]}')
352
- await cmdr.runCmdLine(f'cron stat {guid[:6]}')
353
- self.true(outp.expect(f'enabled: Y'))
354
- outp.clear()
355
-
356
- ###################
357
-
358
- # Delete an expired at job
359
- outp.clear()
360
- await cmdr.runCmdLine(f"cron del {guid}")
361
- self.true(outp.expect('Deleted cron job'))
362
-
363
- ##################
364
-
365
- # Test the aliases
366
- outp.clear()
367
- await cmdr.runCmdLine('cron add --hourly 15 {#bar}')
368
- guid = outp.mesgs[-1].strip().rsplit(' ', 1)[-1]
369
- await cmdr.runCmdLine(f'cron stat {guid[:6]}')
370
- self.true(outp.expect("{'minute': 15}"))
371
-
372
- outp.clear()
373
- await cmdr.runCmdLine('cron add --daily 05:47 {#bar}')
374
- guid = outp.mesgs[-1].strip().rsplit(' ', 1)[-1]
375
- await cmdr.runCmdLine(f'cron stat {guid[:6]}')
376
- self.true(outp.expect("{'hour': 5, 'minute': 47"))
377
-
378
- outp.clear()
379
- await cmdr.runCmdLine('cron add --monthly=-1:12:30 {#bar}')
380
- guid = outp.mesgs[-1].strip().rsplit(' ', 1)[-1]
381
- await cmdr.runCmdLine(f'cron stat {guid[:6]}')
382
- self.true(outp.expect("{'hour': 12, 'minute': 30, 'dayofmonth': -1}"))
383
-
384
- outp.clear()
385
- await cmdr.runCmdLine('cron add --yearly 04:17:12:30 {#bar}')
386
- guid = outp.mesgs[-1].strip().rsplit(' ', 1)[-1]
387
- await cmdr.runCmdLine(f'cron stat {guid[:6]}')
388
- self.true(outp.expect("{'month': 4, 'hour': 12, 'minute': 30, 'dayofmonth': 17}"))
389
-
390
- outp.clear()
391
- await cmdr.runCmdLine('cron add --yearly 04:17:12 {#bar}')
392
- self.true(outp.expect('Failed to parse parameter'))
393
-
394
- outp.clear()
395
- await cmdr.runCmdLine('cron add --daily xx:xx {#bar}')
396
- self.true(outp.expect('Failed to parse ..ly parameter'))
397
-
398
- outp.clear()
399
- await cmdr.runCmdLine('cron add --hourly 1 -M 17 {#bar}')
400
- self.true(outp.expect('may not use both'))
401
-
402
- # Test manipulating cron jobs as another user
403
- bond = await realcore.auth.addUser('bond')
404
-
405
- async with realcore.getLocalProxy(user='bond') as tcore:
406
- toutp = self.getTestOutp()
407
- tcmdr = await s_cmdr.getItemCmdr(tcore, outp=toutp)
408
-
409
- await tcmdr.runCmdLine('cron list')
410
- self.true(toutp.expect('No cron jobs found'))
411
-
412
- toutp.clear()
413
- await tcmdr.runCmdLine(f'cron disable {guid[:6]}')
414
- self.true(toutp.expect('provided iden does not match'))
415
-
416
- toutp.clear()
417
- await tcmdr.runCmdLine(f'cron enable {guid[:6]}')
418
- self.true(toutp.expect('provided iden does not match'))
419
-
420
- toutp.clear()
421
- await tcmdr.runCmdLine(f'cron edit {guid[:6]} {{#foo}}')
422
- self.true(toutp.expect('provided iden does not match'))
423
-
424
- toutp.clear()
425
- await tcmdr.runCmdLine(f'cron del {guid[:6]}')
426
- self.true(toutp.expect('provided iden does not match'))
427
-
428
- # Give explicit perm
429
- await core.addUserRule(bond.iden, (True, ('cron', 'get')))
430
-
431
- toutp.clear()
432
- await tcmdr.runCmdLine('cron list')
433
- self.true(toutp.expect('root'))
434
-
435
- await core.addUserRule(bond.iden, (True, ('cron', 'set')))
436
-
437
- toutp.clear()
438
- await tcmdr.runCmdLine(f'cron disable {guid[:6]}')
439
- self.true(toutp.expect('Disabled cron job'))
440
-
441
- toutp.clear()
442
- await tcmdr.runCmdLine(f'cron enable {guid[:6]}')
443
- self.true(toutp.expect('Enabled cron job'))
444
-
445
- toutp.clear()
446
- await tcmdr.runCmdLine(f'cron edit {guid[:6]} {{#foo}}')
447
- self.true(toutp.expect('Modified cron job'))
448
-
449
- await core.addUserRule(bond.iden, (True, ('cron', 'del')))
450
-
451
- toutp.clear()
452
- await tcmdr.runCmdLine(f'cron del {guid[:6]}')
453
- self.true(toutp.expect('Deleted cron job'))
@@ -1,176 +0,0 @@
1
- import synapse.common as s_common
2
-
3
- import synapse.lib.cmdr as s_cmdr
4
-
5
- import synapse.tests.utils as s_t_utils
6
-
7
- class CmdTriggersTest(s_t_utils.SynTest):
8
-
9
- async def test_triggers(self):
10
-
11
- async with self.getTestCoreAndProxy() as (realcore, core):
12
-
13
- outp = self.getTestOutp()
14
- cmdr = await s_cmdr.getItemCmdr(core, outp=outp)
15
-
16
- await cmdr.runCmdLine('trigger list')
17
- self.true(outp.expect('No triggers found'))
18
-
19
- await cmdr.runCmdLine('trigger add node:add test:str {[ test:int=1 ] }')
20
- trigs = await realcore.view.listTriggers()
21
- self.len(1, trigs)
22
- self.true(outp.expect(f'Added trigger {trigs[0][0]}'))
23
- self.eq(1, await core.count('[ test:str=foo ]'))
24
- self.eq(1, await core.count('test:int'))
25
-
26
- await cmdr.runCmdLine('trigger add tag:add test:str #footag.* {[ +#count test:str=$tag ]}')
27
- self.eq(1, await core.count('[ test:str=bar +#footag.bar ]'))
28
- self.eq(1, await core.count('#count'))
29
- self.eq(1, await core.count('test:str=footag.bar'))
30
-
31
- await cmdr.runCmdLine('trigger add prop:set --disabled test:type10:intprop {[ test:int=6 ]}')
32
- outp.clear()
33
- await cmdr.runCmdLine('trigger list')
34
- self.true(outp.expect('user'))
35
- self.true(outp.expect('root'))
36
- goodbuid = outp.mesgs[-2].split()[1][:6]
37
- goodbuid2 = outp.mesgs[-1].split()[1][:6]
38
-
39
- # Trigger is created disabled, so no nodes yet
40
- self.eq(0, await core.count('test:int=6'))
41
- await cmdr.runCmdLine(f'trigger enable {goodbuid2}')
42
-
43
- # Trigger is enabled, so it should fire
44
- self.eq(1, await core.count('[ test:type10=1 :intprop=25 ]'))
45
- self.eq(1, await core.count('test:int=6'))
46
-
47
- await cmdr.runCmdLine(f'trigger del {goodbuid}')
48
- self.true(outp.expect('Deleted trigger'))
49
-
50
- await cmdr.runCmdLine(f'trigger del deadbeef12341234')
51
- self.true(outp.expect('does not match'))
52
-
53
- outp.clear()
54
- await cmdr.runCmdLine(f'trigger enable deadbeef12341234')
55
- self.true(outp.expect('does not match'))
56
-
57
- outp.clear()
58
- await cmdr.runCmdLine(f'trigger disable deadbeef12341234')
59
- self.true(outp.expect('does not match'))
60
-
61
- await cmdr.runCmdLine(f'trigger disable {goodbuid2}')
62
- self.true(outp.expect('Disabled trigger'))
63
-
64
- await cmdr.runCmdLine(f'trigger enable {goodbuid2}')
65
- self.true(outp.expect('Enabled trigger'))
66
-
67
- await cmdr.runCmdLine(f'trigger mod {goodbuid2} {{[ test:str=different ]}}')
68
- self.true(outp.expect('Modified trigger'))
69
-
70
- outp.clear()
71
- await cmdr.runCmdLine('trigger mod deadbeef12341234 {#foo}')
72
- self.true(outp.expect('does not match'))
73
-
74
- await cmdr.runCmdLine('trigger add tag:add #another {[ +#count2 ]}')
75
-
76
- # Syntax mistakes
77
- await cmdr.runCmdLine(f'trigger')
78
- self.true(outp.expect('Manipulate triggers in a '))
79
-
80
- await cmdr.runCmdLine('trigger add tag:add another {[ +#count2 ]}')
81
- self.true(outp.expect('Missing tag parameter'))
82
-
83
- await cmdr.runCmdLine('trigger add tug:udd another {[ +#count2 ]}')
84
- self.true(outp.expect('invalid choice'))
85
-
86
- await cmdr.runCmdLine('trigger add tag:add')
87
- self.true(outp.expect('trigger add: error: the following'))
88
-
89
- await cmdr.runCmdLine('trigger add tag:add inet:ipv4')
90
- self.true(outp.expect('Missing argument for trigger add'))
91
-
92
- await cmdr.runCmdLine('trigger add')
93
- self.true(outp.expect('Add triggers in a cortex.'))
94
-
95
- await cmdr.runCmdLine('trigger add tag:add {test:str} {test:str}')
96
- self.true(outp.expect('Missing tag param'))
97
-
98
- await cmdr.runCmdLine('trigger add node:add test:str #foo {test:str}')
99
- self.true(outp.expect('node:* does not support'))
100
-
101
- await cmdr.runCmdLine('trigger add prop:set #foo {test:str}')
102
- self.true(outp.expect('Missing prop parameter'))
103
-
104
- await cmdr.runCmdLine('trigger add prop:set test:type10.intprop #foo {test:str}')
105
- self.true(outp.expect('prop:set does not support a tag'))
106
-
107
- await cmdr.runCmdLine('trigger add node:add test:str test:int {test:str}')
108
- self.true(outp.expect('Only a single form'))
109
-
110
- await cmdr.runCmdLine('trigger add prop:set test:type10.intprop test:str {test:str}')
111
- self.true(outp.expect('single prop'))
112
-
113
- await cmdr.runCmdLine('trigger add node:add #tag1 {test:str}')
114
- self.true(outp.expect('Missing form'))
115
-
116
- # Bad storm syntax
117
- await cmdr.runCmdLine('trigger add node:add test:str {[ | | test:int=1 ] }')
118
- self.true(outp.expect('BadSyntax'))
119
-
120
- # (Regression) Just a command as the storm query
121
- await cmdr.runCmdLine('trigger add Node:add test:str {[ test:int=99 ] | spin }')
122
- self.eq(1, await core.count('[ test:str=foo4 ]'))
123
- self.eq(1, await core.count('test:int=99'))
124
-
125
- # Test manipulating triggers as another user
126
- bond = await realcore.auth.addUser('bond')
127
-
128
- async with realcore.getLocalProxy(user='bond') as tcore:
129
-
130
- toutp = self.getTestOutp()
131
- tcmdr = await s_cmdr.getItemCmdr(tcore, outp=toutp)
132
-
133
- await tcmdr.runCmdLine('trigger list')
134
- self.true(toutp.expect('No triggers found'))
135
-
136
- await tcmdr.runCmdLine(f'trigger mod {goodbuid2} {{[ test:str=yep ]}}')
137
- self.true(toutp.expect('provided iden does not match'))
138
-
139
- toutp.clear()
140
- await tcmdr.runCmdLine(f'trigger disable {goodbuid2}')
141
- self.true(toutp.expect('provided iden does not match'))
142
-
143
- toutp.clear()
144
- await tcmdr.runCmdLine(f'trigger enable {goodbuid2}')
145
- self.true(toutp.expect('provided iden does not match'))
146
-
147
- toutp.clear()
148
- await tcmdr.runCmdLine(f'trigger del {goodbuid2}')
149
- self.true(toutp.expect('provided iden does not match'))
150
-
151
- # Give explicit perm
152
- await core.addUserRule(bond.iden, (True, ('trigger', 'get')))
153
-
154
- toutp.clear()
155
- await tcmdr.runCmdLine('trigger list')
156
- self.true(toutp.expect('root'))
157
-
158
- await core.addUserRule(bond.iden, (True, ('trigger', 'set')))
159
-
160
- toutp.clear()
161
- await tcmdr.runCmdLine(f'trigger mod {goodbuid2} {{[ test:str=yep ]}}')
162
- self.true(toutp.expect('Modified trigger'))
163
-
164
- toutp.clear()
165
- await tcmdr.runCmdLine(f'trigger disable {goodbuid2}')
166
- self.true(toutp.expect('Disabled trigger '))
167
-
168
- toutp.clear()
169
- await tcmdr.runCmdLine(f'trigger enable {goodbuid2}')
170
- self.true(toutp.expect('Enabled trigger '))
171
-
172
- await core.addUserRule(bond.iden, (True, ('trigger', 'del')))
173
-
174
- toutp.clear()
175
- await tcmdr.runCmdLine(f'trigger del {goodbuid2}')
176
- self.true(toutp.expect('Deleted trigger '))