refactor(api/core/workflow/nodes/http_request): Remove mask_authorization_header because its alwary true. (#6379)

This commit is contained in:
-LAN- 2024-07-17 16:52:14 +08:00 committed by GitHub
parent 984658f5e9
commit fc37887a21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 34 deletions

View File

@ -58,4 +58,3 @@ class HttpRequestNodeData(BaseNodeData):
params: str
body: Optional[HttpRequestNodeBody] = None
timeout: Optional[HttpRequestNodeTimeout] = None
mask_authorization_header: Optional[bool] = True

View File

@ -283,7 +283,7 @@ class HttpExecutor:
# validate response
return self._validate_and_parse_response(response)
def to_raw_request(self, mask_authorization_header: Optional[bool] = True) -> str:
def to_raw_request(self) -> str:
"""
convert to raw request
"""
@ -295,16 +295,15 @@ class HttpExecutor:
headers = self._assembling_headers()
for k, v in headers.items():
if mask_authorization_header:
# get authorization header
if self.authorization.type == 'api-key':
authorization_header = 'Authorization'
if self.authorization.config and self.authorization.config.header:
authorization_header = self.authorization.config.header
# get authorization header
if self.authorization.type == 'api-key':
authorization_header = 'Authorization'
if self.authorization.config and self.authorization.config.header:
authorization_header = self.authorization.config.header
if k.lower() == authorization_header.lower():
raw_request += f'{k}: {"*" * len(v)}\n'
continue
if k.lower() == authorization_header.lower():
raw_request += f'{k}: {"*" * len(v)}\n'
continue
raw_request += f'{k}: {v}\n'

View File

@ -65,9 +65,7 @@ class HttpRequestNode(BaseNode):
process_data = {}
if http_executor:
process_data = {
'request': http_executor.to_raw_request(
mask_authorization_header=node_data.mask_authorization_header
),
'request': http_executor.to_raw_request(),
}
return NodeRunResult(
status=WorkflowNodeExecutionStatus.FAILED,
@ -86,9 +84,7 @@ class HttpRequestNode(BaseNode):
'files': files,
},
process_data={
'request': http_executor.to_raw_request(
mask_authorization_header=node_data.mask_authorization_header,
),
'request': http_executor.to_raw_request(),
},
)

View File

@ -1,4 +1,6 @@
import re
from collections.abc import Mapping
from typing import Any
from core.workflow.entities.variable_entities import VariableSelector
@ -77,7 +79,7 @@ class VariableTemplateParser:
return variable_selectors
def format(self, inputs: dict, remove_template_variables: bool = True) -> str:
def format(self, inputs: Mapping[str, Any], remove_template_variables: bool = True) -> str:
"""
Formats the template string by replacing the template variables with their corresponding values.
@ -91,6 +93,9 @@ class VariableTemplateParser:
def replacer(match):
key = match.group(1)
value = inputs.get(key, match.group(0)) # return original matched string if key not found
if value is None:
value = ''
# convert the value to string
if isinstance(value, list | dict | bool | int | float):
value = str(value)

View File

@ -43,7 +43,6 @@ def test_get(setup_http_mock):
'headers': 'X-Header:123',
'params': 'A:b',
'body': None,
'mask_authorization_header': False,
}
}, **BASIC_NODE_DATA)
@ -52,7 +51,6 @@ def test_get(setup_http_mock):
data = result.process_data.get('request', '')
assert '?A=b' in data
assert 'api-key: Basic ak-xxx' in data
assert 'X-Header: 123' in data
@ -103,7 +101,6 @@ def test_custom_authorization_header(setup_http_mock):
'headers': 'X-Header:123',
'params': 'A:b',
'body': None,
'mask_authorization_header': False,
}
}, **BASIC_NODE_DATA)
@ -113,7 +110,6 @@ def test_custom_authorization_header(setup_http_mock):
assert '?A=b' in data
assert 'X-Header: 123' in data
assert 'X-Auth: Auth' in data
@pytest.mark.parametrize('setup_http_mock', [['none']], indirect=True)
@ -136,7 +132,6 @@ def test_template(setup_http_mock):
'headers': 'X-Header:123\nX-Header2:{{#a.b123.args2#}}',
'params': 'A:b\nTemplate:{{#a.b123.args2#}}',
'body': None,
'mask_authorization_header': False,
}
}, **BASIC_NODE_DATA)
@ -145,7 +140,6 @@ def test_template(setup_http_mock):
assert '?A=b' in data
assert 'Template=2' in data
assert 'api-key: Basic ak-xxx' in data
assert 'X-Header: 123' in data
assert 'X-Header2: 2' in data
@ -173,7 +167,6 @@ def test_json(setup_http_mock):
'type': 'json',
'data': '{"a": "{{#a.b123.args1#}}"}'
},
'mask_authorization_header': False,
}
}, **BASIC_NODE_DATA)
@ -181,7 +174,6 @@ def test_json(setup_http_mock):
data = result.process_data.get('request', '')
assert '{"a": "1"}' in data
assert 'api-key: Basic ak-xxx' in data
assert 'X-Header: 123' in data
@ -207,7 +199,6 @@ def test_x_www_form_urlencoded(setup_http_mock):
'type': 'x-www-form-urlencoded',
'data': 'a:{{#a.b123.args1#}}\nb:{{#a.b123.args2#}}'
},
'mask_authorization_header': False,
}
}, **BASIC_NODE_DATA)
@ -215,7 +206,6 @@ def test_x_www_form_urlencoded(setup_http_mock):
data = result.process_data.get('request', '')
assert 'a=1&b=2' in data
assert 'api-key: Basic ak-xxx' in data
assert 'X-Header: 123' in data
@ -241,7 +231,6 @@ def test_form_data(setup_http_mock):
'type': 'form-data',
'data': 'a:{{#a.b123.args1#}}\nb:{{#a.b123.args2#}}'
},
'mask_authorization_header': False,
}
}, **BASIC_NODE_DATA)
@ -252,7 +241,6 @@ def test_form_data(setup_http_mock):
assert '1' in data
assert 'form-data; name="b"' in data
assert '2' in data
assert 'api-key: Basic ak-xxx' in data
assert 'X-Header: 123' in data
@ -278,14 +266,12 @@ def test_none_data(setup_http_mock):
'type': 'none',
'data': '123123123'
},
'mask_authorization_header': False,
}
}, **BASIC_NODE_DATA)
result = node.run(pool)
data = result.process_data.get('request', '')
assert 'api-key: Basic ak-xxx' in data
assert 'X-Header: 123' in data
assert '123123123' not in data
@ -305,7 +291,6 @@ def test_mock_404(setup_http_mock):
'body': None,
'params': '',
'headers': 'X-Header:123',
'mask_authorization_header': False,
}
}, **BASIC_NODE_DATA)
@ -334,7 +319,6 @@ def test_multi_colons_parse(setup_http_mock):
'type': 'form-data',
'data': 'Referer:http://example5.com\nRedirect:http://example6.com'
},
'mask_authorization_header': False,
}
}, **BASIC_NODE_DATA)