synapse 2.222.0__py311-none-any.whl → 2.223.0__py311-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of synapse might be problematic. Click here for more details.

@@ -42,6 +42,20 @@ class ExecTeleCaller(s_cell.Cell):
42
42
  resp = await meth(*args, **kwargs)
43
43
  return resp
44
44
 
45
+ class SpecialPathApi(s_cell.CellApi):
46
+ async def __anit__(self, cell, link, user, path):
47
+ await super().__anit__(cell, link, user)
48
+ self.path = path
49
+
50
+ async def getTestPath(self):
51
+ return self.path
52
+
53
+ class PathAwareCell(s_cell.Cell):
54
+ async def getCellApi(self, link, user, path):
55
+ if not path:
56
+ return await self.cellapi.anit(self, link, user)
57
+ return await SpecialPathApi.anit(self, link, user, path)
58
+
45
59
  class AhaTest(s_test.SynTest):
46
60
 
47
61
  async def test_lib_aha_clone(self):
@@ -132,36 +146,36 @@ class AhaTest(s_test.SynTest):
132
146
 
133
147
  async def test_lib_aha_offon(self):
134
148
  with self.getTestDir() as dirn:
135
- cryo0_dirn = s_common.gendir(dirn, 'cryo0')
149
+ cell0_dirn = s_common.gendir(dirn, 'cell0')
136
150
  async with self.getTestAha(dirn=dirn) as aha:
137
151
 
138
152
  replaymult = 1
139
153
  if s_common.envbool('SYNDEV_NEXUS_REPLAY'):
140
154
  replaymult = 2
141
155
 
142
- purl = await aha.addAhaSvcProv('0.cryo')
156
+ purl = await aha.addAhaSvcProv('0.cell')
143
157
 
144
158
  wait00 = aha.waiter(1 * replaymult, 'aha:svcadd')
145
159
 
146
160
  conf = {'aha:provision': purl}
147
- async with self.getTestCryo(dirn=cryo0_dirn, conf=conf) as cryo:
161
+ async with self.getTestCell(dirn=cell0_dirn, conf=conf) as cell:
148
162
  self.len(1 * replaymult, await wait00.wait(timeout=6))
149
163
 
150
- svc = await aha.getAhaSvc('0.cryo...')
164
+ svc = await aha.getAhaSvc('0.cell...')
151
165
  linkiden = svc.get('svcinfo', {}).get('online')
152
166
 
153
167
  # Tear down the Aha cell.
154
168
  await aha.__aexit__(None, None, None)
155
169
 
156
- with self.getAsyncLoggerStream('synapse.lib.aha', f'Set [0.cryo.synapse] offline.') as stream:
170
+ with self.getAsyncLoggerStream('synapse.lib.aha', f'Set [0.cell.synapse] offline.') as stream:
157
171
  async with self.getTestAha(dirn=dirn) as aha:
158
172
  self.true(await asyncio.wait_for(stream.wait(), timeout=12))
159
- svc = await aha.getAhaSvc('0.cryo...')
173
+ svc = await aha.getAhaSvc('0.cell...')
160
174
  self.notin('online', svc.get('svcinfo'))
161
175
 
162
176
  # Try setting something down a second time
163
- await aha.setAhaSvcDown('0.cryo', linkiden, network='synapse')
164
- svc = await aha.getAhaSvc('0.cryo...')
177
+ await aha.setAhaSvcDown('0.cell', linkiden, network='synapse')
178
+ svc = await aha.getAhaSvc('0.cell...')
165
179
  self.notin('online', svc.get('svcinfo'))
166
180
 
167
181
  async def test_lib_aha_basics(self):
@@ -190,7 +204,7 @@ class AhaTest(s_test.SynTest):
190
204
 
191
205
  async with self.getTestAha() as aha:
192
206
 
193
- cryo0_dirn = s_common.gendir(aha.dirn, 'cryo0')
207
+ cell0_dirn = s_common.gendir(aha.dirn, 'cell0')
194
208
 
195
209
  ahaurls = await aha.getAhaUrls()
196
210
 
@@ -200,76 +214,77 @@ class AhaTest(s_test.SynTest):
200
214
  if s_common.envbool('SYNDEV_NEXUS_REPLAY'):
201
215
  replaymult = 2
202
216
 
203
- conf = {'aha:provision': await aha.addAhaSvcProv('0.cryo')}
204
- async with self.getTestCryo(dirn=cryo0_dirn, conf=conf) as cryo:
217
+ conf = {'aha:provision': await aha.addAhaSvcProv('0.cell')}
218
+ async with self.getTestCell(dirn=cell0_dirn, conf=conf) as cell:
205
219
 
206
220
  await wait00.wait(timeout=2)
207
221
 
208
222
  with self.raises(s_exc.NoSuchName):
209
223
  await s_telepath.getAhaProxy({'host': 'hehe.haha'})
210
224
 
211
- async with await s_telepath.openurl('aha://cryo...') as proxy:
225
+ async with await s_telepath.openurl('aha://cell...') as proxy:
212
226
  self.nn(await proxy.getCellIden())
213
227
 
214
228
  with self.raises(s_exc.BadArg):
215
- _proxy = await cryo.ahaclient.proxy(timeout=2)
216
- await _proxy.modAhaSvcInfo('cryo...', {'newp': 'newp'})
229
+ _proxy = await cell.ahaclient.proxy(timeout=2)
230
+ await _proxy.modAhaSvcInfo('cell...', {'newp': 'newp'})
217
231
 
218
- async with await s_telepath.openurl('aha://0.cryo...') as proxy:
232
+ async with await s_telepath.openurl('aha://0.cell...') as proxy:
219
233
  self.nn(await proxy.getCellIden())
220
234
 
221
235
  # force a reconnect...
222
- proxy = await cryo.ahaclient.proxy(timeout=2)
236
+ proxy = await cell.ahaclient.proxy(timeout=2)
223
237
  async with aha.waiter(2 * replaymult, 'aha:svcadd'):
224
238
  await proxy.fini()
225
239
 
226
- async with await s_telepath.openurl('aha://cryo...') as proxy:
240
+ async with await s_telepath.openurl('aha://cell...') as proxy:
227
241
  self.nn(await proxy.getCellIden())
228
242
 
229
243
  # force the service into passive mode...
230
244
  async with aha.waiter(3 * replaymult, 'aha:svcdown', 'aha:svcadd', timeout=6):
231
- await cryo.setCellActive(False)
245
+ await cell.setCellActive(False)
232
246
 
233
247
  with self.raises(s_exc.NoSuchName):
234
- async with await s_telepath.openurl('aha://cryo...') as proxy:
248
+ async with await s_telepath.openurl('aha://cell...') as proxy:
235
249
  pass
236
250
 
237
- async with await s_telepath.openurl('aha://0.cryo...') as proxy:
251
+ async with await s_telepath.openurl('aha://0.cell...') as proxy:
238
252
  self.nn(await proxy.getCellIden())
239
253
 
240
254
  async with aha.waiter(1 * replaymult, 'aha:svcadd', timeout=6):
241
- await cryo.setCellActive(True)
255
+ await cell.setCellActive(True)
242
256
 
243
- async with await s_telepath.openurl('aha://cryo...') as proxy:
257
+ async with await s_telepath.openurl('aha://cell...') as proxy:
244
258
  self.nn(await proxy.getCellIden())
245
259
 
246
260
  wait01 = aha.waiter(2 * replaymult, 'aha:svcadd')
247
261
 
248
- conf = {'aha:provision': await aha.addAhaSvcProv('0.cryo')}
249
- async with self.getTestCryo(conf=conf) as cryo:
262
+ conf = {'aha:provision': await aha.addAhaSvcProv('0.cell')}
263
+ async with self.getTestCell(ctor=PathAwareCell, conf=conf) as cell:
250
264
 
251
- info = await cryo.getCellInfo()
265
+ info = await cell.getCellInfo()
266
+ celliden = info['cell']['iden']
252
267
 
253
- self.eq(info['cell']['aha'], {'name': '0.cryo', 'leader': 'cryo', 'network': 'synapse'})
268
+ self.eq(info['cell']['aha'], {'name': '0.cell', 'leader': 'cell', 'network': 'synapse'})
254
269
 
255
270
  await wait01.wait(timeout=2)
256
271
 
257
- async with await s_telepath.openurl('aha://cryo.synapse') as proxy:
258
- self.nn(await proxy.getCellIden())
272
+ async with await s_telepath.openurl('aha://cell.synapse') as proxy:
273
+ self.eq(celliden, await proxy.getCellIden())
259
274
 
260
- async with await s_telepath.openurl('aha://0.cryo.synapse') as proxy:
261
- self.nn(await proxy.getCellIden())
262
- await proxy.puts('hehe', ('hehe', 'haha'))
275
+ async with await s_telepath.openurl('aha://0.cell.synapse') as proxy:
276
+ self.eq(celliden, await proxy.getCellIden())
263
277
 
264
- async with await s_telepath.openurl('aha://0.cryo.synapse/*/hehe') as proxy:
265
- self.nn(await proxy.iden())
278
+ async with await s_telepath.openurl('aha://0.cell.synapse/*/hehe/haha') as proxy:
279
+ self.eq(celliden, await proxy.getCellIden())
280
+ self.eq(('hehe', 'haha'), await proxy.getTestPath())
266
281
 
267
282
  async with aha.getLocalProxy() as ahaproxy:
268
283
 
269
284
  svcs = [x async for x in ahaproxy.getAhaSvcs('synapse')]
270
285
  self.len(2, svcs)
271
286
  names = [s['name'] for s in svcs]
272
- self.sorteq(('cryo.synapse', '0.cryo.synapse'), names)
287
+ self.sorteq(('cell.synapse', '0.cell.synapse'), names)
273
288
 
274
289
  self.none(await ahaproxy.getCaCert('vertex.link'))
275
290
  cacert0 = await ahaproxy.genCaCert('vertex.link')
@@ -278,7 +293,7 @@ class AhaTest(s_test.SynTest):
278
293
  self.eq(cacert0, cacert1)
279
294
  self.eq(cacert0, await ahaproxy.getCaCert('vertex.link'))
280
295
 
281
- csrpem = cryo.certdir.genHostCsr('cryo.vertex.link').decode()
296
+ csrpem = cell.certdir.genHostCsr('cell.vertex.link').decode()
282
297
 
283
298
  hostcert00 = await ahaproxy.signHostCsr(csrpem)
284
299
  hostcert01 = await ahaproxy.signHostCsr(csrpem)
@@ -287,7 +302,7 @@ class AhaTest(s_test.SynTest):
287
302
  self.nn(hostcert01)
288
303
  self.ne(hostcert00, hostcert01)
289
304
 
290
- csrpem = cryo.certdir.genUserCsr('visi@vertex.link').decode()
305
+ csrpem = cell.certdir.genUserCsr('visi@vertex.link').decode()
291
306
 
292
307
  usercert00 = await ahaproxy.signUserCsr(csrpem)
293
308
  usercert01 = await ahaproxy.signUserCsr(csrpem)
@@ -310,7 +325,7 @@ class AhaTest(s_test.SynTest):
310
325
  self.eq(info.get('status'), 'ok')
311
326
  result = info.get('result')
312
327
  self.len(2, result)
313
- self.eq({'0.cryo.synapse', 'cryo.synapse'},
328
+ self.eq({'0.cell.synapse', 'cell.synapse'},
314
329
  {svcinfo.get('name') for svcinfo in result})
315
330
 
316
331
  async with sess.get(svcsurl, json={'network': 'synapse'}) as resp:
@@ -319,7 +334,7 @@ class AhaTest(s_test.SynTest):
319
334
  self.eq(info.get('status'), 'ok')
320
335
  result = info.get('result')
321
336
  self.len(2, result)
322
- self.eq({'0.cryo.synapse', 'cryo.synapse'},
337
+ self.eq({'0.cell.synapse', 'cell.synapse'},
323
338
  {svcinfo.get('name') for svcinfo in result})
324
339
 
325
340
  async with sess.get(svcsurl, json={'network': 'newp'}) as resp:
@@ -351,10 +366,10 @@ class AhaTest(s_test.SynTest):
351
366
  self.eq(info.get('code'), 'AuthDeny')
352
367
 
353
368
  async with aha.getLocalProxy() as ahaproxy:
354
- await ahaproxy.delAhaSvc('cryo', network='synapse')
355
- await ahaproxy.delAhaSvc('0.cryo', network='synapse')
356
- self.none(await ahaproxy.getAhaSvc('cryo.synapse'))
357
- self.none(await ahaproxy.getAhaSvc('0.cryo.synapse'))
369
+ await ahaproxy.delAhaSvc('cell', network='synapse')
370
+ await ahaproxy.delAhaSvc('0.cell', network='synapse')
371
+ self.none(await ahaproxy.getAhaSvc('cell.synapse'))
372
+ self.none(await ahaproxy.getAhaSvc('0.cell.synapse'))
358
373
  self.len(0, [s async for s in ahaproxy.getAhaSvcs()])
359
374
 
360
375
  with self.raises(s_exc.BadArg):
@@ -431,24 +446,24 @@ class AhaTest(s_test.SynTest):
431
446
  async with self.getTestAha() as aha:
432
447
 
433
448
  wait00 = aha.waiter(1, 'aha:svcadd')
434
- conf = {'aha:provision': await aha.addAhaSvcProv('0.cryo')}
449
+ conf = {'aha:provision': await aha.addAhaSvcProv('0.cell')}
435
450
 
436
- async with self.getTestCryo(conf=conf) as cryo:
451
+ async with self.getTestCell(conf=conf) as cell:
437
452
 
438
453
  self.true(await wait00.wait(timeout=2))
439
454
 
440
- async with await s_telepath.openurl('aha://0.cryo...') as proxy:
455
+ async with await s_telepath.openurl('aha://0.cell...') as proxy:
441
456
  self.nn(await proxy.getCellIden())
442
457
 
443
- proxy = await cryo.ahaclient.proxy()
458
+ proxy = await cell.ahaclient.proxy()
444
459
 
445
460
  # avoid race to notify client...
446
- async with cryo.ahaclient.waiter(1, 'tele:client:linkloop', timeout=2):
461
+ async with cell.ahaclient.waiter(1, 'tele:client:linkloop', timeout=2):
447
462
  await aha.fini()
448
463
  self.true(await proxy.waitfini(timeout=10))
449
464
 
450
465
  with self.raises(asyncio.TimeoutError):
451
- await cryo.ahaclient.proxy(timeout=0.1)
466
+ await cell.ahaclient.proxy(timeout=0.1)
452
467
 
453
468
  async def test_lib_aha_onlink_fail(self):
454
469
 
@@ -463,12 +478,12 @@ class AhaTest(s_test.SynTest):
463
478
  aha.testerr = True
464
479
  wait00 = aha.waiter(1, 'aha:svcadd')
465
480
 
466
- conf = {'aha:provision': await aha.addAhaSvcProv('0.cryo')}
467
- async with self.getTestCryo(conf=conf) as cryo:
481
+ conf = {'aha:provision': await aha.addAhaSvcProv('0.cell')}
482
+ async with self.getTestCell(conf=conf) as cell:
468
483
 
469
484
  self.none(await wait00.wait(timeout=2))
470
485
 
471
- svc = await aha.getAhaSvc('0.cryo...')
486
+ svc = await aha.getAhaSvc('0.cell...')
472
487
  self.none(svc)
473
488
 
474
489
  wait01 = aha.waiter(1 * replaymult, 'aha:svcadd')
@@ -476,11 +491,11 @@ class AhaTest(s_test.SynTest):
476
491
 
477
492
  self.nn(await wait01.wait(timeout=2))
478
493
 
479
- svc = await aha.getAhaSvc('0.cryo...')
494
+ svc = await aha.getAhaSvc('0.cell...')
480
495
  self.nn(svc)
481
496
  self.nn(svc.get('svcinfo', {}).get('online'))
482
497
 
483
- async with await s_telepath.openurl('aha://0.cryo...') as proxy:
498
+ async with await s_telepath.openurl('aha://0.cell...') as proxy:
484
499
  self.nn(await proxy.getCellIden())
485
500
 
486
501
  async def test_lib_aha_bootstrap(self):
@@ -3095,6 +3095,9 @@ class AstTest(s_test.SynTest):
3095
3095
  with self.raises(s_exc.StormRuntimeError):
3096
3096
  self.len(1, await core.nodes('inet:ipv4=1.2.3.4 <(seen)- *=woot'))
3097
3097
 
3098
+ with self.raises(s_exc.NoSuchForm):
3099
+ self.len(1, await core.nodes('$foo=(null) inet:ipv4=1.2.3.4 <(seen)- $foo'))
3100
+
3098
3101
  self.len(1, await core.nodes('inet:ipv4=1.2.3.4 <(seen)- *'))
3099
3102
  self.len(1, await core.nodes('inet:ipv4=1.2.3.4 <(seen)- meta:source'))
3100
3103
  self.len(1, await core.nodes('inet:ipv4=1.2.3.4 <(seen)- meta:source:name'))
@@ -1587,22 +1587,22 @@ class CellTest(s_t_utils.SynTest):
1587
1587
 
1588
1588
  with self.getTestDir() as dirn:
1589
1589
 
1590
- async with self.getTestCryo(dirn=dirn) as cryo:
1590
+ async with self.getTestCell(dirn=dirn) as cell:
1591
1591
 
1592
- cryo.certdir.genCaCert('localca')
1593
- cryo.certdir.genHostCert('localhost', signas='localca')
1594
- cryo.certdir.genUserCert('root@localhost', signas='localca')
1595
- cryo.certdir.genUserCert('newp@localhost', signas='localca')
1592
+ cell.certdir.genCaCert('localca')
1593
+ cell.certdir.genHostCert('localhost', signas='localca')
1594
+ cell.certdir.genUserCert('root@localhost', signas='localca')
1595
+ cell.certdir.genUserCert('newp@localhost', signas='localca')
1596
1596
 
1597
- root = await cryo.auth.addUser('root@localhost')
1597
+ root = await cell.auth.addUser('root@localhost')
1598
1598
  await root.setAdmin(True)
1599
1599
 
1600
- async with self.getTestCryo(dirn=dirn) as cryo:
1600
+ async with self.getTestCell(dirn=dirn) as cell:
1601
1601
 
1602
- addr, port = await cryo.dmon.listen('ssl://0.0.0.0:0?hostname=localhost&ca=localca')
1602
+ addr, port = await cell.dmon.listen('ssl://0.0.0.0:0?hostname=localhost&ca=localca')
1603
1603
 
1604
1604
  async with await s_telepath.openurl(f'ssl://root@127.0.0.1:{port}?hostname=localhost') as proxy:
1605
- self.eq(cryo.iden, await proxy.getCellIden())
1605
+ self.eq(cell.iden, await proxy.getCellIden())
1606
1606
 
1607
1607
  with self.raises(s_exc.BadCertHost):
1608
1608
  url = f'ssl://root@127.0.0.1:{port}?hostname=borked.localhost'
@@ -1616,12 +1616,12 @@ class CellTest(s_t_utils.SynTest):
1616
1616
  self.eq(cm.exception.get('username'), 'newp@localhost')
1617
1617
 
1618
1618
  # add newp
1619
- unfo = await cryo.addUser('newp@localhost')
1619
+ unfo = await cell.addUser('newp@localhost')
1620
1620
  async with await s_telepath.openurl(f'ssl://newp@127.0.0.1:{port}?hostname=localhost') as proxy:
1621
- self.eq(cryo.iden, await proxy.getCellIden())
1621
+ self.eq(cell.iden, await proxy.getCellIden())
1622
1622
 
1623
1623
  # Lock newp
1624
- await cryo.setUserLocked(unfo.get('iden'), True)
1624
+ await cell.setUserLocked(unfo.get('iden'), True)
1625
1625
  with self.raises(s_exc.AuthDeny) as cm:
1626
1626
  url = f'ssl://newp@127.0.0.1:{port}?hostname=localhost'
1627
1627
  async with await s_telepath.openurl(url) as proxy:
@@ -1220,33 +1220,6 @@ class StormTest(s_t_utils.SynTest):
1220
1220
  ''')
1221
1221
  self.eq(email, 'visi@vertex.link')
1222
1222
 
1223
- pkg0 = {'name': 'hehe', 'version': '1.2.3'}
1224
- await core.addStormPkg(pkg0)
1225
- self.eq('1.2.3', await core.callStorm('return($lib.pkg.get(hehe).version)'))
1226
-
1227
- self.eq(None, await core.callStorm('return($lib.pkg.get(nopkg))'))
1228
-
1229
- pkg1 = {'name': 'haha', 'version': '1.2.3'}
1230
- await core.addStormPkg(pkg1)
1231
- msgs = await core.stormlist('pkg.list')
1232
- self.stormIsInPrint('haha', msgs)
1233
- self.stormIsInPrint('hehe', msgs)
1234
-
1235
- self.true(await core.callStorm('return($lib.pkg.has(haha))'))
1236
-
1237
- await core.delStormPkg('haha')
1238
- self.none(await core.callStorm('return($lib.pkg.get(haha))'))
1239
- self.false(await core.callStorm('return($lib.pkg.has(haha))'))
1240
-
1241
- msgs = await core.stormlist('pkg.list --verbose')
1242
- self.stormIsInPrint('not available', msgs)
1243
-
1244
- pkg2 = {'name': 'hoho', 'version': '4.5.6', 'build': {'time': 1732017600000}}
1245
- await core.addStormPkg(pkg2)
1246
- self.eq('4.5.6', await core.callStorm('return($lib.pkg.get(hoho).version)'))
1247
- msgs = await core.stormlist('pkg.list --verbose')
1248
- self.stormIsInPrint('2024-11-19 12:00:00', msgs)
1249
-
1250
1223
  # test for $lib.queue.gen()
1251
1224
  self.eq(0, await core.callStorm('return($lib.queue.gen(woot).size())'))
1252
1225
  # and again to test *not* creating it...
@@ -1575,161 +1548,6 @@ class StormTest(s_t_utils.SynTest):
1575
1548
  nodes = [x for x in msgs if x[0] == 'node']
1576
1549
  self.len(0, nodes)
1577
1550
 
1578
- pkgdef = {
1579
- 'name': 'foobar',
1580
- 'version': '1.2.3',
1581
- }
1582
-
1583
- await core.addStormPkg(pkgdef)
1584
-
1585
- deps = await core.callStorm('return($lib.pkg.deps($pkgdef))', opts={'vars': {'pkgdef': pkgdef}})
1586
- self.eq({
1587
- 'requires': (),
1588
- 'conflicts': (),
1589
- }, deps)
1590
-
1591
- pkgdef = {
1592
- 'name': 'bazfaz',
1593
- 'version': '2.2.2',
1594
- 'depends': {
1595
- 'conflicts': (
1596
- {'name': 'foobar'},
1597
- ),
1598
- }
1599
- }
1600
-
1601
- with self.raises(s_exc.StormPkgConflicts):
1602
- await core.addStormPkg(pkgdef)
1603
-
1604
- deps = await core.callStorm('return($lib.pkg.deps($pkgdef))', opts={'vars': {'pkgdef': pkgdef}})
1605
- self.eq({
1606
- 'requires': (),
1607
- 'conflicts': (
1608
- {'name': 'foobar', 'version': None, 'desc': None, 'ok': False, 'actual': '1.2.3'},
1609
- )
1610
- }, deps)
1611
-
1612
- pkgdef = {
1613
- 'name': 'bazfaz',
1614
- 'version': '2.2.2',
1615
- 'depends': {
1616
- 'conflicts': (
1617
- {'name': 'foobar', 'version': '>=1.0.0', 'desc': 'foo'},
1618
- ),
1619
- }
1620
- }
1621
-
1622
- with self.raises(s_exc.StormPkgConflicts):
1623
- await core.addStormPkg(pkgdef)
1624
-
1625
- deps = await core.callStorm('return($lib.pkg.deps($pkgdef))', opts={'vars': {'pkgdef': pkgdef}})
1626
- self.eq({
1627
- 'requires': (),
1628
- 'conflicts': (
1629
- {'name': 'foobar', 'version': '>=1.0.0', 'desc': 'foo', 'ok': False, 'actual': '1.2.3'},
1630
- )
1631
- }, deps)
1632
-
1633
- pkgdef = {
1634
- 'name': 'bazfaz',
1635
- 'version': '2.2.2',
1636
- 'depends': {
1637
- 'requires': (
1638
- {'name': 'foobar', 'version': '>=2.0.0,<3.0.0'},
1639
- ),
1640
- }
1641
- }
1642
-
1643
- with self.getAsyncLoggerStream('synapse.cortex', 'bazfaz requirement') as stream:
1644
- await core.addStormPkg(pkgdef)
1645
- self.true(await stream.wait(timeout=1))
1646
-
1647
- pkgdef = {
1648
- 'name': 'bazfaz',
1649
- 'version': '2.2.2',
1650
- 'depends': {
1651
- 'requires': (
1652
- {'name': 'foobar', 'version': '>=2.0.0,<3.0.0', 'optional': True},
1653
- ),
1654
- }
1655
- }
1656
-
1657
- with self.getAsyncLoggerStream('synapse.cortex', 'bazfaz optional requirement') as stream:
1658
- await core.addStormPkg(pkgdef)
1659
- self.true(await stream.wait(timeout=1))
1660
-
1661
- deps = await core.callStorm('return($lib.pkg.deps($pkgdef))', opts={'vars': {'pkgdef': pkgdef}})
1662
- self.eq({
1663
- 'requires': (
1664
- {'name': 'foobar', 'version': '>=2.0.0,<3.0.0', 'desc': None,
1665
- 'ok': False, 'actual': '1.2.3', 'optional': True},
1666
- ),
1667
- 'conflicts': ()
1668
- }, deps)
1669
-
1670
- pkgdef = {
1671
- 'name': 'lolzlolz',
1672
- 'version': '1.2.3',
1673
- }
1674
-
1675
- await core.addStormPkg(pkgdef)
1676
-
1677
- deps = await core.callStorm('return($lib.pkg.deps($pkgdef))', opts={'vars': {'pkgdef': pkgdef}})
1678
- self.eq({
1679
- 'requires': (),
1680
- 'conflicts': (),
1681
- }, deps)
1682
-
1683
- pkgdef = {
1684
- 'name': 'bazfaz',
1685
- 'version': '2.2.2',
1686
- 'depends': {
1687
- 'requires': (
1688
- {'name': 'lolzlolz', 'version': '>=1.0.0,<2.0.0', 'desc': 'lol'},
1689
- ),
1690
- 'conflicts': (
1691
- {'name': 'foobar', 'version': '>=3.0.0'},
1692
- ),
1693
- }
1694
- }
1695
-
1696
- await core.addStormPkg(pkgdef)
1697
-
1698
- deps = await core.callStorm('return($lib.pkg.deps($pkgdef))', opts={'vars': {'pkgdef': pkgdef}})
1699
- self.eq({
1700
- 'requires': (
1701
- {'name': 'lolzlolz', 'version': '>=1.0.0,<2.0.0', 'desc': 'lol', 'ok': True, 'actual': '1.2.3'},
1702
- ),
1703
- 'conflicts': (
1704
- {'name': 'foobar', 'version': '>=3.0.0', 'desc': None, 'ok': True, 'actual': '1.2.3'},
1705
- )
1706
- }, deps)
1707
-
1708
- pkgdef = {
1709
- 'name': 'zoinkszoinks',
1710
- 'version': '2.2.2',
1711
- 'depends': {
1712
- 'requires': (
1713
- {'name': 'newpnewp', 'version': '1.2.3'},
1714
- ),
1715
- 'conflicts': (
1716
- {'name': 'newpnewp'},
1717
- ),
1718
- }
1719
- }
1720
-
1721
- await core.addStormPkg(pkgdef)
1722
-
1723
- deps = await core.callStorm('return($lib.pkg.deps($pkgdef))', opts={'vars': {'pkgdef': pkgdef}})
1724
- self.eq({
1725
- 'requires': (
1726
- {'name': 'newpnewp', 'version': '1.2.3', 'desc': None, 'ok': False, 'actual': None},
1727
- ),
1728
- 'conflicts': (
1729
- {'name': 'newpnewp', 'version': None, 'desc': None, 'ok': True, 'actual': None},
1730
- )
1731
- }, deps)
1732
-
1733
1551
  # force old-cron behavior which lacks a view
1734
1552
  await core.nodes('cron.add --hourly 03 { inet:ipv4 }')
1735
1553
  for (iden, cron) in core.agenda.list():
@@ -2980,72 +2798,6 @@ class StormTest(s_t_utils.SynTest):
2980
2798
  with self.raises(s_exc.NoSuchVar):
2981
2799
  await core.callStorm('$foo = 10 $foo = $lib.undef return($foo)')
2982
2800
 
2983
- async def test_storm_pkg_load(self):
2984
- cont = s_common.guid()
2985
- pkg = {
2986
- 'name': 'testload',
2987
- 'version': '0.3.0',
2988
- 'modules': (
2989
- {
2990
- 'name': 'testload',
2991
- 'storm': 'function x() { return((0)) }',
2992
- },
2993
- ),
2994
- 'onload': f'[ ps:contact={cont} ] $lib.print(teststring) $lib.warn(testwarn, key=valu) return($path.vars.newp)'
2995
- }
2996
- class PkgHandler(s_httpapi.Handler):
2997
-
2998
- async def get(self, name):
2999
- assert self.request.headers.get('X-Synapse-Version') == s_version.verstring
3000
-
3001
- if name == 'notok':
3002
- self.sendRestErr('FooBar', 'baz faz')
3003
- return
3004
-
3005
- self.sendRestRetn(pkg)
3006
-
3007
- class PkgHandlerRaw(s_httpapi.Handler):
3008
- async def get(self, name):
3009
- assert self.request.headers.get('X-Synapse-Version') == s_version.verstring
3010
-
3011
- self.set_header('Content-Type', 'application/json')
3012
- return self.write(pkg)
3013
-
3014
- async with self.getTestCore() as core:
3015
- core.addHttpApi('/api/v1/pkgtest/(.*)', PkgHandler, {'cell': core})
3016
- core.addHttpApi('/api/v1/pkgtestraw/(.*)', PkgHandlerRaw, {'cell': core})
3017
- port = (await core.addHttpsPort(0, host='127.0.0.1'))[1]
3018
-
3019
- msgs = await core.stormlist(f'pkg.load --ssl-noverify https://127.0.0.1:{port}/api/v1/newp/newp')
3020
- self.stormIsInWarn('pkg.load got HTTP code: 404', msgs)
3021
-
3022
- msgs = await core.stormlist(f'pkg.load --ssl-noverify https://127.0.0.1:{port}/api/v1/pkgtest/notok')
3023
- self.stormIsInWarn('pkg.load got JSON error: FooBar', msgs)
3024
-
3025
- # onload will on fire once. all other pkg.load events will effectively bounce
3026
- # because the pkg hasn't changed so no loading occurs
3027
- waiter = core.waiter(1, 'core:pkg:onload:complete')
3028
-
3029
- with self.getAsyncLoggerStream('synapse.cortex') as stream:
3030
- msgs = await core.stormlist(f'pkg.load --ssl-noverify https://127.0.0.1:{port}/api/v1/pkgtest/yep')
3031
- self.stormIsInPrint('testload @0.3.0', msgs)
3032
-
3033
- msgs = await core.stormlist(f'pkg.load --ssl-noverify --raw https://127.0.0.1:{port}/api/v1/pkgtestraw/yep')
3034
- self.stormIsInPrint('testload @0.3.0', msgs)
3035
-
3036
- stream.seek(0)
3037
- buf = stream.read()
3038
- self.isin("testload onload output: teststring", buf)
3039
- self.isin("testload onload output: testwarn", buf)
3040
- self.isin("No var with name: newp", buf)
3041
- self.len(1, await core.nodes(f'ps:contact={cont}'))
3042
-
3043
- evnts = await waiter.wait(timeout=4)
3044
- exp = [
3045
- ('core:pkg:onload:complete', {'pkg': 'testload'})
3046
- ]
3047
- self.eq(exp, evnts)
3048
-
3049
2801
  async def test_storm_pkg_onload_active(self):
3050
2802
  pkg = {
3051
2803
  'name': 'testload',
@@ -3294,6 +3046,37 @@ class StormTest(s_t_utils.SynTest):
3294
3046
  await stream.wait(timeout=10)
3295
3047
  self.eq(8, await core.getStormPkgVar('testload', 'testload:version'))
3296
3048
 
3049
+ # init that advances the version
3050
+
3051
+ pkg['version'] = '0.7.0'
3052
+ pkg['inits']['versions'].extend([
3053
+ {
3054
+ 'version': 9,
3055
+ 'name': 'init09',
3056
+ 'query': '''
3057
+ $lib.globals.set(init09, $lib.time.now())
3058
+ $lib.pkg.vars(testload)."testload:version" = (10)
3059
+ ''',
3060
+ },
3061
+ {
3062
+ 'version': 10,
3063
+ 'name': 'init10',
3064
+ 'query': '$lib.globals.set(init10, $lib.time.now())',
3065
+ },
3066
+ {
3067
+ 'version': 11,
3068
+ 'name': 'init11',
3069
+ 'query': '$lib.globals.set(init11, $lib.time.now())',
3070
+ },
3071
+ ])
3072
+
3073
+ await loadPkg(core, pkg)
3074
+
3075
+ self.eq(11, await core.getStormPkgVar('testload', 'testload:version'))
3076
+ self.nn(await core.getStormVar('init09'))
3077
+ self.none(await core.getStormVar('init10'))
3078
+ self.nn(await core.getStormVar('init11'))
3079
+
3297
3080
  async def test_storm_tree(self):
3298
3081
 
3299
3082
  async with self.getTestCore() as core: