synapse 2.201.0__py311-none-any.whl → 2.203.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 +4 -4
- synapse/cmds/cortex.py +4 -6
- synapse/cmds/hive.py +10 -10
- synapse/common.py +17 -58
- synapse/cortex.py +36 -29
- synapse/data/__init__.py +3 -2
- synapse/data/iana.uris.mpk +1 -0
- synapse/lib/autodoc.py +3 -3
- synapse/lib/base.py +2 -12
- synapse/lib/cell.py +9 -13
- synapse/lib/cli.py +2 -2
- synapse/lib/config.py +2 -2
- synapse/lib/encoding.py +4 -3
- synapse/lib/httpapi.py +7 -11
- synapse/lib/json.py +224 -0
- synapse/lib/lmdbslab.py +1 -1
- synapse/lib/oauth.py +176 -54
- synapse/lib/parser.py +2 -1
- synapse/lib/rstorm.py +18 -14
- synapse/lib/schemas.py +87 -1
- synapse/lib/scrape.py +35 -13
- synapse/lib/snap.py +2 -1
- synapse/lib/storm.lark +5 -4
- synapse/lib/storm.py +2 -2
- synapse/lib/storm_format.py +2 -1
- synapse/lib/stormhttp.py +11 -13
- synapse/lib/stormlib/aha.py +4 -4
- synapse/lib/stormlib/auth.py +1 -1
- synapse/lib/stormlib/cache.py +2 -2
- synapse/lib/stormlib/cortex.py +5 -5
- synapse/lib/stormlib/graph.py +1 -1
- synapse/lib/stormlib/imap.py +1 -1
- synapse/lib/stormlib/json.py +8 -11
- synapse/lib/stormlib/model.py +1 -1
- synapse/lib/stormlib/notifications.py +2 -2
- synapse/lib/stormlib/oauth.py +105 -2
- synapse/lib/stormlib/stats.py +4 -0
- synapse/lib/stormlib/stix.py +3 -4
- synapse/lib/stormlib/vault.py +6 -6
- synapse/lib/stormlib/xml.py +2 -2
- synapse/lib/stormtypes.py +19 -28
- synapse/lib/structlog.py +3 -3
- synapse/lib/types.py +2 -1
- synapse/lib/version.py +2 -2
- synapse/lib/view.py +7 -3
- synapse/models/base.py +51 -2
- synapse/telepath.py +79 -18
- synapse/tests/files/__init__.py +0 -1
- synapse/tests/test_axon.py +1 -1
- synapse/tests/test_cmds_cortex.py +3 -2
- synapse/tests/test_cmds_hive.py +4 -4
- synapse/tests/test_common.py +29 -19
- synapse/tests/test_cortex.py +28 -8
- synapse/tests/test_lib_ast.py +3 -3
- synapse/tests/test_lib_autodoc.py +5 -5
- synapse/tests/test_lib_base.py +1 -1
- synapse/tests/test_lib_cell.py +24 -7
- synapse/tests/test_lib_config.py +2 -2
- synapse/tests/test_lib_encoding.py +2 -2
- synapse/tests/test_lib_grammar.py +68 -64
- synapse/tests/test_lib_httpapi.py +13 -13
- synapse/tests/test_lib_json.py +219 -0
- synapse/tests/test_lib_multislabseqn.py +2 -1
- synapse/tests/test_lib_node.py +2 -2
- synapse/tests/test_lib_scrape.py +50 -0
- synapse/tests/test_lib_storm.py +12 -6
- synapse/tests/test_lib_stormhttp.py +4 -4
- synapse/tests/test_lib_stormlib_auth.py +3 -2
- synapse/tests/test_lib_stormlib_cortex.py +10 -12
- synapse/tests/test_lib_stormlib_infosec.py +2 -3
- synapse/tests/test_lib_stormlib_json.py +18 -21
- synapse/tests/test_lib_stormlib_log.py +1 -1
- synapse/tests/test_lib_stormlib_oauth.py +603 -1
- synapse/tests/test_lib_stormlib_stats.py +13 -3
- synapse/tests/test_lib_stormlib_stix.py +5 -5
- synapse/tests/test_lib_stormtypes.py +4 -4
- synapse/tests/test_lib_structlog.py +5 -6
- synapse/tests/test_lib_view.py +8 -0
- synapse/tests/test_model_base.py +32 -0
- synapse/tests/test_model_infotech.py +2 -2
- synapse/tests/test_telepath.py +56 -35
- synapse/tests/test_tools_cryo_cat.py +4 -3
- synapse/tests/test_tools_docker_validate.py +4 -2
- synapse/tests/test_tools_feed.py +30 -2
- synapse/tests/test_tools_genpkg.py +1 -1
- synapse/tests/test_tools_healthcheck.py +8 -7
- synapse/tests/test_utils.py +2 -2
- synapse/tests/test_utils_getrefs.py +35 -28
- synapse/tests/utils.py +3 -3
- synapse/tools/autodoc.py +3 -3
- synapse/tools/changelog.py +2 -2
- synapse/tools/cryo/cat.py +3 -3
- synapse/tools/csvtool.py +2 -3
- synapse/tools/docker/validate.py +5 -5
- synapse/tools/feed.py +2 -1
- synapse/tools/genpkg.py +3 -2
- synapse/tools/healthcheck.py +2 -3
- synapse/tools/json2mpk.py +2 -2
- synapse/utils/getrefs.py +10 -8
- synapse/vendor/cpython/lib/json.py +35 -0
- synapse/vendor/cpython/lib/test/test_json.py +22 -0
- {synapse-2.201.0.dist-info → synapse-2.203.0.dist-info}/METADATA +2 -1
- {synapse-2.201.0.dist-info → synapse-2.203.0.dist-info}/RECORD +106 -101
- {synapse-2.201.0.dist-info → synapse-2.203.0.dist-info}/WHEEL +1 -1
- {synapse-2.201.0.dist-info → synapse-2.203.0.dist-info}/LICENSE +0 -0
- {synapse-2.201.0.dist-info → synapse-2.203.0.dist-info}/top_level.txt +0 -0
|
@@ -192,17 +192,17 @@ Queries = [
|
|
|
192
192
|
'[ test:str=woot .seen=(2014,2015) ]',
|
|
193
193
|
'[ test:str=woot .seen=20 ]',
|
|
194
194
|
'[-#foo]',
|
|
195
|
-
'[meta:
|
|
196
|
-
'[meta:
|
|
197
|
-
'[meta:
|
|
198
|
-
'[meta:
|
|
199
|
-
'[meta:
|
|
195
|
+
'[meta:source=((test:str, foobar), (test:str, foo))]',
|
|
196
|
+
'[meta:source=((test:comp, (2048, horton)), (test:comp, (4096, whoville)))]',
|
|
197
|
+
'[meta:source=((test:comp, (9001, "A mean one")), (test:comp, (40000, greeneggs)))]',
|
|
198
|
+
'[meta:source=((test:int, 16), (test:comp, (9999, greenham)))]',
|
|
199
|
+
'[meta:source=((test:str, 123), (test:int, 123))]',
|
|
200
200
|
'[inet:dns:query=(tcp://1.2.3.4, "", 1)]',
|
|
201
201
|
'[inet:dns:query=(tcp://1.2.3.4, "foo*.haha.com", 1)]',
|
|
202
202
|
'[inet:ipv4=1.2.3.1-1.2.3.3]',
|
|
203
|
-
'[inet:ipv4=1.2.3.4 :asn=10] [meta:
|
|
204
|
-
'[meta:
|
|
205
|
-
'[meta:source=abcd +#omit.nopiv] [meta:
|
|
203
|
+
'[inet:ipv4=1.2.3.4 :asn=10] [meta:source=(abcd, (inet:asn, 10))]',
|
|
204
|
+
'[meta:source=(abcd, (test:str, pennywise))]',
|
|
205
|
+
'[meta:source=abcd +#omit.nopiv] [meta:source=(abcd, (test:pivtarg, foo))]',
|
|
206
206
|
'[test:comp=(1234, 5678)]',
|
|
207
207
|
'[test:comp=(3, foob) +#meep.gorp +#bleep.zlorp +#cond]',
|
|
208
208
|
'[test:guid="*" :tick=2001]',
|
|
@@ -220,8 +220,8 @@ Queries = [
|
|
|
220
220
|
'[test:str=foo :tick=201808021201]',
|
|
221
221
|
'[test:str=hehe] | iden abcd | count',
|
|
222
222
|
'[test:str=hello]',
|
|
223
|
-
'meta:
|
|
224
|
-
'meta:
|
|
223
|
+
'meta:source +:node*range=((test:comp, (1000, green)), (test:comp, (3000, ham)))',
|
|
224
|
+
'meta:source',
|
|
225
225
|
'file:bytes:size=4',
|
|
226
226
|
'for $fqdn in $fqdns { [ inet:fqdn=$fqdn ] }',
|
|
227
227
|
'for ($fqdn, $ipv4) in $dnsa { [ inet:dns:a=($fqdn,$ipv4) ] }',
|
|
@@ -232,8 +232,8 @@ Queries = [
|
|
|
232
232
|
'geo:place:latlong*near=(("34.118560", "-118.300370"), 50m)',
|
|
233
233
|
'geo:place:latlong*near=((0, 0), 50m)',
|
|
234
234
|
'geo:place:latlong*near=((34.1, -118.3), 10km)',
|
|
235
|
-
'geo:place=$place <- meta:
|
|
236
|
-
'geo:place=$place <- meta:
|
|
235
|
+
'geo:place=$place <- meta:source <- *',
|
|
236
|
+
'geo:place=$place <- meta:source <- ps:person',
|
|
237
237
|
'geo:place=abcd $latlong=:latlong $radius=:radius | spin | tel:mob:telem:latlong*near=($latlong, 3km)',
|
|
238
238
|
'meta:note=abcd | noderefs -d 2 --join',
|
|
239
239
|
'help',
|
|
@@ -285,16 +285,16 @@ Queries = [
|
|
|
285
285
|
'inet:user | limit 10 | +inet:user=visi',
|
|
286
286
|
'inet:user | limit 10 | [ +#foo.bar ]',
|
|
287
287
|
'media:news = 00a1f0d928e25729b9e86e2d08c127ce [ :summary = \"\" ]',
|
|
288
|
-
'meta:
|
|
289
|
-
'meta:
|
|
288
|
+
'meta:source:meta:source=$sorc -> *',
|
|
289
|
+
'meta:source:meta:source=$sorc :node -> *',
|
|
290
290
|
'meta:source=8f1401de15918358d5247e21ca29a814',
|
|
291
291
|
'movetag a.b a.m',
|
|
292
292
|
'movetag hehe woot',
|
|
293
|
-
'ps:person=$pers -> meta:
|
|
294
|
-
'ps:person=$pers -> meta:
|
|
295
|
-
'ps:person=$pers -> meta:
|
|
296
|
-
'ps:person=$pers -> meta:
|
|
297
|
-
'ps:person=$pers -> meta:
|
|
293
|
+
'ps:person=$pers -> meta:source -> *',
|
|
294
|
+
'ps:person=$pers -> meta:source -> geo:place',
|
|
295
|
+
'ps:person=$pers -> meta:source +:time@=(2014,2017) -> geo:place',
|
|
296
|
+
'ps:person=$pers -> meta:source -> *',
|
|
297
|
+
'ps:person=$pers -> meta:source :node -> *',
|
|
298
298
|
'reindex --form-counts',
|
|
299
299
|
'sudo | [ inet:ipv4=1.2.3.4 ]',
|
|
300
300
|
'sudo | [ test:cycle0=foo :test:cycle1=bar ]',
|
|
@@ -444,12 +444,12 @@ Queries = [
|
|
|
444
444
|
'test:str=bar <- *',
|
|
445
445
|
'test:str=bar test:pivcomp=(foo,bar) [+#test.bar]',
|
|
446
446
|
'test:str=foo +#lol@=2016',
|
|
447
|
-
'test:str=foo <+- meta:
|
|
448
|
-
'test:str=foo <- meta:
|
|
447
|
+
'test:str=foo <+- meta:source',
|
|
448
|
+
'test:str=foo <- meta:source',
|
|
449
449
|
'test:str=foo | delnode',
|
|
450
|
-
'test:str=foobar -+> meta:
|
|
451
|
-
'test:str=foobar -> meta:
|
|
452
|
-
'test:str=foobar -> meta:
|
|
450
|
+
'test:str=foobar -+> meta:source',
|
|
451
|
+
'test:str=foobar -> meta:source <+- test:str',
|
|
452
|
+
'test:str=foobar -> meta:source <- test:str',
|
|
453
453
|
'test:str=hello [:tick="2001"]',
|
|
454
454
|
'test:str=hello [:tick="2002"]',
|
|
455
455
|
'test:str=pennywise | noderefs --join -d 9 --traverse-edge',
|
|
@@ -476,7 +476,7 @@ Queries = [
|
|
|
476
476
|
inet:fqdn | graph
|
|
477
477
|
--degrees 2
|
|
478
478
|
--filter { -#nope }
|
|
479
|
-
--pivot { <- meta:
|
|
479
|
+
--pivot { <- meta:source <- meta:source }
|
|
480
480
|
--form-pivot inet:fqdn {<- * | limit 20}
|
|
481
481
|
--form-pivot inet:fqdn {-> * | limit 20}
|
|
482
482
|
--form-filter inet:fqdn {-inet:fqdn:issuffix=1}
|
|
@@ -514,7 +514,7 @@ Queries = [
|
|
|
514
514
|
|
|
515
515
|
{[ inet:email:message:attachment=($node, "*") ] -inet:email:message [ :name=sploit.exe ]}
|
|
516
516
|
|
|
517
|
-
{[ meta:
|
|
517
|
+
{[ meta:source=($node, ('inet:email:header', ('to', 'Visi Kensho <visi@vertex.link>'))) ]}
|
|
518
518
|
''',
|
|
519
519
|
'$x = $(1 / 3)',
|
|
520
520
|
'$x = $(1 * 3)',
|
|
@@ -690,18 +690,18 @@ Queries = [
|
|
|
690
690
|
'reverse(*$form=$valu)',
|
|
691
691
|
'test:str=foobar -> inet:dns*',
|
|
692
692
|
'test:str=foobar -> inet:dns:*',
|
|
693
|
-
'test:str=foobar -> (meta:
|
|
694
|
-
'test:str=foobar -> (meta:
|
|
693
|
+
'test:str=foobar -> (meta:source, inet:dns:a)',
|
|
694
|
+
'test:str=foobar -> (meta:source, inet:dns*)',
|
|
695
695
|
'test:str=foobar -> $foo',
|
|
696
696
|
'test:str=foobar -+> inet:dns*',
|
|
697
697
|
'test:str=foobar -+> inet:dns:*',
|
|
698
|
-
'test:str=foobar -+> (meta:
|
|
699
|
-
'test:str=foobar -+> (meta:
|
|
698
|
+
'test:str=foobar -+> (meta:source, inet:dns:a)',
|
|
699
|
+
'test:str=foobar -+> (meta:source, inet:dns*)',
|
|
700
700
|
'test:str=foobar -+> $foo',
|
|
701
701
|
'test:str=foobar -(refs)> inet:dns:*',
|
|
702
|
-
'inet:fqdn=foo.com :zone -> (meta:
|
|
702
|
+
'inet:fqdn=foo.com :zone -> (meta:source, inet:dns:a)',
|
|
703
703
|
'inet:fqdn=foo.com :zone -> $foo',
|
|
704
|
-
'inet:fqdn=foo.com :zone -+> (meta:
|
|
704
|
+
'inet:fqdn=foo.com :zone -+> (meta:source, inet:dns:a)',
|
|
705
705
|
'inet:fqdn=foo.com :zone -+> $foo',
|
|
706
706
|
'test:*#foo',
|
|
707
707
|
'test:*#foo@=2016',
|
|
@@ -746,6 +746,8 @@ Queries = [
|
|
|
746
746
|
'[test:str=foo :bar--=(foo, bar)]',
|
|
747
747
|
'[test:str=foo :bar?++=$baz]',
|
|
748
748
|
'[test:str=foo :bar?--={[it:dev:str=foo]}]',
|
|
749
|
+
'$foo=(notime,)',
|
|
750
|
+
'$foo=(nulltime,)',
|
|
749
751
|
]
|
|
750
752
|
|
|
751
753
|
# Generated with print_parse_list below
|
|
@@ -931,17 +933,17 @@ _ParseResults = [
|
|
|
931
933
|
'Query: [EditNodeAdd: [FormName: [Const: test:str], Const: =, Const: woot], EditPropSet: [UnivProp: [Const: .seen], Const: =, List: [Const: 2014, Const: 2015]]]',
|
|
932
934
|
'Query: [EditNodeAdd: [FormName: [Const: test:str], Const: =, Const: woot], EditPropSet: [UnivProp: [Const: .seen], Const: =, Const: 20]]',
|
|
933
935
|
'Query: [EditTagDel: [TagName: [Const: foo]]]',
|
|
934
|
-
'Query: [EditNodeAdd: [FormName: [Const: meta:
|
|
935
|
-
'Query: [EditNodeAdd: [FormName: [Const: meta:
|
|
936
|
-
'Query: [EditNodeAdd: [FormName: [Const: meta:
|
|
937
|
-
'Query: [EditNodeAdd: [FormName: [Const: meta:
|
|
938
|
-
'Query: [EditNodeAdd: [FormName: [Const: meta:
|
|
936
|
+
'Query: [EditNodeAdd: [FormName: [Const: meta:source], Const: =, List: [List: [Const: test:str, Const: foobar], List: [Const: test:str, Const: foo]]]]',
|
|
937
|
+
'Query: [EditNodeAdd: [FormName: [Const: meta:source], Const: =, List: [List: [Const: test:comp, List: [Const: 2048, Const: horton]], List: [Const: test:comp, List: [Const: 4096, Const: whoville]]]]]',
|
|
938
|
+
'Query: [EditNodeAdd: [FormName: [Const: meta:source], Const: =, List: [List: [Const: test:comp, List: [Const: 9001, Const: A mean one]], List: [Const: test:comp, List: [Const: 40000, Const: greeneggs]]]]]',
|
|
939
|
+
'Query: [EditNodeAdd: [FormName: [Const: meta:source], Const: =, List: [List: [Const: test:int, Const: 16], List: [Const: test:comp, List: [Const: 9999, Const: greenham]]]]]',
|
|
940
|
+
'Query: [EditNodeAdd: [FormName: [Const: meta:source], Const: =, List: [List: [Const: test:str, Const: 123], List: [Const: test:int, Const: 123]]]]',
|
|
939
941
|
'Query: [EditNodeAdd: [FormName: [Const: inet:dns:query], Const: =, List: [Const: tcp://1.2.3.4, Const: , Const: 1]]]',
|
|
940
942
|
'Query: [EditNodeAdd: [FormName: [Const: inet:dns:query], Const: =, List: [Const: tcp://1.2.3.4, Const: foo*.haha.com, Const: 1]]]',
|
|
941
943
|
'Query: [EditNodeAdd: [FormName: [Const: inet:ipv4], Const: =, Const: 1.2.3.1-1.2.3.3]]',
|
|
942
|
-
'Query: [EditNodeAdd: [FormName: [Const: inet:ipv4], Const: =, Const: 1.2.3.4], EditPropSet: [RelProp: [Const: asn], Const: =, Const: 10], EditNodeAdd: [FormName: [Const: meta:
|
|
943
|
-
'Query: [EditNodeAdd: [FormName: [Const: meta:
|
|
944
|
-
'Query: [EditNodeAdd: [FormName: [Const: meta:source], Const: =, Const: abcd], EditTagAdd: [TagName: [Const: omit, Const: nopiv]], EditNodeAdd: [FormName: [Const: meta:
|
|
944
|
+
'Query: [EditNodeAdd: [FormName: [Const: inet:ipv4], Const: =, Const: 1.2.3.4], EditPropSet: [RelProp: [Const: asn], Const: =, Const: 10], EditNodeAdd: [FormName: [Const: meta:source], Const: =, List: [Const: abcd, List: [Const: inet:asn, Const: 10]]]]',
|
|
945
|
+
'Query: [EditNodeAdd: [FormName: [Const: meta:source], Const: =, List: [Const: abcd, List: [Const: test:str, Const: pennywise]]]]',
|
|
946
|
+
'Query: [EditNodeAdd: [FormName: [Const: meta:source], Const: =, Const: abcd], EditTagAdd: [TagName: [Const: omit, Const: nopiv]], EditNodeAdd: [FormName: [Const: meta:source], Const: =, List: [Const: abcd, List: [Const: test:pivtarg, Const: foo]]]]',
|
|
945
947
|
'Query: [EditNodeAdd: [FormName: [Const: test:comp], Const: =, List: [Const: 1234, Const: 5678]]]',
|
|
946
948
|
'Query: [EditNodeAdd: [FormName: [Const: test:comp], Const: =, List: [Const: 3, Const: foob]], EditTagAdd: [TagName: [Const: meep, Const: gorp]], EditTagAdd: [TagName: [Const: bleep, Const: zlorp]], EditTagAdd: [TagName: [Const: cond]]]',
|
|
947
949
|
'Query: [EditNodeAdd: [FormName: [Const: test:guid], Const: =, Const: *], EditPropSet: [RelProp: [Const: tick], Const: =, Const: 2001]]',
|
|
@@ -959,8 +961,8 @@ _ParseResults = [
|
|
|
959
961
|
'Query: [EditNodeAdd: [FormName: [Const: test:str], Const: =, Const: foo], EditPropSet: [RelProp: [Const: tick], Const: =, Const: 201808021201]]',
|
|
960
962
|
'Query: [EditNodeAdd: [FormName: [Const: test:str], Const: =, Const: hehe], CmdOper: [Const: iden, List: [Const: abcd]], CmdOper: [Const: count, Const: ()]]',
|
|
961
963
|
'Query: [EditNodeAdd: [FormName: [Const: test:str], Const: =, Const: hello]]',
|
|
962
|
-
'Query: [LiftProp: [Const: meta:
|
|
963
|
-
'Query: [LiftProp: [Const: meta:
|
|
964
|
+
'Query: [LiftProp: [Const: meta:source], FiltOper: [Const: +, RelPropCond: [RelPropValue: [RelProp: [Const: node]], Const: range=, List: [List: [Const: test:comp, List: [Const: 1000, Const: green]], List: [Const: test:comp, List: [Const: 3000, Const: ham]]]]]]',
|
|
965
|
+
'Query: [LiftProp: [Const: meta:source]]',
|
|
964
966
|
'Query: [LiftPropBy: [Const: file:bytes:size, Const: =, Const: 4]]',
|
|
965
967
|
'Query: [ForLoop: [Const: fqdn, VarValue: [Const: fqdns], SubQuery: [Query: [EditNodeAdd: [FormName: [Const: inet:fqdn], Const: =, VarValue: [Const: fqdn]]]]]]',
|
|
966
968
|
"Query: [ForLoop: [VarList: ['fqdn', 'ipv4'], VarValue: [Const: dnsa], SubQuery: [Query: [EditNodeAdd: [FormName: [Const: inet:dns:a], Const: =, List: [VarValue: [Const: fqdn], VarValue: [Const: ipv4]]]]]]]",
|
|
@@ -971,8 +973,8 @@ _ParseResults = [
|
|
|
971
973
|
'Query: [LiftPropBy: [Const: geo:place:latlong, Const: near=, List: [List: [Const: 34.118560, Const: -118.300370], Const: 50m]]]',
|
|
972
974
|
'Query: [LiftPropBy: [Const: geo:place:latlong, Const: near=, List: [List: [Const: 0, Const: 0], Const: 50m]]]',
|
|
973
975
|
'Query: [LiftPropBy: [Const: geo:place:latlong, Const: near=, List: [List: [Const: 34.1, Const: -118.3], Const: 10km]]]',
|
|
974
|
-
'Query: [LiftPropBy: [Const: geo:place, Const: =, VarValue: [Const: place]], PivotInFrom: [Const: meta:
|
|
975
|
-
'Query: [LiftPropBy: [Const: geo:place, Const: =, VarValue: [Const: place]], PivotInFrom: [Const: meta:
|
|
976
|
+
'Query: [LiftPropBy: [Const: geo:place, Const: =, VarValue: [Const: place]], PivotInFrom: [Const: meta:source], isjoin=False, PivotIn: [], isjoin=False]',
|
|
977
|
+
'Query: [LiftPropBy: [Const: geo:place, Const: =, VarValue: [Const: place]], PivotInFrom: [Const: meta:source], isjoin=False, PivotInFrom: [Const: ps:person], isjoin=False]',
|
|
976
978
|
'Query: [LiftPropBy: [Const: geo:place, Const: =, Const: abcd], SetVarOper: [Const: latlong, RelPropValue: [Const: latlong]], SetVarOper: [Const: radius, RelPropValue: [Const: radius]], CmdOper: [Const: spin, Const: ()], LiftPropBy: [Const: tel:mob:telem:latlong, Const: near=, List: [VarValue: [Const: latlong], Const: 3km]]]',
|
|
977
979
|
'Query: [LiftPropBy: [Const: meta:note, Const: =, Const: abcd], CmdOper: [Const: noderefs, List: [Const: -d, Const: 2, Const: --join]]]',
|
|
978
980
|
'Query: [CmdOper: [Const: help, Const: ()]]',
|
|
@@ -1024,16 +1026,16 @@ _ParseResults = [
|
|
|
1024
1026
|
'Query: [LiftProp: [Const: inet:user], CmdOper: [Const: limit, List: [Const: 10]], FiltOper: [Const: +, AbsPropCond: [Const: inet:user, Const: =, Const: visi]]]',
|
|
1025
1027
|
'Query: [LiftProp: [Const: inet:user], CmdOper: [Const: limit, List: [Const: 10]], EditTagAdd: [TagName: [Const: foo, Const: bar]]]',
|
|
1026
1028
|
'Query: [LiftPropBy: [Const: media:news, Const: =, Const: 00a1f0d928e25729b9e86e2d08c127ce], EditPropSet: [RelProp: [Const: summary], Const: =, Const: ]]',
|
|
1027
|
-
'Query: [LiftPropBy: [Const: meta:
|
|
1028
|
-
'Query: [LiftPropBy: [Const: meta:
|
|
1029
|
+
'Query: [LiftPropBy: [Const: meta:source:meta:source, Const: =, VarValue: [Const: sorc]], PivotOut: [], isjoin=False]',
|
|
1030
|
+
'Query: [LiftPropBy: [Const: meta:source:meta:source, Const: =, VarValue: [Const: sorc]], PropPivotOut: [RelProp: [Const: node]], isjoin=False]',
|
|
1029
1031
|
'Query: [LiftPropBy: [Const: meta:source, Const: =, Const: 8f1401de15918358d5247e21ca29a814]]',
|
|
1030
1032
|
'Query: [CmdOper: [Const: movetag, List: [Const: a.b, Const: a.m]]]',
|
|
1031
1033
|
'Query: [CmdOper: [Const: movetag, List: [Const: hehe, Const: woot]]]',
|
|
1032
|
-
'Query: [LiftPropBy: [Const: ps:person, Const: =, VarValue: [Const: pers]], FormPivot: [Const: meta:
|
|
1033
|
-
'Query: [LiftPropBy: [Const: ps:person, Const: =, VarValue: [Const: pers]], FormPivot: [Const: meta:
|
|
1034
|
-
'Query: [LiftPropBy: [Const: ps:person, Const: =, VarValue: [Const: pers]], FormPivot: [Const: meta:
|
|
1035
|
-
'Query: [LiftPropBy: [Const: ps:person, Const: =, VarValue: [Const: pers]], FormPivot: [Const: meta:
|
|
1036
|
-
'Query: [LiftPropBy: [Const: ps:person, Const: =, VarValue: [Const: pers]], FormPivot: [Const: meta:
|
|
1034
|
+
'Query: [LiftPropBy: [Const: ps:person, Const: =, VarValue: [Const: pers]], FormPivot: [Const: meta:source], isjoin=False, PivotOut: [], isjoin=False]',
|
|
1035
|
+
'Query: [LiftPropBy: [Const: ps:person, Const: =, VarValue: [Const: pers]], FormPivot: [Const: meta:source], isjoin=False, FormPivot: [Const: geo:place], isjoin=False]',
|
|
1036
|
+
'Query: [LiftPropBy: [Const: ps:person, Const: =, VarValue: [Const: pers]], FormPivot: [Const: meta:source], isjoin=False, FiltOper: [Const: +, RelPropCond: [RelPropValue: [RelProp: [Const: time]], Const: @=, List: [Const: 2014, Const: 2017]]], FormPivot: [Const: geo:place], isjoin=False]',
|
|
1037
|
+
'Query: [LiftPropBy: [Const: ps:person, Const: =, VarValue: [Const: pers]], FormPivot: [Const: meta:source], isjoin=False, PivotOut: [], isjoin=False]',
|
|
1038
|
+
'Query: [LiftPropBy: [Const: ps:person, Const: =, VarValue: [Const: pers]], FormPivot: [Const: meta:source], isjoin=False, PropPivotOut: [RelProp: [Const: node]], isjoin=False]',
|
|
1037
1039
|
'Query: [CmdOper: [Const: reindex, List: [Const: --form-counts]]]',
|
|
1038
1040
|
'Query: [CmdOper: [Const: sudo, Const: ()], EditNodeAdd: [FormName: [Const: inet:ipv4], Const: =, Const: 1.2.3.4]]',
|
|
1039
1041
|
'Query: [CmdOper: [Const: sudo, Const: ()], EditNodeAdd: [FormName: [Const: test:cycle0], Const: =, Const: foo], EditPropSet: [RelProp: [Const: test:cycle1], Const: =, Const: bar]]',
|
|
@@ -1183,12 +1185,12 @@ _ParseResults = [
|
|
|
1183
1185
|
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: bar], PivotIn: [], isjoin=False]',
|
|
1184
1186
|
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: bar], LiftPropBy: [Const: test:pivcomp, Const: =, List: [Const: foo, Const: bar]], EditTagAdd: [TagName: [Const: test, Const: bar]]]',
|
|
1185
1187
|
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foo], FiltOper: [Const: +, TagValuCond: [TagMatch: [Const: lol], Const: @=, Const: 2016]]]',
|
|
1186
|
-
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foo], PivotInFrom: [Const: meta:
|
|
1187
|
-
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foo], PivotInFrom: [Const: meta:
|
|
1188
|
+
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foo], PivotInFrom: [Const: meta:source], isjoin=True]',
|
|
1189
|
+
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foo], PivotInFrom: [Const: meta:source], isjoin=False]',
|
|
1188
1190
|
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foo], CmdOper: [Const: delnode, Const: ()]]',
|
|
1189
|
-
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [Const: meta:
|
|
1190
|
-
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [Const: meta:
|
|
1191
|
-
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [Const: meta:
|
|
1191
|
+
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [Const: meta:source], isjoin=True]',
|
|
1192
|
+
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [Const: meta:source], isjoin=False, PivotInFrom: [Const: test:str], isjoin=True]',
|
|
1193
|
+
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [Const: meta:source], isjoin=False, PivotInFrom: [Const: test:str], isjoin=False]',
|
|
1192
1194
|
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: hello], EditPropSet: [RelProp: [Const: tick], Const: =, Const: 2001]]',
|
|
1193
1195
|
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: hello], EditPropSet: [RelProp: [Const: tick], Const: =, Const: 2002]]',
|
|
1194
1196
|
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: pennywise], CmdOper: [Const: noderefs, List: [Const: --join, Const: -d, Const: 9, Const: --traverse-edge]]]',
|
|
@@ -1204,11 +1206,11 @@ _ParseResults = [
|
|
|
1204
1206
|
'Query: [LiftProp: [Const: test:int]]',
|
|
1205
1207
|
'Query: [LiftProp: [Const: test:int]]',
|
|
1206
1208
|
'Query: [LiftProp: [Const: test:int]]',
|
|
1207
|
-
'Query: [LiftProp: [Const: inet:fqdn], CmdOper: [Const: graph, List: [Const: --degrees, Const: 2, Const: --filter, ArgvQuery: [Query: [FiltOper: [Const: -, TagCond: [TagMatch: [Const: nope]]]]], Const: --pivot, ArgvQuery: [Query: [PivotInFrom: [Const: meta:
|
|
1209
|
+
'Query: [LiftProp: [Const: inet:fqdn], CmdOper: [Const: graph, List: [Const: --degrees, Const: 2, Const: --filter, ArgvQuery: [Query: [FiltOper: [Const: -, TagCond: [TagMatch: [Const: nope]]]]], Const: --pivot, ArgvQuery: [Query: [PivotInFrom: [Const: meta:source], isjoin=False, PivotInFrom: [Const: meta:source], isjoin=False]], Const: --form-pivot, Const: inet:fqdn, ArgvQuery: [Query: [PivotIn: [], isjoin=False, CmdOper: [Const: limit, List: [Const: 20]]]], Const: --form-pivot, Const: inet:fqdn, ArgvQuery: [Query: [PivotOut: [], isjoin=False, CmdOper: [Const: limit, List: [Const: 20]]]], Const: --form-filter, Const: inet:fqdn, ArgvQuery: [Query: [FiltOper: [Const: -, AbsPropCond: [Const: inet:fqdn:issuffix, Const: =, Const: 1]]]], Const: --form-pivot, Const: syn:tag, ArgvQuery: [Query: [PivotOut: [], isjoin=False]], Const: --form-pivot, Const: *, ArgvQuery: [Query: [PivotToTags: [TagMatch: []], isjoin=False]]]]]',
|
|
1208
1210
|
"Query: [ForLoop: [Const: foo, VarValue: [Const: foos], SubQuery: [Query: [VarListSetOper: [VarList: ['fqdn', 'ipv4'], FuncCall: [VarDeref: [VarValue: [Const: foo], Const: split], CallArgs: [Const: |], CallKwargs: []]], EditNodeAdd: [FormName: [Const: inet:dns:a], Const: =, List: [VarValue: [Const: fqdn], VarValue: [Const: ipv4]]]]]]]",
|
|
1209
1211
|
'Query: [ForLoop: [Const: tag, FuncCall: [VarDeref: [VarValue: [Const: node], Const: tags], CallArgs: [], CallKwargs: []], SubQuery: [Query: [FormPivot: [Const: test:int], isjoin=False, EditTagAdd: [TagName: [VarValue: [Const: tag]]]]]]]',
|
|
1210
1212
|
'Query: [ForLoop: [Const: tag, FuncCall: [VarDeref: [VarValue: [Const: node], Const: tags], CallArgs: [Const: fo*], CallKwargs: []], SubQuery: [Query: [FormPivot: [Const: test:int], isjoin=False, EditTagDel: [TagName: [VarValue: [Const: tag]]]]]]]',
|
|
1211
|
-
'Query: [EditNodeAdd: [FormName: [Const: inet:email:message], Const: =, Const: *], EditPropSet: [RelProp: [Const: to], Const: =, Const: woot@woot.com], EditPropSet: [RelProp: [Const: from], Const: =, Const: visi@vertex.link], EditPropSet: [RelProp: [Const: replyto], Const: =, Const: root@root.com], EditPropSet: [RelProp: [Const: subject], Const: =, Const: hi there], EditPropSet: [RelProp: [Const: date], Const: =, Const: 2015], EditPropSet: [RelProp: [Const: body], Const: =, Const: there are mad sploitz here!], EditPropSet: [RelProp: [Const: bytes], Const: =, Const: *], SubQuery: [Query: [EditNodeAdd: [FormName: [Const: inet:email:message:link], Const: =, List: [VarValue: [Const: node], Const: https://www.vertex.link]]]], SubQuery: [Query: [EditNodeAdd: [FormName: [Const: inet:email:message:attachment], Const: =, List: [VarValue: [Const: node], Const: *]], FiltOper: [Const: -, HasAbsPropCond: [Const: inet:email:message]], EditPropSet: [RelProp: [Const: name], Const: =, Const: sploit.exe]]], SubQuery: [Query: [EditNodeAdd: [FormName: [Const: meta:
|
|
1213
|
+
'Query: [EditNodeAdd: [FormName: [Const: inet:email:message], Const: =, Const: *], EditPropSet: [RelProp: [Const: to], Const: =, Const: woot@woot.com], EditPropSet: [RelProp: [Const: from], Const: =, Const: visi@vertex.link], EditPropSet: [RelProp: [Const: replyto], Const: =, Const: root@root.com], EditPropSet: [RelProp: [Const: subject], Const: =, Const: hi there], EditPropSet: [RelProp: [Const: date], Const: =, Const: 2015], EditPropSet: [RelProp: [Const: body], Const: =, Const: there are mad sploitz here!], EditPropSet: [RelProp: [Const: bytes], Const: =, Const: *], SubQuery: [Query: [EditNodeAdd: [FormName: [Const: inet:email:message:link], Const: =, List: [VarValue: [Const: node], Const: https://www.vertex.link]]]], SubQuery: [Query: [EditNodeAdd: [FormName: [Const: inet:email:message:attachment], Const: =, List: [VarValue: [Const: node], Const: *]], FiltOper: [Const: -, HasAbsPropCond: [Const: inet:email:message]], EditPropSet: [RelProp: [Const: name], Const: =, Const: sploit.exe]]], SubQuery: [Query: [EditNodeAdd: [FormName: [Const: meta:source], Const: =, List: [VarValue: [Const: node], List: [Const: inet:email:header, List: [Const: to, Const: Visi Kensho <visi@vertex.link>]]]]]]]',
|
|
1212
1214
|
'Query: [SetVarOper: [Const: x, DollarExpr: [ExprNode: [Const: 1, Const: /, Const: 3]]]]',
|
|
1213
1215
|
'Query: [SetVarOper: [Const: x, DollarExpr: [ExprNode: [Const: 1, Const: *, Const: 3]]]]',
|
|
1214
1216
|
'Query: [SetVarOper: [Const: x, DollarExpr: [ExprNode: [ExprNode: [Const: 1, Const: *, Const: 3], Const: +, Const: 2]]]]',
|
|
@@ -1338,18 +1340,18 @@ _ParseResults = [
|
|
|
1338
1340
|
'Query: [LiftPropBy: [VarValue: [Const: form], Const: =, VarValue: [Const: valu]]]',
|
|
1339
1341
|
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [Const: inet:dns*], isjoin=False]',
|
|
1340
1342
|
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [Const: inet:dns:*], isjoin=False]',
|
|
1341
|
-
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [List: [Const: meta:
|
|
1342
|
-
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [List: [Const: meta:
|
|
1343
|
+
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [List: [Const: meta:source, Const: inet:dns:a]], isjoin=False]',
|
|
1344
|
+
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [List: [Const: meta:source, Const: inet:dns*]], isjoin=False]',
|
|
1343
1345
|
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [VarValue: [Const: foo]], isjoin=False]',
|
|
1344
1346
|
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [Const: inet:dns*], isjoin=True]',
|
|
1345
1347
|
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [Const: inet:dns:*], isjoin=True]',
|
|
1346
|
-
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [List: [Const: meta:
|
|
1347
|
-
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [List: [Const: meta:
|
|
1348
|
+
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [List: [Const: meta:source, Const: inet:dns:a]], isjoin=True]',
|
|
1349
|
+
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [List: [Const: meta:source, Const: inet:dns*]], isjoin=True]',
|
|
1348
1350
|
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], FormPivot: [VarValue: [Const: foo]], isjoin=True]',
|
|
1349
1351
|
'Query: [LiftPropBy: [Const: test:str, Const: =, Const: foobar], N1Walk: [Const: refs, Const: inet:dns:*], isjoin=False]',
|
|
1350
|
-
'Query: [LiftPropBy: [Const: inet:fqdn, Const: =, Const: foo.com], PropPivot: [RelPropValue: [RelProp: [Const: zone]], List: [Const: meta:
|
|
1352
|
+
'Query: [LiftPropBy: [Const: inet:fqdn, Const: =, Const: foo.com], PropPivot: [RelPropValue: [RelProp: [Const: zone]], List: [Const: meta:source, Const: inet:dns:a]], isjoin=False]',
|
|
1351
1353
|
'Query: [LiftPropBy: [Const: inet:fqdn, Const: =, Const: foo.com], PropPivot: [RelPropValue: [RelProp: [Const: zone]], VarValue: [Const: foo]], isjoin=False]',
|
|
1352
|
-
'Query: [LiftPropBy: [Const: inet:fqdn, Const: =, Const: foo.com], PropPivot: [RelPropValue: [RelProp: [Const: zone]], List: [Const: meta:
|
|
1354
|
+
'Query: [LiftPropBy: [Const: inet:fqdn, Const: =, Const: foo.com], PropPivot: [RelPropValue: [RelProp: [Const: zone]], List: [Const: meta:source, Const: inet:dns:a]], isjoin=True]',
|
|
1353
1355
|
'Query: [LiftPropBy: [Const: inet:fqdn, Const: =, Const: foo.com], PropPivot: [RelPropValue: [RelProp: [Const: zone]], VarValue: [Const: foo]], isjoin=True]',
|
|
1354
1356
|
'Query: [LiftFormTag: [Const: test:*, TagName: [Const: foo]]]',
|
|
1355
1357
|
'Query: [LiftFormTag: [Const: test:*, TagName: [Const: foo], Const: @=, Const: 2016]]',
|
|
@@ -1394,6 +1396,8 @@ _ParseResults = [
|
|
|
1394
1396
|
'Query: [EditNodeAdd: [FormName: [Const: test:str], Const: =, Const: foo], EditPropSetMulti: [RelProp: [Const: bar], Const: --=, List: [Const: foo, Const: bar]]]',
|
|
1395
1397
|
'Query: [EditNodeAdd: [FormName: [Const: test:str], Const: =, Const: foo], EditPropSetMulti: [RelProp: [Const: bar], Const: ?++=, VarValue: [Const: baz]]]',
|
|
1396
1398
|
'Query: [EditNodeAdd: [FormName: [Const: test:str], Const: =, Const: foo], EditPropSetMulti: [RelProp: [Const: bar], Const: ?--=, SubQuery: [Query: [EditNodeAdd: [FormName: [Const: it:dev:str], Const: =, Const: foo]]]]]',
|
|
1399
|
+
'Query: [SetVarOper: [Const: foo, List: [Const: notime]]]',
|
|
1400
|
+
'Query: [SetVarOper: [Const: foo, List: [Const: nulltime]]]',
|
|
1397
1401
|
]
|
|
1398
1402
|
|
|
1399
1403
|
class GrammarTest(s_t_utils.SynTest):
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import ssl
|
|
2
|
-
import json
|
|
3
2
|
|
|
4
3
|
import aiohttp
|
|
5
4
|
import aiohttp.client_exceptions as a_exc
|
|
@@ -8,6 +7,7 @@ import synapse.common as s_common
|
|
|
8
7
|
import synapse.tools.backup as s_backup
|
|
9
8
|
|
|
10
9
|
import synapse.lib.coro as s_coro
|
|
10
|
+
import synapse.lib.json as s_json
|
|
11
11
|
import synapse.lib.link as s_link
|
|
12
12
|
import synapse.lib.httpapi as s_httpapi
|
|
13
13
|
import synapse.lib.version as s_version
|
|
@@ -671,7 +671,7 @@ class HttpApiTest(s_tests.SynTest):
|
|
|
671
671
|
if not byts:
|
|
672
672
|
break
|
|
673
673
|
|
|
674
|
-
podes.append(
|
|
674
|
+
podes.append(s_json.loads(byts))
|
|
675
675
|
|
|
676
676
|
self.eq(podes[0][0], ('inet:ipv4', 0x01020304))
|
|
677
677
|
|
|
@@ -685,7 +685,7 @@ class HttpApiTest(s_tests.SynTest):
|
|
|
685
685
|
if not byts:
|
|
686
686
|
break
|
|
687
687
|
|
|
688
|
-
msgs.append(
|
|
688
|
+
msgs.append(s_json.loads(byts))
|
|
689
689
|
podes = [m[1] for m in msgs if m[0] == 'node']
|
|
690
690
|
self.eq(podes[0][0], ('inet:ipv4', 0x05050505))
|
|
691
691
|
|
|
@@ -1322,7 +1322,7 @@ class HttpApiTest(s_tests.SynTest):
|
|
|
1322
1322
|
if not byts:
|
|
1323
1323
|
break
|
|
1324
1324
|
|
|
1325
|
-
mesg =
|
|
1325
|
+
mesg = s_json.loads(byts)
|
|
1326
1326
|
|
|
1327
1327
|
if mesg[0] == 'node':
|
|
1328
1328
|
node = mesg[1]
|
|
@@ -1337,7 +1337,7 @@ class HttpApiTest(s_tests.SynTest):
|
|
|
1337
1337
|
if not byts:
|
|
1338
1338
|
break
|
|
1339
1339
|
|
|
1340
|
-
mesg =
|
|
1340
|
+
mesg = s_json.loads(byts)
|
|
1341
1341
|
|
|
1342
1342
|
if mesg[0] == 'node':
|
|
1343
1343
|
node = mesg[1]
|
|
@@ -1354,7 +1354,7 @@ class HttpApiTest(s_tests.SynTest):
|
|
|
1354
1354
|
if not byts:
|
|
1355
1355
|
break
|
|
1356
1356
|
|
|
1357
|
-
node =
|
|
1357
|
+
node = s_json.loads(byts)
|
|
1358
1358
|
|
|
1359
1359
|
self.eq(0x01020304, node[0][1])
|
|
1360
1360
|
|
|
@@ -1365,7 +1365,7 @@ class HttpApiTest(s_tests.SynTest):
|
|
|
1365
1365
|
if not byts:
|
|
1366
1366
|
break
|
|
1367
1367
|
|
|
1368
|
-
node =
|
|
1368
|
+
node = s_json.loads(byts)
|
|
1369
1369
|
|
|
1370
1370
|
self.eq(0x01020304, node[0][1])
|
|
1371
1371
|
|
|
@@ -1385,8 +1385,8 @@ class HttpApiTest(s_tests.SynTest):
|
|
|
1385
1385
|
break
|
|
1386
1386
|
|
|
1387
1387
|
try:
|
|
1388
|
-
node =
|
|
1389
|
-
except
|
|
1388
|
+
node = s_json.loads(byts)
|
|
1389
|
+
except s_exc.BadJsonText:
|
|
1390
1390
|
bufr = jstr
|
|
1391
1391
|
break
|
|
1392
1392
|
|
|
@@ -1407,8 +1407,8 @@ class HttpApiTest(s_tests.SynTest):
|
|
|
1407
1407
|
break
|
|
1408
1408
|
|
|
1409
1409
|
try:
|
|
1410
|
-
mesg =
|
|
1411
|
-
except
|
|
1410
|
+
mesg = s_json.loads(byts)
|
|
1411
|
+
except s_exc.BadJsonText:
|
|
1412
1412
|
bufr = jstr
|
|
1413
1413
|
break
|
|
1414
1414
|
|
|
@@ -1427,7 +1427,7 @@ class HttpApiTest(s_tests.SynTest):
|
|
|
1427
1427
|
if not byts:
|
|
1428
1428
|
break
|
|
1429
1429
|
|
|
1430
|
-
mesg =
|
|
1430
|
+
mesg = s_json.loads(byts)
|
|
1431
1431
|
if mesg[0] == 'node':
|
|
1432
1432
|
task = core.boss.tasks.get(list(core.boss.tasks.keys())[0])
|
|
1433
1433
|
self.eq(core.view.iden, task.info.get('view'))
|
|
@@ -1445,7 +1445,7 @@ class HttpApiTest(s_tests.SynTest):
|
|
|
1445
1445
|
if not byts:
|
|
1446
1446
|
break
|
|
1447
1447
|
|
|
1448
|
-
mesg =
|
|
1448
|
+
mesg = s_json.loads(byts)
|
|
1449
1449
|
self.len(2, mesg) # Is if roughly shaped like a node?
|
|
1450
1450
|
task = core.boss.tasks.get(list(core.boss.tasks.keys())[0])
|
|
1451
1451
|
break
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
import orjson
|
|
5
|
+
|
|
6
|
+
import synapse.exc as s_exc
|
|
7
|
+
import synapse.common as s_common
|
|
8
|
+
|
|
9
|
+
import synapse.lib.json as s_json
|
|
10
|
+
|
|
11
|
+
import synapse.tests.utils as s_test
|
|
12
|
+
|
|
13
|
+
class JsonTest(s_test.SynTest):
|
|
14
|
+
|
|
15
|
+
async def test_lib_json_loads(self):
|
|
16
|
+
self.eq({'a': 'b'}, s_json.loads('{"a": "b"}'))
|
|
17
|
+
|
|
18
|
+
with self.raises(s_exc.BadJsonText) as exc:
|
|
19
|
+
s_json.loads('newp')
|
|
20
|
+
self.eq(exc.exception.get('mesg'), 'Expecting value: line 1 column 1 (char 0)')
|
|
21
|
+
|
|
22
|
+
async def test_lib_json_load(self):
|
|
23
|
+
with self.getTestDir() as dirn:
|
|
24
|
+
|
|
25
|
+
with s_common.genfile(dirn, 'file00') as file00:
|
|
26
|
+
file00.write(b'{"a": "b"}')
|
|
27
|
+
|
|
28
|
+
with s_common.genfile(dirn, 'file00') as file00:
|
|
29
|
+
self.eq({'a': 'b'}, s_json.load(file00))
|
|
30
|
+
|
|
31
|
+
with s_common.genfile(dirn, 'empty') as empty:
|
|
32
|
+
with self.raises(s_exc.BadJsonText) as exc:
|
|
33
|
+
s_json.load(empty)
|
|
34
|
+
self.eq(exc.exception.get('mesg'), 'Expecting value: line 1 column 1 (char 0)')
|
|
35
|
+
|
|
36
|
+
buf = io.BytesIO(b'{"a": "b"}')
|
|
37
|
+
self.eq({'a': 'b'}, s_json.load(buf))
|
|
38
|
+
|
|
39
|
+
buf = io.StringIO('{"a": "b"}')
|
|
40
|
+
self.eq({'a': 'b'}, s_json.load(buf))
|
|
41
|
+
|
|
42
|
+
async def test_lib_json_load_surrogates(self):
|
|
43
|
+
|
|
44
|
+
inval = '{"a": "😀\ud83d\ude47"}'
|
|
45
|
+
outval = {'a': '😀\ud83d\ude47'}
|
|
46
|
+
|
|
47
|
+
# orjson.dumps fails because of the surrogate pairs
|
|
48
|
+
with self.raises(orjson.JSONDecodeError):
|
|
49
|
+
orjson.loads(inval)
|
|
50
|
+
|
|
51
|
+
# stdlib json.loads passes because of voodoo magic
|
|
52
|
+
self.eq(outval, json.loads(inval))
|
|
53
|
+
|
|
54
|
+
self.eq(outval, s_json.loads(inval))
|
|
55
|
+
|
|
56
|
+
buf = io.StringIO(inval)
|
|
57
|
+
self.eq(outval, s_json.load(buf))
|
|
58
|
+
|
|
59
|
+
buf = io.BytesIO(inval.encode('utf8', errors='surrogatepass'))
|
|
60
|
+
self.eq(outval, s_json.load(buf))
|
|
61
|
+
|
|
62
|
+
async def test_lib_json_dump_surrogates(self):
|
|
63
|
+
inval = {'a': '😀\ud83d\ude47'}
|
|
64
|
+
outval = b'{"a": "\\ud83d\\ude00\\ud83d\\ude47"}'
|
|
65
|
+
|
|
66
|
+
# orjson.dumps fails because of the surrogate pairs
|
|
67
|
+
with self.raises(TypeError):
|
|
68
|
+
orjson.dumps(inval)
|
|
69
|
+
|
|
70
|
+
# stdlib json.dumps passes because of voodoo magic
|
|
71
|
+
self.eq(outval.decode(), json.dumps(inval))
|
|
72
|
+
|
|
73
|
+
self.eq(outval, s_json.dumps(inval))
|
|
74
|
+
self.eq(outval + b'\n', s_json.dumps(inval, newline=True))
|
|
75
|
+
|
|
76
|
+
buf = io.BytesIO()
|
|
77
|
+
s_json.dump(inval, buf)
|
|
78
|
+
self.eq(outval, buf.getvalue())
|
|
79
|
+
|
|
80
|
+
async def test_lib_json_dumps(self):
|
|
81
|
+
self.eq(b'{"c":"d","a":"b"}', s_json.dumps({'c': 'd', 'a': 'b'}))
|
|
82
|
+
self.eq(b'{"a":"b","c":"d"}', s_json.dumps({'c': 'd', 'a': 'b'}, sort_keys=True))
|
|
83
|
+
self.eq(b'{\n "c": "d",\n "a": "b"\n}', s_json.dumps({'c': 'd', 'a': 'b'}, indent=True))
|
|
84
|
+
self.eq(b'{"c":"d","a":"b"}\n', s_json.dumps({'c': 'd', 'a': 'b'}, newline=True))
|
|
85
|
+
|
|
86
|
+
with self.raises(s_exc.MustBeJsonSafe) as exc:
|
|
87
|
+
s_json.dumps({}.items())
|
|
88
|
+
self.eq(exc.exception.get('mesg'), 'Type is not JSON serializable: dict_items')
|
|
89
|
+
|
|
90
|
+
with self.raises(s_exc.MustBeJsonSafe) as exc:
|
|
91
|
+
s_json.dumps({1: 'foo'})
|
|
92
|
+
self.eq(exc.exception.get('mesg'), 'Dict key must be str')
|
|
93
|
+
|
|
94
|
+
with self.raises(s_exc.MustBeJsonSafe) as exc:
|
|
95
|
+
s_json.dumps({'\ud83d\ude47': {}.items()})
|
|
96
|
+
self.eq(exc.exception.get('mesg'), 'Object of type dict_items is not JSON serializable')
|
|
97
|
+
|
|
98
|
+
self.eq(b'"dict_items([])"', s_json.dumps({}.items(), default=str))
|
|
99
|
+
|
|
100
|
+
async def test_lib_json_dump(self):
|
|
101
|
+
with self.getTestDir() as dirn:
|
|
102
|
+
binfn = s_common.genpath(dirn, 'bin.json')
|
|
103
|
+
|
|
104
|
+
with open(binfn, 'wb') as binfp:
|
|
105
|
+
s_json.dump({'c': 'd', 'a': 'b'}, binfp)
|
|
106
|
+
|
|
107
|
+
with open(binfn, 'rb') as binfp:
|
|
108
|
+
self.eq(b'{"c":"d","a":"b"}', binfp.read())
|
|
109
|
+
|
|
110
|
+
buf = io.BytesIO()
|
|
111
|
+
s_json.dump({'c': 'd', 'a': 'b'}, buf)
|
|
112
|
+
self.eq(b'{"c":"d","a":"b"}', buf.getvalue())
|
|
113
|
+
|
|
114
|
+
async def test_jsload(self):
|
|
115
|
+
with self.getTestDir() as dirn:
|
|
116
|
+
with s_common.genfile(dirn, 'jsload.json') as fp:
|
|
117
|
+
fp.write(b'{"a":"b"}')
|
|
118
|
+
|
|
119
|
+
obj = s_json.jsload(dirn, 'jsload.json')
|
|
120
|
+
self.eq({'a': 'b'}, obj)
|
|
121
|
+
|
|
122
|
+
s_common.genfile(dirn, 'empty.json').close()
|
|
123
|
+
self.none(s_json.jsload(dirn, 'empty.json'))
|
|
124
|
+
|
|
125
|
+
async def test_jslines(self):
|
|
126
|
+
with self.getTestDir() as dirn:
|
|
127
|
+
with s_common.genfile(dirn, 'jslines.json') as fp:
|
|
128
|
+
fp.write(b'{"a":"b"}\n{"c":"d"}')
|
|
129
|
+
|
|
130
|
+
objs = [k for k in s_json.jslines(dirn, 'jslines.json')]
|
|
131
|
+
self.len(2, objs)
|
|
132
|
+
self.eq([{'a': 'b'}, {'c': 'd'}], objs)
|
|
133
|
+
|
|
134
|
+
async def test_jssave(self):
|
|
135
|
+
with self.getTestDir() as dirn:
|
|
136
|
+
s_json.jssave({'a': 'b'}, dirn, 'jssave.json')
|
|
137
|
+
|
|
138
|
+
with s_common.genfile(dirn, 'jssave.json') as fd:
|
|
139
|
+
data = fd.read()
|
|
140
|
+
|
|
141
|
+
self.eq(data, b'{\n "a": "b"\n}')
|
|
142
|
+
|
|
143
|
+
async def test_lib_json_reqjsonsafe(self):
|
|
144
|
+
self.none(s_json.reqjsonsafe('foo'))
|
|
145
|
+
self.none(s_json.reqjsonsafe({'foo': 'bar'}))
|
|
146
|
+
self.none(s_json.reqjsonsafe(['foo', 'bar']))
|
|
147
|
+
|
|
148
|
+
buf = io.BytesIO()
|
|
149
|
+
|
|
150
|
+
with self.raises(s_exc.MustBeJsonSafe) as exc:
|
|
151
|
+
s_json.reqjsonsafe(buf)
|
|
152
|
+
self.isin('Type is not JSON serializable: _io.BytesIO', exc.exception.get('mesg'))
|
|
153
|
+
|
|
154
|
+
with self.raises(s_exc.MustBeJsonSafe) as exc:
|
|
155
|
+
s_json.reqjsonsafe({'foo': buf})
|
|
156
|
+
self.isin('Type is not JSON serializable: _io.BytesIO', exc.exception.get('mesg'))
|
|
157
|
+
|
|
158
|
+
with self.raises(s_exc.MustBeJsonSafe) as exc:
|
|
159
|
+
s_json.reqjsonsafe(['foo', buf])
|
|
160
|
+
self.isin('Type is not JSON serializable: _io.BytesIO', exc.exception.get('mesg'))
|
|
161
|
+
|
|
162
|
+
items = (
|
|
163
|
+
(None, None),
|
|
164
|
+
(1234, None),
|
|
165
|
+
('1234', None),
|
|
166
|
+
({'asdf': 'haha'}, None),
|
|
167
|
+
({'a': (1,), 'b': [{'': 4}, 56, None, {'t': True, 'f': False}, 'oh my']}, None),
|
|
168
|
+
(b'1234', s_exc.MustBeJsonSafe),
|
|
169
|
+
({'a': 'a', 2: 2}, s_exc.MustBeJsonSafe),
|
|
170
|
+
({'a', 'b', 'c'}, s_exc.MustBeJsonSafe),
|
|
171
|
+
(s_common.novalu, s_exc.MustBeJsonSafe),
|
|
172
|
+
)
|
|
173
|
+
for (item, eret) in items:
|
|
174
|
+
if eret is None:
|
|
175
|
+
self.none(s_json.reqjsonsafe(item))
|
|
176
|
+
else:
|
|
177
|
+
with self.raises(eret):
|
|
178
|
+
s_json.reqjsonsafe(item)
|
|
179
|
+
|
|
180
|
+
text = '😀\ud83d\ude47'
|
|
181
|
+
s_json.reqjsonsafe(text)
|
|
182
|
+
with self.raises(s_exc.MustBeJsonSafe) as exc:
|
|
183
|
+
s_json.reqjsonsafe(text, strict=True)
|
|
184
|
+
self.eq(exc.exception.get('mesg'), 'str is not valid UTF-8: surrogates not allowed')
|
|
185
|
+
|
|
186
|
+
async def test_lib_json_data_at_rest(self):
|
|
187
|
+
async with self.getRegrCore('json-data') as core:
|
|
188
|
+
badjson = {
|
|
189
|
+
1: 'foo',
|
|
190
|
+
'foo': '😀\ud83d\ude47',
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
goodjson = {
|
|
194
|
+
'1': 'foo',
|
|
195
|
+
'foo': '😀',
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
# We can lift nodes with bad :data
|
|
199
|
+
nodes = await core.nodes('it:log:event')
|
|
200
|
+
self.len(1, nodes)
|
|
201
|
+
self.eq(nodes[0].get('data'), badjson)
|
|
202
|
+
|
|
203
|
+
iden = nodes[0].iden()
|
|
204
|
+
|
|
205
|
+
# We can't lift nodes with bad data by querying the prop directly
|
|
206
|
+
opts = {'vars': {'data': badjson}}
|
|
207
|
+
with self.raises(s_exc.BadTypeValu):
|
|
208
|
+
await core.callStorm('it:log:event:data=$data', opts=opts)
|
|
209
|
+
|
|
210
|
+
# We can't set nodes with bad data
|
|
211
|
+
with self.raises(s_exc.BadTypeValu):
|
|
212
|
+
await core.callStorm('[ it:log:event=* :data=$data ]', opts=opts)
|
|
213
|
+
|
|
214
|
+
# We can overwrite bad :data props
|
|
215
|
+
opts = {'vars': {'data': goodjson}}
|
|
216
|
+
nodes = await core.nodes('it:log:event:data [ :data=$data ]', opts=opts)
|
|
217
|
+
self.len(1, nodes)
|
|
218
|
+
self.eq(nodes[0].iden(), iden)
|
|
219
|
+
self.eq(nodes[0].get('data'), goodjson)
|
|
@@ -5,6 +5,7 @@ import synapse.exc as s_exc
|
|
|
5
5
|
import synapse.common as s_common
|
|
6
6
|
|
|
7
7
|
import synapse.lib.coro as s_coro
|
|
8
|
+
import synapse.lib.json as s_json
|
|
8
9
|
import synapse.lib.lmdbslab as s_lmdbslab
|
|
9
10
|
import synapse.lib.multislabseqn as s_multislabseqn
|
|
10
11
|
|
|
@@ -314,7 +315,7 @@ class MultiSlabSeqn(s_t_utils.SynTest):
|
|
|
314
315
|
# Make a slab a non-dir
|
|
315
316
|
slab0dirn = s_common.genpath(baddirn, f'seqn{"0" * 16}.lmdb')
|
|
316
317
|
shutil.rmtree(slab0dirn)
|
|
317
|
-
|
|
318
|
+
s_json.jssave('{}', slab0dirn)
|
|
318
319
|
|
|
319
320
|
with self.getAsyncLoggerStream('synapse.lib.multislabseqn', 'non-directory') as stream:
|
|
320
321
|
async with await s_multislabseqn.MultiSlabSeqn.anit(baddirn) as msqn:
|