synapse 2.164.0__py311-none-any.whl → 2.166.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.
- synapse/axon.py +3 -3
- synapse/cmds/cortex.py +1 -6
- synapse/common.py +7 -1
- synapse/cortex.py +145 -192
- synapse/datamodel.py +36 -1
- synapse/lib/agenda.py +87 -97
- synapse/lib/aha.py +51 -0
- synapse/lib/ast.py +22 -23
- synapse/lib/base.py +0 -6
- synapse/lib/boss.py +3 -0
- synapse/lib/cell.py +70 -39
- synapse/lib/certdir.py +9 -0
- synapse/lib/hiveauth.py +65 -12
- synapse/lib/httpapi.py +1 -0
- synapse/lib/modelrev.py +121 -33
- synapse/lib/modules.py +1 -0
- synapse/lib/nexus.py +64 -26
- synapse/lib/parser.py +2 -0
- synapse/lib/schemas.py +14 -0
- synapse/lib/snap.py +50 -4
- synapse/lib/storm.lark +4 -3
- synapse/lib/storm.py +96 -22
- synapse/lib/storm_format.py +1 -0
- synapse/lib/stormlib/aha.py +7 -1
- synapse/lib/stormlib/auth.py +13 -5
- synapse/lib/stormlib/cache.py +202 -0
- synapse/lib/stormlib/cortex.py +147 -8
- synapse/lib/stormlib/gen.py +53 -6
- synapse/lib/stormlib/math.py +1 -1
- synapse/lib/stormlib/model.py +11 -1
- synapse/lib/stormlib/spooled.py +109 -0
- synapse/lib/stormlib/vault.py +1 -1
- synapse/lib/stormtypes.py +113 -17
- synapse/lib/trigger.py +36 -47
- synapse/lib/types.py +29 -2
- synapse/lib/version.py +2 -2
- synapse/lib/view.py +80 -53
- synapse/models/economic.py +174 -5
- synapse/models/files.py +2 -0
- synapse/models/inet.py +77 -2
- synapse/models/infotech.py +12 -12
- synapse/models/orgs.py +72 -21
- synapse/models/person.py +40 -11
- synapse/models/risk.py +78 -24
- synapse/models/science.py +102 -0
- synapse/telepath.py +117 -35
- synapse/tests/test_cortex.py +84 -158
- synapse/tests/test_datamodel.py +22 -0
- synapse/tests/test_lib_agenda.py +52 -96
- synapse/tests/test_lib_aha.py +126 -4
- synapse/tests/test_lib_ast.py +412 -6
- synapse/tests/test_lib_cell.py +24 -8
- synapse/tests/test_lib_certdir.py +32 -0
- synapse/tests/test_lib_grammar.py +9 -1
- synapse/tests/test_lib_httpapi.py +0 -1
- synapse/tests/test_lib_jupyter.py +0 -1
- synapse/tests/test_lib_modelrev.py +41 -0
- synapse/tests/test_lib_nexus.py +38 -0
- synapse/tests/test_lib_storm.py +95 -5
- synapse/tests/test_lib_stormlib_cache.py +272 -0
- synapse/tests/test_lib_stormlib_cortex.py +71 -0
- synapse/tests/test_lib_stormlib_gen.py +37 -2
- synapse/tests/test_lib_stormlib_model.py +2 -0
- synapse/tests/test_lib_stormlib_spooled.py +190 -0
- synapse/tests/test_lib_stormlib_vault.py +12 -3
- synapse/tests/test_lib_stormsvc.py +0 -10
- synapse/tests/test_lib_stormtypes.py +60 -8
- synapse/tests/test_lib_trigger.py +20 -2
- synapse/tests/test_lib_types.py +17 -1
- synapse/tests/test_model_economic.py +114 -0
- synapse/tests/test_model_files.py +2 -0
- synapse/tests/test_model_inet.py +73 -1
- synapse/tests/test_model_infotech.py +2 -2
- synapse/tests/test_model_orgs.py +10 -1
- synapse/tests/test_model_risk.py +30 -2
- synapse/tests/test_model_science.py +59 -0
- synapse/tests/test_model_syn.py +0 -1
- synapse/tests/test_telepath.py +30 -7
- synapse/tests/test_tools_modrole.py +81 -0
- synapse/tests/test_tools_moduser.py +105 -0
- synapse/tools/modrole.py +59 -7
- synapse/tools/moduser.py +78 -10
- {synapse-2.164.0.dist-info → synapse-2.166.0.dist-info}/METADATA +2 -2
- {synapse-2.164.0.dist-info → synapse-2.166.0.dist-info}/RECORD +87 -83
- {synapse-2.164.0.dist-info → synapse-2.166.0.dist-info}/WHEEL +1 -1
- synapse/lib/provenance.py +0 -111
- synapse/tests/test_lib_provenance.py +0 -37
- {synapse-2.164.0.dist-info → synapse-2.166.0.dist-info}/LICENSE +0 -0
- {synapse-2.164.0.dist-info → synapse-2.166.0.dist-info}/top_level.txt +0 -0
synapse/tests/test_cortex.py
CHANGED
|
@@ -3084,7 +3084,6 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
3084
3084
|
otherpkg = {
|
|
3085
3085
|
'name': 'foosball',
|
|
3086
3086
|
'version': '0.0.1',
|
|
3087
|
-
'synapse_minversion': (2, 144, 0),
|
|
3088
3087
|
'synapse_version': '>=2.8.0,<3.0.0',
|
|
3089
3088
|
}
|
|
3090
3089
|
self.none(await proxy.addStormPkg(otherpkg))
|
|
@@ -3138,7 +3137,7 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
3138
3137
|
oldverpkg = {
|
|
3139
3138
|
'name': 'versionfail',
|
|
3140
3139
|
'version': (0, 0, 1),
|
|
3141
|
-
'
|
|
3140
|
+
'synapse_version': '>=1337.0.0,<2000.0.0',
|
|
3142
3141
|
'commands': ()
|
|
3143
3142
|
}
|
|
3144
3143
|
|
|
@@ -3148,7 +3147,6 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
3148
3147
|
oldverpkg = {
|
|
3149
3148
|
'name': 'versionfail',
|
|
3150
3149
|
'version': (0, 0, 1),
|
|
3151
|
-
'synapse_minversion': [2, 144, 0],
|
|
3152
3150
|
'synapse_version': '>=1337.0.0,<2000.0.0',
|
|
3153
3151
|
'commands': ()
|
|
3154
3152
|
}
|
|
@@ -3159,7 +3157,6 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
3159
3157
|
oldverpkg = {
|
|
3160
3158
|
'name': 'versionfail',
|
|
3161
3159
|
'version': (0, 0, 1),
|
|
3162
|
-
'synapse_minversion': [2, 144, 0],
|
|
3163
3160
|
'synapse_version': '>=0.0.1,<2.0.0',
|
|
3164
3161
|
'commands': ()
|
|
3165
3162
|
}
|
|
@@ -3173,7 +3170,6 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
3173
3170
|
'commands': ()
|
|
3174
3171
|
}
|
|
3175
3172
|
|
|
3176
|
-
# Package with no synapse_minversion shouldn't raise
|
|
3177
3173
|
await core.addStormPkg(noverpkg)
|
|
3178
3174
|
|
|
3179
3175
|
badcmdpkg = {
|
|
@@ -3225,83 +3221,6 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
3225
3221
|
self.eq(node, arg_hit['hit'][0])
|
|
3226
3222
|
self.eq(arg_hit['hit'][1], 'weee')
|
|
3227
3223
|
|
|
3228
|
-
async def test_cortex_onofftag(self):
|
|
3229
|
-
|
|
3230
|
-
async with self.getTestCore() as core:
|
|
3231
|
-
|
|
3232
|
-
tags = {}
|
|
3233
|
-
|
|
3234
|
-
def onadd(node, tag, valu):
|
|
3235
|
-
tags[tag] = valu
|
|
3236
|
-
|
|
3237
|
-
def ondel(node, tag, valu):
|
|
3238
|
-
self.none(node.getTag(tag))
|
|
3239
|
-
self.false(node.hasTag(tag))
|
|
3240
|
-
tags.pop(tag)
|
|
3241
|
-
|
|
3242
|
-
core.onTagAdd('foo', onadd)
|
|
3243
|
-
core.onTagAdd('foo.bar', onadd)
|
|
3244
|
-
core.onTagAdd('foo.bar.baz', onadd)
|
|
3245
|
-
|
|
3246
|
-
core.onTagDel('foo', ondel)
|
|
3247
|
-
core.onTagDel('foo.bar', ondel)
|
|
3248
|
-
core.onTagDel('foo.bar.baz', ondel)
|
|
3249
|
-
|
|
3250
|
-
core.onTagAdd('glob.*', onadd)
|
|
3251
|
-
core.onTagDel('glob.*', ondel)
|
|
3252
|
-
|
|
3253
|
-
nodes = await core.nodes('[test:str=hehe]')
|
|
3254
|
-
self.len(1, nodes)
|
|
3255
|
-
node = nodes[0]
|
|
3256
|
-
await node.addTag('foo.bar.baz', valu=(200, 300))
|
|
3257
|
-
|
|
3258
|
-
self.eq(tags.get('foo'), (None, None))
|
|
3259
|
-
self.eq(tags.get('foo.bar'), (None, None))
|
|
3260
|
-
self.eq(tags.get('foo.bar.baz'), (200, 300))
|
|
3261
|
-
|
|
3262
|
-
await node.delTag('foo.bar')
|
|
3263
|
-
|
|
3264
|
-
self.eq(tags.get('foo'), (None, None))
|
|
3265
|
-
|
|
3266
|
-
self.none(tags.get('foo.bar'))
|
|
3267
|
-
self.none(tags.get('foo.bar.baz'))
|
|
3268
|
-
|
|
3269
|
-
core.offTagAdd('foo.bar', onadd)
|
|
3270
|
-
core.offTagDel('foo.bar', ondel)
|
|
3271
|
-
core.offTagAdd('foo.bar', lambda x: 0)
|
|
3272
|
-
core.offTagDel('foo.bar', lambda x: 0)
|
|
3273
|
-
|
|
3274
|
-
await node.addTag('foo.bar', valu=(200, 300))
|
|
3275
|
-
self.none(tags.get('foo.bar'))
|
|
3276
|
-
|
|
3277
|
-
tags['foo.bar'] = 'fake'
|
|
3278
|
-
await node.delTag('foo.bar')
|
|
3279
|
-
self.eq(tags.get('foo.bar'), 'fake')
|
|
3280
|
-
|
|
3281
|
-
# Coverage for removing something from a
|
|
3282
|
-
# tag we never added a handler for.
|
|
3283
|
-
core.offTagAdd('test.newp', lambda x: 0)
|
|
3284
|
-
core.offTagDel('test.newp', lambda x: 0)
|
|
3285
|
-
|
|
3286
|
-
# Test tag glob handlers
|
|
3287
|
-
await node.addTag('glob.foo', valu=(200, 300))
|
|
3288
|
-
self.eq(tags.get('glob.foo'), (200, 300))
|
|
3289
|
-
|
|
3290
|
-
await node.delTag('glob.foo')
|
|
3291
|
-
self.none(tags.get('glob.foo'))
|
|
3292
|
-
|
|
3293
|
-
await node.addTag('glob.foo.bar', valu=(200, 300))
|
|
3294
|
-
self.none(tags.get('glob.foo.bar'))
|
|
3295
|
-
|
|
3296
|
-
# Test handlers don't run after removed
|
|
3297
|
-
core.offTagAdd('glob.*', onadd)
|
|
3298
|
-
core.offTagDel('glob.*', ondel)
|
|
3299
|
-
await node.addTag('glob.faz', valu=(200, 300))
|
|
3300
|
-
self.none(tags.get('glob.faz'))
|
|
3301
|
-
tags['glob.faz'] = (1, 2)
|
|
3302
|
-
await node.delTag('glob.faz')
|
|
3303
|
-
self.eq(tags['glob.faz'], (1, 2))
|
|
3304
|
-
|
|
3305
3224
|
async def test_storm_logging(self):
|
|
3306
3225
|
async with self.getTestCoreAndProxy() as (realcore, core):
|
|
3307
3226
|
view = await core.callStorm('return( $lib.view.get().iden )')
|
|
@@ -4645,10 +4564,9 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
4645
4564
|
await core1.addFeedData('syn.nodes', data)
|
|
4646
4565
|
self.len(1, await core1.nodes('test:int=8 -#test.12345'))
|
|
4647
4566
|
|
|
4648
|
-
# This tag does match regex
|
|
4649
4567
|
data = [(('test:int', 8), {'tags': {'test.1234': (None, None)}})]
|
|
4650
4568
|
await core1.addFeedData('syn.nodes', data)
|
|
4651
|
-
self.len(0, await core1.nodes('test:int=8 -#
|
|
4569
|
+
self.len(0, await core1.nodes('test:int=8 -#newtag.1234'))
|
|
4652
4570
|
|
|
4653
4571
|
core1.view.layers[0].readonly = True
|
|
4654
4572
|
await self.asyncraises(s_exc.IsReadOnly, core1.addFeedData('syn.nodes', data))
|
|
@@ -6400,66 +6318,6 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
6400
6318
|
msgs = await core.stormlist('cron.list')
|
|
6401
6319
|
self.stormIsInPrint('$lib.print(woot)', msgs)
|
|
6402
6320
|
|
|
6403
|
-
async def test_cortex_migrationmode(self):
|
|
6404
|
-
async with self.getTestCore() as core:
|
|
6405
|
-
async with core.getLocalProxy(user='root') as prox:
|
|
6406
|
-
|
|
6407
|
-
await prox.addUser('fred', passwd='secret')
|
|
6408
|
-
|
|
6409
|
-
self.true(core.agenda.enabled)
|
|
6410
|
-
self.true(core.trigson)
|
|
6411
|
-
async with await core.snap() as snap:
|
|
6412
|
-
self.true(snap.trigson)
|
|
6413
|
-
|
|
6414
|
-
# add triggers
|
|
6415
|
-
# node:add case
|
|
6416
|
-
tdef = {'cond': 'node:add', 'form': 'test:str', 'storm': '[ test:int=1 ]'}
|
|
6417
|
-
await core.view.addTrigger(tdef)
|
|
6418
|
-
await core.nodes('[ test:str=foo ]')
|
|
6419
|
-
self.len(1, await core.nodes('test:int'))
|
|
6420
|
-
|
|
6421
|
-
# node:del case
|
|
6422
|
-
tdef = {'cond': 'node:del', 'storm': '[ test:int=2 ]', 'form': 'test:str'}
|
|
6423
|
-
await core.view.addTrigger(tdef)
|
|
6424
|
-
await core.nodes('test:str=foo | delnode')
|
|
6425
|
-
self.len(2, await core.nodes('test:int'))
|
|
6426
|
-
|
|
6427
|
-
# tag:add case
|
|
6428
|
-
tdef = {'cond': 'tag:add', 'storm': '[ test:int=3 ]', 'tag': 'footag'}
|
|
6429
|
-
await core.view.addTrigger(tdef)
|
|
6430
|
-
await core.nodes('[ test:str=foo +#footag ]')
|
|
6431
|
-
self.len(3, await core.nodes('test:int'))
|
|
6432
|
-
|
|
6433
|
-
# enable migration mode
|
|
6434
|
-
await prox.enableMigrationMode()
|
|
6435
|
-
|
|
6436
|
-
self.false(core.agenda.enabled)
|
|
6437
|
-
self.false(core.trigson)
|
|
6438
|
-
async with await core.snap() as snap:
|
|
6439
|
-
self.false(snap.trigson)
|
|
6440
|
-
|
|
6441
|
-
# check that triggers don't fire
|
|
6442
|
-
await core.nodes('test:int | delnode')
|
|
6443
|
-
await core.nodes('[test:str=foo] [+#footag] | delnode')
|
|
6444
|
-
self.len(0, await core.nodes('test:int'))
|
|
6445
|
-
|
|
6446
|
-
# disable migration mode
|
|
6447
|
-
await prox.disableMigrationMode()
|
|
6448
|
-
|
|
6449
|
-
self.true(core.agenda.enabled)
|
|
6450
|
-
self.true(core.trigson)
|
|
6451
|
-
async with await core.snap() as snap:
|
|
6452
|
-
self.true(snap.trigson)
|
|
6453
|
-
|
|
6454
|
-
# check that triggers fire
|
|
6455
|
-
await core.nodes('[test:str=foo] [+#footag] | delnode')
|
|
6456
|
-
self.len(3, await core.nodes('test:int'))
|
|
6457
|
-
|
|
6458
|
-
async with core.getLocalProxy(user='fred') as prox:
|
|
6459
|
-
# non-admin cannot enable/disable migration mode
|
|
6460
|
-
await self.asyncraises(s_exc.AuthDeny, prox.enableMigrationMode())
|
|
6461
|
-
await self.asyncraises(s_exc.AuthDeny, prox.disableMigrationMode())
|
|
6462
|
-
|
|
6463
6321
|
async def test_cortex_behold(self):
|
|
6464
6322
|
async with self.getTestCore() as core:
|
|
6465
6323
|
async with core.getLocalProxy() as prox:
|
|
@@ -6470,7 +6328,6 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
6470
6328
|
{ # type: ignore
|
|
6471
6329
|
'name': 'foo',
|
|
6472
6330
|
'version': (0, 0, 1),
|
|
6473
|
-
'synapse_minversion': [2, 144, 0],
|
|
6474
6331
|
'synapse_version': '>=2.100.0,<3.0.0',
|
|
6475
6332
|
'modules': [],
|
|
6476
6333
|
'commands': []
|
|
@@ -6578,7 +6435,7 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
6578
6435
|
'name': 'boom',
|
|
6579
6436
|
'desc': 'The boom Module',
|
|
6580
6437
|
'version': (0, 0, 1),
|
|
6581
|
-
'
|
|
6438
|
+
'synapse_version': '>=2.8.0,<3.0.0',
|
|
6582
6439
|
'modules': [
|
|
6583
6440
|
{
|
|
6584
6441
|
'name': 'boom.mod',
|
|
@@ -6651,6 +6508,21 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
6651
6508
|
self.eq(cm.exception.errinfo.get('mesg'),
|
|
6652
6509
|
"Storm package boom has unknown config var type newp.")
|
|
6653
6510
|
|
|
6511
|
+
# Check no synapse_version and synapse_minversion > cortex version
|
|
6512
|
+
minver = list(s_version.version)
|
|
6513
|
+
minver[1] += 1
|
|
6514
|
+
minver = tuple(minver)
|
|
6515
|
+
|
|
6516
|
+
pkg = copy.deepcopy(base_pkg)
|
|
6517
|
+
pkg.pop('synapse_version')
|
|
6518
|
+
pkg['synapse_minversion'] = minver
|
|
6519
|
+
pkgname = pkg.get('name')
|
|
6520
|
+
|
|
6521
|
+
with self.raises(s_exc.BadVersion) as cm:
|
|
6522
|
+
await core.addStormPkg(pkg)
|
|
6523
|
+
mesg = f'Storm package {pkgname} requires Synapse {minver} but Cortex is running {s_version.version}'
|
|
6524
|
+
self.eq(cm.exception.errinfo.get('mesg'), mesg)
|
|
6525
|
+
|
|
6654
6526
|
async def test_cortex_view_persistence(self):
|
|
6655
6527
|
with self.getTestDir() as dirn:
|
|
6656
6528
|
async with self.getTestCore(dirn=dirn) as core:
|
|
@@ -7916,11 +7788,6 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
7916
7788
|
dirn00 = s_common.genpath(dirn, 'cell00')
|
|
7917
7789
|
dirn01 = s_common.genpath(dirn, 'cell01')
|
|
7918
7790
|
|
|
7919
|
-
conf = {
|
|
7920
|
-
'storm:pool': 'aha://pool00...',
|
|
7921
|
-
'storm:pool:timeout:sync': 1,
|
|
7922
|
-
'storm:pool:timeout:connection': 1
|
|
7923
|
-
}
|
|
7924
7791
|
core00 = await base.enter_context(self.addSvcToAha(aha, '00.core', s_cortex.Cortex, dirn=dirn00))
|
|
7925
7792
|
provinfo = {'mirror': '00.core'}
|
|
7926
7793
|
core01 = await base.enter_context(self.addSvcToAha(aha, '01.core', s_cortex.Cortex, dirn=dirn01, provinfo=provinfo))
|
|
@@ -7929,6 +7796,10 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
7929
7796
|
await core01.sync()
|
|
7930
7797
|
self.len(1, await core01.nodes('inet:asn=0'))
|
|
7931
7798
|
|
|
7799
|
+
msgs = await core00.stormlist('cortex.storm.pool.get')
|
|
7800
|
+
self.stormHasNoWarnErr(msgs)
|
|
7801
|
+
self.stormIsInPrint('No Storm pool configuration found.', msgs)
|
|
7802
|
+
|
|
7932
7803
|
msgs = await core00.stormlist('aha.pool.add pool00...')
|
|
7933
7804
|
self.stormHasNoWarnErr(msgs)
|
|
7934
7805
|
self.stormIsInPrint('Created AHA service pool: pool00.loop.vertex.link', msgs)
|
|
@@ -7937,9 +7808,18 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
7937
7808
|
self.stormHasNoWarnErr(msgs)
|
|
7938
7809
|
self.stormIsInPrint('AHA service (01.core...) added to service pool (pool00.loop.vertex.link)', msgs)
|
|
7939
7810
|
|
|
7811
|
+
msgs = await core00.stormlist('cortex.storm.pool.set newp')
|
|
7812
|
+
self.stormIsInErr(':// not found in [newp]', msgs)
|
|
7813
|
+
|
|
7814
|
+
msgs = await core00.stormlist('cortex.storm.pool.set --connection-timeout 1 --sync-timeout 1 aha://pool00...')
|
|
7815
|
+
self.stormHasNoWarnErr(msgs)
|
|
7816
|
+
self.stormIsInPrint('Storm pool configuration set.', msgs)
|
|
7817
|
+
|
|
7940
7818
|
await core00.fini()
|
|
7941
7819
|
|
|
7942
|
-
core00 = await base.enter_context(self.getTestCore(dirn=dirn00
|
|
7820
|
+
core00 = await base.enter_context(self.getTestCore(dirn=dirn00))
|
|
7821
|
+
|
|
7822
|
+
await core00.stormpool.waitready(timeout=12)
|
|
7943
7823
|
|
|
7944
7824
|
with self.getLoggerStream('synapse') as stream:
|
|
7945
7825
|
msgs = await alist(core00.storm('inet:asn=0'))
|
|
@@ -8030,30 +7910,30 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
8030
7910
|
|
|
8031
7911
|
stream.seek(0)
|
|
8032
7912
|
data = stream.read()
|
|
8033
|
-
self.isin('
|
|
7913
|
+
self.isin('Storm query mirror pool is empty, running query locally.', data)
|
|
8034
7914
|
|
|
8035
7915
|
with self.getLoggerStream('synapse') as stream:
|
|
8036
7916
|
self.true(await core00.callStorm('inet:asn=0 return($lib.true)'))
|
|
8037
7917
|
|
|
8038
7918
|
stream.seek(0)
|
|
8039
7919
|
data = stream.read()
|
|
8040
|
-
self.isin('
|
|
7920
|
+
self.isin('Storm query mirror pool is empty, running query locally.', data)
|
|
8041
7921
|
|
|
8042
7922
|
with self.getLoggerStream('synapse') as stream:
|
|
8043
7923
|
self.len(1, await alist(core00.exportStorm('inet:asn=0')))
|
|
8044
7924
|
|
|
8045
7925
|
stream.seek(0)
|
|
8046
7926
|
data = stream.read()
|
|
8047
|
-
self.isin('
|
|
7927
|
+
self.isin('Storm query mirror pool is empty, running query locally.', data)
|
|
8048
7928
|
|
|
8049
7929
|
with self.getLoggerStream('synapse') as stream:
|
|
8050
7930
|
self.eq(1, await core00.count('inet:asn=0'))
|
|
8051
7931
|
|
|
8052
7932
|
stream.seek(0)
|
|
8053
7933
|
data = stream.read()
|
|
8054
|
-
self.isin('
|
|
7934
|
+
self.isin('Storm query mirror pool is empty, running query locally.', data)
|
|
8055
7935
|
|
|
8056
|
-
core01 = await base.enter_context(self.getTestCore(dirn=dirn01
|
|
7936
|
+
core01 = await base.enter_context(self.getTestCore(dirn=dirn01))
|
|
8057
7937
|
await core01.promote(graceful=True)
|
|
8058
7938
|
|
|
8059
7939
|
self.true(core01.isactive)
|
|
@@ -8067,7 +7947,8 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
8067
7947
|
|
|
8068
7948
|
stream.seek(0)
|
|
8069
7949
|
data = stream.read()
|
|
8070
|
-
|
|
7950
|
+
# test that it reverts to local when referencing self
|
|
7951
|
+
self.notin('Offloading Storm query', data)
|
|
8071
7952
|
self.notin('Timeout waiting for query mirror', data)
|
|
8072
7953
|
|
|
8073
7954
|
waiter = core01.stormpool.waiter(1, 'svc:del')
|
|
@@ -8092,3 +7973,48 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
8092
7973
|
stream.seek(0)
|
|
8093
7974
|
data = stream.read()
|
|
8094
7975
|
self.notin('Storm query mirror pool is empty', data)
|
|
7976
|
+
|
|
7977
|
+
msgs = await core00.stormlist('cortex.storm.pool.get')
|
|
7978
|
+
self.stormHasNoWarnErr(msgs)
|
|
7979
|
+
self.stormIsInPrint('Storm Pool URL: aha://pool00...', msgs)
|
|
7980
|
+
|
|
7981
|
+
msgs = await core00.stormlist('cortex.storm.pool.del')
|
|
7982
|
+
self.stormHasNoWarnErr(msgs)
|
|
7983
|
+
self.stormIsInPrint('Storm pool configuration removed.', msgs)
|
|
7984
|
+
|
|
7985
|
+
msgs = await core00.stormlist('cortex.storm.pool.get')
|
|
7986
|
+
self.stormHasNoWarnErr(msgs)
|
|
7987
|
+
self.stormIsInPrint('No Storm pool configuration found.', msgs)
|
|
7988
|
+
|
|
7989
|
+
msgs = await alist(core01.storm('inet:asn=0', opts={'mirror': False}))
|
|
7990
|
+
self.len(1, [m for m in msgs if m[0] == 'node'])
|
|
7991
|
+
|
|
7992
|
+
async def test_cortex_authgate(self):
|
|
7993
|
+
# TODO - Remove this in 3.0.0
|
|
7994
|
+
with self.getTestDir() as dirn:
|
|
7995
|
+
|
|
7996
|
+
async with self.getTestCore(dirn=dirn) as core: # type: s_cortex.Cortex
|
|
7997
|
+
|
|
7998
|
+
unfo = await core.addUser('lowuser')
|
|
7999
|
+
lowuser = unfo.get('iden')
|
|
8000
|
+
|
|
8001
|
+
msgs = await core.stormlist('auth.user.addrule lowuser --gate cortex node')
|
|
8002
|
+
self.stormIsInWarn('Adding rule on the "cortex" authgate. This authgate is not used', msgs)
|
|
8003
|
+
msgs = await core.stormlist('auth.role.addrule all --gate cortex hehe')
|
|
8004
|
+
self.stormIsInWarn('Adding rule on the "cortex" authgate. This authgate is not used', msgs)
|
|
8005
|
+
|
|
8006
|
+
aslow = {'user': lowuser}
|
|
8007
|
+
|
|
8008
|
+
# The cortex authgate does nothing
|
|
8009
|
+
with self.raises(s_exc.AuthDeny) as cm:
|
|
8010
|
+
await core.nodes('[test:str=hello]', opts=aslow)
|
|
8011
|
+
|
|
8012
|
+
with self.getAsyncLoggerStream('synapse.cortex') as stream:
|
|
8013
|
+
async with self.getTestCore(dirn=dirn) as core: # type: s_cortex.Cortex
|
|
8014
|
+
# The cortex authgate still does nothing
|
|
8015
|
+
with self.raises(s_exc.AuthDeny) as cm:
|
|
8016
|
+
await core.nodes('[test:str=hello]', opts=aslow)
|
|
8017
|
+
stream.seek(0)
|
|
8018
|
+
buf = stream.read()
|
|
8019
|
+
self.isin('(lowuser) has a rule on the "cortex" authgate', buf)
|
|
8020
|
+
self.isin('(all) has a rule on the "cortex" authgate', buf)
|
synapse/tests/test_datamodel.py
CHANGED
|
@@ -41,6 +41,28 @@ class DeprecatedModel(s_module.CoreModule):
|
|
|
41
41
|
|
|
42
42
|
class DataModelTest(s_t_utils.SynTest):
|
|
43
43
|
|
|
44
|
+
async def test_datamodel_basics(self):
|
|
45
|
+
async with self.getTestCore() as core:
|
|
46
|
+
core.model.addType('woot:one', 'guid', {}, {
|
|
47
|
+
'display': {
|
|
48
|
+
'columns': (
|
|
49
|
+
{'type': 'newp', 'opts': {}},
|
|
50
|
+
),
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
with self.raises(s_exc.BadFormDef):
|
|
54
|
+
core.model.addForm('woot:one', {}, ())
|
|
55
|
+
|
|
56
|
+
core.model.addType('woot:two', 'guid', {}, {
|
|
57
|
+
'display': {
|
|
58
|
+
'columns': (
|
|
59
|
+
{'type': 'prop', 'opts': {'name': 'hehe'}},
|
|
60
|
+
),
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
with self.raises(s_exc.BadFormDef):
|
|
64
|
+
core.model.addForm('woot:two', {}, ())
|
|
65
|
+
|
|
44
66
|
async def test_datamodel_formname(self):
|
|
45
67
|
modl = s_datamodel.Model()
|
|
46
68
|
mods = (
|
synapse/tests/test_lib_agenda.py
CHANGED
|
@@ -175,7 +175,6 @@ class AgendaTest(s_t_utils.SynTest):
|
|
|
175
175
|
await visi.setAdmin(True)
|
|
176
176
|
|
|
177
177
|
agenda = core.agenda
|
|
178
|
-
await agenda.start() # make sure it doesn't blow up
|
|
179
178
|
|
|
180
179
|
self.eq([], agenda.list())
|
|
181
180
|
|
|
@@ -357,26 +356,22 @@ class AgendaTest(s_t_utils.SynTest):
|
|
|
357
356
|
self.eq(appt.lastresult, "raised exception StormRaise: errname='OmgWtfBbq' mesg='boom'")
|
|
358
357
|
|
|
359
358
|
# Test setting the global enable/disable flag
|
|
360
|
-
# reset
|
|
361
359
|
await agenda.delete(guid)
|
|
362
360
|
self.len(0, agenda.apptheap)
|
|
363
361
|
|
|
364
|
-
agenda._schedtask.cancel()
|
|
365
|
-
agenda._schedtask = agenda.schedCoro(agenda._scheduleLoop())
|
|
366
|
-
|
|
367
362
|
# schedule a query to run every Wednesday and Friday at 10:15am
|
|
368
363
|
cdef = {'creator': visi.iden, 'iden': s_common.guid(), 'storm': '$lib.queue.gen(visi).put(bar)',
|
|
364
|
+
'pool': True,
|
|
369
365
|
'reqs': {s_tu.HOUR: 10, s_tu.MINUTE: 15},
|
|
370
366
|
'incunit': s_agenda.TimeUnit.DAYOFWEEK,
|
|
371
367
|
'incvals': (2, 4)}
|
|
372
368
|
adef = await agenda.add(cdef)
|
|
369
|
+
|
|
370
|
+
self.true(adef['pool'])
|
|
373
371
|
guid = adef.get('iden')
|
|
374
372
|
|
|
375
373
|
self.len(1, agenda.apptheap)
|
|
376
374
|
|
|
377
|
-
# disable crons and advance time
|
|
378
|
-
agenda.enabled = False
|
|
379
|
-
|
|
380
375
|
unixtime = datetime.datetime(year=2019, month=2, day=6, hour=10, minute=16, tzinfo=tz.utc).timestamp()
|
|
381
376
|
nexttime = datetime.datetime(year=2019, month=2, day=8, hour=10, minute=15, tzinfo=tz.utc).timestamp()
|
|
382
377
|
|
|
@@ -387,9 +382,6 @@ class AgendaTest(s_t_utils.SynTest):
|
|
|
387
382
|
self.true(appt.enabled)
|
|
388
383
|
self.eq(0, appt.startcount)
|
|
389
384
|
|
|
390
|
-
# enable crons and advance time
|
|
391
|
-
agenda.enabled = True
|
|
392
|
-
|
|
393
385
|
unixtime = datetime.datetime(year=2019, month=2, day=13, hour=10, minute=16, tzinfo=tz.utc).timestamp()
|
|
394
386
|
self.eq((12, 'bar'), await asyncio.wait_for(core.callStorm('return($lib.queue.gen(visi).pop(wait=$lib.true))'), timeout=5))
|
|
395
387
|
|
|
@@ -418,105 +410,65 @@ class AgendaTest(s_t_utils.SynTest):
|
|
|
418
410
|
|
|
419
411
|
async def test_agenda_persistence(self):
|
|
420
412
|
''' Test we can make/change/delete appointments and they are persisted to storage '''
|
|
421
|
-
with self.getTestDir() as fdir:
|
|
422
|
-
|
|
423
|
-
core = mock.AsyncMock()
|
|
424
|
-
|
|
425
|
-
async def raiseOnBadStorm(q):
|
|
426
|
-
''' Just enough storm parsing for this test '''
|
|
427
|
-
if (q[0] == '[') != (q[-1] == ']'):
|
|
428
|
-
raise s_exc.BadSyntax(mesg='mismatched braces')
|
|
429
|
-
return 'all good'
|
|
430
|
-
|
|
431
|
-
core.getStormQuery = raiseOnBadStorm
|
|
432
|
-
|
|
433
|
-
async with await s_lmdbslab.Slab.anit(fdir, map_size=100000) as slab:
|
|
434
|
-
db = slab.initdb('hive')
|
|
435
|
-
hive = await s_hive.SlabHive.anit(slab, db=db)
|
|
436
|
-
core.hive = hive
|
|
437
|
-
|
|
438
|
-
async with await s_agenda.Agenda.anit(core) as agenda:
|
|
439
|
-
await agenda.start()
|
|
440
|
-
# Schedule a query to run every Wednesday and Friday at 10:15am
|
|
441
|
-
cdef = {'creator': 'visi', 'iden': 'IDEN1', 'storm': '[test:str=bar]',
|
|
442
|
-
'reqs': {s_tu.HOUR: 10, s_tu.MINUTE: 15},
|
|
443
|
-
'incunit': s_agenda.TimeUnit.DAYOFWEEK,
|
|
444
|
-
'incvals': (2, 4)}
|
|
445
|
-
adef = await agenda.add(cdef)
|
|
446
|
-
guid1 = adef.get('iden')
|
|
447
|
-
|
|
448
|
-
# every 6th of the month at 7am and 8am (the 6th is a Thursday)
|
|
449
|
-
cdef = {'creator': 'visi', 'iden': 'IDEN2', 'storm': '[test:str=baz]',
|
|
450
|
-
'reqs': {s_tu.HOUR: (7, 8), s_tu.MINUTE: 0, s_tu.DAYOFMONTH: 6},
|
|
451
|
-
'incunit': s_agenda.TimeUnit.MONTH,
|
|
452
|
-
'incvals': 1}
|
|
453
|
-
adef = await agenda.add(cdef)
|
|
454
|
-
|
|
455
|
-
guid2 = adef.get('iden')
|
|
456
|
-
appt = agenda.appts[guid2]
|
|
457
|
-
appt.lasterrs.append('error happened')
|
|
458
|
-
await appt.save()
|
|
459
413
|
|
|
460
|
-
|
|
461
|
-
cdef = {'creator': 'visi', 'iden': 'BAD1', 'storm': '[test:str=',
|
|
462
|
-
'reqs': {s_tu.HOUR: (7, 8)},
|
|
463
|
-
'incunit': s_agenda.TimeUnit.MONTH,
|
|
464
|
-
'incvals': 1}
|
|
465
|
-
await self.asyncraises(s_exc.BadSyntax, agenda.add(cdef))
|
|
466
|
-
|
|
467
|
-
# Add an appt with a bad version in storage
|
|
468
|
-
cdef = {'creator': 'visi', 'iden': 'BAD2', 'storm': '[test:str=foo]',
|
|
469
|
-
'reqs': {s_tu.HOUR: (7, 8)},
|
|
470
|
-
'incunit': s_agenda.TimeUnit.MONTH,
|
|
471
|
-
'incvals': 1}
|
|
472
|
-
adef = await agenda.add(cdef)
|
|
473
|
-
badguid2 = adef.get('iden')
|
|
414
|
+
with self.getTestDir() as dirn:
|
|
474
415
|
|
|
475
|
-
|
|
476
|
-
full = agenda._hivenode.full + (badguid2,)
|
|
477
|
-
await agenda.core.hive.set(full, adef)
|
|
416
|
+
async with self.getTestCore(dirn=dirn) as core:
|
|
478
417
|
|
|
479
|
-
|
|
480
|
-
|
|
418
|
+
cdef = {'creator': core.auth.rootuser.iden,
|
|
419
|
+
'storm': '[test:str=bar]',
|
|
420
|
+
'reqs': {'hour': 10, 'minute': 15},
|
|
421
|
+
'incunit': 'dayofweek',
|
|
422
|
+
'incvals': (2, 4)}
|
|
423
|
+
adef = await core.addCronJob(cdef)
|
|
424
|
+
guid1 = adef.get('iden')
|
|
481
425
|
|
|
482
|
-
|
|
426
|
+
# every 6th of the month at 7am and 8am (the 6th is a Thursday)
|
|
427
|
+
cdef = {'creator': core.auth.rootuser.iden,
|
|
428
|
+
'storm': '[test:str=baz]',
|
|
429
|
+
'reqs': {'hour': (7, 8), 'minute': 0, 'dayofmonth': 6},
|
|
430
|
+
'incunit': 'month',
|
|
431
|
+
'incvals': 1}
|
|
432
|
+
adef = await core.addCronJob(cdef)
|
|
483
433
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
434
|
+
guid2 = adef.get('iden')
|
|
435
|
+
appt = core.agenda.appts[guid2]
|
|
436
|
+
appt.lasterrs.append('error happened')
|
|
437
|
+
await appt.save()
|
|
438
|
+
|
|
439
|
+
# Add an appt with an invalid query
|
|
440
|
+
cdef = {'creator': core.auth.rootuser.iden,
|
|
441
|
+
'storm': '[test:str=',
|
|
442
|
+
'reqs': {'hour': (7, 8)},
|
|
443
|
+
'incunit': 'month',
|
|
444
|
+
'incvals': 1}
|
|
487
445
|
|
|
488
|
-
|
|
489
|
-
|
|
446
|
+
with self.raises(s_exc.BadSyntax):
|
|
447
|
+
await core.addCronJob(cdef)
|
|
490
448
|
|
|
491
|
-
|
|
449
|
+
xmas = {'dayofmonth': 25, 'month': 12, 'year': 2099}
|
|
450
|
+
lasthanu = {'dayofmonth': 10, 'month': 12, 'year': 2099}
|
|
492
451
|
|
|
493
|
-
|
|
494
|
-
await agenda.start()
|
|
495
|
-
agenda.enabled = True
|
|
452
|
+
await core.delCronJob(guid1)
|
|
496
453
|
|
|
497
|
-
|
|
498
|
-
|
|
454
|
+
# And one-shots for Christmas and last day of Hanukkah of 2018
|
|
455
|
+
cdef = {'creator': core.auth.rootuser.iden,
|
|
456
|
+
'storm': '#happyholidays',
|
|
457
|
+
'reqs': (xmas, lasthanu)}
|
|
499
458
|
|
|
500
|
-
|
|
501
|
-
|
|
459
|
+
adef = await core.addCronJob(cdef)
|
|
460
|
+
guid3 = adef.get('iden')
|
|
502
461
|
|
|
503
|
-
|
|
462
|
+
await core.updateCronJob(guid3, '#bahhumbug')
|
|
504
463
|
|
|
505
|
-
|
|
464
|
+
async with self.getTestCore(dirn=dirn) as core:
|
|
506
465
|
|
|
507
|
-
|
|
508
|
-
await core.callStorm('$lib.queue.add(foo)')
|
|
509
|
-
await core.callStorm('cron.add --minute +1 { $lib.queue.get(foo).put((99)) $lib.time.sleep(10) }')
|
|
510
|
-
appts = core.agenda.list()
|
|
511
|
-
await core.agenda._execute(appts[0][1])
|
|
512
|
-
self.eq((0, 99), await core.callStorm('return($lib.queue.get(foo).get())'))
|
|
466
|
+
appts = await core.listCronJobs()
|
|
513
467
|
|
|
514
|
-
|
|
515
|
-
await core.agenda._execute(appts[0][1])
|
|
516
|
-
self.eq(appts[0][1].lastresult, 'Failed due to unknown user')
|
|
468
|
+
self.len(2, appts)
|
|
517
469
|
|
|
518
|
-
|
|
519
|
-
|
|
470
|
+
last_appt = [appt for appt in appts if appt.get('iden') == guid3][0]
|
|
471
|
+
self.eq(last_appt.get('query'), '#bahhumbug')
|
|
520
472
|
|
|
521
473
|
async def test_agenda_custom_view(self):
|
|
522
474
|
|
|
@@ -685,7 +637,7 @@ class AgendaTest(s_t_utils.SynTest):
|
|
|
685
637
|
nodes = await core.nodes('test:int=97', opts={'view': newview})
|
|
686
638
|
self.len(0, nodes)
|
|
687
639
|
|
|
688
|
-
async def
|
|
640
|
+
async def test_agenda_edit(self):
|
|
689
641
|
|
|
690
642
|
async with self.getTestCore() as core:
|
|
691
643
|
|
|
@@ -696,8 +648,12 @@ class AgendaTest(s_t_utils.SynTest):
|
|
|
696
648
|
self.stormHasNoWarnErr(msgs)
|
|
697
649
|
|
|
698
650
|
cdef = await core.callStorm('for $cron in $lib.cron.list() { return($cron) }')
|
|
651
|
+
self.false(cdef['pool'])
|
|
699
652
|
self.eq(cdef['creator'], core.auth.rootuser.iden)
|
|
700
653
|
|
|
654
|
+
cdef = await core.callStorm('for $cron in $lib.cron.list() { $cron.set(pool, (true)) return($cron) }')
|
|
655
|
+
self.true(cdef['pool'])
|
|
656
|
+
|
|
701
657
|
opts = {'vars': {'lowuser': lowuser}}
|
|
702
658
|
cdef = await core.callStorm('for $cron in $lib.cron.list() { return($cron.set(creator, $lowuser)) }',
|
|
703
659
|
opts=opts)
|