diff --git a/api/core/workflow/nodes/http_request/entities.py b/api/core/workflow/nodes/http_request/entities.py index ce806b6bdb..fbd4da3840 100644 --- a/api/core/workflow/nodes/http_request/entities.py +++ b/api/core/workflow/nodes/http_request/entities.py @@ -1,6 +1,6 @@ from typing import Literal, Optional, Union -from pydantic import BaseModel +from pydantic import BaseModel, validator from core.workflow.entities.base_node_data_entities import BaseNodeData from core.workflow.entities.variable_entities import VariableSelector @@ -17,7 +17,20 @@ class HttpRequestNodeData(BaseNodeData): header: Union[None, str] type: Literal['no-auth', 'api-key'] - config: Config + config: Optional[Config] + + @validator('config', always=True, pre=True) + def check_config(cls, v, values): + """ + Check config, if type is no-auth, config should be None, otherwise it should be a dict. + """ + if values['type'] == 'no-auth': + return None + else: + if not v or not isinstance(v, dict): + raise ValueError('config should be a dict') + + return v class Body(BaseModel): type: Literal[None, 'form-data', 'x-www-form-urlencoded', 'raw', 'json'] diff --git a/api/tests/integration_tests/workflow/nodes/test_http.py b/api/tests/integration_tests/workflow/nodes/test_http.py index 6df8f6b673..584e1d80a5 100644 --- a/api/tests/integration_tests/workflow/nodes/test_http.py +++ b/api/tests/integration_tests/workflow/nodes/test_http.py @@ -54,6 +54,36 @@ def test_get(setup_http_mock): assert 'api-key: Basic ak-xxx' in data assert 'X-Header: 123' in data +@pytest.mark.parametrize('setup_http_mock', [['none']], indirect=True) +def test_no_auth(setup_http_mock): + node = HttpRequestNode(config={ + 'id': '1', + 'data': { + 'title': 'http', + 'desc': '', + 'variables': [{ + 'variable': 'args1', + 'value_selector': ['1', '123', 'args1'], + }], + 'method': 'get', + 'url': 'http://example.com', + 'authorization': { + 'type': 'no-auth', + 'config': None, + }, + 'headers': 'X-Header:123', + 'params': 'A:b', + 'body': None, + } + }, **BASIC_NODE_DATA) + + result = node.run(pool) + + data = result.process_data.get('request', '') + + assert '?A=b' in data + assert 'X-Header: 123' in data + @pytest.mark.parametrize('setup_http_mock', [['none']], indirect=True) def test_template(setup_http_mock): node = HttpRequestNode(config={