synapse 2.221.0__py311-none-any.whl → 2.223.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 +143 -44
- synapse/cryotank.py +1 -1
- synapse/data/lark/storm.lark +9 -6
- synapse/lib/ast.py +13 -5
- synapse/lib/layer.py +18 -11
- synapse/lib/nexus.py +1 -1
- synapse/lib/parser.py +1 -0
- synapse/lib/rstorm.py +19 -1
- synapse/lib/schemas.py +4 -0
- synapse/lib/snap.py +15 -9
- synapse/lib/storm.py +0 -190
- synapse/lib/stormlib/auth.py +1 -1
- synapse/lib/stormlib/cortex.py +1 -1
- synapse/lib/stormlib/mime.py +15 -5
- synapse/lib/stormlib/pkg.py +598 -0
- synapse/lib/stormlib/task.py +115 -0
- synapse/lib/stormtypes.py +42 -178
- synapse/lib/trigger.py +16 -14
- synapse/lib/version.py +2 -2
- synapse/lib/view.py +17 -14
- synapse/models/files.py +1 -1
- synapse/models/orgs.py +3 -0
- synapse/tests/test_cortex.py +1 -1
- synapse/tests/test_lib_aha.py +68 -53
- synapse/tests/test_lib_ast.py +3 -0
- synapse/tests/test_lib_cell.py +12 -12
- synapse/tests/test_lib_grammar.py +4 -4
- synapse/tests/test_lib_rstorm.py +55 -7
- synapse/tests/test_lib_storm.py +105 -249
- synapse/tests/test_lib_stormlib_auth.py +84 -0
- synapse/tests/test_lib_stormlib_cortex.py +1 -0
- synapse/tests/test_lib_stormlib_mime.py +24 -0
- synapse/tests/test_lib_stormlib_pkg.py +456 -0
- synapse/tests/test_lib_stormlib_task.py +98 -0
- synapse/tests/test_lib_stormtypes.py +25 -100
- synapse/tests/test_lib_trigger.py +66 -3
- synapse/tests/test_lib_view.py +53 -0
- synapse/tests/test_model_files.py +11 -0
- synapse/tests/test_model_orgs.py +6 -1
- synapse/tools/cryo/cat.py +2 -1
- synapse/tools/cryo/list.py +2 -0
- {synapse-2.221.0.dist-info → synapse-2.223.0.dist-info}/METADATA +1 -1
- {synapse-2.221.0.dist-info → synapse-2.223.0.dist-info}/RECORD +46 -42
- {synapse-2.221.0.dist-info → synapse-2.223.0.dist-info}/WHEEL +0 -0
- {synapse-2.221.0.dist-info → synapse-2.223.0.dist-info}/licenses/LICENSE +0 -0
- {synapse-2.221.0.dist-info → synapse-2.223.0.dist-info}/top_level.txt +0 -0
synapse/tests/test_lib_storm.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import copy
|
|
2
2
|
import asyncio
|
|
3
|
-
import datetime
|
|
4
3
|
import itertools
|
|
5
4
|
import urllib.parse as u_parse
|
|
6
5
|
import unittest.mock as mock
|
|
@@ -17,6 +16,7 @@ import synapse.lib.storm as s_storm
|
|
|
17
16
|
import synapse.lib.httpapi as s_httpapi
|
|
18
17
|
import synapse.lib.msgpack as s_msgpack
|
|
19
18
|
import synapse.lib.version as s_version
|
|
19
|
+
import synapse.lib.stormtypes as s_stormtypes
|
|
20
20
|
|
|
21
21
|
import synapse.tests.utils as s_t_utils
|
|
22
22
|
from synapse.tests.utils import alist
|
|
@@ -1220,33 +1220,6 @@ class StormTest(s_t_utils.SynTest):
|
|
|
1220
1220
|
''')
|
|
1221
1221
|
self.eq(email, 'visi@vertex.link')
|
|
1222
1222
|
|
|
1223
|
-
pkg0 = {'name': 'hehe', 'version': '1.2.3'}
|
|
1224
|
-
await core.addStormPkg(pkg0)
|
|
1225
|
-
self.eq('1.2.3', await core.callStorm('return($lib.pkg.get(hehe).version)'))
|
|
1226
|
-
|
|
1227
|
-
self.eq(None, await core.callStorm('return($lib.pkg.get(nopkg))'))
|
|
1228
|
-
|
|
1229
|
-
pkg1 = {'name': 'haha', 'version': '1.2.3'}
|
|
1230
|
-
await core.addStormPkg(pkg1)
|
|
1231
|
-
msgs = await core.stormlist('pkg.list')
|
|
1232
|
-
self.stormIsInPrint('haha', msgs)
|
|
1233
|
-
self.stormIsInPrint('hehe', msgs)
|
|
1234
|
-
|
|
1235
|
-
self.true(await core.callStorm('return($lib.pkg.has(haha))'))
|
|
1236
|
-
|
|
1237
|
-
await core.delStormPkg('haha')
|
|
1238
|
-
self.none(await core.callStorm('return($lib.pkg.get(haha))'))
|
|
1239
|
-
self.false(await core.callStorm('return($lib.pkg.has(haha))'))
|
|
1240
|
-
|
|
1241
|
-
msgs = await core.stormlist('pkg.list --verbose')
|
|
1242
|
-
self.stormIsInPrint('not available', msgs)
|
|
1243
|
-
|
|
1244
|
-
pkg2 = {'name': 'hoho', 'version': '4.5.6', 'build': {'time': 1732017600000}}
|
|
1245
|
-
await core.addStormPkg(pkg2)
|
|
1246
|
-
self.eq('4.5.6', await core.callStorm('return($lib.pkg.get(hoho).version)'))
|
|
1247
|
-
msgs = await core.stormlist('pkg.list --verbose')
|
|
1248
|
-
self.stormIsInPrint('2024-11-19 12:00:00', msgs)
|
|
1249
|
-
|
|
1250
1223
|
# test for $lib.queue.gen()
|
|
1251
1224
|
self.eq(0, await core.callStorm('return($lib.queue.gen(woot).size())'))
|
|
1252
1225
|
# and again to test *not* creating it...
|
|
@@ -1575,161 +1548,6 @@ class StormTest(s_t_utils.SynTest):
|
|
|
1575
1548
|
nodes = [x for x in msgs if x[0] == 'node']
|
|
1576
1549
|
self.len(0, nodes)
|
|
1577
1550
|
|
|
1578
|
-
pkgdef = {
|
|
1579
|
-
'name': 'foobar',
|
|
1580
|
-
'version': '1.2.3',
|
|
1581
|
-
}
|
|
1582
|
-
|
|
1583
|
-
await core.addStormPkg(pkgdef)
|
|
1584
|
-
|
|
1585
|
-
deps = await core.callStorm('return($lib.pkg.deps($pkgdef))', opts={'vars': {'pkgdef': pkgdef}})
|
|
1586
|
-
self.eq({
|
|
1587
|
-
'requires': (),
|
|
1588
|
-
'conflicts': (),
|
|
1589
|
-
}, deps)
|
|
1590
|
-
|
|
1591
|
-
pkgdef = {
|
|
1592
|
-
'name': 'bazfaz',
|
|
1593
|
-
'version': '2.2.2',
|
|
1594
|
-
'depends': {
|
|
1595
|
-
'conflicts': (
|
|
1596
|
-
{'name': 'foobar'},
|
|
1597
|
-
),
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
with self.raises(s_exc.StormPkgConflicts):
|
|
1602
|
-
await core.addStormPkg(pkgdef)
|
|
1603
|
-
|
|
1604
|
-
deps = await core.callStorm('return($lib.pkg.deps($pkgdef))', opts={'vars': {'pkgdef': pkgdef}})
|
|
1605
|
-
self.eq({
|
|
1606
|
-
'requires': (),
|
|
1607
|
-
'conflicts': (
|
|
1608
|
-
{'name': 'foobar', 'version': None, 'desc': None, 'ok': False, 'actual': '1.2.3'},
|
|
1609
|
-
)
|
|
1610
|
-
}, deps)
|
|
1611
|
-
|
|
1612
|
-
pkgdef = {
|
|
1613
|
-
'name': 'bazfaz',
|
|
1614
|
-
'version': '2.2.2',
|
|
1615
|
-
'depends': {
|
|
1616
|
-
'conflicts': (
|
|
1617
|
-
{'name': 'foobar', 'version': '>=1.0.0', 'desc': 'foo'},
|
|
1618
|
-
),
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
with self.raises(s_exc.StormPkgConflicts):
|
|
1623
|
-
await core.addStormPkg(pkgdef)
|
|
1624
|
-
|
|
1625
|
-
deps = await core.callStorm('return($lib.pkg.deps($pkgdef))', opts={'vars': {'pkgdef': pkgdef}})
|
|
1626
|
-
self.eq({
|
|
1627
|
-
'requires': (),
|
|
1628
|
-
'conflicts': (
|
|
1629
|
-
{'name': 'foobar', 'version': '>=1.0.0', 'desc': 'foo', 'ok': False, 'actual': '1.2.3'},
|
|
1630
|
-
)
|
|
1631
|
-
}, deps)
|
|
1632
|
-
|
|
1633
|
-
pkgdef = {
|
|
1634
|
-
'name': 'bazfaz',
|
|
1635
|
-
'version': '2.2.2',
|
|
1636
|
-
'depends': {
|
|
1637
|
-
'requires': (
|
|
1638
|
-
{'name': 'foobar', 'version': '>=2.0.0,<3.0.0'},
|
|
1639
|
-
),
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
with self.getAsyncLoggerStream('synapse.cortex', 'bazfaz requirement') as stream:
|
|
1644
|
-
await core.addStormPkg(pkgdef)
|
|
1645
|
-
self.true(await stream.wait(timeout=1))
|
|
1646
|
-
|
|
1647
|
-
pkgdef = {
|
|
1648
|
-
'name': 'bazfaz',
|
|
1649
|
-
'version': '2.2.2',
|
|
1650
|
-
'depends': {
|
|
1651
|
-
'requires': (
|
|
1652
|
-
{'name': 'foobar', 'version': '>=2.0.0,<3.0.0', 'optional': True},
|
|
1653
|
-
),
|
|
1654
|
-
}
|
|
1655
|
-
}
|
|
1656
|
-
|
|
1657
|
-
with self.getAsyncLoggerStream('synapse.cortex', 'bazfaz optional requirement') as stream:
|
|
1658
|
-
await core.addStormPkg(pkgdef)
|
|
1659
|
-
self.true(await stream.wait(timeout=1))
|
|
1660
|
-
|
|
1661
|
-
deps = await core.callStorm('return($lib.pkg.deps($pkgdef))', opts={'vars': {'pkgdef': pkgdef}})
|
|
1662
|
-
self.eq({
|
|
1663
|
-
'requires': (
|
|
1664
|
-
{'name': 'foobar', 'version': '>=2.0.0,<3.0.0', 'desc': None,
|
|
1665
|
-
'ok': False, 'actual': '1.2.3', 'optional': True},
|
|
1666
|
-
),
|
|
1667
|
-
'conflicts': ()
|
|
1668
|
-
}, deps)
|
|
1669
|
-
|
|
1670
|
-
pkgdef = {
|
|
1671
|
-
'name': 'lolzlolz',
|
|
1672
|
-
'version': '1.2.3',
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
|
-
await core.addStormPkg(pkgdef)
|
|
1676
|
-
|
|
1677
|
-
deps = await core.callStorm('return($lib.pkg.deps($pkgdef))', opts={'vars': {'pkgdef': pkgdef}})
|
|
1678
|
-
self.eq({
|
|
1679
|
-
'requires': (),
|
|
1680
|
-
'conflicts': (),
|
|
1681
|
-
}, deps)
|
|
1682
|
-
|
|
1683
|
-
pkgdef = {
|
|
1684
|
-
'name': 'bazfaz',
|
|
1685
|
-
'version': '2.2.2',
|
|
1686
|
-
'depends': {
|
|
1687
|
-
'requires': (
|
|
1688
|
-
{'name': 'lolzlolz', 'version': '>=1.0.0,<2.0.0', 'desc': 'lol'},
|
|
1689
|
-
),
|
|
1690
|
-
'conflicts': (
|
|
1691
|
-
{'name': 'foobar', 'version': '>=3.0.0'},
|
|
1692
|
-
),
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
|
|
1696
|
-
await core.addStormPkg(pkgdef)
|
|
1697
|
-
|
|
1698
|
-
deps = await core.callStorm('return($lib.pkg.deps($pkgdef))', opts={'vars': {'pkgdef': pkgdef}})
|
|
1699
|
-
self.eq({
|
|
1700
|
-
'requires': (
|
|
1701
|
-
{'name': 'lolzlolz', 'version': '>=1.0.0,<2.0.0', 'desc': 'lol', 'ok': True, 'actual': '1.2.3'},
|
|
1702
|
-
),
|
|
1703
|
-
'conflicts': (
|
|
1704
|
-
{'name': 'foobar', 'version': '>=3.0.0', 'desc': None, 'ok': True, 'actual': '1.2.3'},
|
|
1705
|
-
)
|
|
1706
|
-
}, deps)
|
|
1707
|
-
|
|
1708
|
-
pkgdef = {
|
|
1709
|
-
'name': 'zoinkszoinks',
|
|
1710
|
-
'version': '2.2.2',
|
|
1711
|
-
'depends': {
|
|
1712
|
-
'requires': (
|
|
1713
|
-
{'name': 'newpnewp', 'version': '1.2.3'},
|
|
1714
|
-
),
|
|
1715
|
-
'conflicts': (
|
|
1716
|
-
{'name': 'newpnewp'},
|
|
1717
|
-
),
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
|
-
await core.addStormPkg(pkgdef)
|
|
1722
|
-
|
|
1723
|
-
deps = await core.callStorm('return($lib.pkg.deps($pkgdef))', opts={'vars': {'pkgdef': pkgdef}})
|
|
1724
|
-
self.eq({
|
|
1725
|
-
'requires': (
|
|
1726
|
-
{'name': 'newpnewp', 'version': '1.2.3', 'desc': None, 'ok': False, 'actual': None},
|
|
1727
|
-
),
|
|
1728
|
-
'conflicts': (
|
|
1729
|
-
{'name': 'newpnewp', 'version': None, 'desc': None, 'ok': True, 'actual': None},
|
|
1730
|
-
)
|
|
1731
|
-
}, deps)
|
|
1732
|
-
|
|
1733
1551
|
# force old-cron behavior which lacks a view
|
|
1734
1552
|
await core.nodes('cron.add --hourly 03 { inet:ipv4 }')
|
|
1735
1553
|
for (iden, cron) in core.agenda.list():
|
|
@@ -2980,72 +2798,6 @@ class StormTest(s_t_utils.SynTest):
|
|
|
2980
2798
|
with self.raises(s_exc.NoSuchVar):
|
|
2981
2799
|
await core.callStorm('$foo = 10 $foo = $lib.undef return($foo)')
|
|
2982
2800
|
|
|
2983
|
-
async def test_storm_pkg_load(self):
|
|
2984
|
-
cont = s_common.guid()
|
|
2985
|
-
pkg = {
|
|
2986
|
-
'name': 'testload',
|
|
2987
|
-
'version': '0.3.0',
|
|
2988
|
-
'modules': (
|
|
2989
|
-
{
|
|
2990
|
-
'name': 'testload',
|
|
2991
|
-
'storm': 'function x() { return((0)) }',
|
|
2992
|
-
},
|
|
2993
|
-
),
|
|
2994
|
-
'onload': f'[ ps:contact={cont} ] $lib.print(teststring) $lib.warn(testwarn, key=valu) return($path.vars.newp)'
|
|
2995
|
-
}
|
|
2996
|
-
class PkgHandler(s_httpapi.Handler):
|
|
2997
|
-
|
|
2998
|
-
async def get(self, name):
|
|
2999
|
-
assert self.request.headers.get('X-Synapse-Version') == s_version.verstring
|
|
3000
|
-
|
|
3001
|
-
if name == 'notok':
|
|
3002
|
-
self.sendRestErr('FooBar', 'baz faz')
|
|
3003
|
-
return
|
|
3004
|
-
|
|
3005
|
-
self.sendRestRetn(pkg)
|
|
3006
|
-
|
|
3007
|
-
class PkgHandlerRaw(s_httpapi.Handler):
|
|
3008
|
-
async def get(self, name):
|
|
3009
|
-
assert self.request.headers.get('X-Synapse-Version') == s_version.verstring
|
|
3010
|
-
|
|
3011
|
-
self.set_header('Content-Type', 'application/json')
|
|
3012
|
-
return self.write(pkg)
|
|
3013
|
-
|
|
3014
|
-
async with self.getTestCore() as core:
|
|
3015
|
-
core.addHttpApi('/api/v1/pkgtest/(.*)', PkgHandler, {'cell': core})
|
|
3016
|
-
core.addHttpApi('/api/v1/pkgtestraw/(.*)', PkgHandlerRaw, {'cell': core})
|
|
3017
|
-
port = (await core.addHttpsPort(0, host='127.0.0.1'))[1]
|
|
3018
|
-
|
|
3019
|
-
msgs = await core.stormlist(f'pkg.load --ssl-noverify https://127.0.0.1:{port}/api/v1/newp/newp')
|
|
3020
|
-
self.stormIsInWarn('pkg.load got HTTP code: 404', msgs)
|
|
3021
|
-
|
|
3022
|
-
msgs = await core.stormlist(f'pkg.load --ssl-noverify https://127.0.0.1:{port}/api/v1/pkgtest/notok')
|
|
3023
|
-
self.stormIsInWarn('pkg.load got JSON error: FooBar', msgs)
|
|
3024
|
-
|
|
3025
|
-
# onload will on fire once. all other pkg.load events will effectively bounce
|
|
3026
|
-
# because the pkg hasn't changed so no loading occurs
|
|
3027
|
-
waiter = core.waiter(1, 'core:pkg:onload:complete')
|
|
3028
|
-
|
|
3029
|
-
with self.getAsyncLoggerStream('synapse.cortex') as stream:
|
|
3030
|
-
msgs = await core.stormlist(f'pkg.load --ssl-noverify https://127.0.0.1:{port}/api/v1/pkgtest/yep')
|
|
3031
|
-
self.stormIsInPrint('testload @0.3.0', msgs)
|
|
3032
|
-
|
|
3033
|
-
msgs = await core.stormlist(f'pkg.load --ssl-noverify --raw https://127.0.0.1:{port}/api/v1/pkgtestraw/yep')
|
|
3034
|
-
self.stormIsInPrint('testload @0.3.0', msgs)
|
|
3035
|
-
|
|
3036
|
-
stream.seek(0)
|
|
3037
|
-
buf = stream.read()
|
|
3038
|
-
self.isin("testload onload output: teststring", buf)
|
|
3039
|
-
self.isin("testload onload output: testwarn", buf)
|
|
3040
|
-
self.isin("No var with name: newp", buf)
|
|
3041
|
-
self.len(1, await core.nodes(f'ps:contact={cont}'))
|
|
3042
|
-
|
|
3043
|
-
evnts = await waiter.wait(timeout=4)
|
|
3044
|
-
exp = [
|
|
3045
|
-
('core:pkg:onload:complete', {'pkg': 'testload'})
|
|
3046
|
-
]
|
|
3047
|
-
self.eq(exp, evnts)
|
|
3048
|
-
|
|
3049
2801
|
async def test_storm_pkg_onload_active(self):
|
|
3050
2802
|
pkg = {
|
|
3051
2803
|
'name': 'testload',
|
|
@@ -3294,6 +3046,37 @@ class StormTest(s_t_utils.SynTest):
|
|
|
3294
3046
|
await stream.wait(timeout=10)
|
|
3295
3047
|
self.eq(8, await core.getStormPkgVar('testload', 'testload:version'))
|
|
3296
3048
|
|
|
3049
|
+
# init that advances the version
|
|
3050
|
+
|
|
3051
|
+
pkg['version'] = '0.7.0'
|
|
3052
|
+
pkg['inits']['versions'].extend([
|
|
3053
|
+
{
|
|
3054
|
+
'version': 9,
|
|
3055
|
+
'name': 'init09',
|
|
3056
|
+
'query': '''
|
|
3057
|
+
$lib.globals.set(init09, $lib.time.now())
|
|
3058
|
+
$lib.pkg.vars(testload)."testload:version" = (10)
|
|
3059
|
+
''',
|
|
3060
|
+
},
|
|
3061
|
+
{
|
|
3062
|
+
'version': 10,
|
|
3063
|
+
'name': 'init10',
|
|
3064
|
+
'query': '$lib.globals.set(init10, $lib.time.now())',
|
|
3065
|
+
},
|
|
3066
|
+
{
|
|
3067
|
+
'version': 11,
|
|
3068
|
+
'name': 'init11',
|
|
3069
|
+
'query': '$lib.globals.set(init11, $lib.time.now())',
|
|
3070
|
+
},
|
|
3071
|
+
])
|
|
3072
|
+
|
|
3073
|
+
await loadPkg(core, pkg)
|
|
3074
|
+
|
|
3075
|
+
self.eq(11, await core.getStormPkgVar('testload', 'testload:version'))
|
|
3076
|
+
self.nn(await core.getStormVar('init09'))
|
|
3077
|
+
self.none(await core.getStormVar('init10'))
|
|
3078
|
+
self.nn(await core.getStormVar('init11'))
|
|
3079
|
+
|
|
3297
3080
|
async def test_storm_tree(self):
|
|
3298
3081
|
|
|
3299
3082
|
async with self.getTestCore() as core:
|
|
@@ -4874,6 +4657,79 @@ class StormTest(s_t_utils.SynTest):
|
|
|
4874
4657
|
self.len(1, links)
|
|
4875
4658
|
self.eq({'type': 'runtime'}, links[0][1])
|
|
4876
4659
|
|
|
4660
|
+
async def test_storm_derefprops(self):
|
|
4661
|
+
async with self.getTestCore() as core:
|
|
4662
|
+
await core.addTagProp('score', ('int', {}), {})
|
|
4663
|
+
|
|
4664
|
+
mesg = "Expected value of type 'str', got '"
|
|
4665
|
+
|
|
4666
|
+
# editnodeadd
|
|
4667
|
+
msgs = await core.stormlist('$form = inet:fqdn [ *$form=foobar.com ]')
|
|
4668
|
+
self.stormHasNoWarnErr(msgs)
|
|
4669
|
+
|
|
4670
|
+
invals = [10, None, False, [], {}]
|
|
4671
|
+
|
|
4672
|
+
for inval in invals:
|
|
4673
|
+
opts = {'vars': {'form': inval}}
|
|
4674
|
+
with self.raises(s_exc.StormRuntimeError) as exc:
|
|
4675
|
+
await core.nodes('[ *$form=valu ]', opts=opts)
|
|
4676
|
+
self.true(exc.exception.get('mesg').startswith(mesg))
|
|
4677
|
+
|
|
4678
|
+
# liftprop
|
|
4679
|
+
msgs = await core.stormlist('$form = inet:fqdn *$form')
|
|
4680
|
+
self.stormHasNoWarnErr(msgs)
|
|
4681
|
+
|
|
4682
|
+
for inval in invals:
|
|
4683
|
+
opts = {'vars': {'form': inval}}
|
|
4684
|
+
with self.raises(s_exc.StormRuntimeError) as exc:
|
|
4685
|
+
await core.nodes('*$form', opts=opts)
|
|
4686
|
+
self.true(exc.exception.get('mesg').startswith(mesg))
|
|
4687
|
+
|
|
4688
|
+
# liftpropby
|
|
4689
|
+
msgs = await core.stormlist('$form = inet:fqdn *$form=foobar.com')
|
|
4690
|
+
self.stormHasNoWarnErr(msgs)
|
|
4691
|
+
|
|
4692
|
+
for inval in invals:
|
|
4693
|
+
opts = {'vars': {'form': inval}}
|
|
4694
|
+
with self.raises(s_exc.StormRuntimeError) as exc:
|
|
4695
|
+
await core.nodes('*$form=newp', opts=opts)
|
|
4696
|
+
self.true(exc.exception.get('mesg').startswith(mesg))
|
|
4697
|
+
|
|
4698
|
+
# liftformtag
|
|
4699
|
+
msgs = await core.stormlist('$form = inet:fqdn *$form#foo')
|
|
4700
|
+
self.stormHasNoWarnErr(msgs)
|
|
4701
|
+
|
|
4702
|
+
for inval in invals:
|
|
4703
|
+
opts = {'vars': {'form': inval}}
|
|
4704
|
+
with self.raises(s_exc.StormRuntimeError) as exc:
|
|
4705
|
+
await core.nodes('*$form#newp', opts=opts)
|
|
4706
|
+
self.true(exc.exception.get('mesg').startswith(mesg))
|
|
4707
|
+
|
|
4708
|
+
# liftbyarray
|
|
4709
|
+
msgs = await core.stormlist('$form = test:arrayform *$form*[=(10)]')
|
|
4710
|
+
self.stormHasNoWarnErr(msgs)
|
|
4711
|
+
|
|
4712
|
+
for inval in invals:
|
|
4713
|
+
opts = {'vars': {'form': inval}}
|
|
4714
|
+
with self.raises(s_exc.StormRuntimeError) as exc:
|
|
4715
|
+
await core.nodes('*$form*[="newp"]', opts=opts)
|
|
4716
|
+
self.true(exc.exception.get('mesg').startswith(mesg))
|
|
4717
|
+
|
|
4718
|
+
# formtagprop
|
|
4719
|
+
msgs = await core.stormlist('$form = inet:fqdn *$form#foo:score')
|
|
4720
|
+
self.stormHasNoWarnErr(msgs)
|
|
4721
|
+
|
|
4722
|
+
for inval in invals:
|
|
4723
|
+
opts = {'vars': {'form': inval}}
|
|
4724
|
+
with self.raises(s_exc.StormRuntimeError) as exc:
|
|
4725
|
+
await core.nodes('*$form#newp:score', opts=opts)
|
|
4726
|
+
self.true(exc.exception.get('mesg').startswith(mesg))
|
|
4727
|
+
|
|
4728
|
+
# Check Storm Str types
|
|
4729
|
+
name = s_stormtypes.Str('inet:fqdn')
|
|
4730
|
+
msgs = await core.stormlist('*$form', opts={'vars': {'form': name}})
|
|
4731
|
+
self.stormHasNoWarnErr(msgs)
|
|
4732
|
+
|
|
4877
4733
|
async def test_storm_nested_root(self):
|
|
4878
4734
|
async with self.getTestCore() as core:
|
|
4879
4735
|
self.eq(20, await core.callStorm('''
|
|
@@ -427,6 +427,90 @@ class StormLibAuthTest(s_test.SynTest):
|
|
|
427
427
|
opts=asuser
|
|
428
428
|
)
|
|
429
429
|
|
|
430
|
+
async def test_stormlib_auth_asroot_ondeny(self):
|
|
431
|
+
async with self.getTestCore() as core:
|
|
432
|
+
|
|
433
|
+
stormpkg = {
|
|
434
|
+
'name': 'authtest',
|
|
435
|
+
'version': '0.0.1',
|
|
436
|
+
'perms': (
|
|
437
|
+
{'perm': ('authtest', 'perm'), 'desc': 'Elevate mod', 'gate': 'cortex'},
|
|
438
|
+
),
|
|
439
|
+
'modules': (
|
|
440
|
+
{
|
|
441
|
+
'name': 'authtest.mod.default',
|
|
442
|
+
'asroot:perms': (
|
|
443
|
+
('authtest', 'perm'),
|
|
444
|
+
),
|
|
445
|
+
'storm': 'function func() { [ test:guid=* ] return($node) }',
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
'name': 'authtest.mod.allow',
|
|
449
|
+
'asroot:perms': (
|
|
450
|
+
('authtest', 'perm'),
|
|
451
|
+
),
|
|
452
|
+
'asroot:ondeny:import': 'allow',
|
|
453
|
+
'storm': '''
|
|
454
|
+
function func() { [ test:guid=* ] return($node) }
|
|
455
|
+
function func2() { [ test:str=newp ] return($node) }
|
|
456
|
+
''',
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
'name': 'authtest.mod.warn',
|
|
460
|
+
'asroot:perms': (
|
|
461
|
+
('authtest', 'perm'),
|
|
462
|
+
),
|
|
463
|
+
'asroot:ondeny:import': 'warn',
|
|
464
|
+
'storm': '''
|
|
465
|
+
function func() { [ test:guid=* ] return($node) }
|
|
466
|
+
function func2() { [ test:str=newp ] return($node) }
|
|
467
|
+
''',
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
'name': 'authtest.mod.deny',
|
|
471
|
+
'asroot:perms': (
|
|
472
|
+
('authtest', 'perm'),
|
|
473
|
+
),
|
|
474
|
+
'asroot:ondeny:import': 'deny',
|
|
475
|
+
'storm': 'function func() { [ test:guid=* ] return($node) }',
|
|
476
|
+
},
|
|
477
|
+
),
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
await core.stormlist('auth.user.add user')
|
|
481
|
+
await core.stormlist('auth.user.add lowuser')
|
|
482
|
+
|
|
483
|
+
await core.addStormPkg(stormpkg)
|
|
484
|
+
|
|
485
|
+
user = await core.auth.getUserByName('user')
|
|
486
|
+
asuser = {'user': user.iden}
|
|
487
|
+
|
|
488
|
+
lowuser = await core.auth.getUserByName('lowuser')
|
|
489
|
+
aslowuser = {'user': lowuser.iden}
|
|
490
|
+
|
|
491
|
+
await core.stormlist('auth.user.addrule user authtest.perm')
|
|
492
|
+
await core.stormlist('auth.user.addrule lowuser node.add.test:guid')
|
|
493
|
+
|
|
494
|
+
# user has no node perms, but has asroot so perms are elevated
|
|
495
|
+
self.len(1, await core.nodes('yield $lib.import(authtest.mod.default).func()', opts=asuser))
|
|
496
|
+
self.len(1, await core.nodes('yield $lib.import(authtest.mod.allow).func()', opts=asuser))
|
|
497
|
+
self.len(1, await core.nodes('yield $lib.import(authtest.mod.deny).func()', opts=asuser))
|
|
498
|
+
msgs = await core.stormlist('yield $lib.import(authtest.mod.warn).func()', opts=asuser)
|
|
499
|
+
self.stormHasNoWarnErr(msgs)
|
|
500
|
+
self.len(1, [m for m in msgs if m[0] == 'node'])
|
|
501
|
+
|
|
502
|
+
# lowuser does not have asroot perms and gets denied importing certain modules
|
|
503
|
+
await self.asyncraises(s_exc.AuthDeny, core.nodes('yield $lib.import(authtest.mod.deny).func()', opts=aslowuser))
|
|
504
|
+
await self.asyncraises(s_exc.AuthDeny, core.nodes('yield $lib.import(authtest.mod.default).func()', opts=aslowuser))
|
|
505
|
+
# ...and for modules they can import perms are not elevated so they can only add test:guid nodes
|
|
506
|
+
self.len(1, await core.nodes('yield $lib.import(authtest.mod.allow).func()', opts=aslowuser))
|
|
507
|
+
msgs = await core.stormlist('yield $lib.import(authtest.mod.warn).func()', opts=aslowuser)
|
|
508
|
+
self.stormIsInWarn('permissions will not be elevated.', msgs)
|
|
509
|
+
self.len(1, [m for m in msgs if m[0] == 'node'])
|
|
510
|
+
# ...and gets denied on adding test:str nodes
|
|
511
|
+
await self.asyncraises(s_exc.AuthDeny, core.nodes('yield $lib.import(authtest.mod.allow).func2()', opts=aslowuser))
|
|
512
|
+
await self.asyncraises(s_exc.AuthDeny, core.nodes('yield $lib.import(authtest.mod.warn).func2()', opts=aslowuser))
|
|
513
|
+
|
|
430
514
|
async def test_stormlib_auth_userjson(self):
|
|
431
515
|
|
|
432
516
|
async with self.getTestCore() as core:
|
|
@@ -110,6 +110,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
|
|
|
110
110
|
self.eq(resp.status, http.HTTPStatus.OK)
|
|
111
111
|
data = await resp.json()
|
|
112
112
|
self.eq(data.get('method'), 'get')
|
|
113
|
+
self.eq(resp.headers.get('Content-Type'), 'application/json; charset=utf8')
|
|
113
114
|
|
|
114
115
|
resp = await sess.post(f'https://localhost:{hport}/api/ext/testpath00')
|
|
115
116
|
self.eq(resp.status, http.HTTPStatus.CREATED)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import synapse.lib.stormlib.mime as s_mime
|
|
2
|
+
|
|
1
3
|
import synapse.tests.utils as s_test
|
|
2
4
|
|
|
3
5
|
html00 = '''
|
|
@@ -35,20 +37,42 @@ class StormlibMimeTest(s_test.SynTest):
|
|
|
35
37
|
|
|
36
38
|
async def test_stormlib_mime_html(self):
|
|
37
39
|
|
|
40
|
+
# this is mostly for coverage because it looks like code coverage doesn't work for code executed under semafork()
|
|
41
|
+
self.eq('html5lib includes this\na title\nhello there\nother text', s_mime.htmlToText(html00))
|
|
42
|
+
self.eq('html5lib includes this|a title|hello there|other text', s_mime.htmlToText(html00, separator='|'))
|
|
43
|
+
self.eq(' foo ', s_mime.htmlToText('<div> <p> foo </p> </div>', separator='', strip=False))
|
|
44
|
+
|
|
38
45
|
async with self.getTestCore() as core:
|
|
39
46
|
|
|
40
47
|
opts = {'vars': {'html': html00}}
|
|
41
48
|
ret = await core.callStorm('return($lib.mime.html.totext($html))', opts=opts)
|
|
42
49
|
self.eq('html5lib includes this\na title\nhello there\nother text', ret)
|
|
43
50
|
|
|
51
|
+
ret = await core.callStorm('return($lib.mime.html.totext($html, separator="|"))', opts=opts)
|
|
52
|
+
self.eq('html5lib includes this|a title|hello there|other text', ret)
|
|
53
|
+
|
|
44
54
|
opts = {'vars': {'html': html01}}
|
|
45
55
|
ret = await core.callStorm('return($lib.mime.html.totext($html))', opts=opts)
|
|
46
56
|
self.eq('a bad tag\nanother bad tag\nmore text\nfor fun', ret)
|
|
47
57
|
|
|
58
|
+
ret = await core.callStorm('return($lib.mime.html.totext($html, separator=", "))', opts=opts)
|
|
59
|
+
self.eq('a bad tag, another bad tag, more text, for fun', ret)
|
|
60
|
+
|
|
61
|
+
ret = await core.callStorm('return($lib.mime.html.totext($html, separator=(null), strip=(false)))', opts=opts)
|
|
62
|
+
self.eq('\n \n \n \n a bad tag\n \n \n \n another bad tag\n \n more text\n \n \n\nfor fun\n', ret)
|
|
63
|
+
|
|
48
64
|
opts = {'vars': {'html': '<div></div>'}}
|
|
49
65
|
ret = await core.callStorm('return($lib.mime.html.totext($html))', opts=opts)
|
|
50
66
|
self.eq('', ret)
|
|
51
67
|
|
|
68
|
+
opts = {'vars': {'html': '<div> </div>'}}
|
|
69
|
+
ret = await core.callStorm('return($lib.mime.html.totext($html, strip=(false)))', opts=opts)
|
|
70
|
+
self.eq(' ', ret)
|
|
71
|
+
|
|
72
|
+
opts = {'vars': {'html': '<div> <p> foo </p> </div>'}}
|
|
73
|
+
ret = await core.callStorm('return($lib.mime.html.totext($html, separator=(null), strip=(false)))', opts=opts)
|
|
74
|
+
self.eq(' foo ', ret)
|
|
75
|
+
|
|
52
76
|
opts = {'vars': {'html': '...'}}
|
|
53
77
|
ret = await core.callStorm('return($lib.mime.html.totext($html))', opts=opts)
|
|
54
78
|
self.eq('...', ret)
|