synapse 2.204.1__py311-none-any.whl → 2.206.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 (41) hide show
  1. synapse/axon.py +4 -4
  2. synapse/common.py +0 -3
  3. synapse/cortex.py +14 -1
  4. synapse/lib/aha.py +13 -8
  5. synapse/lib/httpapi.py +196 -97
  6. synapse/lib/lmdbslab.py +2 -0
  7. synapse/lib/modelrev.py +3 -3
  8. synapse/lib/schemas.py +11 -0
  9. synapse/lib/spooled.py +2 -1
  10. synapse/lib/stormlib/aha.py +5 -1
  11. synapse/lib/stormlib/model.py +1 -1
  12. synapse/lib/stormtypes.py +10 -0
  13. synapse/lib/version.py +2 -2
  14. synapse/models/base.py +9 -0
  15. synapse/models/economic.py +15 -2
  16. synapse/models/inet.py +9 -1
  17. synapse/models/infotech.py +7 -0
  18. synapse/models/risk.py +2 -0
  19. synapse/models/telco.py +23 -2
  20. synapse/tests/test_axon.py +42 -41
  21. synapse/tests/test_common.py +4 -23
  22. synapse/tests/test_cortex.py +18 -6
  23. synapse/tests/test_lib_aha.py +17 -0
  24. synapse/tests/test_lib_cell.py +5 -3
  25. synapse/tests/test_lib_httpapi.py +225 -33
  26. synapse/tests/test_lib_lmdbslab.py +30 -0
  27. synapse/tests/test_lib_modelrev.py +7 -7
  28. synapse/tests/test_lib_spooled.py +2 -0
  29. synapse/tests/test_lib_stormlib_aha.py +7 -7
  30. synapse/tests/test_lib_stormlib_cortex.py +61 -60
  31. synapse/tests/test_model_economic.py +3 -0
  32. synapse/tests/test_model_infotech.py +2 -0
  33. synapse/tests/test_model_telco.py +7 -2
  34. synapse/tests/utils.py +3 -0
  35. synapse/tools/aha/easycert.py +4 -0
  36. synapse/tools/aha/mirror.py +6 -4
  37. {synapse-2.204.1.dist-info → synapse-2.206.0.dist-info}/METADATA +2 -3
  38. {synapse-2.204.1.dist-info → synapse-2.206.0.dist-info}/RECORD +41 -41
  39. {synapse-2.204.1.dist-info → synapse-2.206.0.dist-info}/WHEEL +1 -1
  40. {synapse-2.204.1.dist-info → synapse-2.206.0.dist-info}/licenses/LICENSE +0 -0
  41. {synapse-2.204.1.dist-info → synapse-2.206.0.dist-info}/top_level.txt +0 -0
@@ -10,6 +10,7 @@ from unittest.mock import patch
10
10
 
11
11
  import synapse.lib.base as s_base
12
12
  import synapse.lib.const as s_const
13
+ import synapse.lib.msgpack as s_msgpack
13
14
  import synapse.lib.lmdbslab as s_lmdbslab
14
15
  import synapse.lib.thisplat as s_thisplat
15
16
 
@@ -1618,6 +1619,35 @@ class LmdbSlabTest(s_t_utils.SynTest):
1618
1619
  subkv2 = subkv1.getSubKeyVal('pref2')
1619
1620
  self.eq(list(subkv2.keys()), ['wow'])
1620
1621
 
1622
+ async def test_lmdbslab_scan_grow(self):
1623
+ with self.getTestDir() as dirn:
1624
+
1625
+ path = os.path.join(dirn, 'test.lmdb')
1626
+
1627
+ mapsize = s_const.kibibyte * 32
1628
+ async with await s_lmdbslab.Slab.anit(path, map_size=mapsize) as slab:
1629
+
1630
+ self.eq(slab.mapsize, mapsize)
1631
+
1632
+ def slabset(key, valu):
1633
+ slab.replace(s_msgpack.en(key), s_msgpack.en(valu))
1634
+
1635
+ def slabitems():
1636
+ for lkey, lval in slab.scanByFull():
1637
+ yield s_msgpack.un(lkey), s_msgpack.un(lval)
1638
+
1639
+ slabset('one', [1, 2, 3])
1640
+ slabset('two', [2, 3, 4])
1641
+
1642
+ seen = set()
1643
+ for key, valu in slabitems():
1644
+ self.notin(key, seen)
1645
+ seen.add(key)
1646
+
1647
+ valu += ('A' * mapsize,)
1648
+ slabset(key, valu)
1649
+
1650
+ self.gt(slab.mapsize, mapsize)
1621
1651
 
1622
1652
  class LmdbSlabMemLockTest(s_t_utils.SynTest):
1623
1653
 
@@ -1630,14 +1630,14 @@ class ModelRevTest(s_tests.SynTest):
1630
1630
  sources: ['008af0047a8350287cde7abe31a7c706', 'a7a4739e0a52674df0fa3a8226de0c3f']
1631
1631
  refs:
1632
1632
  layer: {fork01layr}
1633
- - it:prod:soft:cpe (iden: 9742664e24fe1a3a37d871b1f62af27453c2945b98f421d753db8436e9a44cc9
1634
- - _ext:model:form:cpe (iden: 16e3289346a258c3e3073affad490c1d6ebf1d01295aacc489cdb24658ebc6e7
1635
- - inet:flow:dst:cpes (iden: 7d4c31f1364aaf0b4cfaf4b57bb60157f2e86248391ce8ec75d6b7e3cd5f35b7
1636
- - inet:flow:src:cpes (iden: 7d4c31f1364aaf0b4cfaf4b57bb60157f2e86248391ce8ec75d6b7e3cd5f35b7
1637
- - meta:seen:node (iden: 81973208bc0f5b99250e4cda7889c66e0573c0573bc2a279083d23426ba3c74d
1638
- - meta:seen:node (iden: 85bfc442d87a64a8e75d4ff2831281fb156317767612eef9b75c271ff162c4d9
1633
+ - it:prod:soft:cpe (iden: 9742664e24fe1a3a37d871b1f62af27453c2945b98f421d753db8436e9a44cc9)
1634
+ - _ext:model:form:cpe (iden: 16e3289346a258c3e3073affad490c1d6ebf1d01295aacc489cdb24658ebc6e7)
1635
+ - inet:flow:dst:cpes (iden: 7d4c31f1364aaf0b4cfaf4b57bb60157f2e86248391ce8ec75d6b7e3cd5f35b7)
1636
+ - inet:flow:src:cpes (iden: 7d4c31f1364aaf0b4cfaf4b57bb60157f2e86248391ce8ec75d6b7e3cd5f35b7)
1637
+ - meta:seen:node (iden: 81973208bc0f5b99250e4cda7889c66e0573c0573bc2a279083d23426ba3c74d)
1638
+ - meta:seen:node (iden: 85bfc442d87a64a8e75d4ff2831281fb156317767612eef9b75c271ff162c4d9)
1639
1639
  layer: {fork00layr}
1640
- - risk:vulnerable:node (iden: 5fddf1b5fa06aa8a39a1eb297712cecf9ca146764c4d6e5c79296b9e9978d2c3
1640
+ - risk:vulnerable:node (iden: 5fddf1b5fa06aa8a39a1eb297712cecf9ca146764c4d6e5c79296b9e9978d2c3)
1641
1641
  edges:
1642
1642
  -(refs)> f0315900f365f45f2e027edc66ed8477d8661dad501d51f3ac8067c36565f07c
1643
1643
  <(seen)- 051d93252abe655e43265b89149b6a2d5a8f5f2df33b56c986ab8671c081e394
@@ -125,6 +125,8 @@ class SpooledTest(s_test.SynTest):
125
125
 
126
126
  async with await s_spooled.Dict.anit(size=2) as sd0:
127
127
  await runtest(sd0)
128
+ self.true(sd0.fallback)
128
129
 
129
130
  async with await s_spooled.Dict.anit(size=1000) as sd1:
130
131
  await runtest(sd1)
132
+ self.false(sd1.fallback)
@@ -216,7 +216,7 @@ Connection information:
216
216
 
217
217
  # PeerGenr
218
218
  resp = await core00.callStorm('''
219
- $resps = $lib.list()
219
+ $resps = ()
220
220
  $todo = $lib.utils.todo('getTasks')
221
221
  for ($name, $info) in $lib.aha.callPeerGenr(cell..., $todo) {
222
222
  $resps.append(($name, $info))
@@ -226,7 +226,7 @@ Connection information:
226
226
  self.len(0, resp)
227
227
 
228
228
  resp = await core00.callStorm('''
229
- $resps = $lib.list()
229
+ $resps = ()
230
230
  $todo = $lib.utils.todo('getNexusChanges', (0), wait=(false))
231
231
  for ($name, $info) in $lib.aha.callPeerGenr(cell..., $todo) {
232
232
  $resps.append(($name, $info))
@@ -237,7 +237,7 @@ Connection information:
237
237
 
238
238
  cell00_rid = (await cell00.getCellInfo())['cell']['run']
239
239
  resp = await core00.callStorm('''
240
- $resps = $lib.list()
240
+ $resps = ()
241
241
  $todo = $lib.utils.todo('getNexusChanges', (0), wait=(false))
242
242
  for $info in $lib.aha.callPeerGenr(cell..., $todo, skiprun=$skiprun) {
243
243
  $resps.append($info)
@@ -253,7 +253,7 @@ Connection information:
253
253
 
254
254
  # PeerApi
255
255
  resp = await core00.callStorm('''
256
- $resps = $lib.list()
256
+ $resps = ()
257
257
  $todo = $lib.utils.todo('getCellInfo')
258
258
  for ($name, $info) in $lib.aha.callPeerApi(cell..., $todo) {
259
259
  $resps.append(($name, $info))
@@ -266,7 +266,7 @@ Connection information:
266
266
  self.isinstance(resp[0][1][1], dict)
267
267
 
268
268
  resp = await core00.callStorm('''
269
- $resps = $lib.list()
269
+ $resps = ()
270
270
  $todo = $lib.utils.todo(getCellInfo)
271
271
  for ($name, $info) in $lib.aha.callPeerApi(cell..., $todo) {
272
272
  $resps.append(($name, $info))
@@ -276,7 +276,7 @@ Connection information:
276
276
  self.len(2, resp)
277
277
 
278
278
  resp = await core00.callStorm('''
279
- $resps = $lib.list()
279
+ $resps = ()
280
280
  $todo = $lib.utils.todo(getCellInfo)
281
281
  for ($name, $info) in $lib.aha.callPeerApi(cell..., $todo, skiprun=$skiprun) {
282
282
  $resps.append(($name, $info))
@@ -286,7 +286,7 @@ Connection information:
286
286
  self.len(1, resp)
287
287
 
288
288
  resp = await core00.callStorm('''
289
- $resps = $lib.list()
289
+ $resps = ()
290
290
  $todo = $lib.utils.todo('getCellInfo')
291
291
  for ($name, $info) in $lib.aha.callPeerApi(cell..., $todo, timeout=(10)) {
292
292
  $resps.append(($name, $info))
@@ -1,3 +1,4 @@
1
+ import http
1
2
  import unittest.mock as mock
2
3
 
3
4
  import synapse.exc as s_exc
@@ -106,38 +107,38 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
106
107
 
107
108
  async with self.getHttpSess(auth=('root', 'root'), port=hport) as sess: # type: aiohttp.ClientSession
108
109
  resp = await sess.get(f'https://localhost:{hport}/api/ext/testpath00')
109
- self.eq(resp.status, 200)
110
+ self.eq(resp.status, http.HTTPStatus.OK)
110
111
  data = await resp.json()
111
112
  self.eq(data.get('method'), 'get')
112
113
 
113
114
  resp = await sess.post(f'https://localhost:{hport}/api/ext/testpath00')
114
- self.eq(resp.status, 201)
115
+ self.eq(resp.status, http.HTTPStatus.CREATED)
115
116
  data = await resp.json()
116
117
  self.eq(data.get('method'), 'post')
117
118
 
118
119
  resp = await sess.put(f'https://localhost:{hport}/api/ext/testpath00')
119
- self.eq(resp.status, 202)
120
+ self.eq(resp.status, http.HTTPStatus.ACCEPTED)
120
121
  data = await resp.json()
121
122
  self.eq(data.get('method'), 'put')
122
123
 
123
124
  resp = await sess.patch(f'https://localhost:{hport}/api/ext/testpath00')
124
- self.eq(resp.status, 203)
125
+ self.eq(resp.status, http.HTTPStatus.NON_AUTHORITATIVE_INFORMATION)
125
126
  data = await resp.json()
126
127
  self.eq(data.get('method'), 'patch')
127
128
 
128
129
  resp = await sess.options(f'https://localhost:{hport}/api/ext/testpath00')
129
- self.eq(resp.status, 204)
130
+ self.eq(resp.status, http.HTTPStatus.NO_CONTENT)
130
131
  self.eq(resp.headers.get('Secret-Header'), 'Options')
131
132
  # HTTP 204 code has no response content per rfc9110
132
133
  self.eq(await resp.read(), b'')
133
134
 
134
135
  resp = await sess.delete(f'https://localhost:{hport}/api/ext/testpath00')
135
- self.eq(resp.status, 205)
136
+ self.eq(resp.status, http.HTTPStatus.RESET_CONTENT)
136
137
  data = await resp.json()
137
138
  self.eq(data.get('method'), 'delete')
138
139
 
139
140
  resp = await sess.head(f'https://localhost:{hport}/api/ext/testpath00')
140
- self.eq(resp.status, 206)
141
+ self.eq(resp.status, http.HTTPStatus.PARTIAL_CONTENT)
141
142
  self.eq(resp.headers.get('Secret-Header'), 'Head')
142
143
  self.eq(resp.headers.get('Content-Length'), '13')
143
144
  # HEAD had no body in its response
@@ -174,7 +175,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
174
175
  q = '$api = $lib.cortex.httpapi.get($iden) $api.methods.post = $lib.undef'
175
176
  await core.callStorm(q, opts={'vars': {'iden': testpath00}})
176
177
  resp = await sess.post(f'https://localhost:{hport}/api/ext/testpath00')
177
- self.eq(resp.status, 405)
178
+ self.eq(resp.status, http.HTTPStatus.METHOD_NOT_ALLOWED)
178
179
  self.eq(resp.headers.get('Allowed'), 'GET, PUT, PATCH, OPTIONS, DELETE, HEAD')
179
180
  data = await resp.json()
180
181
  self.eq(data.get('mesg'), f'Extended HTTP API {testpath00} has no method for POST. Supports GET, PUT, PATCH, OPTIONS, DELETE, HEAD.')
@@ -184,13 +185,13 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
184
185
  q = '$api = $lib.cortex.httpapi.get($iden) $api.methods.head = $lib.undef'
185
186
  await core.callStorm(q, opts={'vars': {'iden': testpath00}})
186
187
  resp = await sess.head(f'https://localhost:{hport}/api/ext/testpath00')
187
- self.eq(resp.status, 405)
188
+ self.eq(resp.status, http.HTTPStatus.METHOD_NOT_ALLOWED)
188
189
  self.eq(resp.headers.get('Allowed'), 'GET, PUT, PATCH, OPTIONS, DELETE')
189
190
  self.eq(await resp.read(), b'')
190
191
 
191
192
  # No methods returns a 405 and nothing allowed
192
193
  resp = await sess.get(f'https://localhost:{hport}/api/ext/nomeths')
193
- self.eq(resp.status, 405)
194
+ self.eq(resp.status, http.HTTPStatus.METHOD_NOT_ALLOWED)
194
195
  self.eq(resp.headers.get('Allowed'), '')
195
196
  data = await resp.json()
196
197
  self.eq(data.get('mesg'), f'Extended HTTP API {nomeths} has no method for GET.')
@@ -209,7 +210,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
209
210
  return ( $api.iden )'''
210
211
  testpath01 = await core.callStorm(q)
211
212
  resp = await sess.get(f'https://localhost:{hport}/api/ext/testpath01')
212
- self.eq(resp.status, 200)
213
+ self.eq(resp.status, http.HTTPStatus.OK)
213
214
  data = await resp.json()
214
215
  self.eq(data.get('hehe'), 'haha')
215
216
 
@@ -218,7 +219,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
218
219
  self.stormHasNoWarnErr(msgs)
219
220
 
220
221
  resp = await sess.get(f'https://localhost:{hport}/api/ext/testpath01')
221
- self.eq(resp.status, 404)
222
+ self.eq(resp.status, http.HTTPStatus.NOT_FOUND)
222
223
  data = await resp.json()
223
224
  self.eq(data.get('code'), 'NoSuchPath')
224
225
  self.eq(data.get('mesg'), 'No Extended HTTP API endpoint matches testpath01')
@@ -238,7 +239,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
238
239
  resp = await sess.post(f'https://localhost:{hport}/api/ext/testreply',
239
240
  json={'data': valu}
240
241
  )
241
- self.eq(resp.status, 200)
242
+ self.eq(resp.status, http.HTTPStatus.OK)
242
243
  data = await resp.json()
243
244
  self.eq(data, valu)
244
245
 
@@ -273,7 +274,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
273
274
  resp = await sess.get(url, headers=(('hehe', 'haha'), ('apikey', 'secret'), ('hehe', 'badjoke')),
274
275
  json={'look': 'at this!'},
275
276
  )
276
- self.eq(resp.status, 200)
277
+ self.eq(resp.status, http.HTTPStatus.OK)
277
278
  data = await resp.json()
278
279
  self.eq(data.get('args'), ['sup', ''])
279
280
  self.eq(data.get('echo'), True)
@@ -290,7 +291,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
290
291
  resp = await sess.get(url, headers=(('hehe', 'haha'), ('apikey', 'secret'), ('hehe', 'badjoke')),
291
292
  data=b'hehe',
292
293
  )
293
- self.eq(resp.status, 200)
294
+ self.eq(resp.status, http.HTTPStatus.OK)
294
295
  data = await resp.json()
295
296
  self.eq(data.get('args'), ['words', 'wOw'])
296
297
  self.eq(data.get('json'), 'err')
@@ -300,7 +301,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
300
301
  core.stormlog = True
301
302
  with self.getStructuredAsyncLoggerStream('synapse.storm', 'Executing storm query') as stream:
302
303
  resp = await sess.get(url)
303
- self.eq(resp.status, 200)
304
+ self.eq(resp.status, http.HTTPStatus.OK)
304
305
  self.true(await stream.wait(timeout=12))
305
306
  msgs = stream.jsonlines()
306
307
  self.eq(msgs[0].get('httpapi'), echoiden)
@@ -313,7 +314,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
313
314
  testpath02 = await core.callStorm(q)
314
315
 
315
316
  resp = await sess.get(f'https://localhost:{hport}/api/ext/testpath02')
316
- self.eq(resp.status, 500)
317
+ self.eq(resp.status, http.HTTPStatus.INTERNAL_SERVER_ERROR)
317
318
  data = await resp.json()
318
319
  self.eq(data.get('code'), 'BadArg')
319
320
  self.eq(data.get('mesg'), 'HTTP Response headers must be a dictionary, got str.')
@@ -324,7 +325,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
324
325
  testpath03 = await core.callStorm(q)
325
326
 
326
327
  resp = await sess.get(f'https://localhost:{hport}/api/ext/testpath03')
327
- self.eq(resp.status, 500)
328
+ self.eq(resp.status, http.HTTPStatus.INTERNAL_SERVER_ERROR)
328
329
  data = await resp.json()
329
330
  self.eq(data.get('code'), 'BadArg')
330
331
  self.eq(data.get('mesg'), 'HTTP Response body must be bytes, got str.')
@@ -337,7 +338,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
337
338
  emsg = f'Error executing custom HTTP API {test04}: BadArg Response.reply() has already been called.'
338
339
  with self.getAsyncLoggerStream('synapse.lib.httpapi', emsg) as stream:
339
340
  resp = await sess.get(f'https://localhost:{hport}/api/ext/testpath04')
340
- self.eq(resp.status, 200)
341
+ self.eq(resp.status, http.HTTPStatus.OK)
341
342
  self.eq(await resp.json(), {'hehe': 'yes!'})
342
343
 
343
344
  async def test_libcortex_httpapi_runas_owner(self):
@@ -360,7 +361,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
360
361
 
361
362
  async with self.getHttpSess(auth=('root', 'root'), port=hport) as sess: # type: aiohttp.ClientSession
362
363
  resp = await sess.get(f'https://localhost:{hport}/api/ext/testpath00')
363
- self.eq(resp.status, 200)
364
+ self.eq(resp.status, http.HTTPStatus.OK)
364
365
  data = await resp.json()
365
366
  self.eq(data.get('username'), 'root')
366
367
 
@@ -371,7 +372,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
371
372
  self.eq(name, 'lowuser')
372
373
 
373
374
  resp = await sess.get(f'https://localhost:{hport}/api/ext/testpath00')
374
- self.eq(resp.status, 200)
375
+ self.eq(resp.status, http.HTTPStatus.OK)
375
376
  data = await resp.json()
376
377
  self.eq(data.get('username'), 'lowuser')
377
378
 
@@ -383,13 +384,13 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
383
384
  self.eq(name, 'user')
384
385
 
385
386
  resp = await sess.get(f'https://localhost:{hport}/api/ext/testpath00')
386
- self.eq(resp.status, 200)
387
+ self.eq(resp.status, http.HTTPStatus.OK)
387
388
  data = await resp.json()
388
389
  self.eq(data.get('username'), 'root')
389
390
 
390
391
  async with self.getHttpSess(auth=('lowuser', 'secret'), port=hport) as sess: # type: aiohttp.ClientSession
391
392
  resp = await sess.get(f'https://localhost:{hport}/api/ext/testpath00')
392
- self.eq(resp.status, 200)
393
+ self.eq(resp.status, http.HTTPStatus.OK)
393
394
  data = await resp.json()
394
395
  self.eq(data.get('username'), 'lowuser')
395
396
 
@@ -566,7 +567,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
566
567
 
567
568
  # The paths are matched in case sensitive manner. The current regex fails to match.
568
569
  resp = await sess.get(f'https://localhost:{hport}/api/ext/hehe/OhMy1234')
569
- self.eq(resp.status, 404)
570
+ self.eq(resp.status, http.HTTPStatus.NOT_FOUND)
570
571
 
571
572
  q = "$api=$lib.cortex.httpapi.get($iden) $api.path='hehe/([A-Za-z0-9]*)' "
572
573
  await core.callStorm(q, opts={'vars': {'iden': iden0}})
@@ -714,14 +715,14 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
714
715
 
715
716
  async with self.getHttpSess(auth=('root', 'root'), port=hport) as sess:
716
717
  resp = await sess.get(f'https://localhost:{hport}/api/ext/auth')
717
- self.eq(resp.status, 200)
718
+ self.eq(resp.status, http.HTTPStatus.OK)
718
719
  data = await resp.json()
719
720
  self.eq(data.get('username'), 'root')
720
721
  self.eq(data.get('user'), root)
721
722
 
722
723
  async with self.getHttpSess() as sess:
723
724
  resp = await sess.get(f'https://localhost:{hport}/api/ext/auth')
724
- self.eq(resp.status, 401)
725
+ self.eq(resp.status, http.HTTPStatus.UNAUTHORIZED)
725
726
  data = await resp.json()
726
727
  self.eq(data.get('code'), 'NotAuthenticated')
727
728
 
@@ -730,7 +731,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
730
731
  self.stormHasNoWarnErr(msgs)
731
732
 
732
733
  resp = await sess.get(f'https://localhost:{hport}/api/ext/auth')
733
- self.eq(resp.status, 200)
734
+ self.eq(resp.status, http.HTTPStatus.OK)
734
735
  data = await resp.json()
735
736
  self.eq(data.get('username'), 'root')
736
737
  self.eq(data.get('user'), '')
@@ -741,7 +742,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
741
742
  self.stormHasNoWarnErr(msgs)
742
743
 
743
744
  resp = await sess.get(f'https://localhost:{hport}/api/ext/auth')
744
- self.eq(resp.status, 200)
745
+ self.eq(resp.status, http.HTTPStatus.OK)
745
746
  data = await resp.json()
746
747
  self.eq(data.get('username'), 'root')
747
748
  self.eq(data.get('user'), '')
@@ -750,7 +751,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
750
751
  # indicates who the requester's user iden is.
751
752
  async with self.getHttpSess(auth=('lowuser', 'secret'), port=hport) as sess:
752
753
  resp = await sess.get(f'https://localhost:{hport}/api/ext/auth')
753
- self.eq(resp.status, 200)
754
+ self.eq(resp.status, http.HTTPStatus.OK)
754
755
  data = await resp.json()
755
756
  self.eq(data.get('username'), 'root')
756
757
  self.eq(data.get('user'), '')
@@ -760,7 +761,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
760
761
  self.stormHasNoWarnErr(msgs)
761
762
 
762
763
  resp = await sess.get(f'https://localhost:{hport}/api/ext/auth')
763
- self.eq(resp.status, 200)
764
+ self.eq(resp.status, http.HTTPStatus.OK)
764
765
  data = await resp.json()
765
766
  self.eq(data.get('username'), 'lowuser')
766
767
  self.eq(data.get('user'), lowuser)
@@ -770,7 +771,7 @@ $request.reply(206, headers=$headers, body=({"no":"body"}))
770
771
  self.stormHasNoWarnErr(msgs)
771
772
 
772
773
  resp = await sess.get(f'https://localhost:{hport}/api/ext/auth')
773
- self.eq(resp.status, 200)
774
+ self.eq(resp.status, http.HTTPStatus.OK)
774
775
  data = await resp.json()
775
776
  self.eq(data.get('username'), 'root')
776
777
  self.eq(data.get('user'), lowuser)
@@ -800,7 +801,7 @@ $request.reply(200, headers=$headers, body=$body)
800
801
 
801
802
  async with self.getHttpSess(auth=('root', 'root'), port=hport) as sess:
802
803
  resp = await sess.get(f'https://localhost:{hport}/api/ext/raw')
803
- self.eq(resp.status, 200)
804
+ self.eq(resp.status, http.HTTPStatus.OK)
804
805
  self.eq(resp.headers.get('Content-Type'), 'application/json')
805
806
  self.eq(resp.headers.get('Content-Length'), '11')
806
807
  self.eq(resp.headers.get('Secret-Header'), 'OhBoy!')
@@ -833,7 +834,7 @@ for $i in $values {
833
834
 
834
835
  async with self.getHttpSess(auth=('root', 'root'), port=hport) as sess:
835
836
  resp = await sess.get(f'https://localhost:{hport}/api/ext/jsonlines')
836
- self.eq(resp.status, 200)
837
+ self.eq(resp.status, http.HTTPStatus.OK)
837
838
  self.eq(resp.headers.get('Content-Type'), 'text/plain; charset=utf8')
838
839
 
839
840
  msgs = []
@@ -901,19 +902,19 @@ for $i in $values {
901
902
 
902
903
  async with self.getHttpSess(auth=('lowuser', 'secret'), port=hport) as sess:
903
904
  resp = await sess.get(f'https://localhost:{hport}/api/ext/hehe/haha')
904
- self.eq(resp.status, 403)
905
+ self.eq(resp.status, http.HTTPStatus.FORBIDDEN)
905
906
  data = await resp.json()
906
907
  self.eq(data.get('mesg'), 'User (lowuser) must have permission foocorp.http.user')
907
908
 
908
909
  await core.stormlist('auth.user.addrule lowuser foocorp.http.user')
909
910
 
910
911
  resp = await sess.get(f'https://localhost:{hport}/api/ext/hehe/haha')
911
- self.eq(resp.status, 200)
912
+ self.eq(resp.status, http.HTTPStatus.OK)
912
913
  data = await resp.json()
913
914
  self.eq(data.get('path'), 'hehe/haha')
914
915
 
915
916
  resp = await sess.get(f'https://localhost:{hport}/api/ext/weee')
916
- self.eq(resp.status, 200)
917
+ self.eq(resp.status, http.HTTPStatus.OK)
917
918
  data = await resp.json()
918
919
  self.eq(data.get('path'), 'weee')
919
920
 
@@ -921,7 +922,7 @@ for $i in $values {
921
922
  await core.stormlist('auth.user.addrule lowuser "!apiuser"')
922
923
 
923
924
  resp = await sess.get(f'https://localhost:{hport}/api/ext/weee')
924
- self.eq(resp.status, 403)
925
+ self.eq(resp.status, http.HTTPStatus.FORBIDDEN)
925
926
  data = await resp.json()
926
927
  self.eq(data.get('mesg'), 'User (lowuser) is denied the permission apiuser')
927
928
 
@@ -1048,7 +1049,7 @@ for $i in $values {
1048
1049
  opts={'vars': {'http_iden': iden}})
1049
1050
 
1050
1051
  resp = await sess.get(f'https://localhost:{hport}/api/ext/testpath')
1051
- self.eq(resp.status, 500)
1052
+ self.eq(resp.status, http.HTTPStatus.INTERNAL_SERVER_ERROR)
1052
1053
  data = await resp.json()
1053
1054
  self.eq(data.get('code'), 'NoSuchView')
1054
1055
 
@@ -1101,7 +1102,7 @@ for $i in $values {
1101
1102
  headers=(('secret-KEY', 'myluggagecombination'), ('aaa', 'zzz'), ('aaa', 'wtaf')),
1102
1103
  params=(('hehe', 'haha'), ('wow', 'words'), ('hehe', 'badjoke'), ('HeHe', ':)'))
1103
1104
  )
1104
- self.eq(resp.status, 200)
1105
+ self.eq(resp.status, http.HTTPStatus.OK)
1105
1106
  data = await resp.json()
1106
1107
 
1107
1108
  # Params are flattened and case-sensitive upon access
@@ -1114,13 +1115,13 @@ for $i in $values {
1114
1115
  self.eq(data.get('secret-key'), 'myluggagecombination')
1115
1116
 
1116
1117
  resp = await sess.post(f'https://localhost:{hport}/api/ext/testpath')
1117
- self.eq(resp.status, 500)
1118
+ self.eq(resp.status, http.HTTPStatus.INTERNAL_SERVER_ERROR)
1118
1119
  data = await resp.json()
1119
1120
  self.eq(data.get('code'), 'StormRuntimeError')
1120
1121
  self.eq(data.get('mesg'), 'http:api:request:headers may not be modified by the runtime.')
1121
1122
 
1122
1123
  resp = await sess.post(f'https://localhost:{hport}/api/ext/testpath', headers={'dictmethod': '1'})
1123
- self.eq(resp.status, 500)
1124
+ self.eq(resp.status, http.HTTPStatus.INTERNAL_SERVER_ERROR)
1124
1125
  data = await resp.json()
1125
1126
  self.eq(data.get('code'), 'StormRuntimeError')
1126
1127
  self.eq(data.get('mesg'), 'http:api:request:headers may not be modified by the runtime.')
@@ -1171,7 +1172,7 @@ for $i in $values {
1171
1172
  msgs = await core.stormlist(q, opts={'vars': {'iden': iden}})
1172
1173
  self.stormHasNoWarnErr(msgs)
1173
1174
  resp = await sess.post(f'https://localhost:{hport}/api/ext/testpath', )
1174
- self.eq(resp.status, 500)
1175
+ self.eq(resp.status, http.HTTPStatus.INTERNAL_SERVER_ERROR)
1175
1176
  data = await resp.json()
1176
1177
  self.eq(data.get('code'), 'NoSuchVar')
1177
1178
  self.eq(data.get('mesg'), 'Missing variable: sup')
@@ -1218,7 +1219,7 @@ for $i in $values {
1218
1219
 
1219
1220
  async with self.getHttpSess(auth=('root', 'root'), port=hport) as sess:
1220
1221
  resp = await sess.get(f'https://localhost:{hport}/api/ext/testpath?asn=0')
1221
- self.eq(resp.status, 200)
1222
+ self.eq(resp.status, http.HTTPStatus.OK)
1222
1223
  data = await resp.json()
1223
1224
  self.eq(data, 0)
1224
1225
 
@@ -1227,7 +1228,7 @@ for $i in $values {
1227
1228
  self.stormHasNoWarnErr(msgs)
1228
1229
 
1229
1230
  resp = await sess.get(f'https://localhost:{hport}/api/ext/testpath?asn=1')
1230
- self.eq(resp.status, 500)
1231
+ self.eq(resp.status, http.HTTPStatus.INTERNAL_SERVER_ERROR)
1231
1232
  data = await resp.json()
1232
1233
  self.eq(data.get('code'), 'IsReadOnly')
1233
1234
 
@@ -1237,7 +1238,7 @@ for $i in $values {
1237
1238
  self.stormHasNoWarnErr(msgs)
1238
1239
 
1239
1240
  resp = await sess.get(f'https://localhost:{hport}/api/ext/testpath?asn=0')
1240
- self.eq(resp.status, 200)
1241
+ self.eq(resp.status, http.HTTPStatus.OK)
1241
1242
  data = await resp.json()
1242
1243
  self.eq(data, 0)
1243
1244
 
@@ -1301,20 +1302,20 @@ for $i in $values {
1301
1302
 
1302
1303
  async with self.getHttpSess(auth=('root', 'root'), port=hport) as sess:
1303
1304
  resp = await sess.get(f'https://localhost:{hport}/api/ext/bad00')
1304
- self.eq(resp.status, 500)
1305
+ self.eq(resp.status, http.HTTPStatus.INTERNAL_SERVER_ERROR)
1305
1306
  data = await resp.json()
1306
1307
  self.eq(data.get('code'), 'StormRuntimeError')
1307
1308
  self.eq(data.get('mesg'), f'Extended HTTP API {iden00} never set status code.')
1308
1309
 
1309
1310
  resp = await sess.get(f'https://localhost:{hport}/api/ext/bad01')
1310
- self.eq(resp.status, 500)
1311
+ self.eq(resp.status, http.HTTPStatus.INTERNAL_SERVER_ERROR)
1311
1312
  data = await resp.json()
1312
1313
  self.notin('oh', resp.headers)
1313
1314
  self.eq(data.get('code'), 'StormRuntimeError')
1314
1315
  self.eq(data.get('mesg'), f'Extended HTTP API {iden01} never set status code.')
1315
1316
 
1316
1317
  resp = await sess.get(f'https://localhost:{hport}/api/ext/bad02')
1317
- self.eq(resp.status, 500)
1318
+ self.eq(resp.status, http.HTTPStatus.INTERNAL_SERVER_ERROR)
1318
1319
  data = await resp.json()
1319
1320
  self.notin('oh', resp.headers)
1320
1321
  self.eq(data.get('code'), 'StormRuntimeError')
@@ -1325,18 +1326,18 @@ for $i in $values {
1325
1326
 
1326
1327
  resp = await sess.get(f'https://localhost:{hport}/api/ext/bad03')
1327
1328
  self.true(await stream.wait(timeout=6))
1328
- self.eq(resp.status, 201)
1329
+ self.eq(resp.status, http.HTTPStatus.CREATED)
1329
1330
  self.eq(await resp.read(), b'text')
1330
1331
 
1331
1332
  with self.getAsyncLoggerStream('synapse.lib.httpapi',
1332
1333
  f'Extended HTTP API {iden04} tried to set headers after sending body.') as stream:
1333
1334
  resp = await sess.get(f'https://localhost:{hport}/api/ext/bad04')
1334
1335
  self.true(await stream.wait(timeout=6))
1335
- self.eq(resp.status, 200)
1336
+ self.eq(resp.status, http.HTTPStatus.OK)
1336
1337
  self.eq(await resp.read(), b'text')
1337
1338
 
1338
1339
  resp = await sess.get(f'https://localhost:{hport}/api/ext/bad05')
1339
- self.eq(resp.status, 500)
1340
+ self.eq(resp.status, http.HTTPStatus.INTERNAL_SERVER_ERROR)
1340
1341
  data = await resp.json()
1341
1342
  self.eq(data.get('code'), 'BadTypeValu')
1342
1343
  self.eq(data.get('mesg'), "invalid literal for int() with base 0: 'notAnInt'")
@@ -1345,14 +1346,14 @@ for $i in $values {
1345
1346
  f'Error executing Extended HTTP API {iden06}: BadTypeValu') as stream:
1346
1347
  resp = await sess.get(f'https://localhost:{hport}/api/ext/bad06')
1347
1348
  self.true(await stream.wait(timeout=6))
1348
- self.eq(resp.status, 201)
1349
+ self.eq(resp.status, http.HTTPStatus.CREATED)
1349
1350
  self.eq(await resp.json(), {})
1350
1351
 
1351
1352
  with self.getAsyncLoggerStream('synapse.lib.httpapi',
1352
1353
  f'Error executing Extended HTTP API {iden07}: StormRuntimeError') as stream:
1353
1354
  resp = await sess.get(f'https://localhost:{hport}/api/ext/bad07')
1354
1355
  self.true(await stream.wait(timeout=6))
1355
- self.eq(resp.status, 500)
1356
+ self.eq(resp.status, http.HTTPStatus.INTERNAL_SERVER_ERROR)
1356
1357
  data = await resp.json()
1357
1358
  self.eq(data.get('code'), 'StormRuntimeError')
1358
1359
  self.isin('Failed to decode request body as JSON', data.get('mesg'))
@@ -1395,20 +1396,20 @@ for $i in $values {
1395
1396
 
1396
1397
  async with self.getHttpSess(auth=('root', 'root'), port=hport) as sess:
1397
1398
  resp = await sess.get(f'https://localhost:{hport}/api/ext/dyn00') # type: aiohttp.ClientResponse
1398
- self.eq(resp.status, 200)
1399
+ self.eq(resp.status, http.HTTPStatus.OK)
1399
1400
  self.eq(resp.url.path, '/api/ext/redir01')
1400
1401
  self.len(3, resp.history)
1401
1402
  data = await resp.json()
1402
1403
  self.eq(data, {'end': 'youMadeIt', 'melt': False})
1403
1404
 
1404
1405
  resp = await sess.get(f'https://localhost:{hport}/api/ext/dyn00') # type: aiohttp.ClientResponse
1405
- self.eq(resp.status, 200)
1406
+ self.eq(resp.status, http.HTTPStatus.OK)
1406
1407
  self.len(3, resp.history)
1407
1408
  data = await resp.json()
1408
1409
  self.eq(data, {'end': 'youMadeIt', 'melt': True})
1409
1410
 
1410
1411
  resp = await sess.get(f'https://localhost:{hport}/api/ext/dyn00') # type: aiohttp.ClientResponse
1411
- self.eq(resp.status, 404)
1412
+ self.eq(resp.status, http.HTTPStatus.NOT_FOUND)
1412
1413
  data = await resp.json()
1413
1414
  self.eq(data.get('code'), 'NoSuchPath')
1414
1415
 
@@ -1429,7 +1430,7 @@ for $i in $values {
1429
1430
 
1430
1431
  async with self.getHttpSess(auth=('root', 'root'), port=hport) as sess:
1431
1432
  resp = await sess.get(f'https://localhost:{hport}/api/ext/stuff') # type: aiohttp.ClientResponse
1432
- self.eq(resp.status, 200)
1433
+ self.eq(resp.status, http.HTTPStatus.OK)
1433
1434
  self.eq(resp.headers.get('Weee'), 'valu')
1434
1435
  self.eq(resp.headers.get('Key1'), 'Valu1')
1435
1436
  # general default synapse headers are not present
@@ -1463,7 +1464,7 @@ for $i in $values {
1463
1464
  with mock.patch('synapse.cortex.Cortex.storm', new=storm) as patch:
1464
1465
  async with self.getHttpSess(auth=('root', 'root'), port=hport) as sess:
1465
1466
  resp = await sess.get(f'https://localhost:{hport}/api/ext/stuff') # type: aiohttp.ClientResponse
1466
- self.eq(resp.status, 200)
1467
+ self.eq(resp.status, http.HTTPStatus.OK)
1467
1468
  self.false(data['opts'].get('mirror'))
1468
1469
  data.clear()
1469
1470
 
@@ -1472,7 +1473,7 @@ for $i in $values {
1472
1473
  self.true(adef.get('pool'))
1473
1474
 
1474
1475
  resp = await sess.get(f'https://localhost:{hport}/api/ext/stuff') # type: aiohttp.ClientResponse
1475
- self.eq(resp.status, 200)
1476
+ self.eq(resp.status, http.HTTPStatus.OK)
1476
1477
  self.true(data['opts'].get('mirror'))
1477
1478
  data.clear()
1478
1479
 
@@ -1481,6 +1482,6 @@ for $i in $values {
1481
1482
  self.false(adef.get('pool'))
1482
1483
 
1483
1484
  resp = await sess.get(f'https://localhost:{hport}/api/ext/stuff') # type: aiohttp.ClientResponse
1484
- self.eq(resp.status, 200)
1485
+ self.eq(resp.status, http.HTTPStatus.OK)
1485
1486
  self.false(data['opts'].get('mirror'))
1486
1487
  data.clear()