Skip to content

Commit

Permalink
fix: allow None AuthorizationConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeuoly committed Mar 13, 2024
1 parent 1f4826c commit e80315f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
17 changes: 15 additions & 2 deletions api/core/workflow/nodes/http_request/entities.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,7 +17,20 @@ class Config(BaseModel):
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']
Expand Down
30 changes: 30 additions & 0 deletions api/tests/integration_tests/workflow/nodes/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down

0 comments on commit e80315f

Please sign in to comment.