mirror of
https://github.com/langgenius/dify.git
synced 2026-05-01 06:06:35 +08:00
fix: allow None AuthorizationConfig
This commit is contained in:
parent
e5ff06bcb7
commit
0614ddde7d
@ -1,6 +1,6 @@
|
|||||||
from typing import Literal, Optional, Union
|
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.base_node_data_entities import BaseNodeData
|
||||||
from core.workflow.entities.variable_entities import VariableSelector
|
from core.workflow.entities.variable_entities import VariableSelector
|
||||||
@ -17,7 +17,20 @@ class HttpRequestNodeData(BaseNodeData):
|
|||||||
header: Union[None, str]
|
header: Union[None, str]
|
||||||
|
|
||||||
type: Literal['no-auth', 'api-key']
|
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):
|
class Body(BaseModel):
|
||||||
type: Literal[None, 'form-data', 'x-www-form-urlencoded', 'raw', 'json']
|
type: Literal[None, 'form-data', 'x-www-form-urlencoded', 'raw', 'json']
|
||||||
|
|||||||
@ -54,6 +54,36 @@ def test_get(setup_http_mock):
|
|||||||
assert 'api-key: Basic ak-xxx' in data
|
assert 'api-key: Basic ak-xxx' in data
|
||||||
assert 'X-Header: 123' 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)
|
@pytest.mark.parametrize('setup_http_mock', [['none']], indirect=True)
|
||||||
def test_template(setup_http_mock):
|
def test_template(setup_http_mock):
|
||||||
node = HttpRequestNode(config={
|
node = HttpRequestNode(config={
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user