synapse 2.191.0__py311-none-any.whl → 2.192.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.
- synapse/axon.py +54 -23
- synapse/cortex.py +2 -2
- synapse/lib/ast.py +6 -2
- synapse/lib/cell.py +48 -0
- synapse/lib/nexus.py +2 -1
- synapse/lib/stormhttp.py +32 -35
- synapse/lib/stormtypes.py +102 -20
- synapse/lib/version.py +2 -2
- synapse/tests/test_axon.py +10 -0
- synapse/tests/test_cortex.py +52 -0
- synapse/tests/test_lib_ast.py +6 -0
- synapse/tests/test_lib_cell.py +35 -0
- synapse/tests/test_lib_httpapi.py +9 -2
- synapse/tests/test_lib_stormhttp.py +57 -12
- synapse/tests/test_servers_univ.py +0 -12
- synapse/tests/test_tools_apikey.py +227 -0
- synapse/tools/apikey.py +93 -0
- {synapse-2.191.0.dist-info → synapse-2.192.0.dist-info}/METADATA +1 -1
- {synapse-2.191.0.dist-info → synapse-2.192.0.dist-info}/RECORD +22 -20
- {synapse-2.191.0.dist-info → synapse-2.192.0.dist-info}/LICENSE +0 -0
- {synapse-2.191.0.dist-info → synapse-2.192.0.dist-info}/WHEEL +0 -0
- {synapse-2.191.0.dist-info → synapse-2.192.0.dist-info}/top_level.txt +0 -0
synapse/lib/stormtypes.py
CHANGED
|
@@ -3,6 +3,7 @@ import copy
|
|
|
3
3
|
import gzip
|
|
4
4
|
import json
|
|
5
5
|
import time
|
|
6
|
+
|
|
6
7
|
import regex
|
|
7
8
|
import types
|
|
8
9
|
import base64
|
|
@@ -39,6 +40,7 @@ import synapse.lib.stormctrl as s_stormctrl
|
|
|
39
40
|
logger = logging.getLogger(__name__)
|
|
40
41
|
|
|
41
42
|
AXON_MINVERS_PROXY = (2, 97, 0)
|
|
43
|
+
AXON_MINVERS_PROXYTRUE = (2, 192, 0)
|
|
42
44
|
AXON_MINVERS_SSLOPTS = '>=2.162.0'
|
|
43
45
|
|
|
44
46
|
class Undef:
|
|
@@ -73,6 +75,79 @@ def strifyHttpArg(item, multi=False):
|
|
|
73
75
|
return retn
|
|
74
76
|
return item
|
|
75
77
|
|
|
78
|
+
async def resolveCoreProxyUrl(valu):
|
|
79
|
+
'''
|
|
80
|
+
Resolve a proxy value to a proxy URL.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
valu (str|None|bool): The proxy value.
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
(str|None): A proxy URL string or None.
|
|
87
|
+
'''
|
|
88
|
+
runt = s_scope.get('runt')
|
|
89
|
+
|
|
90
|
+
match valu:
|
|
91
|
+
case None:
|
|
92
|
+
s_common.deprecated('Setting the HTTP proxy argument $lib.null', curv='2.192.0')
|
|
93
|
+
await runt.snap.warnonce('Setting the HTTP proxy argument to $lib.null is deprecated. Use $lib.true instead.')
|
|
94
|
+
return await runt.snap.core.getConfOpt('http:proxy')
|
|
95
|
+
|
|
96
|
+
case True:
|
|
97
|
+
return await runt.snap.core.getConfOpt('http:proxy')
|
|
98
|
+
|
|
99
|
+
case False:
|
|
100
|
+
runt.confirm(('storm', 'lib', 'inet', 'http', 'proxy'))
|
|
101
|
+
return None
|
|
102
|
+
|
|
103
|
+
case str():
|
|
104
|
+
runt.confirm(('storm', 'lib', 'inet', 'http', 'proxy'))
|
|
105
|
+
return valu
|
|
106
|
+
|
|
107
|
+
case _:
|
|
108
|
+
raise s_exc.BadArg(mesg='HTTP proxy argument must be a string or bool.')
|
|
109
|
+
|
|
110
|
+
async def resolveAxonProxyArg(valu):
|
|
111
|
+
'''
|
|
112
|
+
Resolve a proxy value to the kwarg to set for an Axon HTTP call.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
valu (str|null|bool): The proxy value.
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
tuple: A retn tuple where the proxy kwarg should not be set if ok=False, otherwise a proxy URL or None.
|
|
119
|
+
'''
|
|
120
|
+
runt = s_scope.get('runt')
|
|
121
|
+
|
|
122
|
+
axonvers = runt.snap.core.axoninfo['synapse']['version']
|
|
123
|
+
if axonvers < AXON_MINVERS_PROXY:
|
|
124
|
+
await runt.snap.warnonce(f'Axon version does not support proxy argument: {axonvers} < {AXON_MINVERS_PROXY}')
|
|
125
|
+
return False, None
|
|
126
|
+
|
|
127
|
+
match valu:
|
|
128
|
+
case None:
|
|
129
|
+
s_common.deprecated('Setting the Storm HTTP proxy argument $lib.null', curv='2.192.0')
|
|
130
|
+
await runt.snap.warnonce('Setting the Storm HTTP proxy argument to $lib.null is deprecated. Use $lib.true instead.')
|
|
131
|
+
if axonvers >= AXON_MINVERS_PROXYTRUE:
|
|
132
|
+
return True, True
|
|
133
|
+
return True, None
|
|
134
|
+
|
|
135
|
+
case True:
|
|
136
|
+
if axonvers < AXON_MINVERS_PROXYTRUE:
|
|
137
|
+
return True, None
|
|
138
|
+
return True, True
|
|
139
|
+
|
|
140
|
+
case False:
|
|
141
|
+
runt.confirm(('storm', 'lib', 'inet', 'http', 'proxy'))
|
|
142
|
+
return True, False
|
|
143
|
+
|
|
144
|
+
case str():
|
|
145
|
+
runt.confirm(('storm', 'lib', 'inet', 'http', 'proxy'))
|
|
146
|
+
return True, valu
|
|
147
|
+
|
|
148
|
+
case _:
|
|
149
|
+
raise s_exc.BadArg(mesg='HTTP proxy argument must be a string or bool.')
|
|
150
|
+
|
|
76
151
|
class StormTypesRegistry:
|
|
77
152
|
# The following types are currently undefined.
|
|
78
153
|
base_undefined_types = (
|
|
@@ -1993,11 +2068,18 @@ class LibAxon(Lib):
|
|
|
1993
2068
|
|
|
1994
2069
|
For APIs that accept an ssl_opts argument, the dictionary may contain the following values::
|
|
1995
2070
|
|
|
1996
|
-
{
|
|
2071
|
+
({
|
|
1997
2072
|
'verify': <bool> - Perform SSL/TLS verification. Is overridden by the ssl argument.
|
|
1998
2073
|
'client_cert': <str> - PEM encoded full chain certificate for use in mTLS.
|
|
1999
2074
|
'client_key': <str> - PEM encoded key for use in mTLS. Alternatively, can be included in client_cert.
|
|
2000
|
-
}
|
|
2075
|
+
})
|
|
2076
|
+
|
|
2077
|
+
For APIs that accept a proxy argument, the following values are supported::
|
|
2078
|
+
|
|
2079
|
+
$lib.null: Deprecated - Use the proxy defined by the http:proxy configuration option if set.
|
|
2080
|
+
$lib.true: Use the proxy defined by the http:proxy configuration option if set.
|
|
2081
|
+
$lib.false: Do not use the proxy defined by the http:proxy configuration option if set.
|
|
2082
|
+
<str>: A proxy URL string.
|
|
2001
2083
|
'''
|
|
2002
2084
|
_storm_locals = (
|
|
2003
2085
|
{'name': 'wget', 'desc': """
|
|
@@ -2031,8 +2113,8 @@ class LibAxon(Lib):
|
|
|
2031
2113
|
'desc': 'Set to False to disable SSL/TLS certificate verification.', 'default': True},
|
|
2032
2114
|
{'name': 'timeout', 'type': 'int', 'desc': 'Timeout for the download operation.',
|
|
2033
2115
|
'default': None},
|
|
2034
|
-
{'name': 'proxy', 'type': ['
|
|
2035
|
-
'desc': '
|
|
2116
|
+
{'name': 'proxy', 'type': ['bool', 'str'],
|
|
2117
|
+
'desc': 'Configure proxy usage. See $lib.axon help for additional details.', 'default': True},
|
|
2036
2118
|
{'name': 'ssl_opts', 'type': 'dict',
|
|
2037
2119
|
'desc': 'Optional SSL/TLS options. See $lib.axon help for additional details.',
|
|
2038
2120
|
'default': None},
|
|
@@ -2054,8 +2136,8 @@ class LibAxon(Lib):
|
|
|
2054
2136
|
'desc': 'Set to False to disable SSL/TLS certificate verification.', 'default': True},
|
|
2055
2137
|
{'name': 'timeout', 'type': 'int', 'desc': 'Timeout for the download operation.',
|
|
2056
2138
|
'default': None},
|
|
2057
|
-
{'name': 'proxy', 'type': ['
|
|
2058
|
-
'desc': '
|
|
2139
|
+
{'name': 'proxy', 'type': ['bool', 'str'],
|
|
2140
|
+
'desc': 'Configure proxy usage. See $lib.axon help for additional details.', 'default': True},
|
|
2059
2141
|
{'name': 'ssl_opts', 'type': 'dict',
|
|
2060
2142
|
'desc': 'Optional SSL/TLS options. See $lib.axon help for additional details.',
|
|
2061
2143
|
'default': None},
|
|
@@ -2370,7 +2452,7 @@ class LibAxon(Lib):
|
|
|
2370
2452
|
return await axon.del_(sha256b)
|
|
2371
2453
|
|
|
2372
2454
|
async def wget(self, url, headers=None, params=None, method='GET', json=None, body=None,
|
|
2373
|
-
ssl=True, timeout=None, proxy=
|
|
2455
|
+
ssl=True, timeout=None, proxy=True, ssl_opts=None):
|
|
2374
2456
|
|
|
2375
2457
|
if not self.runt.allowed(('axon', 'wget')):
|
|
2376
2458
|
self.runt.confirm(('storm', 'lib', 'axon', 'wget'))
|
|
@@ -2387,20 +2469,19 @@ class LibAxon(Lib):
|
|
|
2387
2469
|
proxy = await toprim(proxy)
|
|
2388
2470
|
ssl_opts = await toprim(ssl_opts)
|
|
2389
2471
|
|
|
2390
|
-
if proxy is not None:
|
|
2391
|
-
self.runt.confirm(('storm', 'lib', 'inet', 'http', 'proxy'))
|
|
2392
|
-
|
|
2393
2472
|
params = strifyHttpArg(params, multi=True)
|
|
2394
2473
|
headers = strifyHttpArg(headers)
|
|
2395
2474
|
|
|
2396
2475
|
await self.runt.snap.core.getAxon()
|
|
2397
2476
|
|
|
2398
2477
|
kwargs = {}
|
|
2399
|
-
|
|
2400
|
-
|
|
2478
|
+
|
|
2479
|
+
ok, proxy = await resolveAxonProxyArg(proxy)
|
|
2480
|
+
if ok:
|
|
2401
2481
|
kwargs['proxy'] = proxy
|
|
2402
2482
|
|
|
2403
2483
|
if ssl_opts is not None:
|
|
2484
|
+
axonvers = self.runt.snap.core.axoninfo['synapse']['version']
|
|
2404
2485
|
mesg = f'The ssl_opts argument requires an Axon Synapse version {AXON_MINVERS_SSLOPTS}, ' \
|
|
2405
2486
|
f'but the Axon is running {axonvers}'
|
|
2406
2487
|
s_version.reqVersion(axonvers, AXON_MINVERS_SSLOPTS, mesg=mesg)
|
|
@@ -2413,7 +2494,7 @@ class LibAxon(Lib):
|
|
|
2413
2494
|
return resp
|
|
2414
2495
|
|
|
2415
2496
|
async def wput(self, sha256, url, headers=None, params=None, method='PUT',
|
|
2416
|
-
ssl=True, timeout=None, proxy=
|
|
2497
|
+
ssl=True, timeout=None, proxy=True, ssl_opts=None):
|
|
2417
2498
|
|
|
2418
2499
|
if not self.runt.allowed(('axon', 'wput')):
|
|
2419
2500
|
self.runt.confirm(('storm', 'lib', 'axon', 'wput'))
|
|
@@ -2432,23 +2513,24 @@ class LibAxon(Lib):
|
|
|
2432
2513
|
params = strifyHttpArg(params, multi=True)
|
|
2433
2514
|
headers = strifyHttpArg(headers)
|
|
2434
2515
|
|
|
2435
|
-
|
|
2436
|
-
self.runt.confirm(('storm', 'lib', 'inet', 'http', 'proxy'))
|
|
2437
|
-
|
|
2438
|
-
axon = self.runt.snap.core.axon
|
|
2439
|
-
sha256byts = s_common.uhex(sha256)
|
|
2516
|
+
await self.runt.snap.core.getAxon()
|
|
2440
2517
|
|
|
2441
2518
|
kwargs = {}
|
|
2442
|
-
|
|
2443
|
-
|
|
2519
|
+
|
|
2520
|
+
ok, proxy = await resolveAxonProxyArg(proxy)
|
|
2521
|
+
if ok:
|
|
2444
2522
|
kwargs['proxy'] = proxy
|
|
2445
2523
|
|
|
2446
2524
|
if ssl_opts is not None:
|
|
2525
|
+
axonvers = self.runt.snap.core.axoninfo['synapse']['version']
|
|
2447
2526
|
mesg = f'The ssl_opts argument requires an Axon Synapse version {AXON_MINVERS_SSLOPTS}, ' \
|
|
2448
2527
|
f'but the Axon is running {axonvers}'
|
|
2449
2528
|
s_version.reqVersion(axonvers, AXON_MINVERS_SSLOPTS, mesg=mesg)
|
|
2450
2529
|
kwargs['ssl_opts'] = ssl_opts
|
|
2451
2530
|
|
|
2531
|
+
axon = self.runt.snap.core.axon
|
|
2532
|
+
sha256byts = s_common.uhex(sha256)
|
|
2533
|
+
|
|
2452
2534
|
return await axon.wput(sha256byts, url, headers=headers, params=params, method=method,
|
|
2453
2535
|
ssl=ssl, timeout=timeout, **kwargs)
|
|
2454
2536
|
|
synapse/lib/version.py
CHANGED
|
@@ -223,6 +223,6 @@ def reqVersion(valu, reqver,
|
|
|
223
223
|
##############################################################################
|
|
224
224
|
# The following are touched during the release process by bumpversion.
|
|
225
225
|
# Do not modify these directly.
|
|
226
|
-
version = (2,
|
|
226
|
+
version = (2, 192, 0)
|
|
227
227
|
verstring = '.'.join([str(x) for x in version])
|
|
228
|
-
commit = '
|
|
228
|
+
commit = '8a442a534d27fff4c6189922c4b0ea85d332f18e'
|
synapse/tests/test_axon.py
CHANGED
|
@@ -945,10 +945,16 @@ bar baz",vv
|
|
|
945
945
|
self.false(resp.get('ok'))
|
|
946
946
|
self.isin('connect to proxy 127.0.0.1:1', resp.get('mesg', ''))
|
|
947
947
|
|
|
948
|
+
resp = await proxy.wget('http://vertex.link/', proxy=None)
|
|
949
|
+
self.false(resp.get('ok'))
|
|
950
|
+
self.isin('connect to proxy 127.0.0.1:1', resp.get('mesg', ''))
|
|
951
|
+
|
|
948
952
|
resp = await proxy.wget('vertex.link')
|
|
949
953
|
self.false(resp.get('ok'))
|
|
950
954
|
self.isin('InvalidUrlClientError: vertex.link', resp.get('mesg', ''))
|
|
951
955
|
|
|
956
|
+
await self.asyncraises(s_exc.BadArg, proxy.wget('http://vertex.link', proxy=1.1))
|
|
957
|
+
|
|
952
958
|
async def test_axon_wput(self):
|
|
953
959
|
|
|
954
960
|
async with self.getTestCore() as core:
|
|
@@ -1025,6 +1031,10 @@ bar baz",vv
|
|
|
1025
1031
|
self.false(resp.get('ok'))
|
|
1026
1032
|
self.isin('connect to proxy 127.0.0.1:1', resp.get('reason'))
|
|
1027
1033
|
|
|
1034
|
+
resp = await proxy.postfiles(fields, f'https://127.0.0.1:{port}/api/v1/pushfile', ssl=False, proxy=None)
|
|
1035
|
+
self.false(resp.get('ok'))
|
|
1036
|
+
self.isin('connect to proxy 127.0.0.1:1', resp.get('reason'))
|
|
1037
|
+
|
|
1028
1038
|
resp = await proxy.wput(sha256, 'vertex.link')
|
|
1029
1039
|
self.false(resp.get('ok'))
|
|
1030
1040
|
self.isin('InvalidUrlClientError: vertex.link', resp.get('mesg', ''))
|
synapse/tests/test_cortex.py
CHANGED
|
@@ -4023,6 +4023,58 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
4023
4023
|
gdef = await core.callStorm('return($lib.graph.add(({"name": "def", "permissions": {"default": 0}})))')
|
|
4024
4024
|
self.eq(0, gdef['permissions']['default'])
|
|
4025
4025
|
|
|
4026
|
+
async def test_graph_projection_query_validation(self):
|
|
4027
|
+
async with self.getTestCore() as core:
|
|
4028
|
+
valid = {
|
|
4029
|
+
'name': 'valid',
|
|
4030
|
+
'forms': {
|
|
4031
|
+
'inet:fqdn': {
|
|
4032
|
+
'pivots': ['<- *'],
|
|
4033
|
+
'filters': []
|
|
4034
|
+
}
|
|
4035
|
+
}
|
|
4036
|
+
}
|
|
4037
|
+
|
|
4038
|
+
self.nn(await core.addStormGraph(valid))
|
|
4039
|
+
|
|
4040
|
+
bad_form_pivot = {
|
|
4041
|
+
'name': 'bad form pivot',
|
|
4042
|
+
'forms': {
|
|
4043
|
+
'inet:fqdn': {
|
|
4044
|
+
'pivots': ['<- * |||'],
|
|
4045
|
+
'filters': []
|
|
4046
|
+
}
|
|
4047
|
+
}
|
|
4048
|
+
}
|
|
4049
|
+
|
|
4050
|
+
await self.asyncraises(s_exc.BadSyntax, core.addStormGraph(bad_form_pivot))
|
|
4051
|
+
|
|
4052
|
+
bad_form_filter = {
|
|
4053
|
+
'name': 'bad form filter',
|
|
4054
|
+
'forms': {
|
|
4055
|
+
'inet:fqdn': {
|
|
4056
|
+
'pivots': [],
|
|
4057
|
+
'filters': ['+++:wat']
|
|
4058
|
+
}
|
|
4059
|
+
}
|
|
4060
|
+
}
|
|
4061
|
+
|
|
4062
|
+
await self.asyncraises(s_exc.BadSyntax, core.addStormGraph(bad_form_filter))
|
|
4063
|
+
|
|
4064
|
+
bad_global_filter = {
|
|
4065
|
+
'name': 'bad global filter',
|
|
4066
|
+
'filters': ['+++:wat']
|
|
4067
|
+
}
|
|
4068
|
+
|
|
4069
|
+
await self.asyncraises(s_exc.BadSyntax, core.addStormGraph(bad_global_filter))
|
|
4070
|
+
|
|
4071
|
+
bad_global_pivot = {
|
|
4072
|
+
'name': 'bad global pivot',
|
|
4073
|
+
'pivots': ['-> * |||']
|
|
4074
|
+
}
|
|
4075
|
+
|
|
4076
|
+
await self.asyncraises(s_exc.BadSyntax, core.addStormGraph(bad_global_pivot))
|
|
4077
|
+
|
|
4026
4078
|
async def test_storm_two_level_assignment(self):
|
|
4027
4079
|
async with self.getTestCore() as core:
|
|
4028
4080
|
q = '$foo=baz $bar=$foo [test:str=$bar]'
|
synapse/tests/test_lib_ast.py
CHANGED
|
@@ -3113,6 +3113,12 @@ class AstTest(s_test.SynTest):
|
|
|
3113
3113
|
off, end = errm[1][1]['highlight']['offsets']
|
|
3114
3114
|
self.eq('haha', text[off:end])
|
|
3115
3115
|
|
|
3116
|
+
text = '$lib.newp'
|
|
3117
|
+
msgs = await core.stormlist(text)
|
|
3118
|
+
errm = [m for m in msgs if m[0] == 'err'][0]
|
|
3119
|
+
off, end = errm[1][1]['highlight']['offsets']
|
|
3120
|
+
self.eq('newp', text[off:end])
|
|
3121
|
+
|
|
3116
3122
|
async def test_ast_bulkedges(self):
|
|
3117
3123
|
|
|
3118
3124
|
async with self.getTestCore() as core:
|
synapse/tests/test_lib_cell.py
CHANGED
|
@@ -125,6 +125,10 @@ class EchoAuthApi(s_cell.CellApi):
|
|
|
125
125
|
|
|
126
126
|
class EchoAuth(s_cell.Cell):
|
|
127
127
|
cellapi = EchoAuthApi
|
|
128
|
+
# non-default commit / version / verstring
|
|
129
|
+
COMMIT = 'mycommit'
|
|
130
|
+
VERSION = (1, 2, 3)
|
|
131
|
+
VERSTRING = '1.2.3'
|
|
128
132
|
|
|
129
133
|
async def answer(self):
|
|
130
134
|
return 42
|
|
@@ -815,6 +819,37 @@ class CellTest(s_t_utils.SynTest):
|
|
|
815
819
|
https = netw.get('https')
|
|
816
820
|
self.eq(https, http_info)
|
|
817
821
|
|
|
822
|
+
# Mirrors & ready flags
|
|
823
|
+
async with self.getTestAha() as aha: # type: s_aha.AhaCell
|
|
824
|
+
|
|
825
|
+
with self.getTestDir() as dirn:
|
|
826
|
+
cdr0 = s_common.genpath(dirn, 'cell00')
|
|
827
|
+
cdr1 = s_common.genpath(dirn, 'cell01')
|
|
828
|
+
cell00 = await aha.enter_context(self.addSvcToAha(aha, '00.cell', EchoAuth,
|
|
829
|
+
dirn=cdr0)) # type: EchoAuth
|
|
830
|
+
# Ensure we have a nexus transaction
|
|
831
|
+
await cell00.sync()
|
|
832
|
+
cell01 = await aha.enter_context(self.addSvcToAha(aha, '01.cell', EchoAuth,
|
|
833
|
+
dirn=cdr1,
|
|
834
|
+
provinfo={'mirror': 'cell'})) # type: EchoAuth
|
|
835
|
+
|
|
836
|
+
self.true(await asyncio.wait_for(cell01.nexsroot.ready.wait(), timeout=12))
|
|
837
|
+
await cell01.sync()
|
|
838
|
+
|
|
839
|
+
cnfo0 = await cell00.getCellInfo()
|
|
840
|
+
cnfo1 = await cell01.getCellInfo()
|
|
841
|
+
self.true(cnfo0['cell']['ready'])
|
|
842
|
+
self.false(cnfo0['cell']['uplink'])
|
|
843
|
+
self.none(cnfo0['cell']['mirror'])
|
|
844
|
+
self.eq(cnfo0['cell']['version'], (1, 2, 3))
|
|
845
|
+
|
|
846
|
+
self.true(cnfo1['cell']['ready'])
|
|
847
|
+
self.true(cnfo1['cell']['uplink'])
|
|
848
|
+
self.eq(cnfo1['cell']['mirror'], 'aha://root@cell...')
|
|
849
|
+
self.eq(cnfo1['cell']['version'], (1, 2, 3))
|
|
850
|
+
|
|
851
|
+
self.eq(cnfo0['cell']['nexsindx'], cnfo1['cell']['nexsindx'])
|
|
852
|
+
|
|
818
853
|
async def test_cell_dyncall(self):
|
|
819
854
|
|
|
820
855
|
with self.getTestDir() as dirn:
|
|
@@ -1744,8 +1744,12 @@ class HttpApiTest(s_tests.SynTest):
|
|
|
1744
1744
|
|
|
1745
1745
|
with self.getStructuredAsyncLoggerStream(logname, 'api/v1/auth/adduser') as stream:
|
|
1746
1746
|
|
|
1747
|
+
headers = {
|
|
1748
|
+
'X-Forwarded-For': '1.2.3.4',
|
|
1749
|
+
'User-Agent': 'test_request_logging',
|
|
1750
|
+
}
|
|
1747
1751
|
async with sess.post(f'https://root:root@localhost:{port}/api/v1/auth/adduser',
|
|
1748
|
-
json=info, headers=
|
|
1752
|
+
json=info, headers=headers) as resp:
|
|
1749
1753
|
item = await resp.json()
|
|
1750
1754
|
self.nn(item.get('result').get('iden'))
|
|
1751
1755
|
visiiden = item['result']['iden']
|
|
@@ -1756,6 +1760,8 @@ class HttpApiTest(s_tests.SynTest):
|
|
|
1756
1760
|
self.eq(mesg.get('uri'), '/api/v1/auth/adduser')
|
|
1757
1761
|
self.eq(mesg.get('username'), 'root')
|
|
1758
1762
|
self.eq(mesg.get('user'), core.auth.rootuser.iden)
|
|
1763
|
+
self.isin('headers', mesg)
|
|
1764
|
+
self.eq(mesg['headers'].get('user-agent'), 'test_request_logging')
|
|
1759
1765
|
self.isin('remoteip', mesg)
|
|
1760
1766
|
self.isin('(root)', mesg.get('message'))
|
|
1761
1767
|
self.isin('200 POST /api/v1/auth/adduser', mesg.get('message'))
|
|
@@ -1763,12 +1769,13 @@ class HttpApiTest(s_tests.SynTest):
|
|
|
1763
1769
|
|
|
1764
1770
|
# No auth provided
|
|
1765
1771
|
with self.getStructuredAsyncLoggerStream(logname, 'api/v1/active') as stream:
|
|
1766
|
-
async with sess.get(f'https://root:root@localhost:{port}/api/v1/active') as resp:
|
|
1772
|
+
async with sess.get(f'https://root:root@localhost:{port}/api/v1/active', skip_auto_headers=['User-Agent']) as resp:
|
|
1767
1773
|
self.eq(resp.status, 200)
|
|
1768
1774
|
self.true(await stream.wait(6))
|
|
1769
1775
|
|
|
1770
1776
|
mesg = get_mesg(stream)
|
|
1771
1777
|
self.eq(mesg.get('uri'), '/api/v1/active')
|
|
1778
|
+
self.notin('headers', mesg)
|
|
1772
1779
|
self.notin('username', mesg)
|
|
1773
1780
|
self.notin('user', mesg)
|
|
1774
1781
|
self.isin('remoteip', mesg)
|
|
@@ -9,7 +9,7 @@ import synapse.common as s_common
|
|
|
9
9
|
import synapse.lib.certdir as s_certdir
|
|
10
10
|
import synapse.lib.httpapi as s_httpapi
|
|
11
11
|
import synapse.lib.stormctrl as s_stormctrl
|
|
12
|
-
import synapse.lib.
|
|
12
|
+
import synapse.lib.stormtypes as s_stormtypes
|
|
13
13
|
|
|
14
14
|
import synapse.tests.utils as s_test
|
|
15
15
|
|
|
@@ -606,11 +606,39 @@ class StormHttpTest(s_test.SynTest):
|
|
|
606
606
|
self.false(resp.get('ok'))
|
|
607
607
|
self.ne(-1, resp['mesg'].find('connect to proxy 127.0.0.1:1'))
|
|
608
608
|
|
|
609
|
+
msgs = await core.stormlist('$resp=$lib.axon.wget("http://vertex.link", proxy=(null)) $lib.print($resp.mesg)')
|
|
610
|
+
self.stormIsInWarn('HTTP proxy argument to $lib.null is deprecated', msgs)
|
|
611
|
+
self.stormIsInPrint('connect to proxy 127.0.0.1:1', msgs)
|
|
612
|
+
|
|
613
|
+
await self.asyncraises(s_exc.BadArg, core.nodes('$lib.axon.wget("http://vertex.link", proxy=(1.1))'))
|
|
614
|
+
|
|
615
|
+
# todo: setting the synapse version can be removed once proxy=true support is released
|
|
616
|
+
try:
|
|
617
|
+
oldv = core.axoninfo['synapse']['version']
|
|
618
|
+
core.axoninfo['synapse']['version'] = (oldv[0], oldv[1] + 1, oldv[2])
|
|
619
|
+
resp = await core.callStorm('return($lib.axon.wget("http://vertex.link", proxy=(null)))')
|
|
620
|
+
self.false(resp.get('ok'))
|
|
621
|
+
self.ne(-1, resp['mesg'].find('connect to proxy 127.0.0.1:1'))
|
|
622
|
+
finally:
|
|
623
|
+
core.axoninfo['synapse']['version'] = oldv
|
|
624
|
+
|
|
625
|
+
size, sha256 = await core.axon.put(b'asdf')
|
|
626
|
+
opts = {'vars': {'sha256': s_common.ehex(sha256)}}
|
|
627
|
+
resp = await core.callStorm(f'return($lib.axon.wput($sha256, http://vertex.link))', opts=opts)
|
|
628
|
+
self.false(resp.get('ok'))
|
|
629
|
+
self.isin('connect to proxy 127.0.0.1:1', resp['mesg'])
|
|
630
|
+
|
|
609
631
|
q = '$resp=$lib.inet.http.get("http://vertex.link") return(($resp.code, $resp.err))'
|
|
610
632
|
code, (errname, _) = await core.callStorm(q)
|
|
611
633
|
self.eq(code, -1)
|
|
612
634
|
self.eq('ProxyConnectionError', errname)
|
|
613
635
|
|
|
636
|
+
msgs = await core.stormlist('$resp=$lib.inet.http.get("http://vertex.link", proxy=(null)) $lib.print($resp.err)')
|
|
637
|
+
self.stormIsInWarn('HTTP proxy argument to $lib.null is deprecated', msgs)
|
|
638
|
+
self.stormIsInPrint('connect to proxy 127.0.0.1:1', msgs)
|
|
639
|
+
|
|
640
|
+
await self.asyncraises(s_exc.BadArg, core.nodes('$lib.inet.http.get("http://vertex.link", proxy=(1.1))'))
|
|
641
|
+
|
|
614
642
|
async with self.getTestCore() as core:
|
|
615
643
|
|
|
616
644
|
visi = await core.auth.addUser('visi')
|
|
@@ -654,6 +682,24 @@ class StormHttpTest(s_test.SynTest):
|
|
|
654
682
|
self.false(resp.get('ok'))
|
|
655
683
|
self.isin('connect to proxy 127.0.0.1:1', resp['mesg'])
|
|
656
684
|
|
|
685
|
+
host, port = await core.addHttpsPort(0)
|
|
686
|
+
opts = {
|
|
687
|
+
'vars': {
|
|
688
|
+
'url': f'https://loop.vertex.link:{port}',
|
|
689
|
+
'proxy': 'socks5://user:pass@127.0.0.1:1',
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
try:
|
|
693
|
+
oldv = core.axoninfo['synapse']['version']
|
|
694
|
+
minver = s_stormtypes.AXON_MINVERS_PROXY
|
|
695
|
+
core.axoninfo['synapse']['version'] = minver[2], minver[1] - 1, minver[0]
|
|
696
|
+
q = '$resp=$lib.axon.wget($url, ssl=(false), proxy=$proxy) $lib.print(`code={$resp.code}`)'
|
|
697
|
+
mesgs = await core.stormlist(q, opts=opts)
|
|
698
|
+
self.stormIsInPrint('code=404', mesgs)
|
|
699
|
+
self.stormIsInWarn('Axon version does not support proxy argument', mesgs)
|
|
700
|
+
finally:
|
|
701
|
+
core.axoninfo['synapse']['version'] = oldv
|
|
702
|
+
|
|
657
703
|
async with self.getTestCore(conf=conf) as core:
|
|
658
704
|
# Proxy permission tests in this section
|
|
659
705
|
|
|
@@ -762,10 +808,15 @@ class StormHttpTest(s_test.SynTest):
|
|
|
762
808
|
($ok, $valu) = $sock.tx(lololol)
|
|
763
809
|
return($sock.rx())
|
|
764
810
|
'''
|
|
765
|
-
opts = {'vars': {'port': port, 'proxy':
|
|
811
|
+
opts = {'vars': {'port': port, 'proxy': True}}
|
|
766
812
|
self.eq((True, ('echo', 'lololol')),
|
|
767
813
|
await core.callStorm(query, opts=opts))
|
|
768
814
|
|
|
815
|
+
opts = {'vars': {'port': port, 'proxy': None}}
|
|
816
|
+
mesgs = await core.stormlist(query, opts=opts)
|
|
817
|
+
self.stormIsInWarn('proxy argument to $lib.null is deprecated', mesgs)
|
|
818
|
+
self.true(mesgs[-2][0] == 'err' and mesgs[-2][1][1]['mesg'] == "(True, ['echo', 'lololol'])")
|
|
819
|
+
|
|
769
820
|
visi = await core.auth.addUser('visi')
|
|
770
821
|
|
|
771
822
|
opts = {'user': visi.iden, 'vars': {'port': port, 'proxy': False}}
|
|
@@ -903,16 +954,10 @@ class StormHttpTest(s_test.SynTest):
|
|
|
903
954
|
core.axoninfo['synapse']['version'] = oldv
|
|
904
955
|
|
|
905
956
|
## version check succeeds
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
self.eq(200, await core.callStorm(axon_queries['postfile'], opts=opts))
|
|
911
|
-
self.eq(200, await core.callStorm(axon_queries['wget'], opts=opts))
|
|
912
|
-
self.eq(200, await core.callStorm(axon_queries['wput'], opts=opts))
|
|
913
|
-
self.len(1, await core.nodes(axon_queries['urlfile'], opts=opts))
|
|
914
|
-
finally:
|
|
915
|
-
core.axoninfo['synapse']['version'] = oldv
|
|
957
|
+
self.eq(200, await core.callStorm(axon_queries['postfile'], opts=opts))
|
|
958
|
+
self.eq(200, await core.callStorm(axon_queries['wget'], opts=opts))
|
|
959
|
+
self.eq(200, await core.callStorm(axon_queries['wput'], opts=opts))
|
|
960
|
+
self.len(1, await core.nodes(axon_queries['urlfile'], opts=opts))
|
|
916
961
|
|
|
917
962
|
# verify arg precedence
|
|
918
963
|
|
|
@@ -56,18 +56,6 @@ class UnivServerTest(s_t_utils.SynTest):
|
|
|
56
56
|
async with await s_telepath.openurl(f'cell://{dirn}') as proxy:
|
|
57
57
|
self.eq('cell', await proxy.getCellType())
|
|
58
58
|
|
|
59
|
-
argv = [
|
|
60
|
-
'synapse.tests.test_lib_cell.EchoAuth',
|
|
61
|
-
'--telepath', 'tcp://127.0.0.1:0/',
|
|
62
|
-
'--https', '0',
|
|
63
|
-
'--name', 'univtest',
|
|
64
|
-
dirn,
|
|
65
|
-
]
|
|
66
|
-
# Or start the Cortex off a a EchoAuth (don't do this in practice...)
|
|
67
|
-
async with await s_s_univ.main(argv) as cell:
|
|
68
|
-
async with await s_telepath.openurl(f'cell://{dirn}') as proxy:
|
|
69
|
-
self.eq('echoauth', await proxy.getCellType())
|
|
70
|
-
|
|
71
59
|
argv = ['synapse.lib.newp.Newp']
|
|
72
60
|
with self.raises(s_exc.NoSuchCtor):
|
|
73
61
|
async with await s_s_univ.main(argv) as core:
|