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
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import json
|
|
2
2
|
|
|
3
|
+
import unittest.mock as mock
|
|
4
|
+
|
|
3
5
|
import aiohttp
|
|
4
6
|
|
|
5
7
|
import synapse.common as s_common
|
|
@@ -393,6 +395,9 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
|
|
|
393
395
|
return ( $api.iden )
|
|
394
396
|
'''
|
|
395
397
|
iden0 = await core.callStorm(q)
|
|
398
|
+
msgs = await core.stormlist('$lib.print($lib.cortex.httpapi.get($iden))', opts={'vars': {'iden': iden0}})
|
|
399
|
+
mesg = 'http:api: the hehe wildcard handler (********************************), path=hehe/([a-z0-9]*)'
|
|
400
|
+
self.stormIsInPrint(mesg, msgs, deguid=True)
|
|
396
401
|
|
|
397
402
|
q = '''
|
|
398
403
|
$api = $lib.cortex.httpapi.add('hehe/haha')
|
|
@@ -401,6 +406,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
|
|
|
401
406
|
$api.name = 'the hehe/haha handler'
|
|
402
407
|
$api.desc = 'beep boop zoop robot captain'
|
|
403
408
|
$api.runas = user
|
|
409
|
+
$api.pool = (true)
|
|
404
410
|
$api.perms = (
|
|
405
411
|
({"perm": ["hehe", "haha"]}),
|
|
406
412
|
({"perm": ["some", "thing"], "default": $lib.true}),
|
|
@@ -428,6 +434,9 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
|
|
|
428
434
|
return ( $api.iden )
|
|
429
435
|
'''
|
|
430
436
|
iden3 = await core.callStorm(q)
|
|
437
|
+
msgs = await core.stormlist('$lib.print($lib.cortex.httpapi.get($iden))', opts={'vars': {'iden': iden3}})
|
|
438
|
+
mesg = 'http:api: <no name> (********************************), path=wow'
|
|
439
|
+
self.stormIsInPrint(mesg, msgs, deguid=True)
|
|
431
440
|
|
|
432
441
|
# $lib.dict accessor methods
|
|
433
442
|
q = '$api=$lib.cortex.httpapi.get($iden) return ($lib.dict.keys($api.vars))'
|
|
@@ -473,6 +482,15 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
|
|
|
473
482
|
self.stormIsInPrint(f'2 {iden2}', msgs)
|
|
474
483
|
self.stormIsInPrint(f'3 {iden3}', msgs)
|
|
475
484
|
|
|
485
|
+
q = '''
|
|
486
|
+
$ret = $lib.null $api = $lib.cortex.httpapi.getByPath($path)
|
|
487
|
+
if $api { $ret = $api.iden}
|
|
488
|
+
return ( $ret )
|
|
489
|
+
'''
|
|
490
|
+
self.eq(iden0, await core.callStorm(q, opts={'vars': {'path': 'hehe/haha'}}))
|
|
491
|
+
self.eq(iden0, await core.callStorm(q, opts={'vars': {'path': 'hehe/ohmy'}}))
|
|
492
|
+
self.none(await core.callStorm(q, opts={'vars': {'path': 'newpnewpnewp'}}))
|
|
493
|
+
|
|
476
494
|
# Order matters. The hehe/haha path occurs after the wildcard.
|
|
477
495
|
async with self.getHttpSess(auth=('root', 'root'), port=hport) as sess:
|
|
478
496
|
resp = await sess.get(f'https://localhost:{hport}/api/ext/hehe/haha')
|
|
@@ -494,6 +512,9 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
|
|
|
494
512
|
msgs = await core.stormlist('cortex.httpapi.index $iden 1', opts={'vars': {'iden': iden0}})
|
|
495
513
|
self.stormIsInPrint(f'Set HTTP API {iden0} to index 1', msgs)
|
|
496
514
|
|
|
515
|
+
self.eq(iden1, await core.callStorm(q, opts={'vars': {'path': 'hehe/haha'}}))
|
|
516
|
+
self.eq(iden0, await core.callStorm(q, opts={'vars': {'path': 'hehe/ohmy'}}))
|
|
517
|
+
|
|
497
518
|
msgs = await core.stormlist('cortex.httpapi.list')
|
|
498
519
|
self.stormIsInPrint(f'0 {iden1}', msgs)
|
|
499
520
|
self.stormIsInPrint(f'1 {iden0}', msgs)
|
|
@@ -562,6 +583,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
|
|
|
562
583
|
self.stormIsInPrint('Owner: root', msgs)
|
|
563
584
|
self.stormIsInPrint('Runas: owner', msgs)
|
|
564
585
|
self.stormIsInPrint('Readonly: false', msgs)
|
|
586
|
+
self.stormIsInPrint('Pool enabled: false', msgs)
|
|
565
587
|
self.stormIsInPrint('Authenticated: true', msgs)
|
|
566
588
|
self.stormIsInPrint('Name: the hehe wildcard handler', msgs)
|
|
567
589
|
self.stormIsInPrint('Description: wildcard words', msgs)
|
|
@@ -596,6 +618,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
|
|
|
596
618
|
self.stormIsInPrint('Owner: root', msgs)
|
|
597
619
|
self.stormIsInPrint('Runas: user', msgs)
|
|
598
620
|
self.stormIsInPrint('Readonly: false', msgs)
|
|
621
|
+
self.stormIsInPrint('Pool enabled: true', msgs)
|
|
599
622
|
self.stormIsInPrint('Authenticated: true', msgs)
|
|
600
623
|
self.stormIsInPrint('Name: the hehe/haha handler', msgs)
|
|
601
624
|
self.stormIsInPrint('Description: beep boop zoop robot captain', msgs)
|
|
@@ -1373,3 +1396,51 @@ for $i in $values {
|
|
|
1373
1396
|
self.none(resp.headers.get('X-Content-Type-Options'))
|
|
1374
1397
|
# Server is still omitted though
|
|
1375
1398
|
self.none(resp.headers.get('Server'))
|
|
1399
|
+
|
|
1400
|
+
async def test_cortex_httpapi_pool(self):
|
|
1401
|
+
|
|
1402
|
+
# Test if we pass the mirror value in opts or not.
|
|
1403
|
+
async with self.getTestCore(conf={'https:headers': {'Key1': 'Valu1'}}) as core:
|
|
1404
|
+
await core.setUserPasswd(core.auth.rootuser.iden, 'root')
|
|
1405
|
+
addr, hport = await core.addHttpsPort(0)
|
|
1406
|
+
|
|
1407
|
+
q = '''$api = $lib.cortex.httpapi.add(stuff)
|
|
1408
|
+
$api.methods.get = ${
|
|
1409
|
+
$request.reply(200, headers=({"Weee": "valu"}) )
|
|
1410
|
+
}
|
|
1411
|
+
return ( ($api.iden) )'''
|
|
1412
|
+
iden00 = await core.callStorm(q)
|
|
1413
|
+
opts_iden00 = {'vars': {'iden': iden00}}
|
|
1414
|
+
|
|
1415
|
+
data = {}
|
|
1416
|
+
|
|
1417
|
+
oldstorm = core.storm
|
|
1418
|
+
async def storm(self, text, opts=None):
|
|
1419
|
+
data['opts'] = opts
|
|
1420
|
+
async for mesg in oldstorm(text, opts=opts):
|
|
1421
|
+
yield mesg
|
|
1422
|
+
|
|
1423
|
+
with mock.patch('synapse.cortex.Cortex.storm', new=storm) as patch:
|
|
1424
|
+
async with self.getHttpSess(auth=('root', 'root'), port=hport) as sess:
|
|
1425
|
+
resp = await sess.get(f'https://localhost:{hport}/api/ext/stuff') # type: aiohttp.ClientResponse
|
|
1426
|
+
self.eq(resp.status, 200)
|
|
1427
|
+
self.false(data['opts'].get('mirror'))
|
|
1428
|
+
data.clear()
|
|
1429
|
+
|
|
1430
|
+
q = '$api=$lib.cortex.httpapi.get($iden) $api.pool = (true) return ( $api.pack() ) '
|
|
1431
|
+
adef = await core.callStorm(q, opts=opts_iden00)
|
|
1432
|
+
self.true(adef.get('pool'))
|
|
1433
|
+
|
|
1434
|
+
resp = await sess.get(f'https://localhost:{hport}/api/ext/stuff') # type: aiohttp.ClientResponse
|
|
1435
|
+
self.eq(resp.status, 200)
|
|
1436
|
+
self.true(data['opts'].get('mirror'))
|
|
1437
|
+
data.clear()
|
|
1438
|
+
|
|
1439
|
+
q = '$api=$lib.cortex.httpapi.get($iden) $api.pool = (false) return ( $api.pack() ) '
|
|
1440
|
+
adef = await core.callStorm(q, opts=opts_iden00)
|
|
1441
|
+
self.false(adef.get('pool'))
|
|
1442
|
+
|
|
1443
|
+
resp = await sess.get(f'https://localhost:{hport}/api/ext/stuff') # type: aiohttp.ClientResponse
|
|
1444
|
+
self.eq(resp.status, 200)
|
|
1445
|
+
self.false(data['opts'].get('mirror'))
|
|
1446
|
+
data.clear()
|
|
@@ -70,6 +70,23 @@ class StormLibGenTest(s_test.SynTest):
|
|
|
70
70
|
nodes01 = await core.nodes('gen.risk.vuln CVE-2022-00001')
|
|
71
71
|
self.eq(nodes00[0].ndef, nodes01[0].ndef)
|
|
72
72
|
|
|
73
|
+
self.len(1, await core.nodes('risk:vuln:cve=cve-2022-00001 [ :reporter:name=foo ]'))
|
|
74
|
+
nodes02 = await core.nodes('gen.risk.vuln CVE-2022-00001')
|
|
75
|
+
self.eq(nodes00[0].ndef, nodes02[0].ndef)
|
|
76
|
+
|
|
77
|
+
nodes03 = await core.nodes('gen.risk.vuln CVE-2022-00001 foo')
|
|
78
|
+
self.eq(nodes00[0].ndef, nodes03[0].ndef)
|
|
79
|
+
self.nn(nodes03[0].get('reporter'))
|
|
80
|
+
|
|
81
|
+
nodes04 = await core.nodes('gen.risk.vuln CVE-2022-00001 bar')
|
|
82
|
+
nodes05 = await core.nodes('yield $lib.gen.vulnByCve(CVE-2022-00001, reporter=bar)')
|
|
83
|
+
self.eq(nodes04[0].ndef, nodes05[0].ndef)
|
|
84
|
+
self.ne(nodes00[0].ndef, nodes05[0].ndef)
|
|
85
|
+
self.eq('bar', nodes05[0].get('reporter:name'))
|
|
86
|
+
self.nn(nodes05[0].get('reporter'))
|
|
87
|
+
|
|
88
|
+
self.len(0, await core.nodes('gen.risk.vuln newp --try'))
|
|
89
|
+
|
|
73
90
|
nodes00 = await core.nodes('yield $lib.gen.orgIdType(barcode)')
|
|
74
91
|
nodes01 = await core.nodes('gen.ou.id.type barcode')
|
|
75
92
|
self.eq(nodes00[0].ndef, nodes01[0].ndef)
|
|
@@ -80,8 +97,6 @@ class StormLibGenTest(s_test.SynTest):
|
|
|
80
97
|
self.eq(nodes00[0].ndef, nodes01[0].ndef)
|
|
81
98
|
self.eq(nodes00[0].get('type'), barcode)
|
|
82
99
|
|
|
83
|
-
self.len(0, await core.nodes('gen.risk.vuln newp --try'))
|
|
84
|
-
|
|
85
100
|
nodes00 = await core.nodes('yield $lib.gen.polCountryByIso2(UA)')
|
|
86
101
|
nodes01 = await core.nodes('gen.pol.country ua')
|
|
87
102
|
self.eq(nodes00[0].ndef, nodes01[0].ndef)
|
|
@@ -210,3 +225,23 @@ class StormLibGenTest(s_test.SynTest):
|
|
|
210
225
|
|
|
211
226
|
self.len(1, await core.nodes('ou:org:name=forkorg'))
|
|
212
227
|
self.len(1, await core.nodes('ou:org:name=anotherforkorg'))
|
|
228
|
+
|
|
229
|
+
nodes = await core.nodes('geo:place')
|
|
230
|
+
self.len(0, nodes)
|
|
231
|
+
|
|
232
|
+
nodes = await core.nodes('gen.geo.place Zimbabwe')
|
|
233
|
+
self.len(1, nodes)
|
|
234
|
+
self.eq(nodes[0].get('name'), 'zimbabwe')
|
|
235
|
+
self.none(nodes[0].get('names'))
|
|
236
|
+
|
|
237
|
+
iden = nodes[0].iden()
|
|
238
|
+
|
|
239
|
+
msgs = await core.stormlist('geo:place:name=zimbabwe [ :names+=Rhodesia ]')
|
|
240
|
+
self.stormHasNoWarnErr(msgs)
|
|
241
|
+
|
|
242
|
+
nodes = await core.nodes('gen.geo.place Rhodesia')
|
|
243
|
+
self.len(1, nodes)
|
|
244
|
+
self.eq(nodes[0].iden(), iden)
|
|
245
|
+
names = nodes[0].get('names')
|
|
246
|
+
self.len(1, names)
|
|
247
|
+
self.isin('rhodesia', names)
|
|
@@ -25,6 +25,8 @@ class StormlibModelTest(s_test.SynTest):
|
|
|
25
25
|
self.eq('inet:dns:a', await core.callStorm('return($lib.model.type(inet:dns:a).name)'))
|
|
26
26
|
|
|
27
27
|
self.eq('1.2.3.4', await core.callStorm('return($lib.model.type(inet:ipv4).repr($(0x01020304)))'))
|
|
28
|
+
self.eq('123', await core.callStorm('return($lib.model.type(int).repr((1.23 *100)))'))
|
|
29
|
+
self.eq((123, {}), await core.callStorm('return($lib.model.type(int).norm((1.23 *100)))'))
|
|
28
30
|
self.eq(0x01020304, await core.callStorm('return($lib.model.type(inet:ipv4).norm(1.2.3.4).index(0))'))
|
|
29
31
|
self.eq({'subs': {'type': 'unicast'}}, await core.callStorm('return($lib.model.type(inet:ipv4).norm(1.2.3.4).index(1))'))
|
|
30
32
|
self.eq('inet:dns:a:ipv4', await core.callStorm('return($lib.model.form(inet:dns:a).prop(ipv4).full)'))
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import synapse.exc as s_exc
|
|
2
|
+
import synapse.lib.stormtypes as s_stormtypes
|
|
3
|
+
|
|
4
|
+
import synapse.tests.utils as s_test
|
|
5
|
+
|
|
6
|
+
class StormlibSpooledTest(s_test.SynTest):
|
|
7
|
+
async def test_lib_spooled_set(self):
|
|
8
|
+
async with self.getTestCore() as core:
|
|
9
|
+
await core.nodes('[inet:ipv4=1.2.3.4 :asn=20]')
|
|
10
|
+
await core.nodes('[inet:ipv4=5.6.7.8 :asn=30]')
|
|
11
|
+
|
|
12
|
+
q = '''
|
|
13
|
+
$set = $lib.spooled.set()
|
|
14
|
+
$set.add(1, 2, 3, 4)
|
|
15
|
+
return($set)
|
|
16
|
+
'''
|
|
17
|
+
valu = await core.callStorm(q)
|
|
18
|
+
self.eq({'1', '2', '3', '4'}, valu)
|
|
19
|
+
|
|
20
|
+
q = '''
|
|
21
|
+
$set = $lib.spooled.set()
|
|
22
|
+
$set.adds($lib.list(1, 2, 3, 4))
|
|
23
|
+
return($set)
|
|
24
|
+
'''
|
|
25
|
+
valu = await core.callStorm(q)
|
|
26
|
+
self.eq({'1', '2', '3', '4'}, valu)
|
|
27
|
+
|
|
28
|
+
q = '''
|
|
29
|
+
$set = $lib.spooled.set()
|
|
30
|
+
inet:ipv4 $set.add(:asn)
|
|
31
|
+
$set.rems((:asn,:asn))
|
|
32
|
+
[ graph:node="*" ] +graph:node [ :data=$set.list() ]
|
|
33
|
+
'''
|
|
34
|
+
nodes = await core.nodes(q)
|
|
35
|
+
self.len(1, nodes)
|
|
36
|
+
self.eq(nodes[0].get('data'), ())
|
|
37
|
+
|
|
38
|
+
q = '''
|
|
39
|
+
$set = $lib.spooled.set()
|
|
40
|
+
$set.add($foo)
|
|
41
|
+
$set.add($bar)
|
|
42
|
+
$set.add($biz)
|
|
43
|
+
return(($set.has($foo), $set.has(lolnop)))
|
|
44
|
+
'''
|
|
45
|
+
valu = await core.callStorm(q, opts={'vars': {'foo': b'foo', 'bar': b'bar', 'biz': b'biz'}})
|
|
46
|
+
self.eq(True, valu[0])
|
|
47
|
+
self.eq(False, valu[1])
|
|
48
|
+
|
|
49
|
+
q = '''
|
|
50
|
+
$set = $lib.spooled.set()
|
|
51
|
+
$set.adds(('foo', 'bar', 'baz', 'biz', 'biz', 'biz', 'beep', 'boop'))
|
|
52
|
+
return($set.size())
|
|
53
|
+
'''
|
|
54
|
+
valu = await core.callStorm(q)
|
|
55
|
+
self.eq(6, valu)
|
|
56
|
+
|
|
57
|
+
q = '''
|
|
58
|
+
$set = $lib.spooled.set()
|
|
59
|
+
$set.adds(('foo', 'bar', 'baz', 'biz', 'biz', 'biz', 'beep', 'boop'))
|
|
60
|
+
|
|
61
|
+
$set.rems(('baz', 'beep', 'bar'))
|
|
62
|
+
return($set)
|
|
63
|
+
|
|
64
|
+
'''
|
|
65
|
+
valu = await core.callStorm(q)
|
|
66
|
+
self.eq({'foo', 'boop', 'biz'}, valu)
|
|
67
|
+
|
|
68
|
+
q = '''
|
|
69
|
+
$set = $lib.spooled.set(1, 2, 3, 4 ,5)
|
|
70
|
+
$set.add(1, 2, 3, 4)
|
|
71
|
+
return($set.list())
|
|
72
|
+
'''
|
|
73
|
+
valu = await core.callStorm(q)
|
|
74
|
+
self.isinstance(valu, tuple)
|
|
75
|
+
self.len(5, valu)
|
|
76
|
+
self.isin('1', valu)
|
|
77
|
+
self.isin('2', valu)
|
|
78
|
+
self.isin('3', valu)
|
|
79
|
+
self.isin('4', valu)
|
|
80
|
+
self.isin('5', valu)
|
|
81
|
+
|
|
82
|
+
q = '''
|
|
83
|
+
$set = $lib.spooled.set()
|
|
84
|
+
$set.add($lib.true)
|
|
85
|
+
$set.add($lib.false)
|
|
86
|
+
$set.add($lib.true)
|
|
87
|
+
$set.add($lib.false)
|
|
88
|
+
$set.add('more stuff')
|
|
89
|
+
|
|
90
|
+
$dict = ({
|
|
91
|
+
"foo": "bar",
|
|
92
|
+
"biz": "baz",
|
|
93
|
+
})
|
|
94
|
+
$set.adds($dict)
|
|
95
|
+
return($set)
|
|
96
|
+
'''
|
|
97
|
+
valu = await core.callStorm(q)
|
|
98
|
+
self.len(5, valu)
|
|
99
|
+
self.isin(False, valu)
|
|
100
|
+
self.isin(True, valu)
|
|
101
|
+
self.isin('more stuff', valu)
|
|
102
|
+
self.isin(('biz', 'baz'), valu)
|
|
103
|
+
self.isin(('foo', 'bar'), valu)
|
|
104
|
+
|
|
105
|
+
q = '''
|
|
106
|
+
$set = $lib.spooled.set()
|
|
107
|
+
$set.adds($items)
|
|
108
|
+
for $x in $set {
|
|
109
|
+
$lib.print(`{$x} exists in the set`)
|
|
110
|
+
}
|
|
111
|
+
return()
|
|
112
|
+
'''
|
|
113
|
+
msgs = await core.stormlist(q, opts={'vars': {'items': [True, 'neato', False, 9001]}})
|
|
114
|
+
self.len(7, msgs)
|
|
115
|
+
self.stormIsInPrint('false exists in the set', msgs)
|
|
116
|
+
self.stormIsInPrint('true exists in the set', msgs)
|
|
117
|
+
self.stormIsInPrint('neato exists in the set', msgs)
|
|
118
|
+
self.stormIsInPrint('9001 exists in the set', msgs)
|
|
119
|
+
|
|
120
|
+
q = '''
|
|
121
|
+
$set = $lib.spooled.set(neato, neato, neato, neato)
|
|
122
|
+
$lib.print(`The set is {$set}`)
|
|
123
|
+
'''
|
|
124
|
+
msgs = await core.stormlist(q, opts={'vars': {'items': [True, 'neato', False, 9001]}})
|
|
125
|
+
self.stormIsInPrint("The set is {'neato'}", msgs)
|
|
126
|
+
|
|
127
|
+
# force a fallback
|
|
128
|
+
q = '''
|
|
129
|
+
$set = $lib.spooled.set()
|
|
130
|
+
$set.adds($lib.range(1500))
|
|
131
|
+
return($set.size())
|
|
132
|
+
'''
|
|
133
|
+
valu = await core.callStorm(q)
|
|
134
|
+
self.eq(1500, valu)
|
|
135
|
+
|
|
136
|
+
# sad paths
|
|
137
|
+
# too complex
|
|
138
|
+
q = '''
|
|
139
|
+
$set = $lib.spooled.set()
|
|
140
|
+
$set.add($stormnode)
|
|
141
|
+
return($set)
|
|
142
|
+
'''
|
|
143
|
+
stormnode = s_stormtypes.Node(nodes[0])
|
|
144
|
+
await self.asyncraises(s_exc.StormRuntimeError, core.callStorm(q, {'vars': {'stormnode': stormnode}}))
|
|
145
|
+
|
|
146
|
+
# mutable failures
|
|
147
|
+
q = '''
|
|
148
|
+
$set = $lib.spooled.set()
|
|
149
|
+
$set.add(({'neato': 'burrito'}))
|
|
150
|
+
return($set)
|
|
151
|
+
'''
|
|
152
|
+
await self.asyncraises(s_exc.StormRuntimeError, core.callStorm(q))
|
|
153
|
+
|
|
154
|
+
q = '''
|
|
155
|
+
$set = $lib.spooled.set()
|
|
156
|
+
$dict = ({'neato': 'burrito'})
|
|
157
|
+
$set.adds(($dict, $dict))
|
|
158
|
+
return($set)
|
|
159
|
+
'''
|
|
160
|
+
await self.asyncraises(s_exc.StormRuntimeError, core.callStorm(q))
|
|
161
|
+
|
|
162
|
+
q = '''
|
|
163
|
+
$set = $lib.spooled.set()
|
|
164
|
+
$form = $lib.model.form('inet:ipv4')
|
|
165
|
+
$set.adds(($stormnode, $form, $form))
|
|
166
|
+
return($set)
|
|
167
|
+
'''
|
|
168
|
+
# it'll blow up on the first
|
|
169
|
+
await self.asyncraises(s_exc.StormRuntimeError, core.callStorm(q, {'vars': {'stormnode': stormnode}}))
|
|
170
|
+
|
|
171
|
+
q = '''
|
|
172
|
+
$dict = ({'foo': 'bar'})
|
|
173
|
+
$set = $lib.spooled.set($dict)
|
|
174
|
+
return($set)
|
|
175
|
+
'''
|
|
176
|
+
await self.asyncraises(s_exc.StormRuntimeError, core.callStorm(q))
|
|
177
|
+
|
|
178
|
+
# type not msgpack-able
|
|
179
|
+
q = '''
|
|
180
|
+
$set = $lib.spooled.set()
|
|
181
|
+
$set.add($lib.model.form("inet:ipv4"))
|
|
182
|
+
return($set)
|
|
183
|
+
'''
|
|
184
|
+
await self.asyncraises(s_exc.StormRuntimeError, core.callStorm(q))
|
|
185
|
+
|
|
186
|
+
q = '''
|
|
187
|
+
$set = $lib.spooled.set($stormnode)
|
|
188
|
+
return($set)
|
|
189
|
+
'''
|
|
190
|
+
await self.asyncraises(s_exc.StormRuntimeError, core.callStorm(q, {'vars': {'stormnode': stormnode}}))
|
|
@@ -397,22 +397,31 @@ class StormlibVaultTest(s_test.SynTest):
|
|
|
397
397
|
self.true(core._hasEasyPerm(vault, visi1, s_cell.PERM_READ))
|
|
398
398
|
|
|
399
399
|
rvault_out = split(f'''
|
|
400
|
-
Vault:
|
|
400
|
+
Vault: {riden}
|
|
401
|
+
Name: rvault
|
|
401
402
|
Type: {vtype}
|
|
402
403
|
Scope: role
|
|
403
|
-
Iden: {riden}
|
|
404
404
|
Permissions:
|
|
405
405
|
Users:
|
|
406
406
|
visi1: read
|
|
407
407
|
Roles:
|
|
408
408
|
contributor: read
|
|
409
|
+
Configs:
|
|
410
|
+
server: rvault
|
|
409
411
|
''')[1:]
|
|
410
412
|
|
|
411
413
|
opts = {'vars': {'vtype': vtype}, 'user': visi1.iden}
|
|
412
414
|
msgs = await core.stormlist('vault.list --type $vtype', opts=opts)
|
|
413
|
-
for line in
|
|
415
|
+
for line in rvault_out:
|
|
414
416
|
self.stormIsInPrint(line, msgs)
|
|
415
417
|
|
|
418
|
+
msgs = await core.stormlist('vault.set.perm rvault --level admin --role contributor')
|
|
419
|
+
self.stormHasNoWarnErr(msgs)
|
|
420
|
+
self.stormIsInPrint('Successfully set permissions on vault rvault.', msgs)
|
|
421
|
+
|
|
422
|
+
msgs = await core.stormlist('vault.list --type $vtype', opts=opts)
|
|
423
|
+
self.stormIsInPrint('contributor: admin', msgs)
|
|
424
|
+
|
|
416
425
|
# vault.del
|
|
417
426
|
msgs = await core.stormlist('vault.del uvault')
|
|
418
427
|
self.stormIsInPrint('Successfully deleted vault uvault.', msgs)
|
|
@@ -15,7 +15,6 @@ import synapse.tools.backup as s_tools_backup
|
|
|
15
15
|
old_pkg = {
|
|
16
16
|
'name': 'old',
|
|
17
17
|
'version': (0, 0, 1),
|
|
18
|
-
'synapse_minversion': [2, 144, 0],
|
|
19
18
|
'synapse_version': '>=2.8.0,<3.0.0',
|
|
20
19
|
'modules': (
|
|
21
20
|
{'name': 'old.bar', 'storm': 'function bar(x, y) { return ($($x + $y)) }'},
|
|
@@ -40,7 +39,6 @@ old_pkg = {
|
|
|
40
39
|
new_old_pkg = {
|
|
41
40
|
'name': 'old',
|
|
42
41
|
'version': (0, 1, 0),
|
|
43
|
-
'synapse_minversion': [2, 144, 0],
|
|
44
42
|
'synapse_version': '>=2.8.0,<3.0.0',
|
|
45
43
|
'modules': (
|
|
46
44
|
{'name': 'old.bar', 'storm': 'function bar(x, y) { return ($($x + $y)) }'},
|
|
@@ -65,7 +63,6 @@ new_old_pkg = {
|
|
|
65
63
|
new_pkg = {
|
|
66
64
|
'name': 'new',
|
|
67
65
|
'version': (0, 0, 1),
|
|
68
|
-
'synapse_minversion': [2, 144, 0],
|
|
69
66
|
'synapse_version': '>=2.8.0,<3.0.0',
|
|
70
67
|
'modules': (
|
|
71
68
|
{'name': 'echo', 'storm': '''function echo(arg1, arg2) {
|
|
@@ -124,7 +121,6 @@ class RealService(s_stormsvc.StormSvc):
|
|
|
124
121
|
{ # type: ignore
|
|
125
122
|
'name': 'foo',
|
|
126
123
|
'version': (0, 0, 1),
|
|
127
|
-
'synapse_minversion': [2, 144, 0],
|
|
128
124
|
'synapse_version': '>=2.8.0,<3.0.0',
|
|
129
125
|
'modules': (
|
|
130
126
|
{'name': 'foo.bar',
|
|
@@ -188,7 +184,6 @@ class NodeCreateService(s_stormsvc.StormSvc):
|
|
|
188
184
|
{
|
|
189
185
|
'name': 'ncreate',
|
|
190
186
|
'version': (0, 0, 1),
|
|
191
|
-
'synapse_minversion': [2, 144, 0],
|
|
192
187
|
'synapse_version': '>=2.8.0,<3.0.0',
|
|
193
188
|
'commands': (
|
|
194
189
|
{
|
|
@@ -207,7 +202,6 @@ class BoomService(s_stormsvc.StormSvc):
|
|
|
207
202
|
{ # type: ignore
|
|
208
203
|
'name': 'boom',
|
|
209
204
|
'version': (0, 0, 1),
|
|
210
|
-
'synapse_minversion': [2, 144, 0],
|
|
211
205
|
'synapse_version': '>=2.8.0,<3.0.0',
|
|
212
206
|
'modules': (
|
|
213
207
|
{'name': 'blah', 'storm': '+}'},
|
|
@@ -266,7 +260,6 @@ class LifterService(s_stormsvc.StormSvc):
|
|
|
266
260
|
{ # type: ignore
|
|
267
261
|
'name': 'lifter',
|
|
268
262
|
'version': (0, 0, 1),
|
|
269
|
-
'synapse_minversion': [2, 144, 0],
|
|
270
263
|
'synapse_version': '>=2.8.0,<3.0.0',
|
|
271
264
|
'commands': (
|
|
272
265
|
{
|
|
@@ -292,7 +285,6 @@ class StormvarService(s_cell.CellApi, s_stormsvc.StormSvc):
|
|
|
292
285
|
{ # type: ignore
|
|
293
286
|
'name': 'stormvar',
|
|
294
287
|
'version': (0, 0, 1),
|
|
295
|
-
'synapse_minversion': [2, 144, 0],
|
|
296
288
|
'synapse_version': '>=2.8.0,<3.0.0',
|
|
297
289
|
'commands': (
|
|
298
290
|
{
|
|
@@ -379,7 +371,6 @@ class ShareService(s_cell.CellApi, s_stormsvc.StormSvc):
|
|
|
379
371
|
{ # type: ignore
|
|
380
372
|
'name': 'sharer',
|
|
381
373
|
'version': (0, 0, 1),
|
|
382
|
-
'synapse_minversion': [2, 144, 0],
|
|
383
374
|
'synapse_version': '>=2.8.0,<3.0.0',
|
|
384
375
|
'modules': (
|
|
385
376
|
{
|
|
@@ -503,7 +494,6 @@ class StormSvcTest(s_test.SynTest):
|
|
|
503
494
|
pkg = {
|
|
504
495
|
'name': 'foobar',
|
|
505
496
|
'version': (0, 0, 1),
|
|
506
|
-
'synapse_minversion': [2, 144, 0],
|
|
507
497
|
'synapse_version': '>=2.8.0,<3.0.0',
|
|
508
498
|
'modules': (
|
|
509
499
|
{'name': 'hehe.haha', 'storm': 'function add(x, y) { return ($($x + $y)) }'},
|