synapse 2.211.0__py311-none-any.whl → 2.213.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.

@@ -46,11 +46,13 @@ class JsonTest(s_test.SynTest):
46
46
  q = '''$schemaObj = $lib.json.schema($schema)
47
47
  $item=({})
48
48
  $item."key:integer"=(4)
49
+ $item."key:multi"=(4)
49
50
  return ( $schemaObj.validate($item) )
50
51
  '''
51
52
  isok, valu = await core.callStorm(q, opts=opts)
52
53
  self.true(isok)
53
54
  self.eq(4, valu.get('key:integer'))
55
+ self.eq(4, valu.get('key:multi'))
54
56
  self.eq('Default string!', valu.get('key:string'))
55
57
 
56
58
  q = '''$schemaObj = $lib.json.schema($schema)
@@ -68,12 +70,13 @@ class JsonTest(s_test.SynTest):
68
70
 
69
71
  q = '''
70
72
  $schemaObj = $lib.json.schema($schema, use_default=$lib.false)
71
- $item = ({"key:integer": 4})
73
+ $item = ({"key:integer": 4, "key:multi": "4"})
72
74
  return($schemaObj.validate($item))
73
75
  '''
74
76
  isok, valu = await core.callStorm(q, opts={'vars': {'schema': s_test.test_schema}})
75
77
  self.true(isok)
76
78
  self.eq(4, valu.get('key:integer'))
79
+ self.eq('4', valu.get('key:multi'))
77
80
  self.notin('key:string', valu)
78
81
 
79
82
  # Print a json schema obj
@@ -124,6 +124,17 @@ class StormlibSpooledTest(s_test.SynTest):
124
124
  msgs = await core.stormlist(q, opts={'vars': {'items': [True, 'neato', False, 9001]}})
125
125
  self.stormIsInPrint("The set is {'neato'}", msgs)
126
126
 
127
+ q = '''
128
+ $set = $lib.spooled.set()
129
+ for $v in $lib.range($n) {
130
+ $set.add($v)
131
+ }
132
+ if $set { return ( (true) ) }
133
+ else { return ( (false) ) }
134
+ '''
135
+ self.false(await core.callStorm(q, opts={'vars': {'n': 0}}))
136
+ self.true(await core.callStorm(q, opts={'vars': {'n': 1}}))
137
+
127
138
  # force a fallback
128
139
  q = '''
129
140
  $set = $lib.spooled.set()
@@ -1902,6 +1902,17 @@ class StormTypesTest(s_test.SynTest):
1902
1902
  self.len(1, nodes)
1903
1903
  self.eq(nodes[0].ndef, ('test:str', 'asdf'))
1904
1904
 
1905
+ q = '''
1906
+ $set = $lib.set()
1907
+ for $v in $lib.range($n) {
1908
+ $set.add($v)
1909
+ }
1910
+ if $set { return ( (true) ) }
1911
+ else { return ( (false) ) }
1912
+ '''
1913
+ self.false(await core.callStorm(q, opts={'vars': {'n': 0}}))
1914
+ self.true(await core.callStorm(q, opts={'vars': {'n': 1}}))
1915
+
1905
1916
  # test that some of the more complex objects we've got uniq down properly
1906
1917
  # Bool
1907
1918
  q = '''
@@ -338,42 +338,80 @@ class TypesTest(s_t_utils.SynTest):
338
338
  t = core.model.type('test:hexa')
339
339
  # Test norming to index values
340
340
  testvectors = [
341
- ('0C', b'\x0c'),
342
- ('0X010001', b'\x01\x00\x01'),
343
- ('0FfF', b'\x0f\xff'),
344
- ('f12A3e', b'\xf1\x2a\x3e'),
345
- (b'\x01\x00\x01', b'\x01\x00\x01'),
341
+ (0xc, '0c'),
342
+ (-0xc, 'f4'),
343
+ ('c', '0c'),
344
+ ('0c', '0c'),
345
+ ('-0c', (s_exc.BadTypeValu, 'Non-hexadecimal digit found')),
346
+ ('0x0c', '0c'),
347
+ ('-0x0c', (s_exc.BadTypeValu, 'Non-hexadecimal digit found')),
348
+ (b'\x0c', '0c'),
349
+
350
+ (0x10001, '010001'),
351
+ ('10001', '010001'),
352
+ ('0x10001', '010001'),
353
+ ('010001', '010001'),
354
+ ('0x010001', '010001'),
355
+ (b'\x01\x00\x01', '010001'),
356
+
357
+ (0xFfF, '0fff'),
358
+ ('FfF', '0fff'),
359
+ ('0FfF', '0fff'),
360
+ ('0x0FfF', '0fff'),
361
+ (b'\x0F\xfF', '0fff'),
362
+
346
363
  (b'\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~',
347
- b'\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~'),
348
- (65537, s_exc.BadTypeValu),
364
+ 'd41d8cd98f00b204e9800998ecf8427e'),
365
+
366
+ ('01\udcfe0101', (s_exc.BadTypeValu, 'string argument should contain only ASCII characters')),
349
367
  ]
350
368
 
351
- for v, b in testvectors:
352
- if isinstance(b, bytes):
353
- r, subs = t.norm(v)
354
- self.isinstance(r, str)
369
+ for valu, expected in testvectors:
370
+ if isinstance(expected, str):
371
+ norm, subs = t.norm(valu)
372
+ self.isinstance(norm, str)
355
373
  self.eq(subs, {})
374
+ self.eq(norm, expected)
356
375
  else:
357
- self.raises(b, t.norm, v)
376
+ etype, mesg = expected
377
+ with self.raises(etype) as exc:
378
+ t.norm(valu)
379
+ self.eq(exc.exception.get('mesg'), mesg, f'{valu=}')
358
380
 
359
- # width = 4
381
+ # size = 4
360
382
  testvectors4 = [
361
- ('d41d', b'\xd4\x1d'),
362
- (b'\x10\x01', b'\x10\x01'),
363
- ('01', s_exc.BadTypeValu),
364
- ('010101', s_exc.BadTypeValu),
365
- (b'\x10\x01\xff', s_exc.BadTypeValu),
366
- (b'\xff', s_exc.BadTypeValu),
367
- ('01\udcfe0101', s_exc.BadTypeValu),
383
+ (0xc, (s_exc.BadTypeValu, 'Invalid width.')),
384
+ (-0xc, (s_exc.BadTypeValu, 'Invalid width.')),
385
+ ('0c', (s_exc.BadTypeValu, 'Invalid width.')),
386
+ ('0x0c', (s_exc.BadTypeValu, 'Invalid width.')),
387
+ (b'\x0c', (s_exc.BadTypeValu, 'Invalid width.')),
388
+
389
+ (0xd41d, 'd41d'),
390
+ ('d41d', 'd41d'),
391
+ ('0xd41d', 'd41d'),
392
+ (b'\xd4\x1d', 'd41d'),
393
+
394
+ (0x10001, (s_exc.BadTypeValu, 'Invalid width.')),
395
+ ('10001', (s_exc.BadTypeValu, 'Invalid width.')),
396
+ ('0x10001', (s_exc.BadTypeValu, 'Invalid width.')),
397
+ ('010001', (s_exc.BadTypeValu, 'Invalid width.')),
398
+ ('0x010001', (s_exc.BadTypeValu, 'Invalid width.')),
399
+ (b'\x01\x00\x01', (s_exc.BadTypeValu, 'Invalid width.')),
400
+
401
+ ('01\udcfe0101', (s_exc.BadTypeValu, 'string argument should contain only ASCII characters')),
368
402
  ]
369
403
  t = core.model.type('test:hex4')
370
- for v, b in testvectors4:
371
- if isinstance(b, bytes):
372
- r, subs = t.norm(v)
373
- self.isinstance(r, str)
404
+ for valu, expected in testvectors4:
405
+ if isinstance(expected, str):
406
+ norm, subs = t.norm(valu)
407
+ self.isinstance(norm, str)
374
408
  self.eq(subs, {})
409
+ self.eq(norm, expected)
375
410
  else:
376
- self.raises(b, t.norm, v)
411
+ etype, mesg = expected
412
+ with self.raises(etype) as exc:
413
+ t.norm(valu)
414
+ self.eq(exc.exception.get('mesg'), mesg, f'{valu=}')
377
415
 
378
416
  # size = 8, zeropad = True
379
417
  testvectors = [
@@ -384,29 +422,45 @@ class TypesTest(s_t_utils.SynTest):
384
422
  ('0X12345678', '12345678'),
385
423
  ('56:78', '00005678'),
386
424
  ('12:34:56:78', '12345678'),
387
- ('::', s_exc.BadTypeValu),
388
- ('0x::', s_exc.BadTypeValu),
389
- ('0x1234qwer', s_exc.BadTypeValu),
390
- ('0x123456789a', s_exc.BadTypeValu),
391
- ('::', s_exc.BadTypeValu),
425
+ (-1, 'ffffffff'),
426
+ (-0xff, 'ffffff01'),
427
+ (1234, '000004d2'),
428
+ (0x12345678, '12345678'),
429
+ (0x123456789a, (s_exc.BadTypeValu, 'Invalid width.')),
430
+ ('::', (s_exc.BadTypeValu, 'No string left after stripping.')),
431
+ ('0x::', (s_exc.BadTypeValu, 'No string left after stripping.')),
432
+ ('0x1234qwer', (s_exc.BadTypeValu, 'Non-hexadecimal digit found')),
433
+ ('0x123456789a', (s_exc.BadTypeValu, 'Invalid width.')),
392
434
  (b'\x12', '00000012'),
393
435
  (b'\x12\x34', '00001234'),
394
436
  (b'\x12\x34\x56', '00123456'),
395
437
  (b'\x12\x34\x56\x78', '12345678'),
396
- (b'\x12\x34\x56\x78\x9a', s_exc.BadTypeValu),
438
+ (b'\x12\x34\x56\x78\x9a', (s_exc.BadTypeValu, 'Invalid width.')),
397
439
  ]
398
440
  t = core.model.type('test:hexpad')
399
- for v, b in testvectors:
400
- if isinstance(b, (str, bytes)):
401
- r, subs = t.norm(v)
402
- self.isinstance(r, str)
441
+ for valu, expected in testvectors:
442
+ if isinstance(expected, str):
443
+ norm, subs = t.norm(valu)
444
+ self.isinstance(norm, str)
403
445
  self.eq(subs, {})
404
- self.eq(r, b)
446
+ self.eq(norm, expected)
405
447
  else:
406
- self.raises(b, t.norm, v)
448
+ etype, mesg = expected
449
+ with self.raises(etype) as exc:
450
+ t.norm(valu)
451
+ self.eq(exc.exception.get('mesg'), mesg, f'{valu=}')
407
452
 
408
453
  # zeropad = 20
409
454
  testvectors = [
455
+ (-1, 'ffffffffffffffffffff'),
456
+ (-0xff, 'ffffffffffffffffff01'),
457
+ (0x12, '00000000000000000012'),
458
+ (0x123, '00000000000000000123'),
459
+ (0x1234, '00000000000000001234'),
460
+ (0x123456, '00000000000000123456'),
461
+ (0x12345678, '00000000000012345678'),
462
+ (0x123456789abcdef123456789abcdef, '123456789abcdef123456789abcdef'),
463
+ (-0x123456789abcdef123456789abcdef, 'edcba9876543210edcba9876543211'),
410
464
  ('0x12', '00000000000000000012'),
411
465
  ('0x123', '00000000000000000123'),
412
466
  ('0x1234', '00000000000000001234'),
@@ -421,14 +475,17 @@ class TypesTest(s_t_utils.SynTest):
421
475
  (b'\x12\x34\x56\x78\x9a\xbc\xde\xf1\x23\x45\x67\x89\xab\xcd\xef', '123456789abcdef123456789abcdef'),
422
476
  ]
423
477
  t = core.model.type('test:zeropad')
424
- for v, b in testvectors:
425
- if isinstance(b, (str, bytes)):
426
- r, subs = t.norm(v)
427
- self.isinstance(r, str)
478
+ for valu, expected in testvectors:
479
+ if isinstance(expected, str):
480
+ norm, subs = t.norm(valu)
481
+ self.isinstance(norm, str)
428
482
  self.eq(subs, {})
429
- self.eq(r, b)
483
+ self.eq(norm, expected)
430
484
  else:
431
- self.raises(b, t.norm, v)
485
+ etype, mesg = expected
486
+ with self.raises(etype) as exc:
487
+ t.norm(valu)
488
+ self.eq(exc.exception.get('mesg'), mesg, f'{valu=}')
432
489
 
433
490
  # Do some node creation and lifting
434
491
  nodes = await core.nodes('[test:hexa="01:00 01"]')
@@ -436,8 +493,19 @@ class TypesTest(s_t_utils.SynTest):
436
493
  node = nodes[0]
437
494
  self.eq(node.ndef, ('test:hexa', '010001'))
438
495
  self.len(1, await core.nodes('test:hexa=010001'))
496
+ self.len(1, await core.nodes('test:hexa=(0x10001)'))
439
497
  self.len(1, await core.nodes('test:hexa=$byts', opts={'vars': {'byts': b'\x01\x00\x01'}}))
440
498
 
499
+ nodes = await core.nodes('[test:hexa=(-10)]')
500
+ self.len(1, nodes)
501
+ self.eq(nodes[0].repr(), 'f6')
502
+
503
+ self.len(1, await core.nodes('test:hexa=(-10)'))
504
+
505
+ with self.raises(s_exc.BadTypeValu) as exc:
506
+ await core.callStorm('test:hexa^=(-10)')
507
+ self.eq(exc.exception.get('mesg'), 'Hex prefix lift values must be str, not int.')
508
+
441
509
  # Do some fancy prefix searches for test:hexa
442
510
  valus = ['deadb33f',
443
511
  'deadb33fb33f',
@@ -467,9 +535,25 @@ class TypesTest(s_t_utils.SynTest):
467
535
  self.len(1, await core.nodes('[test:hexa=0xf00fb33b00000000]'))
468
536
  self.len(1, await core.nodes('test:hexa=0xf00fb33b00000000'))
469
537
  self.len(1, await core.nodes('test:hexa^=0xf00fb33b'))
538
+ self.len(1, await core.nodes('test:hexa^=0xf00fb33'))
539
+
540
+ with self.raises(s_exc.BadTypeValu):
541
+ await core.nodes('test:hexa^=(0xf00fb33b)')
542
+
543
+ with self.raises(s_exc.BadTypeValu):
544
+ await core.nodes('test:hexa^=(0xf00fb33)')
470
545
 
471
546
  # Check creating and lifting zeropadded hex types
472
- self.len(3, await core.nodes('[test:zeropad=11 test:zeropad=0x22 test:zeropad=111]'))
547
+ q = '''
548
+ [
549
+ test:zeropad=11
550
+ test:zeropad=0x22
551
+ test:zeropad=111
552
+ test:zeropad=(0x33)
553
+ test:zeropad=(0x444)
554
+ ]
555
+ '''
556
+ self.len(5, await core.nodes(q))
473
557
  self.len(1, await core.nodes('test:zeropad=0x11'))
474
558
  self.len(1, await core.nodes('test:zeropad=0x111'))
475
559
  self.len(1, await core.nodes('test:zeropad=000000000011'))
@@ -479,6 +563,14 @@ class TypesTest(s_t_utils.SynTest):
479
563
  self.len(1, await core.nodes('test:zeropad=000000000022'))
480
564
  self.len(1, await core.nodes('test:zeropad=00000000000000000022')) # len=20
481
565
  self.len(0, await core.nodes('test:zeropad=0000000000000000000022')) # len=22
566
+ self.len(1, await core.nodes('test:zeropad=(0x33)'))
567
+ self.len(1, await core.nodes('test:zeropad=000000000033'))
568
+ self.len(1, await core.nodes('test:zeropad=00000000000000000033')) # len=20
569
+ self.len(0, await core.nodes('test:zeropad=0000000000000000000033')) # len=22
570
+ self.len(1, await core.nodes('test:zeropad=(0x444)'))
571
+ self.len(1, await core.nodes('test:zeropad=000000000444'))
572
+ self.len(1, await core.nodes('test:zeropad=00000000000000000444')) # len=20
573
+ self.len(0, await core.nodes('test:zeropad=0000000000000000000444')) # len=22
482
574
 
483
575
  def test_int(self):
484
576
 
@@ -545,6 +545,14 @@ class CryptoModelTest(s_t_utils.SynTest):
545
545
  self.eq(nodes[0].get('identities:ipv4s'), (0x01020304, 0x05050505))
546
546
  self.eq(nodes[0].get('identities:ipv6s'), ('ff::11', 'ff::aa'))
547
547
 
548
+ nodes = await core.nodes('[ crypto:x509:cert=* :serial=(1234) ]')
549
+ self.len(1, nodes)
550
+ self.eq(nodes[0].get('serial'), '00000000000000000000000000000000000004d2')
551
+
552
+ nodes = await core.nodes('[ crypto:x509:cert=* :serial=(-1234) ]')
553
+ self.len(1, nodes)
554
+ self.eq(nodes[0].get('serial'), 'fffffffffffffffffffffffffffffffffffffb2e')
555
+
548
556
  nodes = await core.nodes('''
549
557
  [
550
558
  crypto:x509:crl=$crl
@@ -2908,10 +2908,10 @@ class InetModelTest(s_t_utils.SynTest):
2908
2908
  :flow=*
2909
2909
  :server=$server
2910
2910
  :server:cert=*
2911
- :server:fingerprint:ja3=$ja3s
2911
+ :server:ja3s=$ja3s
2912
2912
  :client=$client
2913
2913
  :client:cert=*
2914
- :client:fingerprint:ja3=$ja3
2914
+ :client:ja3=$ja3
2915
2915
  ]
2916
2916
  ''', opts={'vars': props})
2917
2917
  self.len(1, nodes)
@@ -2920,8 +2920,8 @@ class InetModelTest(s_t_utils.SynTest):
2920
2920
  self.nn(nodes[0].get('server:cert'))
2921
2921
  self.nn(nodes[0].get('client:cert'))
2922
2922
 
2923
- self.eq(props['ja3'], nodes[0].get('client:fingerprint:ja3'))
2924
- self.eq(props['ja3s'], nodes[0].get('server:fingerprint:ja3'))
2923
+ self.eq(props['ja3'], nodes[0].get('client:ja3'))
2924
+ self.eq(props['ja3s'], nodes[0].get('server:ja3s'))
2925
2925
 
2926
2926
  self.eq(props['client'], nodes[0].get('client'))
2927
2927
  self.eq(props['server'], nodes[0].get('server'))
@@ -3498,3 +3498,41 @@ class InetModelTest(s_t_utils.SynTest):
3498
3498
  self.len(1, await core.nodes('inet:service:subscription -> inet:service:subscription:level:taxonomy'))
3499
3499
  self.len(1, await core.nodes('inet:service:subscription :pay:instrument -> econ:bank:account'))
3500
3500
  self.len(1, await core.nodes('inet:service:subscription :subscriber -> inet:service:tenant'))
3501
+
3502
+ async def test_model_inet_tls_ja4(self):
3503
+
3504
+ async with self.getTestCore() as core:
3505
+
3506
+ nodes = await core.nodes('[ inet:tls:ja4:sample=(1.2.3.4, t13d190900_9dc949149365_97f8aa674fd9) ]')
3507
+ self.len(1, nodes)
3508
+ self.eq(nodes[0].get('ja4'), 't13d190900_9dc949149365_97f8aa674fd9')
3509
+ self.eq(nodes[0].get('client'), 'tcp://1.2.3.4')
3510
+ self.len(1, await core.nodes('inet:tls:ja4:sample -> inet:client'))
3511
+ self.len(1, await core.nodes('inet:tls:ja4:sample -> inet:tls:ja4'))
3512
+
3513
+ nodes = await core.nodes('[ inet:tls:ja4s:sample=(1.2.3.4:443, t130200_1301_a56c5b993250) ]')
3514
+ self.len(1, nodes)
3515
+ self.eq(nodes[0].get('ja4s'), 't130200_1301_a56c5b993250')
3516
+ self.eq(nodes[0].get('server'), 'tcp://1.2.3.4:443')
3517
+ self.len(1, await core.nodes('inet:tls:ja4s:sample -> inet:server'))
3518
+ self.len(1, await core.nodes('inet:tls:ja4s:sample -> inet:tls:ja4s'))
3519
+
3520
+ nodes = await core.nodes('''[
3521
+ inet:tls:handshake=*
3522
+ :client:ja4=t13d190900_9dc949149365_97f8aa674fd9
3523
+ :server:ja4s=t130200_1301_a56c5b993250
3524
+ ]''')
3525
+ self.len(1, nodes)
3526
+ self.eq(nodes[0].get('client:ja4'), 't13d190900_9dc949149365_97f8aa674fd9')
3527
+ self.eq(nodes[0].get('server:ja4s'), 't130200_1301_a56c5b993250')
3528
+ self.len(1, await core.nodes('inet:tls:handshake :client:ja4 -> inet:tls:ja4'))
3529
+ self.len(1, await core.nodes('inet:tls:handshake :server:ja4s -> inet:tls:ja4s'))
3530
+
3531
+ ja4_t = core.model.type('inet:tls:ja4')
3532
+ ja4s_t = core.model.type('inet:tls:ja4s')
3533
+ self.eq('t13d1909Tg_9dc949149365_97f8aa674fd9', ja4_t.norm(' t13d1909Tg_9dc949149365_97f8aa674fd9 ')[0])
3534
+ self.eq('t1302Tg_1301_a56c5b993250', ja4s_t.norm(' t1302Tg_1301_a56c5b993250 ')[0])
3535
+ with self.raises(s_exc.BadTypeValu):
3536
+ ja4_t.norm('t13d190900_9dc949149365_97f8aa674fD9')
3537
+ with self.raises(s_exc.BadTypeValu):
3538
+ ja4s_t.norm('t130200_1301_a56c5B993250')
@@ -316,6 +316,24 @@ class TeleTest(s_t_utils.SynTest):
316
316
  self.true(prox.isfini)
317
317
  await self.asyncraises(s_exc.IsFini, prox.bar((10, 20)))
318
318
 
319
+ async def test_telepath_openinfo_cell(self):
320
+ with self.getTestDir() as dirn:
321
+ async with self.getTestCore(dirn=dirn) as core:
322
+
323
+ layr00 = core.getView().layers[0]
324
+
325
+ async with await s_telepath.openurl(f'cell://root@{dirn}:*', name=f'*/layer/{layr00.iden}') as layer:
326
+ self.eq(layr00.iden, await layer.getIden())
327
+
328
+ async def test_telepath_openinfo_unix(self):
329
+ with self.getTestDir() as dirn:
330
+ async with self.getTestCore(dirn=dirn) as core:
331
+
332
+ layr00 = core.getView().layers[0]
333
+
334
+ async with await s_telepath.openurl(f'unix://root@{dirn}/sock:*', name=f'*/layer/{layr00.iden}') as layer:
335
+ self.eq(layr00.iden, await layer.getIden())
336
+
319
337
  async def test_telepath_sync_genr(self):
320
338
 
321
339
  foo = Foo()
synapse/tests/utils.py CHANGED
@@ -987,6 +987,10 @@ test_schema = {
987
987
  'description': 'Foo String',
988
988
  'type': 'string',
989
989
  },
990
+ 'key:multi': {
991
+ 'description': 'String or integer',
992
+ 'type': ['string', 'integer'],
993
+ }
990
994
  },
991
995
  'type': 'object',
992
996
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: synapse
3
- Version: 2.211.0
3
+ Version: 2.213.0
4
4
  Summary: Synapse Intelligence Analysis Framework
5
5
  Author-email: The Vertex Project LLC <root@vertex.link>
6
6
  License-Expression: Apache-2.0