synapse 2.214.0__py311-none-any.whl → 2.216.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/cortex.py +17 -2
- synapse/lib/cell.py +12 -0
- synapse/lib/cmd.py +6 -2
- synapse/lib/jsonstor.py +4 -1
- synapse/lib/layer.py +13 -6
- synapse/lib/schemas.py +9 -2
- synapse/lib/snap.py +15 -5
- synapse/lib/storm.py +1 -1
- synapse/lib/types.py +3 -0
- synapse/lib/version.py +2 -2
- synapse/lib/view.py +16 -7
- synapse/models/inet.py +7 -1
- synapse/models/infotech.py +45 -0
- synapse/models/risk.py +2 -0
- synapse/tests/test_cortex.py +262 -0
- synapse/tests/test_lib_auth.py +2 -0
- synapse/tests/test_lib_jsonstor.py +45 -0
- synapse/tests/test_lib_layer.py +10 -0
- synapse/tests/test_lib_storm.py +52 -1
- synapse/tests/test_lib_stormlib_iters.py +1 -1
- synapse/tests/test_lib_stormsvc.py +2 -2
- synapse/tests/test_lib_stormtypes.py +15 -0
- synapse/tests/test_lib_types.py +11 -1
- synapse/tests/test_model_inet.py +2 -0
- synapse/tests/test_model_infotech.py +31 -0
- synapse/tests/test_tools_cryo_cat.py +3 -8
- synapse/tests/test_tools_storm.py +3 -2
- synapse/tests/utils.py +2 -0
- synapse/tools/aha/clone.py +3 -13
- synapse/tools/aha/easycert.py +5 -18
- synapse/tools/aha/enroll.py +3 -12
- synapse/tools/aha/list.py +2 -15
- synapse/tools/aha/mirror.py +3 -14
- synapse/tools/aha/provision/service.py +3 -13
- synapse/tools/aha/provision/user.py +3 -12
- synapse/tools/apikey.py +3 -13
- synapse/tools/autodoc.py +7 -19
- synapse/tools/axon2axon.py +1 -9
- synapse/tools/cellauth.py +5 -14
- synapse/tools/changelog.py +12 -16
- synapse/tools/cmdr.py +2 -6
- synapse/tools/cryo/cat.py +5 -15
- synapse/tools/cryo/list.py +3 -10
- synapse/tools/csvtool.py +40 -49
- synapse/tools/demote.py +1 -6
- synapse/tools/docker/validate.py +0 -1
- synapse/tools/easycert.py +3 -8
- synapse/tools/feed.py +7 -18
- synapse/tools/genpkg.py +3 -12
- synapse/tools/guid.py +4 -6
- synapse/tools/healthcheck.py +4 -11
- synapse/tools/json2mpk.py +1 -5
- synapse/tools/livebackup.py +3 -13
- synapse/tools/modrole.py +3 -12
- synapse/tools/moduser.py +3 -12
- synapse/tools/pkgs/gendocs.py +1 -1
- synapse/tools/promote.py +3 -13
- synapse/tools/pullfile.py +6 -18
- synapse/tools/pushfile.py +6 -18
- synapse/tools/reload.py +5 -14
- synapse/tools/rstorm.py +4 -12
- synapse/tools/shutdown.py +1 -2
- synapse/tools/snapshot.py +3 -14
- synapse/tools/storm.py +4 -12
- {synapse-2.214.0.dist-info → synapse-2.216.0.dist-info}/METADATA +1 -1
- {synapse-2.214.0.dist-info → synapse-2.216.0.dist-info}/RECORD +69 -69
- {synapse-2.214.0.dist-info → synapse-2.216.0.dist-info}/WHEEL +0 -0
- {synapse-2.214.0.dist-info → synapse-2.216.0.dist-info}/licenses/LICENSE +0 -0
- {synapse-2.214.0.dist-info → synapse-2.216.0.dist-info}/top_level.txt +0 -0
synapse/tests/test_cortex.py
CHANGED
|
@@ -8776,6 +8776,268 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
8776
8776
|
self.eq(core._test_pre_nexus_index, offs)
|
|
8777
8777
|
self.ge(core._test_post_nexus_index, core._test_pre_nexus_index)
|
|
8778
8778
|
|
|
8779
|
+
async def test_cortex_safemode(self):
|
|
8780
|
+
safemode = {'safemode': True}
|
|
8781
|
+
nosafe = {'safemode': False}
|
|
8782
|
+
|
|
8783
|
+
# Cortex safemode disables the following functionality:
|
|
8784
|
+
# - crons
|
|
8785
|
+
# - triggers
|
|
8786
|
+
# - dmons
|
|
8787
|
+
# - storm package onloads
|
|
8788
|
+
# - merge tasks (e.g. for quorum)
|
|
8789
|
+
# - storm pools
|
|
8790
|
+
|
|
8791
|
+
# Make sure we're logging the message
|
|
8792
|
+
with self.getStructuredAsyncLoggerStream('synapse.lib.cell', 'Booting cortex in safe-mode.') as stream:
|
|
8793
|
+
async with self.getTestCore(conf=safemode) as core:
|
|
8794
|
+
self.true(core.safemode)
|
|
8795
|
+
self.true(await stream.wait(10))
|
|
8796
|
+
msgs = stream.jsonlines()
|
|
8797
|
+
self.len(1, msgs)
|
|
8798
|
+
self.eq(msgs[0].get('message'), 'Booting cortex in safe-mode. Some functionality may be disabled.')
|
|
8799
|
+
self.eq(msgs[0].get('level'), 'WARNING')
|
|
8800
|
+
|
|
8801
|
+
# Check crons, triggers, dmons in this section
|
|
8802
|
+
with self.getTestDir() as dirn:
|
|
8803
|
+
|
|
8804
|
+
# Setup the cortex
|
|
8805
|
+
async with self.getTestCore(dirn=dirn) as core:
|
|
8806
|
+
await core.addCoreQueue('queue:safemode:done', {})
|
|
8807
|
+
# Add a cron job and immediately disable it
|
|
8808
|
+
q = '''
|
|
8809
|
+
cron.add --minute +1 {
|
|
8810
|
+
$now = $lib.cast(time, now)
|
|
8811
|
+
$lib.log.warning(`SAFEMODE CRON: {$now}`)
|
|
8812
|
+
[ test:str=CRON :tick=$now ]
|
|
8813
|
+
} |
|
|
8814
|
+
$job = $lib.cron.list().0
|
|
8815
|
+
cron.disable $job.iden
|
|
8816
|
+
'''
|
|
8817
|
+
await core.callStorm(q)
|
|
8818
|
+
jobs = await core.listCronJobs()
|
|
8819
|
+
self.len(1, jobs)
|
|
8820
|
+
self.eq(jobs[0].get('enabled'), False)
|
|
8821
|
+
|
|
8822
|
+
# Add a regular trigger
|
|
8823
|
+
q = '''
|
|
8824
|
+
$lib.log.warning(`SAFEMODE TRIGGER: {$node}`)
|
|
8825
|
+
$tick = :tick
|
|
8826
|
+
$str = { [( test:str=TRIGGER :hehe=$tick )] }
|
|
8827
|
+
$queue = $lib.queue.gen(queue:safemode)
|
|
8828
|
+
$queue.put($tick)
|
|
8829
|
+
'''
|
|
8830
|
+
opts = {'vars': {'query': q}}
|
|
8831
|
+
await core.callStorm(f'trigger.add prop:set --prop test:str:tick --query {{{q}}}')
|
|
8832
|
+
|
|
8833
|
+
# Add an async trigger
|
|
8834
|
+
q = '''
|
|
8835
|
+
$lib.log.warning(`SAFEMODE ATRIGGER: {$node}`)
|
|
8836
|
+
$tick = :tick
|
|
8837
|
+
$str = { [( test:str=ATRIGGER :hehe=$tick )] }
|
|
8838
|
+
$queue = $lib.queue.gen(queue:safemode)
|
|
8839
|
+
$queue.put($tick)
|
|
8840
|
+
'''
|
|
8841
|
+
opts = {'vars': {'query': q}}
|
|
8842
|
+
await core.callStorm(f'trigger.add prop:set --prop test:str:tick --async --query {{{q}}}')
|
|
8843
|
+
|
|
8844
|
+
# Add a dmon
|
|
8845
|
+
q = '''
|
|
8846
|
+
$queue = $lib.queue.gen(queue:safemode)
|
|
8847
|
+
$queue2 = $lib.queue.gen(queue:safemode:done)
|
|
8848
|
+
while (true) {
|
|
8849
|
+
($offs, $item) = $queue.get()
|
|
8850
|
+
$lib.log.warning(`SAFEMODE DMON: {$item}`)
|
|
8851
|
+
[ test:str=DMON :hehe=$item ]
|
|
8852
|
+
$queue2.put($item)
|
|
8853
|
+
}
|
|
8854
|
+
'''
|
|
8855
|
+
await core.callStorm(f'$iden = $lib.dmon.add(${{{q}}}) $lib.dmon.start($iden)')
|
|
8856
|
+
|
|
8857
|
+
nodes = await core.nodes('test:str')
|
|
8858
|
+
self.len(0, nodes)
|
|
8859
|
+
|
|
8860
|
+
# Run in safemode and verify cron, trigger, and dmons don't execute
|
|
8861
|
+
with self.getLoggerStream('synapse.storm') as stream:
|
|
8862
|
+
async with self.getTestCore(dirn=dirn, conf=safemode) as core:
|
|
8863
|
+
await core.callStorm('cron.enable $lib.cron.list().0.iden')
|
|
8864
|
+
# Increment the cron tick to get it to fire
|
|
8865
|
+
core.agenda._addTickOff(60)
|
|
8866
|
+
|
|
8867
|
+
# Add a test:str:tick to get the trigger to fire
|
|
8868
|
+
await core.callStorm('[ test:str=newp :tick=1234 ]')
|
|
8869
|
+
|
|
8870
|
+
# Check for test:strs
|
|
8871
|
+
nodes = await core.nodes('test:str')
|
|
8872
|
+
self.len(1, nodes)
|
|
8873
|
+
self.eq(nodes[0].repr(), 'newp')
|
|
8874
|
+
|
|
8875
|
+
with self.raises(TimeoutError):
|
|
8876
|
+
await s_common.wait_for(core.coreQueueGet('queue:safemode:done', wait=True), timeout=2)
|
|
8877
|
+
|
|
8878
|
+
# Add a dmon to make sure it doesn't start
|
|
8879
|
+
await core.addCoreQueue('queue:safemode:started', {})
|
|
8880
|
+
q = '''
|
|
8881
|
+
$queue = $lib.queue.gen(queue:safemode)
|
|
8882
|
+
$queue2 = $lib.queue.get(queue:safemode:started)
|
|
8883
|
+
while (true) {
|
|
8884
|
+
$queue2.put(foo)
|
|
8885
|
+
$lib.log.warning(`SAFEMODE DMON START`)
|
|
8886
|
+
($offs, $item) = $queue.get()
|
|
8887
|
+
}
|
|
8888
|
+
'''
|
|
8889
|
+
await core.callStorm(f'$iden = $lib.dmon.add(${{{q}}}) $lib.dmon.start($iden)')
|
|
8890
|
+
|
|
8891
|
+
with self.raises(TimeoutError):
|
|
8892
|
+
await s_common.wait_for(core.coreQueueGet('queue:safemode:started', wait=True), timeout=2)
|
|
8893
|
+
|
|
8894
|
+
stream.seek(0)
|
|
8895
|
+
data = stream.read()
|
|
8896
|
+
self.notin('SAFEMODE CRON', data)
|
|
8897
|
+
self.notin('SAFEMODE TRIGGER', data)
|
|
8898
|
+
self.notin('SAFEMODE ATRIGGER', data)
|
|
8899
|
+
self.notin('SAFEMODE DMON', data)
|
|
8900
|
+
|
|
8901
|
+
with self.getLoggerStream('synapse.storm') as stream:
|
|
8902
|
+
async with self.getTestCore(dirn=dirn) as core:
|
|
8903
|
+
core.agenda._addTickOff(60)
|
|
8904
|
+
|
|
8905
|
+
item = await s_common.wait_for(core.coreQueueGet('queue:safemode:done', wait=True), timeout=5)
|
|
8906
|
+
self.len(2, item)
|
|
8907
|
+
|
|
8908
|
+
nodes = await core.nodes('test:str')
|
|
8909
|
+
self.len(5, nodes)
|
|
8910
|
+
self.sorteq(
|
|
8911
|
+
['newp', 'CRON', 'TRIGGER', 'DMON', 'ATRIGGER'],
|
|
8912
|
+
[k.repr() for k in nodes]
|
|
8913
|
+
)
|
|
8914
|
+
|
|
8915
|
+
stream.seek(0)
|
|
8916
|
+
data = stream.read()
|
|
8917
|
+
self.isin('SAFEMODE CRON', data)
|
|
8918
|
+
self.isin('SAFEMODE TRIGGER', data)
|
|
8919
|
+
self.isin('SAFEMODE ATRIGGER', data)
|
|
8920
|
+
self.isin('SAFEMODE DMON', data)
|
|
8921
|
+
|
|
8922
|
+
# Check storm package onload handlers are not executed
|
|
8923
|
+
with self.getTestDir() as dirn:
|
|
8924
|
+
async with self.getTestCore(dirn=dirn, conf=safemode) as core:
|
|
8925
|
+
pkgdef = {
|
|
8926
|
+
'name': 'foopkg',
|
|
8927
|
+
'version': (0, 0, 1),
|
|
8928
|
+
'onload': '$lib.import(foo.setup).onload()',
|
|
8929
|
+
'modules': (
|
|
8930
|
+
{
|
|
8931
|
+
'name': 'foo.setup',
|
|
8932
|
+
'storm': '''
|
|
8933
|
+
function onload() {
|
|
8934
|
+
$lib.warn('foopkg onload')
|
|
8935
|
+
}
|
|
8936
|
+
''',
|
|
8937
|
+
},
|
|
8938
|
+
)
|
|
8939
|
+
}
|
|
8940
|
+
|
|
8941
|
+
waiter = core.waiter(1, 'core:pkg:onload:skipped')
|
|
8942
|
+
await core.addStormPkg(pkgdef)
|
|
8943
|
+
events = await waiter.wait(timeout=10)
|
|
8944
|
+
self.nn(events)
|
|
8945
|
+
self.len(1, events)
|
|
8946
|
+
self.eq(events, (('core:pkg:onload:skipped', {'pkg': 'foopkg', 'reason': 'safemode'}),))
|
|
8947
|
+
|
|
8948
|
+
with self.getAsyncLoggerStream('synapse.cortex', 'foopkg onload output: foopkg onload') as stream:
|
|
8949
|
+
async with self.getTestCore(dirn=dirn, conf=nosafe) as core:
|
|
8950
|
+
self.false(core.safemode)
|
|
8951
|
+
await stream.wait(timeout=10)
|
|
8952
|
+
|
|
8953
|
+
# Check merge tasks are not executed
|
|
8954
|
+
with self.getTestDir() as dirn:
|
|
8955
|
+
async with self.getTestCore(dirn=dirn, conf=safemode) as core:
|
|
8956
|
+
alliden = core.auth.allrole.iden
|
|
8957
|
+
|
|
8958
|
+
blackout = await core.auth.addUser('blackout')
|
|
8959
|
+
await blackout.allow(('view', 'read'))
|
|
8960
|
+
|
|
8961
|
+
await core.auth.rootuser.grant(alliden)
|
|
8962
|
+
|
|
8963
|
+
view = core.getView()
|
|
8964
|
+
qnfo = {
|
|
8965
|
+
'count': 1,
|
|
8966
|
+
'roles': [alliden],
|
|
8967
|
+
}
|
|
8968
|
+
await view.setViewInfo('quorum', qnfo)
|
|
8969
|
+
|
|
8970
|
+
forkiden = (await view.fork()).get('iden')
|
|
8971
|
+
|
|
8972
|
+
opts = {'view': forkiden}
|
|
8973
|
+
|
|
8974
|
+
nodes = await core.nodes('[ test:str=fork ]', opts=opts)
|
|
8975
|
+
self.len(1, nodes)
|
|
8976
|
+
|
|
8977
|
+
await core.callStorm('$lib.view.get().setMergeRequest()', opts=opts)
|
|
8978
|
+
await core.callStorm('$lib.view.get().setMergeVote()', opts=opts | {'user': blackout.iden})
|
|
8979
|
+
|
|
8980
|
+
fork = core.getView(forkiden)
|
|
8981
|
+
|
|
8982
|
+
self.true(await fork.isMergeReady())
|
|
8983
|
+
self.none(fork.mergetask)
|
|
8984
|
+
|
|
8985
|
+
self.len(0, await core.nodes('test:str'))
|
|
8986
|
+
|
|
8987
|
+
async with self.getTestCore(dirn=dirn, conf=nosafe) as core:
|
|
8988
|
+
nodes = await core.nodes('test:str')
|
|
8989
|
+
self.len(1, nodes)
|
|
8990
|
+
self.eq(nodes[0].repr(), 'fork')
|
|
8991
|
+
|
|
8992
|
+
# Check storm pools are not enabled
|
|
8993
|
+
async with self.getTestAha() as aha:
|
|
8994
|
+
|
|
8995
|
+
ahanet = aha.conf.req('aha:network')
|
|
8996
|
+
|
|
8997
|
+
async with await s_base.Base.anit() as base:
|
|
8998
|
+
|
|
8999
|
+
with self.getTestDir() as dirn:
|
|
9000
|
+
|
|
9001
|
+
dirn00 = s_common.genpath(dirn, 'cell00')
|
|
9002
|
+
dirn01 = s_common.genpath(dirn, 'cell01')
|
|
9003
|
+
|
|
9004
|
+
core00 = await base.enter_context(self.addSvcToAha(aha, '00.core', s_cortex.Cortex, dirn=dirn00,
|
|
9005
|
+
conf=safemode))
|
|
9006
|
+
provinfo = {'mirror': 'core'}
|
|
9007
|
+
core01 = await base.enter_context(self.addSvcToAha(aha, '01.core', s_cortex.Cortex, dirn=dirn01,
|
|
9008
|
+
provinfo=provinfo))
|
|
9009
|
+
|
|
9010
|
+
msgs = await core01.stormlist('aha.pool.add pool00...')
|
|
9011
|
+
self.stormHasNoWarnErr(msgs)
|
|
9012
|
+
self.stormIsInPrint('Created AHA service pool: pool00.synapse', msgs)
|
|
9013
|
+
|
|
9014
|
+
msgs = await core01.stormlist('aha.pool.svc.add pool00... 01.core...')
|
|
9015
|
+
self.stormHasNoWarnErr(msgs)
|
|
9016
|
+
self.stormIsInPrint('AHA service (01.core...) added to service pool (pool00.synapse)', msgs)
|
|
9017
|
+
|
|
9018
|
+
msgs = await core00.stormlist('cortex.storm.pool.set --connection-timeout 1 --sync-timeout 1 aha://pool00...')
|
|
9019
|
+
self.stormHasNoWarnErr(msgs)
|
|
9020
|
+
self.stormIsInPrint('Storm pool configuration set.', msgs)
|
|
9021
|
+
|
|
9022
|
+
# Make sure queries still work
|
|
9023
|
+
nodes = await core00.nodes('[ it:dev:str="stormpools!" ]', opts={'mirror': True})
|
|
9024
|
+
self.len(1, nodes)
|
|
9025
|
+
|
|
9026
|
+
self.none(core00.stormpool)
|
|
9027
|
+
|
|
9028
|
+
await core00.fini()
|
|
9029
|
+
|
|
9030
|
+
# Now disable safemode and check that the stormpool is enabled
|
|
9031
|
+
core00 = await base.enter_context(self.getTestCore(dirn=dirn00, conf=nosafe))
|
|
9032
|
+
|
|
9033
|
+
nodes = await core00.nodes('it:dev:str', opts={'mirror': True})
|
|
9034
|
+
self.len(1, nodes)
|
|
9035
|
+
|
|
9036
|
+
self.nn(core00.stormpool)
|
|
9037
|
+
|
|
9038
|
+
await core00.fini()
|
|
9039
|
+
await core01.fini()
|
|
9040
|
+
|
|
8779
9041
|
async def test_cortex_queue_mirror_authgates(self):
|
|
8780
9042
|
async with self.getRegrCore('2.213.0-queue-authgates') as core:
|
|
8781
9043
|
self.nn(await core.getAuthGate('queue:stillhere'))
|
synapse/tests/test_lib_auth.py
CHANGED
|
@@ -431,6 +431,8 @@ class AuthTest(s_test.SynTest):
|
|
|
431
431
|
await core.auth.allrole.setRules([(True, ('hehe', 'haha'), 'newp')])
|
|
432
432
|
with self.raises(s_exc.SchemaViolation):
|
|
433
433
|
await core.auth.allrole.setRules([(True, )])
|
|
434
|
+
with self.raises(s_exc.SchemaViolation):
|
|
435
|
+
await core.auth.allrole.setRules([(True, '')])
|
|
434
436
|
|
|
435
437
|
async def test_auth_archived_locked_interaction(self):
|
|
436
438
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import synapse.exc as s_exc
|
|
2
|
+
import synapse.lib.lmdbslab as s_lmdbslab
|
|
2
3
|
import synapse.lib.jsonstor as s_jsonstor
|
|
3
4
|
|
|
4
5
|
import synapse.tests.utils as s_test
|
|
@@ -125,3 +126,47 @@ class JsonStorTest(s_test.SynTest):
|
|
|
125
126
|
|
|
126
127
|
self.true(await prox.delQueue('hehe'))
|
|
127
128
|
self.false(await prox.delQueue('hehe'))
|
|
129
|
+
|
|
130
|
+
async def test_lib_jsonstor_syncing(self):
|
|
131
|
+
|
|
132
|
+
with self.getTestDir() as dirn:
|
|
133
|
+
async with self.getTestJsonStor(dirn=dirn) as jsonstor:
|
|
134
|
+
async with jsonstor.getLocalProxy() as prox:
|
|
135
|
+
|
|
136
|
+
await prox.setPathObj('foo/bar', {'hehe': 'haha'})
|
|
137
|
+
await s_lmdbslab.Slab.syncLoopOnce()
|
|
138
|
+
|
|
139
|
+
self.true(await prox.setPathObjProp('foo/bar', 'zip', 'zop'))
|
|
140
|
+
self.len(1, jsonstor.jsonstor.dirty.items())
|
|
141
|
+
|
|
142
|
+
await s_lmdbslab.Slab.syncLoopOnce()
|
|
143
|
+
self.len(0, jsonstor.jsonstor.dirty.items())
|
|
144
|
+
|
|
145
|
+
self.eq({'hehe': 'haha', 'zip': 'zop'}, await prox.getPathObj('foo/bar'))
|
|
146
|
+
|
|
147
|
+
self.true(await prox.delPathObjProp('foo/bar', 'zip'))
|
|
148
|
+
self.len(1, jsonstor.jsonstor.dirty.items())
|
|
149
|
+
|
|
150
|
+
await s_lmdbslab.Slab.syncLoopOnce()
|
|
151
|
+
self.len(0, jsonstor.jsonstor.dirty.items())
|
|
152
|
+
|
|
153
|
+
self.eq({'hehe': 'haha'}, await prox.getPathObj('foo/bar'))
|
|
154
|
+
|
|
155
|
+
self.true(await prox.cmpDelPathObjProp('foo/bar', 'hehe', 'haha'))
|
|
156
|
+
self.len(1, jsonstor.jsonstor.dirty.items())
|
|
157
|
+
|
|
158
|
+
await s_lmdbslab.Slab.syncLoopOnce()
|
|
159
|
+
self.len(0, jsonstor.jsonstor.dirty.items())
|
|
160
|
+
|
|
161
|
+
self.eq({}, await prox.getPathObj('foo/bar'))
|
|
162
|
+
|
|
163
|
+
self.true(await prox.setPathObjProp('foo/bar', 'zip', 'zop'))
|
|
164
|
+
await s_lmdbslab.Slab.syncLoopOnce()
|
|
165
|
+
|
|
166
|
+
self.true(await prox.popPathObjProp('foo/bar', 'zip'))
|
|
167
|
+
self.len(1, jsonstor.jsonstor.dirty.items())
|
|
168
|
+
|
|
169
|
+
await s_lmdbslab.Slab.syncLoopOnce()
|
|
170
|
+
self.len(0, jsonstor.jsonstor.dirty.items())
|
|
171
|
+
|
|
172
|
+
self.eq({}, await prox.getPathObj('foo/bar'))
|
synapse/tests/test_lib_layer.py
CHANGED
|
@@ -1281,6 +1281,16 @@ class LayerTest(s_t_utils.SynTest):
|
|
|
1281
1281
|
|
|
1282
1282
|
self.len(0, list(layr.dataslab.scanByDups(abrv, db=layr.dataname)))
|
|
1283
1283
|
|
|
1284
|
+
await core.addTagProp('score2', ('int', {}), {})
|
|
1285
|
+
nodes = await core.nodes('[test:str=multi +#foo:score=5 +#foo:score2=6]')
|
|
1286
|
+
self.eq(('score', 'score2'), nodes[0].getTagProps('foo'))
|
|
1287
|
+
|
|
1288
|
+
nodes = await core.nodes('test:str=multi [-#foo:score]')
|
|
1289
|
+
self.eq(('score2',), nodes[0].getTagProps('foo'))
|
|
1290
|
+
|
|
1291
|
+
nodes = await core.nodes('test:str=multi')
|
|
1292
|
+
self.eq(('score2',), nodes[0].getTagProps('foo'))
|
|
1293
|
+
|
|
1284
1294
|
async def test_layer_waitForHot(self):
|
|
1285
1295
|
self.thisHostMust(hasmemlocking=True)
|
|
1286
1296
|
|
synapse/tests/test_lib_storm.py
CHANGED
|
@@ -101,7 +101,8 @@ class StormTest(s_t_utils.SynTest):
|
|
|
101
101
|
with self.raises(s_exc.BadTypeValu):
|
|
102
102
|
await core.nodes('[ ou:org=({}) ]')
|
|
103
103
|
|
|
104
|
-
self.
|
|
104
|
+
with self.raises(s_exc.BadTypeValu):
|
|
105
|
+
await core.nodes('[ ou:org=() ]')
|
|
105
106
|
|
|
106
107
|
with self.raises(s_exc.BadTypeValu):
|
|
107
108
|
await core.nodes('[ ou:org=({}) ]')
|
|
@@ -293,6 +294,56 @@ class StormTest(s_t_utils.SynTest):
|
|
|
293
294
|
|
|
294
295
|
self.len(0, await core.nodes('inet:service:platform:name=barplat'))
|
|
295
296
|
|
|
297
|
+
# Gutors work for props
|
|
298
|
+
nodes = await core.nodes('''[
|
|
299
|
+
test:str=guidprop
|
|
300
|
+
:gprop=({'name': 'someprop', '$props': {'size': 5}})
|
|
301
|
+
]''')
|
|
302
|
+
self.len(1, nodes)
|
|
303
|
+
node = nodes[0]
|
|
304
|
+
self.eq(node.ndef, ('test:str', 'guidprop'))
|
|
305
|
+
self.nn(node.get('gprop'))
|
|
306
|
+
|
|
307
|
+
nodes = await core.nodes('test:str=guidprop -> test:guid')
|
|
308
|
+
self.len(1, nodes)
|
|
309
|
+
node = nodes[0]
|
|
310
|
+
self.eq(node.get('name'), 'someprop')
|
|
311
|
+
self.eq(node.get('size'), 5)
|
|
312
|
+
|
|
313
|
+
with self.raises(s_exc.BadTypeValu) as cm:
|
|
314
|
+
nodes = await core.nodes('''[
|
|
315
|
+
test:str=newpprop
|
|
316
|
+
:gprop=({'size': 'newp'})
|
|
317
|
+
]''')
|
|
318
|
+
|
|
319
|
+
self.eq(cm.exception.get('form'), 'test:guid')
|
|
320
|
+
self.eq(cm.exception.get('prop'), 'size')
|
|
321
|
+
self.true(cm.exception.get('mesg').startswith('Bad value for prop test:guid:size: invalid literal'))
|
|
322
|
+
|
|
323
|
+
nodes = await core.nodes('''[
|
|
324
|
+
test:str=newpprop
|
|
325
|
+
:gprop?=({'size': 'newp'})
|
|
326
|
+
]''')
|
|
327
|
+
self.len(1, nodes)
|
|
328
|
+
node = nodes[0]
|
|
329
|
+
self.eq(node.ndef, ('test:str', 'newpprop'))
|
|
330
|
+
self.none(node.get('gprop'))
|
|
331
|
+
|
|
332
|
+
nodes = await core.nodes('''
|
|
333
|
+
[ test:str=methset ]
|
|
334
|
+
$node.props.gprop = ({'name': 'someprop'})
|
|
335
|
+
''')
|
|
336
|
+
self.len(1, nodes)
|
|
337
|
+
node = nodes[0]
|
|
338
|
+
self.eq(node.ndef, ('test:str', 'methset'))
|
|
339
|
+
self.nn(node.get('gprop'))
|
|
340
|
+
|
|
341
|
+
nodes = await core.nodes('test:str=methset -> test:guid')
|
|
342
|
+
self.len(1, nodes)
|
|
343
|
+
node = nodes[0]
|
|
344
|
+
self.eq(node.get('name'), 'someprop')
|
|
345
|
+
self.eq(node.get('size'), 5)
|
|
346
|
+
|
|
296
347
|
async def test_lib_storm_jsonexpr(self):
|
|
297
348
|
async with self.getTestCore() as core:
|
|
298
349
|
|
|
@@ -780,7 +780,7 @@ class StormSvcTest(s_test.SynTest):
|
|
|
780
780
|
}
|
|
781
781
|
with patchcore(core, 'setStormSvcEvents', badSetStormSvcEvents):
|
|
782
782
|
svci = await core.addStormSvc(sdef)
|
|
783
|
-
self.true(await core.waitStormSvc('dead', timeout=
|
|
783
|
+
self.true(await core.waitStormSvc('dead', timeout=12))
|
|
784
784
|
await core.delStormSvc(svci.get('iden'))
|
|
785
785
|
|
|
786
786
|
self.len(1, badiden)
|
|
@@ -792,7 +792,7 @@ class StormSvcTest(s_test.SynTest):
|
|
|
792
792
|
|
|
793
793
|
with patchcore(core, '_runStormSvcAdd', badRunStormSvcAdd):
|
|
794
794
|
svci = await core.addStormSvc(sdef)
|
|
795
|
-
self.true(await core.waitStormSvc('dead', timeout=
|
|
795
|
+
self.true(await core.waitStormSvc('dead', timeout=12))
|
|
796
796
|
await core.delStormSvc(svci.get('iden'))
|
|
797
797
|
self.len(1, badiden)
|
|
798
798
|
self.eq(svci.get('iden'), badiden[0])
|
|
@@ -2999,6 +2999,21 @@ class StormTypesTest(s_test.SynTest):
|
|
|
2999
2999
|
self.eq((5, 'baz'), await core.callStorm('return($lib.queue.get(poptest).pop())'))
|
|
3000
3000
|
self.none(await core.callStorm('return($lib.queue.get(poptest).pop())'))
|
|
3001
3001
|
|
|
3002
|
+
# Coverage for the Cortex queue:del nexus handler
|
|
3003
|
+
name = 'deleteme'
|
|
3004
|
+
iden = s_common.guid()
|
|
3005
|
+
await core.addCoreQueue(
|
|
3006
|
+
name,
|
|
3007
|
+
{'name': name,
|
|
3008
|
+
'creator': core.auth.rootuser.iden,
|
|
3009
|
+
'created': s_common.now(),
|
|
3010
|
+
'iden': iden}
|
|
3011
|
+
)
|
|
3012
|
+
await core.auth.delAuthGate(f'queue:{name}')
|
|
3013
|
+
await core.delCoreQueue(name)
|
|
3014
|
+
with self.raises(s_exc.NoSuchName):
|
|
3015
|
+
await core.getCoreQueue(name)
|
|
3016
|
+
|
|
3002
3017
|
async def test_storm_node_data(self):
|
|
3003
3018
|
|
|
3004
3019
|
async with self.getTestCore() as core:
|
synapse/tests/test_lib_types.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import math
|
|
2
2
|
import decimal
|
|
3
|
+
import datetime
|
|
3
4
|
import synapse.exc as s_exc
|
|
4
5
|
import synapse.common as s_common
|
|
5
6
|
import synapse.datamodel as s_datamodel
|
|
@@ -315,6 +316,12 @@ class TypesTest(s_t_utils.SynTest):
|
|
|
315
316
|
self.true(s_common.isguid(lnorm))
|
|
316
317
|
self.eq(lnorm, tnorm)
|
|
317
318
|
|
|
319
|
+
with self.raises(s_exc.BadTypeValu) as exc:
|
|
320
|
+
model.type('guid').norm(())
|
|
321
|
+
self.eq(exc.exception.get('name'), 'guid')
|
|
322
|
+
self.eq(exc.exception.get('valu'), ())
|
|
323
|
+
self.eq(exc.exception.get('mesg'), 'Guid list values cannot be empty.')
|
|
324
|
+
|
|
318
325
|
async def test_hex(self):
|
|
319
326
|
|
|
320
327
|
async with self.getTestCore() as core:
|
|
@@ -1320,7 +1327,10 @@ class TypesTest(s_t_utils.SynTest):
|
|
|
1320
1327
|
nodes = await core.nodes('test:str:tick=201401*')
|
|
1321
1328
|
self.eq({node.ndef[1] for node in nodes}, {'a'})
|
|
1322
1329
|
|
|
1323
|
-
|
|
1330
|
+
utc = datetime.timezone.utc
|
|
1331
|
+
delta = datetime.datetime.now(tz=utc) - datetime.datetime(2014, 1, 1, tzinfo=utc)
|
|
1332
|
+
days = delta.days + 14
|
|
1333
|
+
nodes = await core.nodes(f'test:str:tick*range=("-{days} days", now)')
|
|
1324
1334
|
self.eq({node.ndef[1] for node in nodes}, {'a', 'b', 'c', 'd'})
|
|
1325
1335
|
|
|
1326
1336
|
opts = {'vars': {'tick': tick, 'tock': tock}}
|
synapse/tests/test_model_inet.py
CHANGED
|
@@ -3017,6 +3017,8 @@ class InetModelTest(s_t_utils.SynTest):
|
|
|
3017
3017
|
platinst = nodes[0]
|
|
3018
3018
|
app00 = nodes[0].get('app')
|
|
3019
3019
|
|
|
3020
|
+
self.len(1, await core.nodes('inet:service:instance:id=T2XK1223Y -> inet:service:app [ :provider=* :provider:name=vertex ] :provider -> ou:org'))
|
|
3021
|
+
|
|
3020
3022
|
q = '''
|
|
3021
3023
|
[
|
|
3022
3024
|
(inet:service:account=(blackout, account, vertex, slack)
|
|
@@ -2438,3 +2438,34 @@ class InfotechModelTest(s_t_utils.SynTest):
|
|
|
2438
2438
|
self.eq(2, nodes[0].get('assets:vulns:preexisting'))
|
|
2439
2439
|
|
|
2440
2440
|
self.len(1, await core.nodes('it:sec:metrics -> ou:org +:name=vertex'))
|
|
2441
|
+
|
|
2442
|
+
async def test_infotech_windows(self):
|
|
2443
|
+
|
|
2444
|
+
async with self.getTestCore() as core:
|
|
2445
|
+
|
|
2446
|
+
nodes = await core.nodes('''
|
|
2447
|
+
[ it:os:windows:service=*
|
|
2448
|
+
:name=Woot
|
|
2449
|
+
:host=*
|
|
2450
|
+
:type=(0x20)
|
|
2451
|
+
:start=(0x20)
|
|
2452
|
+
:errorcontrol=(0x20)
|
|
2453
|
+
:displayname="Foo Bar Baz"
|
|
2454
|
+
:imagepath=c:/windows/system32/woot.exe
|
|
2455
|
+
:description="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
|
|
2456
|
+
]
|
|
2457
|
+
''')
|
|
2458
|
+
|
|
2459
|
+
self.len(1, nodes)
|
|
2460
|
+
self.eq(nodes[0].get('name'), 'woot')
|
|
2461
|
+
self.eq(nodes[0].get('type'), 0x20)
|
|
2462
|
+
self.eq(nodes[0].get('start'), 0x20)
|
|
2463
|
+
self.eq(nodes[0].get('errorcontrol'), 0x20)
|
|
2464
|
+
self.eq(nodes[0].get('displayname'), 'foo bar baz')
|
|
2465
|
+
self.eq(nodes[0].get('imagepath'), 'c:/windows/system32/woot.exe')
|
|
2466
|
+
self.eq(nodes[0].get('description'), 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.')
|
|
2467
|
+
|
|
2468
|
+
self.len(1, await core.nodes('it:os:windows:service -> it:host'))
|
|
2469
|
+
self.len(1, await core.nodes('it:os:windows:service -> file:path'))
|
|
2470
|
+
|
|
2471
|
+
self.len(1, await core.nodes('[ it:exec:proc=* :windows:service={ it:os:windows:service } ] -> it:os:windows:service'))
|
|
@@ -93,14 +93,9 @@ class CryoCatTest(s_t_utils.SynTest):
|
|
|
93
93
|
stdout.buffer = io.BytesIO()
|
|
94
94
|
|
|
95
95
|
with mock.patch('sys.stdout', stdout):
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
self.eq(0, retn)
|
|
100
|
-
|
|
101
|
-
stream.seek(0)
|
|
102
|
-
mesgs = stream.read()
|
|
103
|
-
self.isin(f'connecting to: {cryourl}', mesgs)
|
|
96
|
+
argv = ['--msgpack', '--size', '20', cryourl]
|
|
97
|
+
retn, _ = await self.execToolMain(s_cryocat.main, argv)
|
|
98
|
+
self.eq(0, retn)
|
|
104
99
|
|
|
105
100
|
stdout.buffer.seek(0)
|
|
106
101
|
outdata = list(msgpack.Unpacker(stdout.buffer, raw=False, use_list=False))
|
|
@@ -62,7 +62,8 @@ class StormCliTest(s_test.SynTest):
|
|
|
62
62
|
|
|
63
63
|
await core.addTagProp('foo', ('int', {}), {})
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
outp = self.getTestOutp()
|
|
66
|
+
pars = s_t_storm.getArgParser(outp)
|
|
66
67
|
opts = pars.parse_args(('woot',))
|
|
67
68
|
self.eq('woot', opts.cortex)
|
|
68
69
|
self.none(opts.view)
|
|
@@ -263,7 +264,7 @@ class StormCliTest(s_test.SynTest):
|
|
|
263
264
|
|
|
264
265
|
url = core.getLocalUrl()
|
|
265
266
|
|
|
266
|
-
pars = s_t_storm.getArgParser()
|
|
267
|
+
pars = s_t_storm.getArgParser(self.getTestOutp())
|
|
267
268
|
opts = pars.parse_args(('woot', '--view', '246e7d5dab883eb28d345a33abcdb577'))
|
|
268
269
|
self.eq(opts.view, '246e7d5dab883eb28d345a33abcdb577')
|
|
269
270
|
|
synapse/tests/utils.py
CHANGED
|
@@ -439,6 +439,7 @@ testmodel = {
|
|
|
439
439
|
|
|
440
440
|
('test:guid', {}, (
|
|
441
441
|
('size', ('test:int', {}), {}),
|
|
442
|
+
('name', ('test:str', {}), {}),
|
|
442
443
|
('tick', ('test:time', {}), {}),
|
|
443
444
|
('posneg', ('test:sub', {}), {}),
|
|
444
445
|
('posneg:isbig', ('bool', {}), {}),
|
|
@@ -459,6 +460,7 @@ testmodel = {
|
|
|
459
460
|
('hehe', ('str', {}), {}),
|
|
460
461
|
('ndefs', ('array', {'type': 'ndef'}), {}),
|
|
461
462
|
('somestr', ('test:str', {}), {}),
|
|
463
|
+
('gprop', ('test:guid', {}), {}),
|
|
462
464
|
)),
|
|
463
465
|
('test:strregex', {}, ()),
|
|
464
466
|
|
synapse/tools/aha/clone.py
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import asyncio
|
|
3
|
-
import argparse
|
|
4
|
-
|
|
5
1
|
import synapse.exc as s_exc
|
|
6
2
|
import synapse.telepath as s_telepath
|
|
7
3
|
|
|
8
|
-
import synapse.lib.
|
|
4
|
+
import synapse.lib.cmd as s_cmd
|
|
9
5
|
import synapse.lib.output as s_output
|
|
10
6
|
|
|
11
7
|
descr = '''
|
|
@@ -19,8 +15,7 @@ Examples:
|
|
|
19
15
|
|
|
20
16
|
async def main(argv, outp=s_output.stdout):
|
|
21
17
|
|
|
22
|
-
pars =
|
|
23
|
-
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
18
|
+
pars = s_cmd.Parser(prog='synapse.tools.aha.clone', outp=outp, description=descr)
|
|
24
19
|
|
|
25
20
|
pars.add_argument('dnsname', help='The DNS name of the new AHA server.')
|
|
26
21
|
pars.add_argument('--port', type=int, default=27492, help='The port that the new AHA server should listen on.')
|
|
@@ -49,10 +44,5 @@ async def main(argv, outp=s_output.stdout):
|
|
|
49
44
|
outp.printf(f'ERROR: {mesg}')
|
|
50
45
|
return 1
|
|
51
46
|
|
|
52
|
-
async def _main(argv, outp=s_output.stdout): # pragma: no cover
|
|
53
|
-
ret = await main(argv, outp=outp)
|
|
54
|
-
await asyncio.wait_for(s_coro.await_bg_tasks(), timeout=60)
|
|
55
|
-
return ret
|
|
56
|
-
|
|
57
47
|
if __name__ == '__main__': # pragma: no cover
|
|
58
|
-
|
|
48
|
+
s_cmd.exitmain(main)
|