chore: refactor the http executor node (#5212)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from urllib.parse import urlencode
|
||||
|
||||
import pytest
|
||||
|
||||
from core.app.entities.app_invoke_entities import InvokeFrom
|
||||
@@ -20,6 +22,7 @@ pool = VariablePool(system_variables={}, user_inputs={})
|
||||
pool.append_variable(node_id='a', variable_key_list=['b123', 'args1'], value=1)
|
||||
pool.append_variable(node_id='a', variable_key_list=['b123', 'args2'], value=2)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('setup_http_mock', [['none']], indirect=True)
|
||||
def test_get(setup_http_mock):
|
||||
node = HttpRequestNode(config={
|
||||
@@ -33,7 +36,7 @@ def test_get(setup_http_mock):
|
||||
'type': 'api-key',
|
||||
'config': {
|
||||
'type': 'basic',
|
||||
'api_key':'ak-xxx',
|
||||
'api_key': 'ak-xxx',
|
||||
'header': 'api-key',
|
||||
}
|
||||
},
|
||||
@@ -52,6 +55,7 @@ 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={
|
||||
@@ -78,6 +82,7 @@ def test_no_auth(setup_http_mock):
|
||||
assert '?A=b' in data
|
||||
assert 'X-Header: 123' in data
|
||||
|
||||
|
||||
@pytest.mark.parametrize('setup_http_mock', [['none']], indirect=True)
|
||||
def test_custom_authorization_header(setup_http_mock):
|
||||
node = HttpRequestNode(config={
|
||||
@@ -110,6 +115,7 @@ def test_custom_authorization_header(setup_http_mock):
|
||||
assert 'X-Header: 123' in data
|
||||
assert 'X-Auth: Auth' in data
|
||||
|
||||
|
||||
@pytest.mark.parametrize('setup_http_mock', [['none']], indirect=True)
|
||||
def test_template(setup_http_mock):
|
||||
node = HttpRequestNode(config={
|
||||
@@ -123,7 +129,7 @@ def test_template(setup_http_mock):
|
||||
'type': 'api-key',
|
||||
'config': {
|
||||
'type': 'basic',
|
||||
'api_key':'ak-xxx',
|
||||
'api_key': 'ak-xxx',
|
||||
'header': 'api-key',
|
||||
}
|
||||
},
|
||||
@@ -143,6 +149,7 @@ def test_template(setup_http_mock):
|
||||
assert 'X-Header: 123' in data
|
||||
assert 'X-Header2: 2' in data
|
||||
|
||||
|
||||
@pytest.mark.parametrize('setup_http_mock', [['none']], indirect=True)
|
||||
def test_json(setup_http_mock):
|
||||
node = HttpRequestNode(config={
|
||||
@@ -156,7 +163,7 @@ def test_json(setup_http_mock):
|
||||
'type': 'api-key',
|
||||
'config': {
|
||||
'type': 'basic',
|
||||
'api_key':'ak-xxx',
|
||||
'api_key': 'ak-xxx',
|
||||
'header': 'api-key',
|
||||
}
|
||||
},
|
||||
@@ -177,6 +184,7 @@ def test_json(setup_http_mock):
|
||||
assert 'api-key: Basic ak-xxx' in data
|
||||
assert 'X-Header: 123' in data
|
||||
|
||||
|
||||
def test_x_www_form_urlencoded(setup_http_mock):
|
||||
node = HttpRequestNode(config={
|
||||
'id': '1',
|
||||
@@ -189,7 +197,7 @@ def test_x_www_form_urlencoded(setup_http_mock):
|
||||
'type': 'api-key',
|
||||
'config': {
|
||||
'type': 'basic',
|
||||
'api_key':'ak-xxx',
|
||||
'api_key': 'ak-xxx',
|
||||
'header': 'api-key',
|
||||
}
|
||||
},
|
||||
@@ -210,6 +218,7 @@ def test_x_www_form_urlencoded(setup_http_mock):
|
||||
assert 'api-key: Basic ak-xxx' in data
|
||||
assert 'X-Header: 123' in data
|
||||
|
||||
|
||||
def test_form_data(setup_http_mock):
|
||||
node = HttpRequestNode(config={
|
||||
'id': '1',
|
||||
@@ -222,7 +231,7 @@ def test_form_data(setup_http_mock):
|
||||
'type': 'api-key',
|
||||
'config': {
|
||||
'type': 'basic',
|
||||
'api_key':'ak-xxx',
|
||||
'api_key': 'ak-xxx',
|
||||
'header': 'api-key',
|
||||
}
|
||||
},
|
||||
@@ -246,6 +255,7 @@ def test_form_data(setup_http_mock):
|
||||
assert 'api-key: Basic ak-xxx' in data
|
||||
assert 'X-Header: 123' in data
|
||||
|
||||
|
||||
def test_none_data(setup_http_mock):
|
||||
node = HttpRequestNode(config={
|
||||
'id': '1',
|
||||
@@ -258,7 +268,7 @@ def test_none_data(setup_http_mock):
|
||||
'type': 'api-key',
|
||||
'config': {
|
||||
'type': 'basic',
|
||||
'api_key':'ak-xxx',
|
||||
'api_key': 'ak-xxx',
|
||||
'header': 'api-key',
|
||||
}
|
||||
},
|
||||
@@ -278,3 +288,59 @@ def test_none_data(setup_http_mock):
|
||||
assert 'api-key: Basic ak-xxx' in data
|
||||
assert 'X-Header: 123' in data
|
||||
assert '123123123' not in data
|
||||
|
||||
|
||||
def test_mock_404(setup_http_mock):
|
||||
node = HttpRequestNode(config={
|
||||
'id': '1',
|
||||
'data': {
|
||||
'title': 'http',
|
||||
'desc': '',
|
||||
'method': 'get',
|
||||
'url': 'http://404.com',
|
||||
'authorization': {
|
||||
'type': 'no-auth',
|
||||
'config': None,
|
||||
},
|
||||
'body': None,
|
||||
'params': '',
|
||||
'headers': 'X-Header:123',
|
||||
'mask_authorization_header': False,
|
||||
}
|
||||
}, **BASIC_NODE_DATA)
|
||||
|
||||
result = node.run(pool)
|
||||
resp = result.outputs
|
||||
|
||||
assert 404 == resp.get('status_code')
|
||||
assert 'Not Found' in resp.get('body')
|
||||
|
||||
|
||||
def test_multi_colons_parse(setup_http_mock):
|
||||
node = HttpRequestNode(config={
|
||||
'id': '1',
|
||||
'data': {
|
||||
'title': 'http',
|
||||
'desc': '',
|
||||
'method': 'get',
|
||||
'url': 'http://example.com',
|
||||
'authorization': {
|
||||
'type': 'no-auth',
|
||||
'config': None,
|
||||
},
|
||||
'params': 'Referer:http://example1.com\nRedirect:http://example2.com',
|
||||
'headers': 'Referer:http://example3.com\nRedirect:http://example4.com',
|
||||
'body': {
|
||||
'type': 'form-data',
|
||||
'data': 'Referer:http://example5.com\nRedirect:http://example6.com'
|
||||
},
|
||||
'mask_authorization_header': False,
|
||||
}
|
||||
}, **BASIC_NODE_DATA)
|
||||
|
||||
result = node.run(pool)
|
||||
resp = result.outputs
|
||||
|
||||
assert urlencode({'Redirect': 'http://example2.com'}) in result.process_data.get('request')
|
||||
assert 'form-data; name="Redirect"\n\nhttp://example6.com' in result.process_data.get('request')
|
||||
assert 'http://example3.com' == resp.get('headers').get('referer')
|
||||
|
Reference in New Issue
Block a user