synapse 2.192.0__py311-none-any.whl → 2.194.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/common.py +15 -0
- synapse/cortex.py +19 -25
- synapse/datamodel.py +6 -3
- synapse/exc.py +6 -1
- synapse/lib/agenda.py +17 -6
- synapse/lib/ast.py +242 -97
- synapse/lib/auth.py +1 -0
- synapse/lib/cell.py +31 -85
- synapse/lib/cli.py +20 -11
- synapse/lib/parser.py +5 -1
- synapse/lib/snap.py +44 -15
- synapse/lib/storm.lark +16 -1
- synapse/lib/storm.py +40 -21
- synapse/lib/storm_format.py +1 -0
- synapse/lib/stormctrl.py +88 -6
- synapse/lib/stormlib/cache.py +6 -2
- synapse/lib/stormlib/json.py +5 -2
- synapse/lib/stormlib/scrape.py +1 -1
- synapse/lib/stormlib/stix.py +8 -8
- synapse/lib/stormtypes.py +32 -5
- synapse/lib/version.py +2 -2
- synapse/lib/view.py +20 -3
- synapse/models/geopol.py +1 -0
- synapse/models/geospace.py +1 -0
- synapse/models/inet.py +20 -1
- synapse/models/infotech.py +24 -6
- synapse/models/orgs.py +7 -2
- synapse/models/person.py +15 -4
- synapse/models/risk.py +19 -2
- synapse/models/telco.py +10 -3
- synapse/tests/test_axon.py +6 -6
- synapse/tests/test_cortex.py +133 -14
- synapse/tests/test_exc.py +4 -0
- synapse/tests/test_lib_agenda.py +282 -2
- synapse/tests/test_lib_aha.py +13 -6
- synapse/tests/test_lib_ast.py +301 -10
- synapse/tests/test_lib_auth.py +6 -7
- synapse/tests/test_lib_cell.py +71 -1
- synapse/tests/test_lib_grammar.py +14 -0
- synapse/tests/test_lib_layer.py +1 -1
- synapse/tests/test_lib_lmdbslab.py +3 -3
- synapse/tests/test_lib_storm.py +273 -55
- synapse/tests/test_lib_stormctrl.py +65 -0
- synapse/tests/test_lib_stormhttp.py +5 -5
- synapse/tests/test_lib_stormlib_auth.py +5 -5
- synapse/tests/test_lib_stormlib_cache.py +38 -6
- synapse/tests/test_lib_stormlib_json.py +20 -0
- synapse/tests/test_lib_stormlib_modelext.py +3 -3
- synapse/tests/test_lib_stormlib_scrape.py +6 -6
- synapse/tests/test_lib_stormlib_spooled.py +1 -1
- synapse/tests/test_lib_stormlib_xml.py +5 -5
- synapse/tests/test_lib_stormtypes.py +54 -57
- synapse/tests/test_lib_view.py +1 -1
- synapse/tests/test_model_base.py +1 -2
- synapse/tests/test_model_geopol.py +4 -0
- synapse/tests/test_model_geospace.py +6 -0
- synapse/tests/test_model_inet.py +43 -5
- synapse/tests/test_model_infotech.py +10 -1
- synapse/tests/test_model_orgs.py +17 -2
- synapse/tests/test_model_person.py +23 -1
- synapse/tests/test_model_risk.py +13 -0
- synapse/tests/test_tools_healthcheck.py +4 -4
- synapse/tests/test_tools_storm.py +95 -0
- synapse/tests/test_utils.py +17 -18
- synapse/tests/test_utils_getrefs.py +1 -1
- synapse/tests/utils.py +0 -35
- synapse/tools/changelog.py +6 -4
- synapse/tools/storm.py +1 -1
- synapse/utils/getrefs.py +14 -3
- synapse/vendor/cpython/lib/http/__init__.py +0 -0
- synapse/vendor/cpython/lib/http/cookies.py +59 -0
- synapse/vendor/cpython/lib/test/test_http_cookies.py +49 -0
- {synapse-2.192.0.dist-info → synapse-2.194.0.dist-info}/METADATA +6 -6
- {synapse-2.192.0.dist-info → synapse-2.194.0.dist-info}/RECORD +77 -73
- {synapse-2.192.0.dist-info → synapse-2.194.0.dist-info}/WHEEL +1 -1
- {synapse-2.192.0.dist-info → synapse-2.194.0.dist-info}/LICENSE +0 -0
- {synapse-2.192.0.dist-info → synapse-2.194.0.dist-info}/top_level.txt +0 -0
|
@@ -138,19 +138,51 @@ class StormlibCacheTest(s_test.SynTest):
|
|
|
138
138
|
self.none(await core.callStorm('return($lib.cache.fixed("if (0) { return(yup) }").get(foo))'))
|
|
139
139
|
|
|
140
140
|
## control flow exceptions don't propagate up
|
|
141
|
-
|
|
141
|
+
msgs = await core.stormlist('''
|
|
142
142
|
$cache = $lib.cache.fixed( ${ if ($cache_key < (2)) { return (`key={$cache_key}`) } else { break } } )
|
|
143
143
|
|
|
144
|
-
$
|
|
144
|
+
for $i in $lib.range(4) {
|
|
145
|
+
$lib.print(`{$cache.get($i)}`)
|
|
146
|
+
}
|
|
147
|
+
''')
|
|
148
|
+
self.stormIsInPrint('key=1', msgs)
|
|
149
|
+
self.stormNotInPrint('key=2', msgs)
|
|
150
|
+
self.stormIsInErr('Storm control flow "break" not allowed in cache callbacks.', msgs)
|
|
151
|
+
|
|
152
|
+
msgs = await core.stormlist('''
|
|
153
|
+
$cache = $lib.cache.fixed( ${ if ($cache_key < (2)) { return (`key={$cache_key}`) } else { continue } } )
|
|
145
154
|
|
|
146
155
|
for $i in $lib.range(4) {
|
|
147
|
-
$
|
|
156
|
+
$lib.print(`{$cache.get($i)}`)
|
|
148
157
|
}
|
|
158
|
+
''')
|
|
159
|
+
self.stormIsInPrint('key=1', msgs)
|
|
160
|
+
self.stormNotInPrint('key=2', msgs)
|
|
161
|
+
self.stormIsInErr('Storm control flow "continue" not allowed in cache callbacks.', msgs)
|
|
149
162
|
|
|
150
|
-
|
|
151
|
-
return($
|
|
163
|
+
msgs = await core.stormlist('''
|
|
164
|
+
$cache = $lib.cache.fixed( ${ if ($cache_key < (2)) { return (`key={$cache_key}`) } else { stop } } )
|
|
165
|
+
|
|
166
|
+
for $i in $lib.range(4) {
|
|
167
|
+
$lib.print(`{$cache.get($i)}`)
|
|
168
|
+
}
|
|
152
169
|
''')
|
|
153
|
-
self.
|
|
170
|
+
self.stormIsInPrint('key=1', msgs)
|
|
171
|
+
self.stormNotInPrint('key=2', msgs)
|
|
172
|
+
self.stormIsInErr('Storm control flow "stop" not allowed in cache callbacks.', msgs)
|
|
173
|
+
|
|
174
|
+
msgs = await core.stormlist('''
|
|
175
|
+
$cache = $lib.cache.fixed(
|
|
176
|
+
${ if ($cache_key < (2)) { return (`key={$cache_key}`) } else { $lib.exit(mesg=newp) } }
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
for $i in $lib.range(4) {
|
|
180
|
+
$lib.print(`{$cache.get($i)}`)
|
|
181
|
+
}
|
|
182
|
+
''')
|
|
183
|
+
self.stormIsInPrint('key=1', msgs)
|
|
184
|
+
self.stormNotInPrint('key=2', msgs)
|
|
185
|
+
self.stormIsInErr('Storm control flow "StormExit" not allowed in cache callbacks.', msgs)
|
|
154
186
|
|
|
155
187
|
## control flow scoped inside the callback
|
|
156
188
|
rets = await core.callStorm("""
|
|
@@ -12,6 +12,26 @@ class JsonTest(s_test.SynTest):
|
|
|
12
12
|
|
|
13
13
|
self.eq(((1, 2, 3)), await core.callStorm('return($lib.json.load("[1, 2, 3]"))'))
|
|
14
14
|
self.eq(('["foo", "bar", "baz"]'), await core.callStorm('return($lib.json.save((foo, bar, baz)))'))
|
|
15
|
+
self.eq(('{"foo": 1, "bar": {"baz": "hello"}}'), await core.callStorm('return($lib.json.save(({"foo": 1, "bar": {"baz": "hello"}})))'))
|
|
16
|
+
self.eq(('{"foo": 1, "bar": {"baz": "hello"}}'), await core.callStorm('return($lib.json.save(({"foo": 1, "bar": {"baz": "hello"}}), (null)))'))
|
|
17
|
+
self.eq((
|
|
18
|
+
'''{
|
|
19
|
+
"foo": 1,
|
|
20
|
+
"bar": {
|
|
21
|
+
"baz": "hello"
|
|
22
|
+
}
|
|
23
|
+
}'''), await core.callStorm('return($lib.json.save(({"foo": 1, "bar": {"baz": "hello"}}), indent=(4)))'))
|
|
24
|
+
|
|
25
|
+
self.eq((
|
|
26
|
+
'''{
|
|
27
|
+
"foo": 1,
|
|
28
|
+
"bar": {
|
|
29
|
+
"baz": "hello"
|
|
30
|
+
}
|
|
31
|
+
}'''), await core.callStorm('return($lib.json.save(({"foo": 1, "bar": {"baz": "hello"}}), indent=2))'))
|
|
32
|
+
|
|
33
|
+
with self.raises(s_exc.BadCast):
|
|
34
|
+
await core.callStorm('return($lib.json.save(({"foo": 1, "bar": {"baz": "hello"}}), indent=x))')
|
|
15
35
|
|
|
16
36
|
with self.raises(s_exc.BadJsonText):
|
|
17
37
|
await core.callStorm('return($lib.json.load(foo))')
|
|
@@ -122,7 +122,7 @@ class StormtypesModelextTest(s_test.SynTest):
|
|
|
122
122
|
self.none(core.model.edge(('inet:user', '_copies', None)))
|
|
123
123
|
|
|
124
124
|
# Underscores can exist in extended names but only at specific locations
|
|
125
|
-
q = '''$l
|
|
125
|
+
q = '''$l =(['str', {}]) $d=({"doc": "Foo"})
|
|
126
126
|
$lib.model.ext.addFormProp('test:str', '_test:_myprop', $l, $d)
|
|
127
127
|
'''
|
|
128
128
|
self.none(await core.callStorm(q))
|
|
@@ -144,13 +144,13 @@ class StormtypesModelextTest(s_test.SynTest):
|
|
|
144
144
|
await core.callStorm(q)
|
|
145
145
|
|
|
146
146
|
with self.raises(s_exc.BadPropDef):
|
|
147
|
-
q = '''$l
|
|
147
|
+
q = '''$l =(['str', {}]) $d=({"doc": "Foo"})
|
|
148
148
|
$lib.model.ext.addFormProp('test:str', '_test:_my^prop', $l, $d)
|
|
149
149
|
'''
|
|
150
150
|
await core.callStorm(q)
|
|
151
151
|
|
|
152
152
|
with self.raises(s_exc.BadPropDef):
|
|
153
|
-
q = '''$l
|
|
153
|
+
q = '''$l =(['str', {}]) $d=({"doc": "Foo"})
|
|
154
154
|
$lib.model.ext.addFormProp('test:str', '_test::_myprop', $l, $d)
|
|
155
155
|
'''
|
|
156
156
|
await core.callStorm(q)
|
|
@@ -24,7 +24,7 @@ class StormScrapeTest(s_test.SynTest):
|
|
|
24
24
|
The helper does require a named match for valu this is extracted.
|
|
25
25
|
*/
|
|
26
26
|
function scrape(text) {
|
|
27
|
-
$ret =
|
|
27
|
+
$ret = ()
|
|
28
28
|
for ($valu, $info) in $lib.scrape.genMatches($text, $modRe) {
|
|
29
29
|
$ret.append(($modForm, $valu, $info))
|
|
30
30
|
}
|
|
@@ -49,7 +49,7 @@ class StormScrapeTest(s_test.SynTest):
|
|
|
49
49
|
Example of an storm module that scraps and matches on hzzp enfanged urls.
|
|
50
50
|
*/
|
|
51
51
|
function scrape(text) {
|
|
52
|
-
$ret =
|
|
52
|
+
$ret = ()
|
|
53
53
|
for ($valu, $info) in $lib.scrape.genMatches($text, $modRe, fangs=$modFangs) {
|
|
54
54
|
$ret.append(($modForm, $valu, $info))
|
|
55
55
|
}
|
|
@@ -92,7 +92,7 @@ class StormScrapeTest(s_test.SynTest):
|
|
|
92
92
|
self.len(0, mods)
|
|
93
93
|
self.len(0, core.modsbyiface.get('scrape'))
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
core.loadStormPkg(pkgdef)
|
|
96
96
|
|
|
97
97
|
mods = await core.getStormIfaces('scrape')
|
|
98
98
|
self.len(2, mods)
|
|
@@ -105,7 +105,7 @@ class StormScrapeTest(s_test.SynTest):
|
|
|
105
105
|
self.stormIsInPrint('inet:url=https://giggles.com/mallory.html', msgs)
|
|
106
106
|
self.stormIsInPrint("'match': 'hzzps[:]\\\\giggles.com/mallory.html'", msgs)
|
|
107
107
|
|
|
108
|
-
cq = '''$ret
|
|
108
|
+
cq = '''$ret=()
|
|
109
109
|
for ($form, $valu) in $lib.scrape.ndefs($text) {
|
|
110
110
|
$ret.append(($form, $valu))
|
|
111
111
|
}
|
|
@@ -131,7 +131,7 @@ class StormScrapeTest(s_test.SynTest):
|
|
|
131
131
|
conf = {'storm:interface:scrape': False, }
|
|
132
132
|
async with self.getTestCore(conf=conf) as core:
|
|
133
133
|
|
|
134
|
-
|
|
134
|
+
core.loadStormPkg(pkgdef)
|
|
135
135
|
|
|
136
136
|
mods = await core.getStormIfaces('scrape')
|
|
137
137
|
self.len(2, mods)
|
|
@@ -180,7 +180,7 @@ class StormScrapeTest(s_test.SynTest):
|
|
|
180
180
|
self.eq(result, {'inet:ipv4=16909060': 1, 'inet:fqdn=foo.bar': 1, 'inet:fqdn=woot.com': 1})
|
|
181
181
|
|
|
182
182
|
# $lib.scrape.context() - this is currently just wrapping s_scrape.contextscrape
|
|
183
|
-
query = '''$list =
|
|
183
|
+
query = '''$list = () for $info in $lib.scrape.context($text)
|
|
184
184
|
{ $list.append($info) }
|
|
185
185
|
fini { return ( $list ) }
|
|
186
186
|
'''
|
|
@@ -38,7 +38,7 @@ class XmlTest(s_test.SynTest):
|
|
|
38
38
|
|
|
39
39
|
async with self.getTestCore() as core:
|
|
40
40
|
valu = await core.callStorm('''
|
|
41
|
-
$retn =
|
|
41
|
+
$retn = ()
|
|
42
42
|
$root = $lib.xml.parse($xmltext)
|
|
43
43
|
for $elem in $root {
|
|
44
44
|
$retn.append((
|
|
@@ -56,7 +56,7 @@ class XmlTest(s_test.SynTest):
|
|
|
56
56
|
))
|
|
57
57
|
|
|
58
58
|
valu = await core.callStorm('''
|
|
59
|
-
$retn =
|
|
59
|
+
$retn = ()
|
|
60
60
|
$root = $lib.xml.parse($xmltext)
|
|
61
61
|
for $elem in $root.find(country) {
|
|
62
62
|
$retn.append((
|
|
@@ -74,7 +74,7 @@ class XmlTest(s_test.SynTest):
|
|
|
74
74
|
))
|
|
75
75
|
|
|
76
76
|
valu = await core.callStorm('''
|
|
77
|
-
$retn =
|
|
77
|
+
$retn = ()
|
|
78
78
|
$root = $lib.xml.parse($xmltext)
|
|
79
79
|
for $elem in $root.find(rank) {
|
|
80
80
|
$retn.append($elem.text)
|
|
@@ -84,7 +84,7 @@ class XmlTest(s_test.SynTest):
|
|
|
84
84
|
self.eq(valu, ('1', '4', '68'))
|
|
85
85
|
|
|
86
86
|
valu = await core.callStorm('''
|
|
87
|
-
$retn =
|
|
87
|
+
$retn = ()
|
|
88
88
|
$root = $lib.xml.parse($xmltext)
|
|
89
89
|
for $elem in $root.find(rank, nested=$lib.false) {
|
|
90
90
|
$retn.append($elem.text)
|
|
@@ -94,7 +94,7 @@ class XmlTest(s_test.SynTest):
|
|
|
94
94
|
self.eq(valu, ())
|
|
95
95
|
|
|
96
96
|
valu = await core.callStorm('''
|
|
97
|
-
$retn =
|
|
97
|
+
$retn = ()
|
|
98
98
|
$root = $lib.xml.parse($xmltext)
|
|
99
99
|
for $elem in $root.find(rank, nested=$lib.false) {
|
|
100
100
|
$retn.append($elem.text)
|
|
@@ -196,7 +196,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
196
196
|
|
|
197
197
|
await core.callStorm('$lib.jsonstor.set(hi, hehe, prop=foo)')
|
|
198
198
|
items = await core.callStorm('''
|
|
199
|
-
$list =
|
|
199
|
+
$list = ()
|
|
200
200
|
for $item in $lib.jsonstor.iter(bye) { $list.append($item) }
|
|
201
201
|
return($list)
|
|
202
202
|
''')
|
|
@@ -573,9 +573,9 @@ class StormTypesTest(s_test.SynTest):
|
|
|
573
573
|
self.eq(2, await core.callStorm('$x = asdf return($x.find(d))'))
|
|
574
574
|
self.eq(None, await core.callStorm('$x = asdf return($x.find(v))'))
|
|
575
575
|
|
|
576
|
-
self.eq(('f', 'o', 'o'), await core.callStorm('$x =
|
|
577
|
-
self.eq(('o', 'o', 'b', 'a'), await core.callStorm('$x =
|
|
578
|
-
self.eq(('o', 'o', 'b', 'a', 'r'), await core.callStorm('$x =
|
|
576
|
+
self.eq(('f', 'o', 'o'), await core.callStorm('$x = () $x.extend((f, o, o)) return($x)'))
|
|
577
|
+
self.eq(('o', 'o', 'b', 'a'), await core.callStorm('$x = (f, o, o, b, a, r) return($x.slice(1, 5))'))
|
|
578
|
+
self.eq(('o', 'o', 'b', 'a', 'r'), await core.callStorm('$x = (f, o, o, b, a, r) return($x.slice(1))'))
|
|
579
579
|
|
|
580
580
|
self.true(await core.callStorm('return($lib.trycast(inet:ipv4, 1.2.3.4).0)'))
|
|
581
581
|
self.false(await core.callStorm('return($lib.trycast(inet:ipv4, asdf).0)'))
|
|
@@ -595,11 +595,11 @@ class StormTypesTest(s_test.SynTest):
|
|
|
595
595
|
self.false(await core.callStorm('$x=(foo,bar) return($x.has((foo,bar)))'))
|
|
596
596
|
|
|
597
597
|
await core.addStormPkg(pdef)
|
|
598
|
-
nodes = await core.nodes('[ inet:asn=$lib.min(20,
|
|
598
|
+
nodes = await core.nodes('[ inet:asn=$lib.min(20, (0x30)) ]')
|
|
599
599
|
self.len(1, nodes)
|
|
600
600
|
self.eq(20, nodes[0].ndef[1])
|
|
601
601
|
|
|
602
|
-
nodes = await core.nodes('[ inet:asn=$lib.min(20,
|
|
602
|
+
nodes = await core.nodes('[ inet:asn=$lib.min(20, (10, 30)) ]')
|
|
603
603
|
self.len(1, nodes)
|
|
604
604
|
self.eq(10, nodes[0].ndef[1])
|
|
605
605
|
|
|
@@ -744,7 +744,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
744
744
|
await core.nodes('$lib.print($lib.len($true))', opts=opts)
|
|
745
745
|
self.eq(cm.exception.get('mesg'), 'Object builtins.bool does not have a length.')
|
|
746
746
|
|
|
747
|
-
mesgs = await core.stormlist('$lib.print(
|
|
747
|
+
mesgs = await core.stormlist('$lib.print((1,(2),3))')
|
|
748
748
|
self.stormIsInPrint("['1', 2, '3']", mesgs)
|
|
749
749
|
|
|
750
750
|
mesgs = await core.stormlist('$lib.print(${ $foo=bar })')
|
|
@@ -768,7 +768,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
768
768
|
mesgs = await core.stormlist('$lib.print($lib.queue.add(testq))')
|
|
769
769
|
self.stormIsInPrint("queue: testq", mesgs)
|
|
770
770
|
|
|
771
|
-
mesgs = await core.stormlist('$lib.pprint(
|
|
771
|
+
mesgs = await core.stormlist('$lib.pprint((1,2,3))')
|
|
772
772
|
self.stormIsInPrint("('1', '2', '3')", mesgs)
|
|
773
773
|
|
|
774
774
|
mesgs = await core.stormlist('$lib.pprint(({"foo": "1", "bar": "2"}))')
|
|
@@ -788,7 +788,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
788
788
|
# lib.guid()
|
|
789
789
|
opts = {'vars': {'x': {'foo': 'bar'}, 'y': ['foo']}}
|
|
790
790
|
guid00 = await core.callStorm('return($lib.guid($x, $y))', opts=opts)
|
|
791
|
-
guid01 = await core.callStorm('$x=({"foo": "bar"}) $y
|
|
791
|
+
guid01 = await core.callStorm('$x=({"foo": "bar"}) $y=(foo,) return($lib.guid($x, $y))')
|
|
792
792
|
self.eq(guid00, guid01)
|
|
793
793
|
|
|
794
794
|
guid00 = await core.callStorm('return($lib.guid(foo))')
|
|
@@ -1519,8 +1519,8 @@ class StormTypesTest(s_test.SynTest):
|
|
|
1519
1519
|
async def test_storm_lib_list(self):
|
|
1520
1520
|
async with self.getTestCore() as core:
|
|
1521
1521
|
# Base List object behavior
|
|
1522
|
-
q = '''
|
|
1523
|
-
$list
|
|
1522
|
+
q = '''
|
|
1523
|
+
$list=(1,2,3)
|
|
1524
1524
|
// __len__
|
|
1525
1525
|
$lib.print('List size is {len}', len=$lib.len($list))
|
|
1526
1526
|
// aiter/iter method
|
|
@@ -1541,7 +1541,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
1541
1541
|
}
|
|
1542
1542
|
$lib.print('Sum is now {sum}', sum=$sum)
|
|
1543
1543
|
// Empty lists may also be made
|
|
1544
|
-
$elst
|
|
1544
|
+
$elst=()
|
|
1545
1545
|
$lib.print('elst size is {len}', len=$lib.len($elst))
|
|
1546
1546
|
'''
|
|
1547
1547
|
msgs = await core.stormlist(q)
|
|
@@ -1570,26 +1570,13 @@ class StormTypesTest(s_test.SynTest):
|
|
|
1570
1570
|
ret = await core.callStorm(q)
|
|
1571
1571
|
self.eq(ret, ('bar', 'baz', 'foo',))
|
|
1572
1572
|
|
|
1573
|
-
# Sort a few text objects
|
|
1574
|
-
q = '$foo=$lib.text(foo) $bar=$lib.text(bar) $baz=$lib.text(baz) $v=($foo, $bar, $baz) $v.sort() return ($v)'
|
|
1575
|
-
ret = await core.callStorm(q)
|
|
1576
|
-
self.eq(ret, ('bar', 'baz', 'foo',))
|
|
1577
|
-
|
|
1578
1573
|
# incompatible sort types
|
|
1579
1574
|
with self.raises(s_exc.StormRuntimeError):
|
|
1580
1575
|
await core.callStorm('$v=(foo,bar,(1)) $v.sort() return ($v)')
|
|
1581
1576
|
|
|
1582
|
-
# mix Prims and heavy objects
|
|
1583
|
-
with self.raises(s_exc.StormRuntimeError):
|
|
1584
|
-
q = '$foo=$lib.text(foo) $bar=$lib.text(bar) $v=($foo, aString, $bar,) $v.sort() return ($v)'
|
|
1585
|
-
await core.callStorm(q)
|
|
1586
|
-
|
|
1587
1577
|
q = '$l = (1, 2, (3), 4, 1, (3), 3, asdf) return ( $l.unique() )'
|
|
1588
1578
|
self.eq(['1', '2', 3, '4', '3', 'asdf'], await core.callStorm(q))
|
|
1589
1579
|
|
|
1590
|
-
q = '$a=$lib.text(hehe) $b=$lib.text(haha) $c=$lib.text(hehe) $foo=($a, $b, $c) return ($foo.unique())'
|
|
1591
|
-
self.eq(['hehe', 'haha'], await core.callStorm(q))
|
|
1592
|
-
|
|
1593
1580
|
await core.addUser('lowuser1')
|
|
1594
1581
|
await core.addUser('lowuser2')
|
|
1595
1582
|
q = '''
|
|
@@ -1672,7 +1659,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
1672
1659
|
self.eq([1, 3, 4], await core.callStorm('$list = ([1, 2, 3, 4]) $list.pop(1) return($list)'))
|
|
1673
1660
|
|
|
1674
1661
|
with self.raises(s_exc.StormRuntimeError) as exc:
|
|
1675
|
-
await core.callStorm('$
|
|
1662
|
+
await core.callStorm('$foo=() $foo.pop()')
|
|
1676
1663
|
self.eq(exc.exception.get('mesg'), 'pop from empty list')
|
|
1677
1664
|
|
|
1678
1665
|
with self.raises(s_exc.StormRuntimeError) as exc:
|
|
@@ -1702,6 +1689,9 @@ class StormTypesTest(s_test.SynTest):
|
|
|
1702
1689
|
out = await core.callStorm(q, opts=opts)
|
|
1703
1690
|
self.eq(out, ["foo", "baz"])
|
|
1704
1691
|
|
|
1692
|
+
msgs = await core.stormlist('$list = $lib.list(foo, bar)')
|
|
1693
|
+
self.stormIsInWarn('$lib.list() is deprecated. Use ([]) instead.', msgs)
|
|
1694
|
+
|
|
1705
1695
|
async def test_storm_layer_getstornode(self):
|
|
1706
1696
|
|
|
1707
1697
|
async with self.getTestCore() as core:
|
|
@@ -1804,6 +1794,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
1804
1794
|
|
|
1805
1795
|
async def test_storm_text(self):
|
|
1806
1796
|
async with self.getTestCore() as core:
|
|
1797
|
+
# $lib.text() is deprecated (SYN-8482); test ensures the object works as expected until removed
|
|
1807
1798
|
nodes = await core.nodes('''
|
|
1808
1799
|
[ test:int=10 ] $text=$lib.text(hehe) { +test:int>=10 $text.add(haha) }
|
|
1809
1800
|
[ test:str=$text.str() ] +test:str''')
|
|
@@ -1817,6 +1808,10 @@ class StormTypesTest(s_test.SynTest):
|
|
|
1817
1808
|
self.stormIsInPrint('8', msgs)
|
|
1818
1809
|
self.stormIsInPrint('13', msgs)
|
|
1819
1810
|
|
|
1811
|
+
msgs = await core.stormlist('help --verbose $lib.text')
|
|
1812
|
+
self.stormIsInPrint('Warning', msgs)
|
|
1813
|
+
self.stormIsInPrint('$lib.text`` has been deprecated and will be removed in version 3.0.0', msgs)
|
|
1814
|
+
|
|
1820
1815
|
async def test_storm_set(self):
|
|
1821
1816
|
|
|
1822
1817
|
async with self.getTestCore() as core:
|
|
@@ -2139,14 +2134,14 @@ class StormTypesTest(s_test.SynTest):
|
|
|
2139
2134
|
|
|
2140
2135
|
# List
|
|
2141
2136
|
q = '''
|
|
2142
|
-
$list =
|
|
2137
|
+
$list = (1, 2, 3)
|
|
2143
2138
|
$set = $lib.set($list)
|
|
2144
2139
|
'''
|
|
2145
2140
|
msgs = await core.stormlist(q)
|
|
2146
2141
|
self.stormIsInErr('is mutable and cannot be used in a set', msgs)
|
|
2147
2142
|
|
|
2148
2143
|
q = '''
|
|
2149
|
-
$list =
|
|
2144
|
+
$list = (1, 2, 3, 1, 2, 3, 1, 2, 3)
|
|
2150
2145
|
$set = $lib.set()
|
|
2151
2146
|
$set.adds($list)
|
|
2152
2147
|
$lib.print('There are {count} items in the set', count=$lib.len($set))
|
|
@@ -2155,7 +2150,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
2155
2150
|
self.stormIsInPrint('There are 3 items in the set', msgs)
|
|
2156
2151
|
|
|
2157
2152
|
q = '''
|
|
2158
|
-
$list =
|
|
2153
|
+
$list = ((4, 5, 6, 7), (1, 2, 3, 4))
|
|
2159
2154
|
$set = $lib.set()
|
|
2160
2155
|
$set.adds($list)
|
|
2161
2156
|
$lib.print('There are {count} items in the set', count=$lib.len($set))
|
|
@@ -2212,7 +2207,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
2212
2207
|
|
|
2213
2208
|
# text
|
|
2214
2209
|
q = '''
|
|
2215
|
-
$text = $
|
|
2210
|
+
$text = () $text.append(beepboopgetthejedi)
|
|
2216
2211
|
$set = $lib.set($text)
|
|
2217
2212
|
'''
|
|
2218
2213
|
msgs = await core.stormlist(q)
|
|
@@ -2327,7 +2322,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
2327
2322
|
|
|
2328
2323
|
q = '''
|
|
2329
2324
|
inet:fqdn=vertex.link
|
|
2330
|
-
$path.meta.foobar =
|
|
2325
|
+
$path.meta.foobar = ('neato', 'burrito')
|
|
2331
2326
|
'''
|
|
2332
2327
|
msgs = [mesg async for mesg in proxy.storm(q)]
|
|
2333
2328
|
pode = [m[1] for m in msgs if m[0] == 'node'][0]
|
|
@@ -2350,7 +2345,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
2350
2345
|
|
|
2351
2346
|
q = '''
|
|
2352
2347
|
inet:fqdn=vertex.link
|
|
2353
|
-
$path.meta.$node =
|
|
2348
|
+
$path.meta.$node = ('foo', 'bar')
|
|
2354
2349
|
'''
|
|
2355
2350
|
msgs = [mesg async for mesg in proxy.storm(q)]
|
|
2356
2351
|
pode = [m[1] for m in msgs if m[0] == 'node'][0]
|
|
@@ -3427,8 +3422,6 @@ class StormTypesTest(s_test.SynTest):
|
|
|
3427
3422
|
self.eq('telepath:proxy:method', await core.callStorm('return( $lib.vars.type($lib.telepath.open($url).getCellInfo) )', opts))
|
|
3428
3423
|
self.eq('telepath:proxy:genrmethod', await core.callStorm('return( $lib.vars.type($lib.telepath.open($url).storm) )', opts))
|
|
3429
3424
|
|
|
3430
|
-
self.eq('text', await core.callStorm('return ( $lib.vars.type($lib.text(hehe)) )'))
|
|
3431
|
-
|
|
3432
3425
|
self.eq('node', await core.callStorm('[test:str=foo] return ($lib.vars.type($node))'))
|
|
3433
3426
|
self.eq('node:props', await core.callStorm('[test:str=foo] return ($lib.vars.type($node.props))'))
|
|
3434
3427
|
self.eq('node:data', await core.callStorm('[test:str=foo] return ($lib.vars.type($node.data))'))
|
|
@@ -3840,7 +3833,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
3840
3833
|
# Get the main view
|
|
3841
3834
|
mainiden = await core.callStorm('return($lib.view.get().iden)')
|
|
3842
3835
|
altview = await core.callStorm('''
|
|
3843
|
-
$layers =
|
|
3836
|
+
$layers = ()
|
|
3844
3837
|
for $layer in $lib.view.get().layers {
|
|
3845
3838
|
$layers.append($layer.iden)
|
|
3846
3839
|
}
|
|
@@ -3885,7 +3878,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
3885
3878
|
|
|
3886
3879
|
# List the views in the cortex
|
|
3887
3880
|
q = '''
|
|
3888
|
-
$views =
|
|
3881
|
+
$views = ()
|
|
3889
3882
|
for $view in $lib.view.list() {
|
|
3890
3883
|
$views.append($view.iden)
|
|
3891
3884
|
}
|
|
@@ -4310,7 +4303,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
4310
4303
|
view2['iden'],
|
|
4311
4304
|
)
|
|
4312
4305
|
self.eq(expect, await core.callStorm('''
|
|
4313
|
-
$views =
|
|
4306
|
+
$views = ()
|
|
4314
4307
|
for $view in $lib.view.list(deporder=$lib.true) {
|
|
4315
4308
|
$views.append($view.iden)
|
|
4316
4309
|
}
|
|
@@ -5445,7 +5438,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
5445
5438
|
self.eq(valu['none'], None)
|
|
5446
5439
|
self.eq(valu['bool'], True)
|
|
5447
5440
|
|
|
5448
|
-
q = '$list =
|
|
5441
|
+
q = '$list = () $list.append(foo) $list.append(bar) return($list)'
|
|
5449
5442
|
self.eq(('foo', 'bar'), await core.callStorm(q))
|
|
5450
5443
|
self.eq({'foo': 'bar'}, await core.callStorm('$dict = ({}) $dict.foo = bar return($dict)'))
|
|
5451
5444
|
q = '$tally = $lib.stats.tally() $tally.inc(foo) $tally.inc(foo) return($tally)'
|
|
@@ -5541,7 +5534,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
5541
5534
|
await core.nodes('[inet:ipv4=1.2.3.4]')
|
|
5542
5535
|
|
|
5543
5536
|
# TODO: should we asciify the buid here so it is json compatible?
|
|
5544
|
-
q = '''$list =
|
|
5537
|
+
q = '''$list = ()
|
|
5545
5538
|
for ($offs, $edit) in $lib.layer.get().edits(wait=$lib.false) {
|
|
5546
5539
|
$list.append($edit)
|
|
5547
5540
|
}
|
|
@@ -5954,7 +5947,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
5954
5947
|
with self.raises(s_ctrl.StormExit) as cm:
|
|
5955
5948
|
q = '[test:str=beep.sys] $lib.exit(foo)'
|
|
5956
5949
|
_ = await core.callStorm(q)
|
|
5957
|
-
self.eq(cm.exception.
|
|
5950
|
+
self.eq(cm.exception.get('mesg'), 'foo')
|
|
5958
5951
|
|
|
5959
5952
|
# Remote tests
|
|
5960
5953
|
async with core.getLocalProxy() as prox:
|
|
@@ -5968,7 +5961,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
5968
5961
|
q = '[test:str=beep.sys] $lib.exit()'
|
|
5969
5962
|
with self.raises(s_exc.SynErr) as cm:
|
|
5970
5963
|
_ = await prox.callStorm(q)
|
|
5971
|
-
self.eq(cm.exception.get('mesg'), '')
|
|
5964
|
+
self.eq(cm.exception.get('mesg'), 'StormExit: ')
|
|
5972
5965
|
self.eq(cm.exception.get('errx'), 'StormExit')
|
|
5973
5966
|
|
|
5974
5967
|
# A warn is emitted
|
|
@@ -5980,7 +5973,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
5980
5973
|
q = '[test:str=beep.sys] $lib.exit("foo {bar}", bar=baz)'
|
|
5981
5974
|
with self.raises(s_exc.SynErr) as cm:
|
|
5982
5975
|
_ = await prox.callStorm(q)
|
|
5983
|
-
self.eq(cm.exception.get('mesg'), 'foo baz')
|
|
5976
|
+
self.eq(cm.exception.get('mesg'), "StormExit: mesg='foo baz'")
|
|
5984
5977
|
self.eq(cm.exception.get('errx'), 'StormExit')
|
|
5985
5978
|
|
|
5986
5979
|
async def test_iter(self):
|
|
@@ -6003,7 +5996,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
6003
5996
|
self.len(2, nodes)
|
|
6004
5997
|
|
|
6005
5998
|
# set adds
|
|
6006
|
-
ret = await core.callStorm('$x=$lib.set() $y
|
|
5999
|
+
ret = await core.callStorm('$x=$lib.set() $y=(1,2,3) $x.adds($y) return($x)')
|
|
6007
6000
|
self.eq({'1', '2', '3'}, ret)
|
|
6008
6001
|
|
|
6009
6002
|
ret = await core.callStorm('$x=$lib.set() $y=({"foo": "1", "bar": "2"}) $x.adds($y) return($x)')
|
|
@@ -6019,7 +6012,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
6019
6012
|
self.eq({'a', 'b', 'c', 'd'}, ret)
|
|
6020
6013
|
|
|
6021
6014
|
# set rems
|
|
6022
|
-
ret = await core.callStorm('$x=$lib.set(1,2,3) $y
|
|
6015
|
+
ret = await core.callStorm('$x=$lib.set(1,2,3) $y=(1,2) $x.rems($y) return($x)')
|
|
6023
6016
|
self.eq({'3'}, ret)
|
|
6024
6017
|
|
|
6025
6018
|
scmd = '''
|
|
@@ -6043,7 +6036,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
6043
6036
|
self.eq({'d', 'c'}, ret)
|
|
6044
6037
|
|
|
6045
6038
|
# str join
|
|
6046
|
-
ret = await core.callStorm('$x
|
|
6039
|
+
ret = await core.callStorm('$x=(foo,bar,baz) $y=$lib.str.join("-", $x) return($y)')
|
|
6047
6040
|
self.eq('foo-bar-baz', ret)
|
|
6048
6041
|
|
|
6049
6042
|
ret = await core.callStorm('$y=$lib.str.join("-", (foo, bar, baz)) return($y)')
|
|
@@ -6093,7 +6086,7 @@ class StormTypesTest(s_test.SynTest):
|
|
|
6093
6086
|
self.eq(nodes[0].ndef[0], 'file:bytes')
|
|
6094
6087
|
sha256, size, created = nodes[0].get('sha256'), nodes[0].get('size'), nodes[0].get('.created')
|
|
6095
6088
|
|
|
6096
|
-
items = await core.callStorm('$x
|
|
6089
|
+
items = await core.callStorm('$x=() for $i in $lib.axon.list() { $x.append($i) } return($x)')
|
|
6097
6090
|
self.eq([(0, sha256, size)], items)
|
|
6098
6091
|
|
|
6099
6092
|
# test $lib.axon.del()
|
|
@@ -6108,21 +6101,21 @@ class StormTypesTest(s_test.SynTest):
|
|
|
6108
6101
|
self.eq((True, False), await core.callStorm('return($lib.axon.dels(($sha256, $sha256)))', opts=delopts))
|
|
6109
6102
|
self.false(await core.callStorm('return($lib.axon.del($sha256))', opts=delopts))
|
|
6110
6103
|
|
|
6111
|
-
items = await core.callStorm('$x
|
|
6104
|
+
items = await core.callStorm('$x=() for $i in $lib.axon.list() { $x.append($i) } return($x)')
|
|
6112
6105
|
self.len(0, items)
|
|
6113
6106
|
|
|
6114
6107
|
msgs = await core.stormlist(f'wget --no-ssl-verify https://127.0.0.1:{port}/api/v1/newp')
|
|
6115
6108
|
self.stormIsInWarn('HTTP code 404', msgs)
|
|
6116
6109
|
|
|
6117
|
-
self.len(1, await core.callStorm('$x
|
|
6110
|
+
self.len(1, await core.callStorm('$x=() for $i in $lib.axon.list() { $x.append($i) } return($x)'))
|
|
6118
6111
|
|
|
6119
6112
|
size, sha256 = await core.callStorm('return($lib.axon.put($buf))', opts={'vars': {'buf': b'foo'}})
|
|
6120
6113
|
|
|
6121
|
-
items = await core.callStorm('$x
|
|
6114
|
+
items = await core.callStorm('$x=() for $i in $lib.axon.list() { $x.append($i) } return($x)')
|
|
6122
6115
|
self.len(2, items)
|
|
6123
6116
|
self.eq((2, sha256, size), items[1])
|
|
6124
6117
|
|
|
6125
|
-
items = await core.callStorm('$x
|
|
6118
|
+
items = await core.callStorm('$x=() for $i in $lib.axon.list(2) { $x.append($i) } return($x)')
|
|
6126
6119
|
self.eq([(2, sha256, size)], items)
|
|
6127
6120
|
|
|
6128
6121
|
# test request timeout
|
|
@@ -6144,28 +6137,28 @@ class StormTypesTest(s_test.SynTest):
|
|
|
6144
6137
|
|
|
6145
6138
|
opts = {'vars': {'sha256': asdfitem[1]}}
|
|
6146
6139
|
self.eq(('asdf',), await core.callStorm('''
|
|
6147
|
-
$items =
|
|
6140
|
+
$items = ()
|
|
6148
6141
|
for $item in $lib.axon.readlines($sha256) { $items.append($item) }
|
|
6149
6142
|
return($items)
|
|
6150
6143
|
''', opts=opts))
|
|
6151
6144
|
|
|
6152
6145
|
opts = {'vars': {'sha256': linesitem[1]}}
|
|
6153
6146
|
self.eq(('vertex.link', 'woot.com'), await core.callStorm('''
|
|
6154
|
-
$items =
|
|
6147
|
+
$items = ()
|
|
6155
6148
|
for $item in $lib.axon.readlines($sha256) { $items.append($item) }
|
|
6156
6149
|
return($items)
|
|
6157
6150
|
''', opts=opts))
|
|
6158
6151
|
|
|
6159
6152
|
opts = {'vars': {'sha256': jsonsitem[1]}}
|
|
6160
6153
|
self.eq(({'fqdn': 'vertex.link'}, {'fqdn': 'woot.com'}), await core.callStorm('''
|
|
6161
|
-
$items =
|
|
6154
|
+
$items = ()
|
|
6162
6155
|
for $item in $lib.axon.jsonlines($sha256) { $items.append($item) }
|
|
6163
6156
|
return($items)
|
|
6164
6157
|
''', opts=opts))
|
|
6165
6158
|
|
|
6166
6159
|
async def waitlist():
|
|
6167
6160
|
items = await core.callStorm('''
|
|
6168
|
-
$x
|
|
6161
|
+
$x=()
|
|
6169
6162
|
for $i in $lib.axon.list(2, wait=$lib.true, timeout=1) {
|
|
6170
6163
|
$x.append($i)
|
|
6171
6164
|
}
|
|
@@ -6235,7 +6228,7 @@ words\tword\twrd'''
|
|
|
6235
6228
|
opts = {'vars': {'sha256': s_common.ehex(bin256)}}
|
|
6236
6229
|
with self.raises(s_exc.BadDataValu):
|
|
6237
6230
|
self.eq('', await core.callStorm('''
|
|
6238
|
-
$items =
|
|
6231
|
+
$items = ()
|
|
6239
6232
|
for $item in $lib.axon.readlines($sha256, errors=$lib.null) {
|
|
6240
6233
|
$items.append($item)
|
|
6241
6234
|
}
|
|
@@ -6243,7 +6236,7 @@ words\tword\twrd'''
|
|
|
6243
6236
|
''', opts=opts))
|
|
6244
6237
|
|
|
6245
6238
|
self.eq(('/$A\x00_v4\x1b',), await core.callStorm('''
|
|
6246
|
-
$items =
|
|
6239
|
+
$items = ()
|
|
6247
6240
|
for $item in $lib.axon.readlines($sha256, errors=ignore) { $items.append($item) }
|
|
6248
6241
|
return($items)
|
|
6249
6242
|
''', opts=opts))
|
|
@@ -6639,7 +6632,7 @@ words\tword\twrd'''
|
|
|
6639
6632
|
'newname': 'oops'
|
|
6640
6633
|
}})
|
|
6641
6634
|
|
|
6642
|
-
self.stormIsInErr('
|
|
6635
|
+
self.stormIsInErr('Setting name on auth:user is not marked readonly safe.', msgs)
|
|
6643
6636
|
|
|
6644
6637
|
mesg = 'Storm runtime is in readonly mode, cannot create or edit nodes and other graph data.'
|
|
6645
6638
|
|
|
@@ -6670,6 +6663,10 @@ words\tword\twrd'''
|
|
|
6670
6663
|
msgs = await core.stormlist(q, opts={'readonly': True, 'vars': {'iden': user}})
|
|
6671
6664
|
self.stormIsInErr(mesg, msgs)
|
|
6672
6665
|
|
|
6666
|
+
q = '$lib.pkg.add(({}))'
|
|
6667
|
+
msgs = await core.stormlist(q, opts={'readonly': True, 'vars': {'iden': user}})
|
|
6668
|
+
self.stormIsInErr('$lib.pkg.add() is not marked readonly safe.', msgs)
|
|
6669
|
+
|
|
6673
6670
|
async def test_storm_view_counts(self):
|
|
6674
6671
|
|
|
6675
6672
|
async with self.getTestCore() as core:
|
synapse/tests/test_lib_view.py
CHANGED
|
@@ -547,7 +547,7 @@ class ViewTest(s_t_utils.SynTest):
|
|
|
547
547
|
await core.nodes('inet:ipv4=0 | delnode')
|
|
548
548
|
|
|
549
549
|
edits = await core.callStorm('''
|
|
550
|
-
$nodeedits =
|
|
550
|
+
$nodeedits = ()
|
|
551
551
|
for ($offs, $edits) in $lib.layer.get().edits(wait=$lib.false) {
|
|
552
552
|
$nodeedits.extend($edits)
|
|
553
553
|
}
|
synapse/tests/test_model_base.py
CHANGED
|
@@ -338,8 +338,7 @@ class BaseTest(s_t_utils.SynTest):
|
|
|
338
338
|
'tel:mob:telem:cell:carrier', 'tel:mob:telem:imsi', 'tel:mob:telem:imei',
|
|
339
339
|
'tel:mob:telem:phone', 'tel:mob:telem:mac', 'tel:mob:telem:ipv4',
|
|
340
340
|
'tel:mob:telem:ipv6', 'tel:mob:telem:wifi', 'tel:mob:telem:wifi:ssid',
|
|
341
|
-
'tel:mob:telem:wifi:bssid', 'tel:mob:telem:
|
|
342
|
-
'tel:mob:telem:idfa', 'tel:mob:telem:name', 'tel:mob:telem:email',
|
|
341
|
+
'tel:mob:telem:wifi:bssid', 'tel:mob:telem:name', 'tel:mob:telem:email',
|
|
343
342
|
'tel:mob:telem:app', 'tel:mob:telem:data',
|
|
344
343
|
'inet:http:request:response:time', 'inet:http:request:response:code',
|
|
345
344
|
'inet:http:request:response:reason', 'inet:http:request:response:body',
|