synapse 2.175.0__py311-none-any.whl → 2.177.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.

Files changed (73) hide show
  1. synapse/axon.py +24 -9
  2. synapse/cortex.py +330 -168
  3. synapse/cryotank.py +46 -37
  4. synapse/datamodel.py +17 -4
  5. synapse/exc.py +19 -0
  6. synapse/lib/agenda.py +7 -13
  7. synapse/lib/ast.py +6 -5
  8. synapse/lib/auth.py +1520 -0
  9. synapse/lib/cell.py +255 -53
  10. synapse/lib/grammar.py +5 -0
  11. synapse/lib/hive.py +24 -3
  12. synapse/lib/hiveauth.py +6 -32
  13. synapse/lib/layer.py +7 -4
  14. synapse/lib/link.py +21 -17
  15. synapse/lib/lmdbslab.py +149 -0
  16. synapse/lib/modelrev.py +1 -1
  17. synapse/lib/schemas.py +136 -0
  18. synapse/lib/storm.py +70 -33
  19. synapse/lib/stormlib/aha.py +1 -1
  20. synapse/lib/stormlib/auth.py +185 -10
  21. synapse/lib/stormlib/cortex.py +16 -5
  22. synapse/lib/stormlib/gen.py +80 -0
  23. synapse/lib/stormlib/model.py +55 -0
  24. synapse/lib/stormlib/modelext.py +60 -0
  25. synapse/lib/stormlib/storm.py +117 -5
  26. synapse/lib/stormlib/tabular.py +212 -0
  27. synapse/lib/stormtypes.py +14 -1
  28. synapse/lib/trigger.py +1 -1
  29. synapse/lib/version.py +2 -2
  30. synapse/lib/view.py +55 -28
  31. synapse/models/base.py +7 -0
  32. synapse/models/biz.py +4 -0
  33. synapse/models/files.py +8 -1
  34. synapse/models/inet.py +31 -0
  35. synapse/tests/files/changelog/model_2.176.0_16ee721a6b7221344eaf946c3ab4602dda546b1a.yaml.gz +0 -0
  36. synapse/tests/files/changelog/model_2.176.0_2a25c58bbd344716cd7cbc3f4304d8925b0f4ef2.yaml.gz +0 -0
  37. synapse/tests/test_axon.py +7 -4
  38. synapse/tests/test_cortex.py +127 -82
  39. synapse/tests/test_cryotank.py +4 -4
  40. synapse/tests/test_datamodel.py +7 -0
  41. synapse/tests/test_lib_agenda.py +7 -0
  42. synapse/tests/{test_lib_hiveauth.py → test_lib_auth.py} +314 -11
  43. synapse/tests/test_lib_cell.py +161 -8
  44. synapse/tests/test_lib_httpapi.py +18 -14
  45. synapse/tests/test_lib_layer.py +33 -33
  46. synapse/tests/test_lib_link.py +42 -1
  47. synapse/tests/test_lib_lmdbslab.py +68 -0
  48. synapse/tests/test_lib_nexus.py +4 -4
  49. synapse/tests/test_lib_node.py +0 -7
  50. synapse/tests/test_lib_storm.py +45 -0
  51. synapse/tests/test_lib_stormlib_aha.py +1 -2
  52. synapse/tests/test_lib_stormlib_auth.py +21 -0
  53. synapse/tests/test_lib_stormlib_cortex.py +12 -12
  54. synapse/tests/test_lib_stormlib_gen.py +99 -0
  55. synapse/tests/test_lib_stormlib_model.py +108 -0
  56. synapse/tests/test_lib_stormlib_modelext.py +64 -0
  57. synapse/tests/test_lib_stormlib_storm.py +82 -1
  58. synapse/tests/test_lib_stormlib_tabular.py +226 -0
  59. synapse/tests/test_lib_stormsvc.py +4 -1
  60. synapse/tests/test_lib_stormtypes.py +10 -0
  61. synapse/tests/test_model_base.py +3 -0
  62. synapse/tests/test_model_biz.py +3 -0
  63. synapse/tests/test_model_files.py +12 -2
  64. synapse/tests/test_model_inet.py +55 -0
  65. synapse/tests/test_tools_changelog.py +196 -0
  66. synapse/tests/test_tools_healthcheck.py +4 -3
  67. synapse/tests/utils.py +1 -1
  68. synapse/tools/changelog.py +774 -15
  69. {synapse-2.175.0.dist-info → synapse-2.177.0.dist-info}/METADATA +3 -3
  70. {synapse-2.175.0.dist-info → synapse-2.177.0.dist-info}/RECORD +73 -67
  71. {synapse-2.175.0.dist-info → synapse-2.177.0.dist-info}/WHEEL +1 -1
  72. {synapse-2.175.0.dist-info → synapse-2.177.0.dist-info}/LICENSE +0 -0
  73. {synapse-2.175.0.dist-info → synapse-2.177.0.dist-info}/top_level.txt +0 -0
@@ -23,6 +23,7 @@ import synapse.cortex as s_cortex
23
23
  import synapse.daemon as s_daemon
24
24
  import synapse.telepath as s_telepath
25
25
 
26
+ import synapse.lib.auth as s_auth
26
27
  import synapse.lib.base as s_base
27
28
  import synapse.lib.cell as s_cell
28
29
  import synapse.lib.coro as s_coro
@@ -31,7 +32,6 @@ import synapse.lib.nexus as s_nexus
31
32
  import synapse.lib.certdir as s_certdir
32
33
  import synapse.lib.msgpack as s_msgpack
33
34
  import synapse.lib.version as s_version
34
- import synapse.lib.hiveauth as s_hiveauth
35
35
  import synapse.lib.lmdbslab as s_lmdbslab
36
36
  import synapse.lib.crypto.passwd as s_passwd
37
37
  import synapse.lib.platforms.linux as s_linux
@@ -133,7 +133,27 @@ async def altAuthCtor(cell):
133
133
  authconf = cell.conf.get('auth:conf')
134
134
  assert authconf['foo'] == 'bar'
135
135
  authconf['baz'] = 'faz'
136
- return await s_cell.Cell._initCellHiveAuth(cell)
136
+
137
+ maxusers = cell.conf.get('max:users')
138
+
139
+ seed = s_common.guid((cell.iden, 'hive', 'auth'))
140
+
141
+ auth = await s_auth.Auth.anit(
142
+ cell.slab,
143
+ 'auth',
144
+ seed=seed,
145
+ nexsroot=cell.getCellNexsRoot(),
146
+ maxusers=maxusers
147
+ )
148
+
149
+ auth.link(cell.dist)
150
+
151
+ def finilink():
152
+ auth.unlink(cell.dist)
153
+
154
+ cell.onfini(finilink)
155
+ cell.onfini(auth.fini)
156
+ return auth
137
157
 
138
158
  class CellTest(s_t_utils.SynTest):
139
159
 
@@ -417,8 +437,6 @@ class CellTest(s_t_utils.SynTest):
417
437
  # Ensure the cell and its auth have been fini'd
418
438
  self.true(echo.isfini)
419
439
  self.true(echo.auth.isfini)
420
- root = await echo.auth.getUserByName('root')
421
- self.true(root.isfini)
422
440
 
423
441
  async def test_cell_userapi(self):
424
442
 
@@ -1189,6 +1207,7 @@ class CellTest(s_t_utils.SynTest):
1189
1207
  async with await s_cell.Cell.anit(dirn, conf=conf) as cell:
1190
1208
  self.eq('faz', cell.conf.get('auth:conf')['baz'])
1191
1209
  await cell.auth.addUser('visi')
1210
+ await cell._storCellAuthMigration()
1192
1211
 
1193
1212
  async def test_cell_auth_userlimit(self):
1194
1213
  maxusers = 3
@@ -1237,7 +1256,8 @@ class CellTest(s_t_utils.SynTest):
1237
1256
 
1238
1257
  with self.setTstEnvars(SYN_CELL_MAX_USERS=str(maxusers)):
1239
1258
  with self.getTestDir() as dirn:
1240
- async with await s_cell.Cell.initFromArgv([dirn]) as cell:
1259
+ argv = [dirn, '--https', '0', '--telepath', 'tcp://0.0.0.0:0']
1260
+ async with await s_cell.Cell.initFromArgv(argv) as cell:
1241
1261
  await cell.auth.addUser('visi1')
1242
1262
  await cell.auth.addUser('visi2')
1243
1263
  await cell.auth.addUser('visi3')
@@ -1597,7 +1617,7 @@ class CellTest(s_t_utils.SynTest):
1597
1617
 
1598
1618
  async with self.getTestCell(s_cell.Cell, conf=conf) as cell: # type: s_cell.Cell
1599
1619
  iden = s_common.guid((cell.iden, 'auth', 'user', 'foo@bar.mynet.com'))
1600
- user = cell.auth.user(iden) # type: s_hiveauth.HiveUser
1620
+ user = cell.auth.user(iden) # type: s_auth.User
1601
1621
  self.eq(user.name, 'foo@bar.mynet.com')
1602
1622
  self.eq(user.pack().get('email'), 'foo@barcorp.com')
1603
1623
  self.false(user.isAdmin())
@@ -1607,7 +1627,7 @@ class CellTest(s_t_utils.SynTest):
1607
1627
  self.false(user.allowed(('newp', 'secret')))
1608
1628
 
1609
1629
  iden = s_common.guid((cell.iden, 'auth', 'user', 'sally@bar.mynet.com'))
1610
- user = cell.auth.user(iden) # type: s_hiveauth.HiveUser
1630
+ user = cell.auth.user(iden) # type: s_auth.User
1611
1631
  self.eq(user.name, 'sally@bar.mynet.com')
1612
1632
  self.true(user.isAdmin())
1613
1633
 
@@ -2036,6 +2056,23 @@ class CellTest(s_t_utils.SynTest):
2036
2056
  self.true(await user.tryPasswd('hehe'))
2037
2057
  self.false(await user.tryPasswd('secret1234'))
2038
2058
 
2059
+ # Password policies do not prevent live migration of an existing password
2060
+ with self.getRegrDir('cells', 'passwd-2.109.0') as dirn:
2061
+ policy = {'complexity': {'length': 5}}
2062
+ conf = {'auth:passwd:policy': policy}
2063
+ async with self.getTestCell(s_cell.Cell, conf=conf, dirn=dirn) as cell: # type: s_cell.Cell
2064
+ root = await cell.auth.getUserByName('root')
2065
+ shadow = root.info.get('passwd')
2066
+ self.isinstance(shadow, tuple)
2067
+ self.len(2, shadow)
2068
+
2069
+ # Old password works and is migrated to the new password scheme
2070
+ self.false(await root.tryPasswd('newp'))
2071
+ self.true(await root.tryPasswd('root'))
2072
+ shadow = root.info.get('passwd')
2073
+ self.isinstance(shadow, dict)
2074
+ self.eq(shadow.get('type'), s_passwd.DEFAULT_PTYP)
2075
+
2039
2076
  # Pre-nexus changes of root via auth:passwd work too.
2040
2077
  with self.getRegrDir('cells', 'passwd-2.109.0') as dirn:
2041
2078
  conf = {'auth:passwd': 'supersecretpassword'}
@@ -2625,6 +2662,122 @@ class CellTest(s_t_utils.SynTest):
2625
2662
  with self.raises(s_exc.NoSuchIden):
2626
2663
  await cell.delUserApiKey(newp)
2627
2664
 
2665
+ async def test_cell_iter_slab_data(self):
2666
+ async with self.getTestCell(s_cell.Cell) as cell:
2667
+ data = await s_t_utils.alist(cell.iterSlabData('cell:info'))
2668
+ self.eq(data, (
2669
+ ('cell:version', s_version.version),
2670
+ ('nexus:version', s_cell.NEXUS_VERSION),
2671
+ ('synapse:version', s_version.version)
2672
+ ))
2673
+ with self.raises(s_exc.BadArg):
2674
+ await s_t_utils.alist(cell.iterSlabData('newp'))
2675
+
2676
+ sfkv = cell.slab.getSafeKeyVal('hehe', prefix='yup')
2677
+ sfkv.set('wow', 'yes')
2678
+ data = await s_t_utils.alist(cell.iterSlabData('hehe'))
2679
+ self.eq(data, [('yupwow', 'yes')])
2680
+ data = await s_t_utils.alist(cell.iterSlabData('hehe', prefix='yup'))
2681
+ self.eq(data, [('wow', 'yes')])
2682
+
2683
+ async def test_cell_nexus_compat(self):
2684
+ with mock.patch('synapse.lib.cell.NEXUS_VERSION', (0, 0)):
2685
+ async with self.getRegrCore('hive-migration') as core0:
2686
+ with mock.patch('synapse.lib.cell.NEXUS_VERSION', (2, 177)):
2687
+ conf = {'mirror': core0.getLocalUrl()}
2688
+ async with self.getRegrCore('hive-migration', conf=conf) as core1:
2689
+ await core1.sync()
2690
+
2691
+ await core1.nodes('$lib.user.vars.set(foo, bar)')
2692
+ self.eq('bar', await core0.callStorm('return($lib.user.vars.get(foo))'))
2693
+
2694
+ await core1.nodes('$lib.user.vars.pop(foo)')
2695
+ self.none(await core0.callStorm('return($lib.user.vars.get(foo))'))
2696
+
2697
+ await core1.nodes('$lib.user.profile.set(bar, baz)')
2698
+ self.eq('baz', await core0.callStorm('return($lib.user.profile.get(bar))'))
2699
+
2700
+ await core1.nodes('$lib.user.profile.pop(bar)')
2701
+ self.none(await core0.callStorm('return($lib.user.profile.get(bar))'))
2702
+
2703
+ self.eq((0, 0), core1.nexsvers)
2704
+ await core0.setNexsVers((2, 177))
2705
+ await core1.sync()
2706
+ self.eq((2, 177), core1.nexsvers)
2707
+
2708
+ await core1.nodes('$lib.user.vars.set(foo, bar)')
2709
+ self.eq('bar', await core0.callStorm('return($lib.user.vars.get(foo))'))
2710
+
2711
+ await core1.nodes('$lib.user.vars.pop(foo)')
2712
+ self.none(await core0.callStorm('return($lib.user.vars.get(foo))'))
2713
+
2714
+ await core1.nodes('$lib.user.profile.set(bar, baz)')
2715
+ self.eq('baz', await core0.callStorm('return($lib.user.profile.get(bar))'))
2716
+
2717
+ await core1.nodes('$lib.user.profile.pop(bar)')
2718
+ self.none(await core0.callStorm('return($lib.user.profile.get(bar))'))
2719
+
2720
+ async def test_cell_hive_migration(self):
2721
+
2722
+ with self.getAsyncLoggerStream('synapse.lib.cell') as stream:
2723
+
2724
+ async with self.getRegrCore('hive-migration') as core:
2725
+ visi = await core.auth.getUserByName('visi')
2726
+ asvisi = {'user': visi.iden}
2727
+
2728
+ valu = await core.callStorm('return($lib.user.vars.get(foovar))', opts=asvisi)
2729
+ self.eq('barvalu', valu)
2730
+
2731
+ valu = await core.callStorm('return($lib.user.profile.get(fooprof))', opts=asvisi)
2732
+ self.eq('barprof', valu)
2733
+
2734
+ msgs = await core.stormlist('cron.list')
2735
+ self.stormIsInPrint('visi 8437c35a', msgs)
2736
+ self.stormIsInPrint('[tel:mob:telem=*]', msgs)
2737
+
2738
+ msgs = await core.stormlist('dmon.list')
2739
+ self.stormIsInPrint('0973342044469bc40b577969028c5079: (foodmon ): running', msgs)
2740
+
2741
+ msgs = await core.stormlist('trigger.list')
2742
+ self.stormIsInPrint('visi 27f5dc524e7c3ee8685816ddf6ca1326', msgs)
2743
+ self.stormIsInPrint('[ +#count test:str=$tag ]', msgs)
2744
+
2745
+ msgs = await core.stormlist('testcmd0 foo')
2746
+ self.stormIsInPrint('foo haha', msgs)
2747
+
2748
+ msgs = await core.stormlist('testcmd1')
2749
+ self.stormIsInPrint('hello', msgs)
2750
+
2751
+ msgs = await core.stormlist('model.deprecated.locks')
2752
+ self.stormIsInPrint('ou:hasalias', msgs)
2753
+
2754
+ nodes = await core.nodes('_visi:int')
2755
+ self.len(1, nodes)
2756
+ node = nodes[0]
2757
+ self.eq(node.get('tick'), 1577836800000,)
2758
+ self.eq(node.get('._woot'), 5)
2759
+ self.nn(node.getTagProp('test', 'score'), 6)
2760
+
2761
+ roles = s_t_utils.deguidify('[{"type": "role", "iden": "e1ef725990aa62ae3c4b98be8736d89f", "name": "all", "rules": [], "authgates": {"46cfde2c1682566602860f8df7d0cc83": {"rules": [[true, ["layer", "read"]]]}, "4d50eb257549436414643a71e057091a": {"rules": [[true, ["view", "read"]]]}}}]')
2762
+ users = s_t_utils.deguidify('[{"type": "user", "iden": "a357138db50780b62093a6ce0d057fd8", "name": "root", "rules": [], "roles": [], "admin": true, "email": null, "locked": false, "archived": false, "authgates": {"46cfde2c1682566602860f8df7d0cc83": {"admin": true}, "4d50eb257549436414643a71e057091a": {"admin": true}}}, {"type": "user", "iden": "f77ac6744671a845c27e571071877827", "name": "visi", "rules": [[true, ["cron", "add"]], [true, ["dmon", "add"]], [true, ["trigger", "add"]]], "roles": [{"type": "role", "iden": "e1ef725990aa62ae3c4b98be8736d89f", "name": "all", "rules": [], "authgates": {"46cfde2c1682566602860f8df7d0cc83": {"rules": [[true, ["layer", "read"]]]}, "4d50eb257549436414643a71e057091a": {"rules": [[true, ["view", "read"]]]}}}], "admin": false, "email": null, "locked": false, "archived": false, "authgates": {"f21b7ae79c2dacb89484929a8409e5d8": {"admin": true}, "d7d0380dd4e743e35af31a20d014ed48": {"admin": true}}}]')
2763
+ gates = s_t_utils.deguidify('[{"iden": "46cfde2c1682566602860f8df7d0cc83", "type": "layer", "users": [{"iden": "a357138db50780b62093a6ce0d057fd8", "rules": [], "admin": true}], "roles": [{"iden": "e1ef725990aa62ae3c4b98be8736d89f", "rules": [[true, ["layer", "read"]]], "admin": false}]}, {"iden": "d7d0380dd4e743e35af31a20d014ed48", "type": "trigger", "users": [{"iden": "f77ac6744671a845c27e571071877827", "rules": [], "admin": true}], "roles": []}, {"iden": "f21b7ae79c2dacb89484929a8409e5d8", "type": "cronjob", "users": [{"iden": "f77ac6744671a845c27e571071877827", "rules": [], "admin": true}], "roles": []}, {"iden": "4d50eb257549436414643a71e057091a", "type": "view", "users": [{"iden": "a357138db50780b62093a6ce0d057fd8", "rules": [], "admin": true}], "roles": [{"iden": "e1ef725990aa62ae3c4b98be8736d89f", "rules": [[true, ["view", "read"]]], "admin": false}]}, {"iden": "cortex", "type": "cortex", "users": [], "roles": []}]')
2764
+
2765
+ self.eq(roles, s_t_utils.deguidify(json.dumps(await core.callStorm('return($lib.auth.roles.list())'))))
2766
+ self.eq(users, s_t_utils.deguidify(json.dumps(await core.callStorm('return($lib.auth.users.list())'))))
2767
+ self.eq(gates, s_t_utils.deguidify(json.dumps(await core.callStorm('return($lib.auth.gates.list())'))))
2768
+
2769
+ with self.raises(s_exc.BadTag):
2770
+ await core.nodes('[ it:dev:str=foo +#test.newp ]')
2771
+
2772
+ stream.seek(0)
2773
+ data = stream.getvalue()
2774
+ newprole = s_common.guid('newprole')
2775
+ newpuser = s_common.guid('newpuser')
2776
+
2777
+ self.isin(f'Unknown user {newpuser} on gate', data)
2778
+ self.isin(f'Unknown role {newprole} on gate', data)
2779
+ self.isin(f'Unknown role {newprole} on user', data)
2780
+
2628
2781
  async def test_cell_check_sysctl(self):
2629
2782
  sysctls = s_linux.getSysctls()
2630
2783
 
@@ -2640,7 +2793,7 @@ class CellTest(s_t_utils.SynTest):
2640
2793
 
2641
2794
  stream.seek(0)
2642
2795
  data = stream.getvalue()
2643
- raw_mesgs = [m for m in data.split('\\n') if m]
2796
+ raw_mesgs = [m for m in data.split('\n') if m]
2644
2797
  msgs = [json.loads(m) for m in raw_mesgs]
2645
2798
 
2646
2799
  self.len(1, msgs)
@@ -525,7 +525,7 @@ class HttpApiTest(s_tests.SynTest):
525
525
 
526
526
  async with self.getHttpSess() as noobsess:
527
527
  info = {'user': 'noob', 'passwd': 'nooblet'}
528
- async with sess.post(f'https://localhost:{port}/api/v1/login', json=info) as resp:
528
+ async with noobsess.post(f'https://localhost:{port}/api/v1/login', json=info) as resp:
529
529
  item = await resp.json()
530
530
  self.eq('AuthDeny', item.get('code'))
531
531
 
@@ -1136,6 +1136,11 @@ class HttpApiTest(s_tests.SynTest):
1136
1136
  self.len(1, data['gates'])
1137
1137
  self.eq(data['gates'][0]['iden'], 'cortex')
1138
1138
 
1139
+ deflayr, defview = await core.callStorm('''
1140
+ $view = $lib.view.get()
1141
+ return(($view.layers.0.iden, $view.iden))
1142
+ ''')
1143
+
1139
1144
  # user add. couple of messages fall out from it
1140
1145
  await core.callStorm('auth.user.add beep --email beep@vertex.link')
1141
1146
  mesg = await sock.receive_json()
@@ -1151,18 +1156,6 @@ class HttpApiTest(s_tests.SynTest):
1151
1156
  mesg = await sock.receive_json()
1152
1157
  data = mesg['data']
1153
1158
  self.eq(data['event'], 'user:info')
1154
- self.eq(data['info']['name'], 'email')
1155
- self.eq(data['info']['valu'], 'beep@vertex.link')
1156
- self.gt(data['offset'], base)
1157
- base = data['offset']
1158
-
1159
- mesg = await sock.receive_json()
1160
- data = mesg['data']
1161
- deflayr, defview = await core.callStorm('''
1162
- $view = $lib.view.get()
1163
- return(($view.layers.0.iden, $view.iden))
1164
- ''')
1165
- self.eq(data['event'], 'user:info')
1166
1159
  self.eq(data['info']['name'], 'role:grant')
1167
1160
  self.eq(data['info']['iden'], beepiden)
1168
1161
  self.eq(data['info']['role']['iden'], rall.iden)
@@ -1174,6 +1167,14 @@ class HttpApiTest(s_tests.SynTest):
1174
1167
  self.gt(data['offset'], base)
1175
1168
  base = data['offset']
1176
1169
 
1170
+ mesg = await sock.receive_json()
1171
+ data = mesg['data']
1172
+ self.eq(data['event'], 'user:info')
1173
+ self.eq(data['info']['name'], 'email')
1174
+ self.eq(data['info']['valu'], 'beep@vertex.link')
1175
+ self.gt(data['offset'], base)
1176
+ base = data['offset']
1177
+
1177
1178
  # set password
1178
1179
  await core.callStorm('$lib.auth.users.byname("beep").setPasswd("plzdontdothis")')
1179
1180
  mesg = await sock.receive_json()
@@ -1893,7 +1894,10 @@ class HttpApiTest(s_tests.SynTest):
1893
1894
  self.eq(roles, {'all', 'ninjas'})
1894
1895
 
1895
1896
  # Remove the role from the Auth subsystem.
1896
- core.auth.rolesbyiden.pop(ninjas.get('iden'))
1897
+ core.auth.roledefs.delete(ninjas.get('iden'))
1898
+ core.auth.roleidenbyname.delete('ninjas')
1899
+ core.auth.rolebyidencache.pop(ninjas.get('iden'))
1900
+ core.auth.roleidenbynamecache.pop('ninjas')
1897
1901
 
1898
1902
  async with self.getHttpSess() as sess:
1899
1903
  async with sess.post(f'https://localhost:{port}/api/v1/login',
@@ -7,11 +7,11 @@ import synapse.common as s_common
7
7
  import synapse.cortex as s_cortex
8
8
  import synapse.telepath as s_telepath
9
9
 
10
+ import synapse.lib.auth as s_auth
10
11
  import synapse.lib.time as s_time
11
12
  import synapse.lib.layer as s_layer
12
13
  import synapse.lib.msgpack as s_msgpack
13
14
  import synapse.lib.spooled as s_spooled
14
- import synapse.lib.hiveauth as s_hiveauth
15
15
 
16
16
  import synapse.tools.backup as s_tools_backup
17
17
 
@@ -1369,6 +1369,8 @@ class LayerTest(s_t_utils.SynTest):
1369
1369
  readlayr = core.getLayer(readlayrinfo.get('iden'))
1370
1370
  self.true(readlayr.readonly)
1371
1371
 
1372
+ self.none(await core._cloneLayer(readlayrinfo['iden'], readlayrinfo, None))
1373
+
1372
1374
  async def test_layer_ro(self):
1373
1375
  with self.getTestDir() as dirn:
1374
1376
  async with self.getTestCore(dirn=dirn) as core:
@@ -1966,7 +1968,7 @@ class LayerTest(s_t_utils.SynTest):
1966
1968
  parent = core.view.layers[0]
1967
1969
 
1968
1970
  seen.clear()
1969
- with mock.patch.object(s_hiveauth.HiveUser, 'confirm', confirm):
1971
+ with mock.patch.object(s_auth.User, 'confirm', confirm):
1970
1972
  with mock.patch.object(s_cortex.Cortex, 'confirmPropSet', confirmPropSet):
1971
1973
  with mock.patch.object(s_cortex.Cortex, 'confirmPropDel', confirmPropDel):
1972
1974
  await layr.confirmLayerEditPerms(user, parent.iden)
@@ -2015,7 +2017,7 @@ class LayerTest(s_t_utils.SynTest):
2015
2017
  ''', opts=opts)
2016
2018
 
2017
2019
  seen.clear()
2018
- with mock.patch.object(s_hiveauth.HiveUser, 'confirm', confirm):
2020
+ with mock.patch.object(s_auth.User, 'confirm', confirm):
2019
2021
  with mock.patch.object(s_cortex.Cortex, 'confirmPropSet', confirmPropSet):
2020
2022
  with mock.patch.object(s_cortex.Cortex, 'confirmPropDel', confirmPropDel):
2021
2023
  await layr.confirmLayerEditPerms(user, parent.iden)
@@ -2046,7 +2048,7 @@ class LayerTest(s_t_utils.SynTest):
2046
2048
  })
2047
2049
 
2048
2050
  seen.clear()
2049
- with mock.patch.object(s_hiveauth.HiveUser, 'confirm', confirm):
2051
+ with mock.patch.object(s_auth.User, 'confirm', confirm):
2050
2052
  with mock.patch.object(s_cortex.Cortex, 'confirmPropSet', confirmPropSet):
2051
2053
  with mock.patch.object(s_cortex.Cortex, 'confirmPropDel', confirmPropDel):
2052
2054
  await layr.confirmLayerEditPerms(user, layr.iden, delete=True)
@@ -2107,7 +2109,7 @@ class LayerTest(s_t_utils.SynTest):
2107
2109
  parent = core.view.layers[0]
2108
2110
 
2109
2111
  seen.clear()
2110
- with mock.patch.object(s_hiveauth.HiveUser, 'confirm', confirm):
2112
+ with mock.patch.object(s_auth.User, 'confirm', confirm):
2111
2113
  with mock.patch.object(s_cortex.Cortex, 'confirmPropSet', confirmPropSet):
2112
2114
  with mock.patch.object(s_cortex.Cortex, 'confirmPropDel', confirmPropDel):
2113
2115
  await layr.confirmLayerEditPerms(user, parent.iden)
@@ -2122,7 +2124,7 @@ class LayerTest(s_t_utils.SynTest):
2122
2124
  await user.delRule((False, ('node', 'data', 'set', 'hehe')))
2123
2125
 
2124
2126
  seen.clear()
2125
- with mock.patch.object(s_hiveauth.HiveUser, 'confirm', confirm):
2127
+ with mock.patch.object(s_auth.User, 'confirm', confirm):
2126
2128
  with mock.patch.object(s_cortex.Cortex, 'confirmPropSet', confirmPropSet):
2127
2129
  with mock.patch.object(s_cortex.Cortex, 'confirmPropDel', confirmPropDel):
2128
2130
  await layr.confirmLayerEditPerms(user, parent.iden)
@@ -2189,30 +2191,28 @@ class LayerTest(s_t_utils.SynTest):
2189
2191
 
2190
2192
  async def test_push_pull_default_migration(self):
2191
2193
  async with self.getRegrCore('2.159.0-layr-pdefs') as core:
2192
- def_tree = await core.saveHiveTree(('cortex', 'layers', '507ebf7e6ec7aadc47ace6f1f8f77954'))
2193
- dst_tree = await core.saveHiveTree(('cortex', 'layers', '9bf7a3adbf69bd16832529ab1fcd1c83'))
2194
-
2195
- epulls = {'value':
2196
- {'28cb757e9e390a234822f55b922f3295':
2197
- {'chunk:size': 1000,
2198
- 'iden': '28cb757e9e390a234822f55b922f3295',
2199
- 'offs': 0,
2200
- 'queue:size': 10000,
2201
- 'time': 1703781215891,
2202
- 'url': 'cell://./cells/pdefmigr00:*/layer/9bf7a3adbf69bd16832529ab1fcd1c83',
2203
- 'user': '1d8e6e87a2931f8d27690ff408debdab'}}}
2204
- epushs = {'value':
2205
- {'e112f93f09e43f3a10ae945b84721778':
2206
- {'chunk:size': 1000,
2207
- 'iden': 'e112f93f09e43f3a10ae945b84721778',
2208
- 'offs': 0,
2209
- 'queue:size': 10000,
2210
- 'time': 1703781208684,
2211
- 'url': 'cell://./cells/pdefmigr00:*/layer/9bf7a3adbf69bd16832529ab1fcd1c83',
2212
- 'user': '1d8e6e87a2931f8d27690ff408debdab'}}}
2213
-
2214
- self.eq(def_tree.get('kids').get('pulls'), epulls)
2215
- self.eq(def_tree.get('kids').get('pushs'), epushs)
2216
-
2217
- self.notin('pulls', dst_tree.get('kids'))
2218
- self.notin('pushs', dst_tree.get('kids'))
2194
+ def_tree = core.getLayer('507ebf7e6ec7aadc47ace6f1f8f77954').layrinfo
2195
+ dst_tree = core.getLayer('9bf7a3adbf69bd16832529ab1fcd1c83').layrinfo
2196
+
2197
+ epulls = {'28cb757e9e390a234822f55b922f3295':
2198
+ {'chunk:size': 1000,
2199
+ 'iden': '28cb757e9e390a234822f55b922f3295',
2200
+ 'offs': 0,
2201
+ 'queue:size': 10000,
2202
+ 'time': 1703781215891,
2203
+ 'url': 'cell://./cells/pdefmigr00:*/layer/9bf7a3adbf69bd16832529ab1fcd1c83',
2204
+ 'user': '1d8e6e87a2931f8d27690ff408debdab'}}
2205
+ epushs = {'e112f93f09e43f3a10ae945b84721778':
2206
+ {'chunk:size': 1000,
2207
+ 'iden': 'e112f93f09e43f3a10ae945b84721778',
2208
+ 'offs': 0,
2209
+ 'queue:size': 10000,
2210
+ 'time': 1703781208684,
2211
+ 'url': 'cell://./cells/pdefmigr00:*/layer/9bf7a3adbf69bd16832529ab1fcd1c83',
2212
+ 'user': '1d8e6e87a2931f8d27690ff408debdab'}}
2213
+
2214
+ self.eq(def_tree.get('pulls'), epulls)
2215
+ self.eq(def_tree.get('pushs'), epushs)
2216
+
2217
+ self.notin('pulls', dst_tree)
2218
+ self.notin('pushs', dst_tree)
@@ -63,10 +63,15 @@ class LinkTest(s_test.SynTest):
63
63
  host, port = serv.sockets[0].getsockname()
64
64
 
65
65
  link = await s_link.connect(host, port)
66
-
66
+ info = link.getAddrInfo()
67
+ self.eq(info.get('family'), 'tcp')
68
+ self.eq(info.get('ipver'), 'ipv4')
67
69
  await link.send(b'visi')
68
70
  self.eq(b'vert', await link.recvsize(4))
69
71
  self.none(await link.recvsize(1))
72
+ await link.fini()
73
+ # We can still get the info after we've closed the socket / fini'd the link.
74
+ self.eq(info, link.getAddrInfo())
70
75
 
71
76
  async def test_link_tx_sadpath(self):
72
77
 
@@ -295,3 +300,39 @@ class LinkTest(s_test.SynTest):
295
300
  await s_link.connect(hostname, port=port, ssl=sslctx)
296
301
  finally:
297
302
  server.close()
303
+
304
+ # Ensure we can talk to a TLS link though.
305
+ async def func(link: s_link.Link):
306
+ self.eq(b'go', await link.recv(2))
307
+ await link.tx(link.getAddrInfo())
308
+ await link.fini()
309
+
310
+ srv_sslctx = certdir.getServerSSLContext(hostname) # type: ssl.SSLContext
311
+ server = await s_link.listen(hostname, lport, onlink=func, ssl=srv_sslctx)
312
+ sslctx = certdir.getClientSSLContext() # type: ssl.SSLContext
313
+ _, port = server.sockets[0].getsockname()
314
+ print(f'listening on port {port=}')
315
+ async with await s_link.connect(hostname, port=port, ssl=sslctx) as link:
316
+ await link.send(b'go')
317
+ item = await link.rx()
318
+ self.eq(link.getAddrInfo().get('family'), 'tls')
319
+ self.eq(item.get('family'), 'tls')
320
+ server.close()
321
+
322
+ async def test_link_unix(self):
323
+ with self.getTestDir() as dirn:
324
+
325
+ async def func(link: s_link.Link):
326
+ self.eq(b'go', await link.recv(2))
327
+ await link.tx(link.getAddrInfo())
328
+ await link.fini()
329
+ fp = s_common.genpath(dirn, 'sock')
330
+ server = await s_link.unixlisten(fp, onlink=func)
331
+
332
+ async with await s_link.unixconnect(fp) as link:
333
+ await link.send(b'go')
334
+ item = await link.rx()
335
+ self.eq(link.getAddrInfo().get('family'), 'unix')
336
+ self.eq(item.get('addr'), fp)
337
+ self.eq(item.get('family'), 'unix')
338
+ server.close()
@@ -1528,6 +1528,74 @@ class LmdbSlabTest(s_t_utils.SynTest):
1528
1528
 
1529
1529
  self.eq(3, slab.count(b'foo', db=dupsdb))
1530
1530
 
1531
+ async def test_safekeyval(self):
1532
+ with self.getTestDir() as dirn:
1533
+
1534
+ path = os.path.join(dirn, 'test.lmdb')
1535
+
1536
+ async with await s_lmdbslab.Slab.anit(path) as slab:
1537
+
1538
+ safekv = slab.getSafeKeyVal('test')
1539
+
1540
+ subkv1 = safekv.getSubKeyVal('pref1')
1541
+ subkv2 = subkv1.getSubKeyVal('pref2')
1542
+
1543
+ self.eq(subkv2.prefix, 'pref1pref2')
1544
+
1545
+ subkv2.set('foo', 'bar')
1546
+ subkv2.set('baz', 'faz')
1547
+
1548
+ self.eq(list(subkv2.keys()), ['baz', 'foo'])
1549
+ self.eq(list(safekv.keys()), ['pref1pref2baz', 'pref1pref2foo'])
1550
+ self.eq(list(safekv.values()), ['faz', 'bar'])
1551
+
1552
+ await safekv.truncate()
1553
+ self.len(0, safekv.items())
1554
+
1555
+ subkv2.set('wow', 'guys')
1556
+
1557
+ newp = 'a' * 512
1558
+
1559
+ with self.raises(s_exc.BadArg):
1560
+ safekv.getSubKeyVal(newp)
1561
+
1562
+ with self.raises(s_exc.BadArg):
1563
+ safekv.get(newp)
1564
+
1565
+ with self.raises(s_exc.BadArg):
1566
+ safekv.set(newp, 'newp')
1567
+
1568
+ with self.raises(s_exc.BadArg):
1569
+ safekv.pop(newp)
1570
+
1571
+ with self.raises(s_exc.BadArg):
1572
+ safekv.delete(newp)
1573
+
1574
+ with self.raises(s_exc.BadArg):
1575
+ list(safekv.keys(pref=newp))
1576
+
1577
+ with self.raises(s_exc.BadArg):
1578
+ list(safekv.items(pref=newp))
1579
+
1580
+ with self.raises(s_exc.BadArg):
1581
+ list(safekv.values(pref=newp))
1582
+
1583
+ with self.raises(s_exc.BadArg):
1584
+ await safekv.truncate(pref=newp)
1585
+
1586
+ with self.raises(s_exc.BadArg):
1587
+ safekv.getSubKeyVal('')
1588
+
1589
+ with self.raises(s_exc.BadArg):
1590
+ slab.getSafeKeyVal('newp', create=False)
1591
+
1592
+ async with await s_lmdbslab.Slab.anit(path) as slab:
1593
+ safekv = slab.getSafeKeyVal('test', create=False)
1594
+ subkv1 = safekv.getSubKeyVal('pref1')
1595
+ subkv2 = subkv1.getSubKeyVal('pref2')
1596
+ self.eq(list(subkv2.keys()), ['wow'])
1597
+
1598
+
1531
1599
  class LmdbSlabMemLockTest(s_t_utils.SynTest):
1532
1600
 
1533
1601
  async def test_lmdbslabmemlock(self):
@@ -4,9 +4,9 @@ from unittest import mock
4
4
  import synapse.exc as s_exc
5
5
  import synapse.common as s_common
6
6
 
7
+ import synapse.lib.auth as s_auth
7
8
  import synapse.lib.cell as s_cell
8
9
  import synapse.lib.nexus as s_nexus
9
- import synapse.lib.hiveauth as s_hiveauth
10
10
 
11
11
  import synapse.tests.utils as s_t_utils
12
12
 
@@ -207,7 +207,7 @@ class NexusTest(s_t_utils.SynTest):
207
207
 
208
208
  async def test_nexus_safety(self):
209
209
 
210
- orig = s_hiveauth.Auth.reqUser
210
+ orig = s_auth.Auth.reqUser
211
211
  async def slowReq(self, iden):
212
212
  await asyncio.sleep(0.2)
213
213
  return await orig(self, iden)
@@ -215,7 +215,7 @@ class NexusTest(s_t_utils.SynTest):
215
215
  with self.getTestDir() as dirn:
216
216
  async with self.getTestCore(dirn=dirn) as core:
217
217
 
218
- with mock.patch('synapse.lib.hiveauth.Auth.reqUser', slowReq):
218
+ with mock.patch('synapse.lib.auth.Auth.reqUser', slowReq):
219
219
 
220
220
  vcnt = len(core.views)
221
221
  deflayr = (await core.getLayerDef()).get('iden')
@@ -245,7 +245,7 @@ class NexusTest(s_t_utils.SynTest):
245
245
  vcnt = len(core.views)
246
246
  strt = await core.nexsroot.index()
247
247
 
248
- with mock.patch('synapse.lib.hiveauth.Auth.reqUser', slowReq):
248
+ with mock.patch('synapse.lib.auth.Auth.reqUser', slowReq):
249
249
  for x in range(3):
250
250
  vdef = {'layers': (deflayr,), 'name': f'someview{x}'}
251
251
  with self.raises(TimeoutError):
@@ -174,13 +174,6 @@ class NodeTest(s_t_utils.SynTest):
174
174
  self.isin('tick', props)
175
175
  self.notin('newp', props)
176
176
 
177
- form = 'test:str'
178
- valu = 'cool'
179
- props = {'tick': 12345,
180
- 'hehe': 'hehe',
181
- }
182
- tval = (None, None)
183
-
184
177
  async with self.getTestCore() as core:
185
178
  await core.addTagProp('score', ('int', {}), {})
186
179
  await core.addTagProp('note', ('str', {'lower': True, 'strip': 'True'}), {})