synapse 2.205.0__py311-none-any.whl → 2.207.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 (38) hide show
  1. synapse/axon.py +8 -8
  2. synapse/cortex.py +14 -1
  3. synapse/lib/aha.py +13 -8
  4. synapse/lib/httpapi.py +196 -97
  5. synapse/lib/lmdbslab.py +2 -0
  6. synapse/lib/modelrev.py +3 -3
  7. synapse/lib/schemas.py +11 -0
  8. synapse/lib/spooled.py +2 -1
  9. synapse/lib/stormhttp.py +6 -6
  10. synapse/lib/stormlib/aha.py +5 -1
  11. synapse/lib/stormlib/model.py +1 -1
  12. synapse/lib/stormtypes.py +53 -17
  13. synapse/lib/version.py +2 -2
  14. synapse/models/base.py +9 -0
  15. synapse/models/inet.py +9 -1
  16. synapse/models/infotech.py +5 -0
  17. synapse/models/telco.py +10 -0
  18. synapse/tests/test_axon.py +52 -41
  19. synapse/tests/test_cortex.py +18 -6
  20. synapse/tests/test_lib_aha.py +17 -0
  21. synapse/tests/test_lib_cell.py +5 -3
  22. synapse/tests/test_lib_httpapi.py +225 -33
  23. synapse/tests/test_lib_lmdbslab.py +30 -0
  24. synapse/tests/test_lib_modelrev.py +7 -7
  25. synapse/tests/test_lib_spooled.py +2 -0
  26. synapse/tests/test_lib_stormhttp.py +13 -0
  27. synapse/tests/test_lib_stormlib_aha.py +7 -7
  28. synapse/tests/test_lib_stormlib_cortex.py +61 -60
  29. synapse/tests/test_lib_stormtypes.py +8 -0
  30. synapse/tests/test_model_infotech.py +2 -0
  31. synapse/tests/test_model_telco.py +4 -1
  32. synapse/tools/aha/easycert.py +4 -0
  33. synapse/tools/aha/mirror.py +6 -4
  34. {synapse-2.205.0.dist-info → synapse-2.207.0.dist-info}/METADATA +1 -1
  35. {synapse-2.205.0.dist-info → synapse-2.207.0.dist-info}/RECORD +38 -38
  36. {synapse-2.205.0.dist-info → synapse-2.207.0.dist-info}/WHEEL +0 -0
  37. {synapse-2.205.0.dist-info → synapse-2.207.0.dist-info}/licenses/LICENSE +0 -0
  38. {synapse-2.205.0.dist-info → synapse-2.207.0.dist-info}/top_level.txt +0 -0
@@ -1,7 +1,7 @@
1
1
  import io
2
2
  import os
3
3
  import csv
4
- import sys
4
+ import http
5
5
  import base64
6
6
  import shutil
7
7
  import struct
@@ -19,6 +19,7 @@ import synapse.common as s_common
19
19
  import synapse.telepath as s_telepath
20
20
 
21
21
  import synapse.lib.coro as s_coro
22
+ import synapse.lib.json as s_json
22
23
  import synapse.lib.certdir as s_certdir
23
24
  import synapse.lib.httpapi as s_httpapi
24
25
  import synapse.lib.msgpack as s_msgpack
@@ -573,14 +574,14 @@ bar baz",vv
573
574
  # No auth - coverage
574
575
  async with self.getHttpSess() as sess:
575
576
  async with sess.get(f'{url_dl}/foobar') as resp:
576
- self.eq(401, resp.status)
577
+ self.eq(resp.status, http.HTTPStatus.UNAUTHORIZED)
577
578
  info = await resp.json()
578
579
  self.eq('NotAuthenticated', info.get('code'))
579
580
  async with sess.head(f'{url_dl}/foobar') as resp:
580
- self.eq(401, resp.status)
581
+ self.eq(resp.status, http.HTTPStatus.UNAUTHORIZED)
581
582
  # aiohttp ignores HEAD bodies
582
583
  async with sess.delete(f'{url_dl}/foobar') as resp:
583
- self.eq(401, resp.status)
584
+ self.eq(resp.status, http.HTTPStatus.UNAUTHORIZED)
584
585
  info = await resp.json()
585
586
  self.eq('NotAuthenticated', info.get('code'))
586
587
 
@@ -588,31 +589,31 @@ bar baz",vv
588
589
  async with self.getHttpSess(auth=('newb', 'secret'), port=port) as sess:
589
590
 
590
591
  async with sess.get(f'{url_dl}/{asdfhash_h}') as resp:
591
- self.eq(403, resp.status)
592
+ self.eq(resp.status, http.HTTPStatus.FORBIDDEN)
592
593
  item = await resp.json()
593
594
  self.eq('err', item.get('status'))
594
595
 
595
596
  async with sess.delete(f'{url_dl}/{asdfhash_h}') as resp:
596
- self.eq(403, resp.status)
597
+ self.eq(resp.status, http.HTTPStatus.FORBIDDEN)
597
598
  item = await resp.json()
598
599
  self.eq('err', item.get('status'))
599
600
 
600
601
  async with sess.get(f'{url_hs}/{asdfhash_h}') as resp:
601
- self.eq(403, resp.status)
602
+ self.eq(resp.status, http.HTTPStatus.FORBIDDEN)
602
603
  item = await resp.json()
603
604
  self.eq('err', item.get('status'))
604
605
 
605
606
  async with sess.head(f'{url_dl}/{asdfhash_h}') as resp:
606
- self.eq(403, resp.status)
607
+ self.eq(resp.status, http.HTTPStatus.FORBIDDEN)
607
608
  item = await resp.json()
608
609
 
609
610
  async with sess.post(url_de) as resp:
610
- self.eq(403, resp.status)
611
+ self.eq(resp.status, http.HTTPStatus.FORBIDDEN)
611
612
  item = await resp.json()
612
613
  self.eq('err', item.get('status'))
613
614
 
614
615
  async with sess.post(url_ul, data=abuf) as resp:
615
- self.eq(403, resp.status)
616
+ self.eq(resp.status, http.HTTPStatus.FORBIDDEN)
616
617
  item = await resp.json()
617
618
  self.eq('err', item.get('status'))
618
619
 
@@ -631,27 +632,27 @@ bar baz",vv
631
632
  # Basic
632
633
  async with self.getHttpSess(auth=('newb', 'secret'), port=port) as sess:
633
634
  async with sess.get(f'{url_dl}/foobar') as resp:
634
- self.eq(404, resp.status)
635
+ self.eq(resp.status, http.HTTPStatus.NOT_FOUND)
635
636
  info = await resp.json()
636
637
  self.eq('err', info.get('status'))
637
638
  self.eq('BadArg', info.get('code'))
638
639
  self.eq('Hash is not a SHA-256: foobar', info.get('mesg'))
639
640
 
640
641
  async with sess.get(f'{url_dl}/{asdfhash_h}') as resp:
641
- self.eq(404, resp.status)
642
+ self.eq(resp.status, http.HTTPStatus.NOT_FOUND)
642
643
  info = await resp.json()
643
644
  self.eq('err', info.get('status'))
644
645
  self.eq('NoSuchFile', info.get('code'))
645
646
  self.eq(f'SHA-256 not found: {asdfhash_h}', info.get('mesg'))
646
647
 
647
648
  async with sess.get(f'{url_hs}/{asdfhash_h}') as resp:
648
- self.eq(200, resp.status)
649
+ self.eq(resp.status, http.HTTPStatus.OK)
649
650
  item = await resp.json()
650
651
  self.eq('ok', item.get('status'))
651
652
  self.false(item.get('result'))
652
653
 
653
654
  async with sess.post(url_ul, data=abuf) as resp:
654
- self.eq(200, resp.status)
655
+ self.eq(resp.status, http.HTTPStatus.OK)
655
656
  item = await resp.json()
656
657
  self.eq('ok', item.get('status'))
657
658
  result = item.get('result')
@@ -661,13 +662,13 @@ bar baz",vv
661
662
  self.true(await realaxon.has(asdfhash))
662
663
 
663
664
  async with sess.get(f'{url_hs}/{asdfhash_h}') as resp:
664
- self.eq(200, resp.status)
665
+ self.eq(resp.status, http.HTTPStatus.OK)
665
666
  item = await resp.json()
666
667
  self.eq('ok', item.get('status'))
667
668
  self.true(item.get('result'))
668
669
 
669
670
  async with sess.put(url_ul, data=abuf) as resp:
670
- self.eq(200, resp.status)
671
+ self.eq(resp.status, http.HTTPStatus.OK)
671
672
  item = await resp.json()
672
673
  self.eq('ok', item.get('status'))
673
674
  result = item.get('result')
@@ -676,14 +677,14 @@ bar baz",vv
676
677
  self.true(await realaxon.has(asdfhash))
677
678
 
678
679
  async with sess.get(f'{url_dl}/{asdfhash_h}') as resp:
679
- self.eq(200, resp.status)
680
+ self.eq(resp.status, http.HTTPStatus.OK)
680
681
  self.eq(abuf, await resp.read())
681
682
 
682
683
  # Streaming upload
683
684
  byts = io.BytesIO(bbuf)
684
685
 
685
686
  async with sess.post(url_ul, data=byts) as resp:
686
- self.eq(200, resp.status)
687
+ self.eq(resp.status, http.HTTPStatus.OK)
687
688
  item = await resp.json()
688
689
  self.eq('ok', item.get('status'))
689
690
  result = item.get('result')
@@ -694,7 +695,7 @@ bar baz",vv
694
695
  byts = io.BytesIO(bbuf)
695
696
 
696
697
  async with sess.put(url_ul, data=byts) as resp:
697
- self.eq(200, resp.status)
698
+ self.eq(resp.status, http.HTTPStatus.OK)
698
699
  item = await resp.json()
699
700
  self.eq('ok', item.get('status'))
700
701
  result = item.get('result')
@@ -705,7 +706,7 @@ bar baz",vv
705
706
  byts = io.BytesIO(b'')
706
707
 
707
708
  async with sess.post(url_ul, data=byts) as resp:
708
- self.eq(200, resp.status)
709
+ self.eq(resp.status, http.HTTPStatus.OK)
709
710
  item = await resp.json()
710
711
  self.eq('ok', item.get('status'))
711
712
  result = item.get('result')
@@ -715,7 +716,7 @@ bar baz",vv
715
716
 
716
717
  # Streaming download
717
718
  async with sess.get(f'{url_dl}/{bbufhash_h}') as resp:
718
- self.eq(200, resp.status)
719
+ self.eq(resp.status, http.HTTPStatus.OK)
719
720
 
720
721
  byts = []
721
722
  async for bytz in resp.content.iter_chunked(1024):
@@ -726,44 +727,44 @@ bar baz",vv
726
727
 
727
728
  # HEAD
728
729
  async with sess.head(f'{url_dl}/{bbufhash_h}') as resp:
729
- self.eq(200, resp.status)
730
+ self.eq(resp.status, http.HTTPStatus.OK)
730
731
  self.eq('33554437', resp.headers.get('content-length'))
731
732
  self.none(resp.headers.get('content-range'))
732
733
 
733
734
  async with sess.head(f'{url_dl}/foobar') as resp:
734
- self.eq(404, resp.status)
735
+ self.eq(resp.status, http.HTTPStatus.NOT_FOUND)
735
736
  self.eq('0', resp.headers.get('content-length'))
736
737
 
737
738
  # DELETE method by sha256
738
739
  async with sess.delete(f'{url_dl}/foobar') as resp:
739
- self.eq(404, resp.status)
740
+ self.eq(resp.status, http.HTTPStatus.NOT_FOUND)
740
741
  info = await resp.json()
741
742
  self.eq('err', info.get('status'))
742
743
  self.eq('BadArg', info.get('code'))
743
744
  self.eq('Hash is not a SHA-256: foobar', info.get('mesg'))
744
745
 
745
746
  async with sess.delete(f'{url_dl}/{asdfhash_h}') as resp:
746
- self.eq(200, resp.status)
747
+ self.eq(resp.status, http.HTTPStatus.OK)
747
748
  item = await resp.json()
748
749
  self.eq('ok', item.get('status'))
749
750
  self.true(item.get('result'))
750
751
 
751
752
  async with sess.delete(f'{url_dl}/{asdfhash_h}') as resp:
752
- self.eq(404, resp.status)
753
+ self.eq(resp.status, http.HTTPStatus.NOT_FOUND)
753
754
  item = await resp.json()
754
755
  self.eq('err', item.get('status'))
755
756
 
756
757
  # test /api/v1/axon/file/del API
757
758
  data = {'sha256s': (asdfhash_h, asdfhash_h)}
758
759
  async with sess.post(url_de, json=data) as resp:
759
- self.eq(200, resp.status)
760
+ self.eq(resp.status, http.HTTPStatus.OK)
760
761
  item = await resp.json()
761
762
  self.eq('ok', item.get('status'))
762
763
  self.eq(((asdfhash_h, False), (asdfhash_h, False)), item.get('result'))
763
764
 
764
765
  data = {'newp': 'newp'}
765
766
  async with sess.post(url_de, json=data) as resp:
766
- self.eq(200, resp.status)
767
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
767
768
  item = await resp.json()
768
769
  self.eq('err', item.get('status'))
769
770
  self.eq('SchemaViolation', item.get('code'))
@@ -783,7 +784,7 @@ bar baz",vv
783
784
 
784
785
  headers = {'range': 'bytes=2-4'}
785
786
  async with sess.get(f'{url_dl}/{shatext}', headers=headers) as resp:
786
- self.eq(206, resp.status)
787
+ self.eq(resp.status, http.HTTPStatus.PARTIAL_CONTENT)
787
788
  self.eq('3', resp.headers.get('content-length'))
788
789
  self.eq('bytes 2-4/12', resp.headers.get('content-range'))
789
790
  buf = b''
@@ -793,7 +794,7 @@ bar baz",vv
793
794
 
794
795
  headers = {'range': 'bytes=,2-'}
795
796
  async with sess.get(f'{url_dl}/{shatext}', headers=headers) as resp:
796
- self.eq(206, resp.status)
797
+ self.eq(resp.status, http.HTTPStatus.PARTIAL_CONTENT)
797
798
  self.eq('10', resp.headers.get('content-length'))
798
799
  self.eq('bytes 2-11/12', resp.headers.get('content-range'))
799
800
  buf = b''
@@ -803,7 +804,7 @@ bar baz",vv
803
804
 
804
805
  headers = {'range': 'bytes=0-11'}
805
806
  async with sess.get(f'{url_dl}/{shatext}', headers=headers) as resp:
806
- self.eq(206, resp.status)
807
+ self.eq(resp.status, http.HTTPStatus.PARTIAL_CONTENT)
807
808
  self.eq('12', resp.headers.get('content-length'))
808
809
  self.eq('bytes 0-11/12', resp.headers.get('content-range'))
809
810
  buf = b''
@@ -813,7 +814,7 @@ bar baz",vv
813
814
 
814
815
  headers = {'range': 'bytes=10-11'}
815
816
  async with sess.get(f'{url_dl}/{shatext}', headers=headers) as resp:
816
- self.eq(206, resp.status)
817
+ self.eq(resp.status, http.HTTPStatus.PARTIAL_CONTENT)
817
818
  self.eq('2', resp.headers.get('content-length'))
818
819
  self.eq('bytes 10-11/12', resp.headers.get('content-range'))
819
820
  buf = b''
@@ -823,7 +824,7 @@ bar baz",vv
823
824
 
824
825
  headers = {'range': 'bytes=11-11'}
825
826
  async with sess.get(f'{url_dl}/{shatext}', headers=headers) as resp:
826
- self.eq(206, resp.status)
827
+ self.eq(resp.status, http.HTTPStatus.PARTIAL_CONTENT)
827
828
  self.eq('1', resp.headers.get('content-length'))
828
829
  self.eq('bytes 11-11/12', resp.headers.get('content-range'))
829
830
  buf = b''
@@ -833,7 +834,7 @@ bar baz",vv
833
834
 
834
835
  headers = {'range': 'bytes=2-4,8-11'}
835
836
  async with sess.get(f'{url_dl}/{shatext}', headers=headers) as resp:
836
- self.eq(206, resp.status)
837
+ self.eq(resp.status, http.HTTPStatus.PARTIAL_CONTENT)
837
838
  self.eq('3', resp.headers.get('content-length'))
838
839
  self.eq('bytes 2-4/12', resp.headers.get('content-range'))
839
840
  buf = b''
@@ -844,39 +845,40 @@ bar baz",vv
844
845
  # HEAD tests
845
846
  headers = {'range': 'bytes=2-4'}
846
847
  async with sess.head(f'{url_dl}/{shatext}', headers=headers) as resp:
847
- self.eq(206, resp.status)
848
+ self.eq(resp.status, http.HTTPStatus.PARTIAL_CONTENT)
848
849
  self.eq('3', resp.headers.get('content-length'))
849
850
  self.eq('bytes 2-4/12', resp.headers.get('content-range'))
850
851
 
851
852
  headers = {'range': 'bytes=10-11'}
852
853
  async with sess.head(f'{url_dl}/{shatext}', headers=headers) as resp:
853
- self.eq(206, resp.status)
854
+ self.eq(resp.status, http.HTTPStatus.PARTIAL_CONTENT)
854
855
  self.eq('2', resp.headers.get('content-length'))
855
856
  self.eq('bytes 10-11/12', resp.headers.get('content-range'))
856
857
 
857
858
  headers = {'range': 'bytes=11-11'}
858
859
  async with sess.head(f'{url_dl}/{shatext}', headers=headers) as resp:
859
- self.eq(206, resp.status)
860
+ self.eq(resp.status, http.HTTPStatus.PARTIAL_CONTENT)
860
861
  self.eq('1', resp.headers.get('content-length'))
861
862
  self.eq('bytes 11-11/12', resp.headers.get('content-range'))
862
863
 
864
+ # TODO - In python 3.13+ this can be HTTPStatus.RANGE_NOT_SATISFIABLE
863
865
  # Reading past blobsize isn't valid HTTP
864
866
  headers = {'range': 'bytes=10-20'}
865
867
  async with sess.head(f'{url_dl}/{shatext}', headers=headers) as resp:
866
- self.eq(416, resp.status)
868
+ self.eq(resp.status, http.HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE)
867
869
 
868
870
  headers = {'range': 'bytes=11-12'}
869
871
  async with sess.head(f'{url_dl}/{shatext}', headers=headers) as resp:
870
- self.eq(416, resp.status)
872
+ self.eq(resp.status, http.HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE)
871
873
 
872
874
  headers = {'range': 'bytes=20-40'}
873
875
  async with sess.head(f'{url_dl}/{shatext}', headers=headers) as resp:
874
- self.eq(416, resp.status)
876
+ self.eq(resp.status, http.HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE)
875
877
 
876
878
  # Negative size
877
879
  headers = {'range': 'bytes=20-4'}
878
880
  async with sess.head(f'{url_dl}/{shatext}', headers=headers) as resp:
879
- self.eq(416, resp.status)
881
+ self.eq(resp.status, http.HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE)
880
882
 
881
883
  async def test_axon_perms(self):
882
884
  async with self.getTestAxon() as axon:
@@ -1004,6 +1006,15 @@ bar baz",vv
1004
1006
  self.eq(True, resp['ok'])
1005
1007
  self.eq(200, resp['code'])
1006
1008
 
1009
+ jsonq = f'''$resp = $lib.axon.wput($sha256, "https://127.0.0.1:{port}/api/v1/pushfile", ssl=(0))
1010
+ return ( $lib.json.save($resp) )
1011
+ '''
1012
+ resp = await core.callStorm(jsonq, opts=opts)
1013
+ self.isinstance(resp, str)
1014
+ resp = s_json.loads(resp)
1015
+ self.eq(True, resp['ok'])
1016
+ self.eq(200, resp['code'])
1017
+
1007
1018
  opts = {'vars': {'sha256': s_common.ehex(s_common.buid())}}
1008
1019
  resp = await core.callStorm(q, opts=opts)
1009
1020
  self.eq(False, resp['ok'])
@@ -1,5 +1,6 @@
1
1
  import os
2
2
  import copy
3
+ import http
3
4
  import time
4
5
  import asyncio
5
6
  import hashlib
@@ -83,6 +84,12 @@ class CortexTest(s_t_utils.SynTest):
83
84
 
84
85
  await core.nodes('[ inet:ipv4=1.2.3.4 :asn=99 .seen=now +#foo:score=10 ]')
85
86
 
87
+ conf = {'modules': [('NewpModule', {})]}
88
+ warn = '''"'modules' Cortex config value" is deprecated'''
89
+ with self.assertWarnsRegex(DeprecationWarning, warn) as cm:
90
+ async with self.getTestCore(dirn=dirn, conf=conf) as core:
91
+ pass
92
+
86
93
  async def test_cortex_cellguid(self):
87
94
  iden = s_common.guid()
88
95
  conf = {'cell:guid': iden}
@@ -1178,11 +1185,11 @@ class CortexTest(s_t_utils.SynTest):
1178
1185
  async with self.getHttpSess(port=port, auth=('visi', 'secret')) as sess:
1179
1186
  body = {'query': 'return(asdf)', 'opts': {'user': core.auth.rootuser.iden}}
1180
1187
  async with sess.get(f'https://localhost:{port}/api/v1/storm/call', json=body) as resp:
1181
- self.eq(resp.status, 403)
1188
+ self.eq(resp.status, http.HTTPStatus.FORBIDDEN)
1182
1189
 
1183
1190
  async with self.getHttpSess(port=port) as sess:
1184
1191
  resp = await sess.post(f'https://localhost:{port}/api/v1/storm/call')
1185
- self.eq(401, resp.status)
1192
+ self.eq(resp.status, http.HTTPStatus.UNAUTHORIZED)
1186
1193
 
1187
1194
  async with self.getHttpSess() as sess:
1188
1195
  async with sess.post(f'https://localhost:{port}/api/v1/login',
@@ -1193,12 +1200,14 @@ class CortexTest(s_t_utils.SynTest):
1193
1200
 
1194
1201
  body = {'query': 'return (asdf)'}
1195
1202
  async with sess.get(f'https://localhost:{port}/api/v1/storm/call', json=body) as resp:
1203
+ self.eq(resp.status, http.HTTPStatus.OK)
1196
1204
  retn = await resp.json()
1197
1205
  self.eq('ok', retn.get('status'))
1198
1206
  self.eq('asdf', retn['result'])
1199
1207
 
1200
1208
  body = {'query': '$foo=() $bar=$foo.index(10) return ( $bar )'}
1201
1209
  async with sess.get(f'https://localhost:{port}/api/v1/storm/call', json=body) as resp:
1210
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
1202
1211
  retn = await resp.json()
1203
1212
  self.eq('err', retn.get('status'))
1204
1213
  self.eq('StormRuntimeError', retn.get('code'))
@@ -1206,6 +1215,7 @@ class CortexTest(s_t_utils.SynTest):
1206
1215
 
1207
1216
  body = {'query': 'return ( $lib.exit() )'}
1208
1217
  async with sess.post(f'https://localhost:{port}/api/v1/storm/call', json=body) as resp:
1218
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
1209
1219
  retn = await resp.json()
1210
1220
  self.eq('err', retn.get('status'))
1211
1221
  self.eq('StormExit', retn.get('code'))
@@ -1214,6 +1224,7 @@ class CortexTest(s_t_utils.SynTest):
1214
1224
  # No body
1215
1225
  async with sess.get(f'https://localhost:{port}/api/v1/storm/call') as resp:
1216
1226
  retn = await resp.json()
1227
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
1217
1228
  self.eq('err', retn.get('status'))
1218
1229
  self.eq('SchemaViolation', retn.get('code'))
1219
1230
 
@@ -7402,18 +7413,17 @@ class CortexBasicTest(s_t_utils.SynTest):
7402
7413
 
7403
7414
  async with self.getHttpSess(port=port) as sess:
7404
7415
  resp = await sess.post(f'https://localhost:{port}/api/v1/storm/export')
7405
- self.eq(401, resp.status)
7416
+ self.eq(resp.status, http.HTTPStatus.UNAUTHORIZED)
7406
7417
 
7407
7418
  async with self.getHttpSess(port=port, auth=('visi', 'secret')) as sess:
7408
7419
  body = {'query': 'inet:ipv4', 'opts': {'user': core.auth.rootuser.iden}}
7409
7420
  async with sess.get(f'https://localhost:{port}/api/v1/storm/export', json=body) as resp:
7410
- self.eq(resp.status, 403)
7421
+ self.eq(resp.status, http.HTTPStatus.FORBIDDEN)
7411
7422
 
7412
7423
  async with self.getHttpSess(port=port, auth=('root', 'secret')) as sess:
7413
7424
 
7414
7425
  resp = await sess.post(f'https://localhost:{port}/api/v1/storm/export')
7415
- self.eq(200, resp.status)
7416
-
7426
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
7417
7427
  reply = await resp.json()
7418
7428
  self.eq('err', reply.get('status'))
7419
7429
  self.eq('SchemaViolation', reply.get('code'))
@@ -7423,6 +7433,7 @@ class CortexBasicTest(s_t_utils.SynTest):
7423
7433
  'opts': {'scrub': {'include': {'tags': ('visi',)}}},
7424
7434
  }
7425
7435
  resp = await sess.post(f'https://localhost:{port}/api/v1/storm/export', json=body)
7436
+ self.eq(resp.status, http.HTTPStatus.OK)
7426
7437
  byts = await resp.read()
7427
7438
 
7428
7439
  podes = [i[1] for i in s_msgpack.Unpk().feed(byts)]
@@ -7440,6 +7451,7 @@ class CortexBasicTest(s_t_utils.SynTest):
7440
7451
  body = {'query': 'inet:ipv4=asdfasdf'}
7441
7452
  resp = await sess.post(f'https://localhost:{port}/api/v1/storm/export', json=body)
7442
7453
  retval = await resp.json()
7454
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
7443
7455
  self.eq('err', retval['status'])
7444
7456
  self.eq('BadTypeValu', retval['code'])
7445
7457
 
@@ -1,4 +1,5 @@
1
1
  import os
2
+ import http
2
3
  import asyncio
3
4
 
4
5
  from unittest import mock
@@ -304,6 +305,7 @@ class AhaTest(s_test.SynTest):
304
305
 
305
306
  async with self.getHttpSess(auth=('root', 'secret'), port=httpsport) as sess:
306
307
  async with sess.get(svcsurl) as resp:
308
+ self.eq(resp.status, http.HTTPStatus.OK)
307
309
  info = await resp.json()
308
310
  self.eq(info.get('status'), 'ok')
309
311
  result = info.get('result')
@@ -312,6 +314,7 @@ class AhaTest(s_test.SynTest):
312
314
  {svcinfo.get('name') for svcinfo in result})
313
315
 
314
316
  async with sess.get(svcsurl, json={'network': 'synapse'}) as resp:
317
+ self.eq(resp.status, http.HTTPStatus.OK)
315
318
  info = await resp.json()
316
319
  self.eq(info.get('status'), 'ok')
317
320
  result = info.get('result')
@@ -320,6 +323,7 @@ class AhaTest(s_test.SynTest):
320
323
  {svcinfo.get('name') for svcinfo in result})
321
324
 
322
325
  async with sess.get(svcsurl, json={'network': 'newp'}) as resp:
326
+ self.eq(resp.status, http.HTTPStatus.OK)
323
327
  info = await resp.json()
324
328
  self.eq(info.get('status'), 'ok')
325
329
  result = info.get('result')
@@ -327,11 +331,13 @@ class AhaTest(s_test.SynTest):
327
331
 
328
332
  # Sad path
329
333
  async with sess.get(svcsurl, json={'newp': 'hehe'}) as resp:
334
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
330
335
  info = await resp.json()
331
336
  self.eq(info.get('status'), 'err')
332
337
  self.eq(info.get('code'), 'SchemaViolation')
333
338
 
334
339
  async with sess.get(svcsurl, json={'network': 'mynet', 'newp': 'hehe'}) as resp:
340
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
335
341
  info = await resp.json()
336
342
  self.eq(info.get('status'), 'err')
337
343
  self.eq(info.get('code'), 'SchemaViolation')
@@ -339,6 +345,7 @@ class AhaTest(s_test.SynTest):
339
345
  # Sad path
340
346
  async with self.getHttpSess(auth=('lowuser', 'lowuser'), port=httpsport) as sess:
341
347
  async with sess.get(svcsurl) as resp:
348
+ self.eq(resp.status, http.HTTPStatus.FORBIDDEN)
342
349
  info = await resp.json()
343
350
  self.eq(info.get('status'), 'err')
344
351
  self.eq(info.get('code'), 'AuthDeny')
@@ -877,6 +884,7 @@ class AhaTest(s_test.SynTest):
877
884
  async with self.getHttpSess(auth=('root', 'secret'), port=httpsport) as sess:
878
885
  # Simple request works
879
886
  async with sess.post(url, json={'name': '00.foosvc'}) as resp:
887
+ self.eq(resp.status, http.HTTPStatus.OK)
880
888
  info = await resp.json()
881
889
  self.eq(info.get('status'), 'ok')
882
890
  result = info.get('result')
@@ -904,6 +912,7 @@ class AhaTest(s_test.SynTest):
904
912
  }
905
913
  }
906
914
  async with sess.post(url, json=data) as resp:
915
+ self.eq(resp.status, http.HTTPStatus.OK)
907
916
  info = await resp.json()
908
917
  self.eq(info.get('status'), 'ok')
909
918
  result = info.get('result')
@@ -919,30 +928,37 @@ class AhaTest(s_test.SynTest):
919
928
 
920
929
  # Sad path
921
930
  async with sess.post(url) as resp:
931
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
922
932
  info = await resp.json()
923
933
  self.eq(info.get('status'), 'err')
924
934
  self.eq(info.get('code'), 'SchemaViolation')
925
935
  async with sess.post(url, json={}) as resp:
936
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
926
937
  info = await resp.json()
927
938
  self.eq(info.get('status'), 'err')
928
939
  self.eq(info.get('code'), 'SchemaViolation')
929
940
  async with sess.post(url, json={'name': 1234}) as resp:
941
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
930
942
  info = await resp.json()
931
943
  self.eq(info.get('status'), 'err')
932
944
  self.eq(info.get('code'), 'SchemaViolation')
933
945
  async with sess.post(url, json={'name': ''}) as resp:
946
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
934
947
  info = await resp.json()
935
948
  self.eq(info.get('status'), 'err')
936
949
  self.eq(info.get('code'), 'SchemaViolation')
937
950
  async with sess.post(url, json={'name': '00.newp', 'provinfo': 5309}) as resp:
951
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
938
952
  info = await resp.json()
939
953
  self.eq(info.get('status'), 'err')
940
954
  self.eq(info.get('code'), 'SchemaViolation')
941
955
  async with sess.post(url, json={'name': '00.newp', 'provinfo': {'dmon:port': -1}}) as resp:
956
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
942
957
  info = await resp.json()
943
958
  self.eq(info.get('status'), 'err')
944
959
  self.eq(info.get('code'), 'SchemaViolation')
945
960
  async with sess.post(url, json={'name': 'doom' * 16}) as resp:
961
+ self.eq(resp.status, http.HTTPStatus.BAD_REQUEST)
946
962
  info = await resp.json()
947
963
  self.eq(info.get('status'), 'err')
948
964
  self.eq(info.get('code'), 'BadArg')
@@ -951,6 +967,7 @@ class AhaTest(s_test.SynTest):
951
967
  await aha.addUser('lowuser', passwd='lowuser')
952
968
  async with self.getHttpSess(auth=('lowuser', 'lowuser'), port=httpsport) as sess:
953
969
  async with sess.post(url, json={'name': '00.newp'}) as resp:
970
+ self.eq(resp.status, http.HTTPStatus.FORBIDDEN)
954
971
  info = await resp.json()
955
972
  self.eq(info.get('status'), 'err')
956
973
  self.eq(info.get('code'), 'AuthDeny')
@@ -1,3 +1,4 @@
1
+ import http
1
2
  import os
2
3
  import ssl
3
4
  import sys
@@ -2923,7 +2924,7 @@ class CellTest(s_t_utils.SynTest):
2923
2924
  headers2 = {'X-API-KEY': rtk1}
2924
2925
  resp = await sess.post(f'https://localhost:{hport}/api/v1/auth/onepass/issue', headers=headers2,
2925
2926
  json={'user': lowuser})
2926
- self.eq(401, resp.status)
2927
+ self.eq(resp.status, http.HTTPStatus.UNAUTHORIZED)
2927
2928
  answ = await resp.json()
2928
2929
  self.eq('err', answ['status'])
2929
2930
 
@@ -2945,7 +2946,7 @@ class CellTest(s_t_utils.SynTest):
2945
2946
 
2946
2947
  resp = await sess.post(f'https://localhost:{hport}/api/v1/auth/onepass/issue', headers=headers2,
2947
2948
  json={'user': lowuser})
2948
- self.eq(401, resp.status)
2949
+ self.eq(resp.status, http.HTTPStatus.UNAUTHORIZED)
2949
2950
  answ = await resp.json()
2950
2951
  self.eq('err', answ['status'])
2951
2952
 
@@ -2985,13 +2986,14 @@ class CellTest(s_t_utils.SynTest):
2985
2986
  await cell.setUserLocked(lowuser, True)
2986
2987
  resp = await sess.post(f'https://localhost:{hport}/api/v1/auth/password/{lowuser}', headers=headers2,
2987
2988
  json={'passwd': 'secret'})
2988
- self.eq(401, resp.status)
2989
+ self.eq(resp.status, http.HTTPStatus.UNAUTHORIZED)
2989
2990
  answ = await resp.json()
2990
2991
  self.eq('err', answ['status'])
2991
2992
 
2992
2993
  await cell.delUser(lowuser)
2993
2994
  resp = await sess.post(f'https://localhost:{hport}/api/v1/auth/password/{lowuser}', headers=headers2,
2994
2995
  json={'passwd': 'secret'})
2996
+ self.eq(resp.status, http.HTTPStatus.UNAUTHORIZED)
2995
2997
  answ = await resp.json()
2996
2998
  self.eq('err', answ['status'])
2997
2999