-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from kat.harness import Query | ||
from abstract_tests import AmbassadorTest, ServiceType, HTTP | ||
import json | ||
|
||
class BufferLimitBytesTest(AmbassadorTest): | ||
target: ServiceType | ||
|
||
def init(self): | ||
self.target = HTTP(name="target") | ||
|
||
# Test generating config with an increased buffer and that the lua body() funciton runs to buffer the request body | ||
def config(self): | ||
yield self, self.format(""" | ||
--- | ||
apiVersion: getambassador.io/v3alpha1 | ||
kind: Module | ||
name: ambassador | ||
config: | ||
buffer_limit_bytes: 5242880 | ||
lua_scripts: | | ||
function envoy_on_request(request_handle) | ||
request_handle:headers():add("request_body_size", request_handle:body():length()) | ||
end | ||
--- | ||
apiVersion: getambassador.io/v3alpha1 | ||
kind: Mapping | ||
name: {self.target.path.k8s}-foo | ||
hostname: "*" | ||
prefix: /foo/ | ||
service: {self.target.path.fqdn} | ||
""") | ||
|
||
def queries(self): | ||
yield Query(self.url("foo/")) | ||
yield Query(self.url("ambassador/v0/diag/")) | ||
|
||
def check(self): | ||
assert self.results[0].status == 200 | ||
assert self.results[1].status == 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
import logging | ||
|
||
import pytest | ||
|
||
logging.basicConfig( | ||
level=logging.INFO, | ||
format="%(asctime)s test %(levelname)s: %(message)s", | ||
datefmt='%Y-%m-%d %H:%M:%S' | ||
) | ||
|
||
logger = logging.getLogger("ambassador") | ||
|
||
from ambassador import Config, IR, EnvoyConfig | ||
from ambassador.fetch import ResourceFetcher | ||
from ambassador.utils import NullSecretHandler | ||
|
||
from tests.utils import default_listener_manifests | ||
|
||
def _get_envoy_config(yaml, version='V3'): | ||
aconf = Config() | ||
fetcher = ResourceFetcher(logger, aconf) | ||
fetcher.parse_yaml(default_listener_manifests() + yaml, k8s=True) | ||
aconf.load_all(fetcher.sorted()) | ||
secret_handler = NullSecretHandler(logger, None, None, "0") | ||
ir = IR(aconf, file_checker=lambda path: True, secret_handler=secret_handler) | ||
|
||
assert ir | ||
|
||
econf = EnvoyConfig.generate(ir, version) | ||
assert econf, "could not create an econf" | ||
|
||
return econf | ||
|
||
|
||
@pytest.mark.compilertest | ||
def test_setting_buffer_limit(): | ||
yaml = """ | ||
--- | ||
apiVersion: getambassador.io/v2 | ||
kind: Module | ||
metadata: | ||
name: ambassador | ||
namespace: default | ||
spec: | ||
config: | ||
buffer_limit_bytes: 5242880 | ||
--- | ||
apiVersion: x.getambassador.io/v3alpha1 | ||
kind: Mapping | ||
metadata: | ||
name: ambassador | ||
namespace: default | ||
spec: | ||
prefix: /test/ | ||
hostname: "*" | ||
service: test:9999 | ||
""" | ||
econf = _get_envoy_config(yaml, version='V2') | ||
expected = 5242880 | ||
key_found = False | ||
|
||
conf = econf.as_dict() | ||
|
||
for listener in conf['static_resources']['listeners']: | ||
per_connection_buffer_limit_bytes = listener.get('per_connection_buffer_limit_bytes', None) | ||
assert per_connection_buffer_limit_bytes is not None, \ | ||
f"per_connection_buffer_limit_bytes not found on listener: {listener.name}" | ||
print(f"Found per_connection_buffer_limit_bytes = {per_connection_buffer_limit_bytes}") | ||
key_found = True | ||
assert expected == int(per_connection_buffer_limit_bytes), \ | ||
"per_connection_buffer_limit_bytes must equal the value set on the ambassador Module" | ||
assert key_found, 'per_connection_buffer_limit_bytes must be found in the envoy config' | ||
|
||
|
||
@pytest.mark.compilertest | ||
def test_setting_buffer_limit_V3(): | ||
yaml = """ | ||
--- | ||
apiVersion: getambassador.io/v2 | ||
kind: Module | ||
metadata: | ||
name: ambassador | ||
namespace: default | ||
spec: | ||
config: | ||
buffer_limit_bytes: 5242880 | ||
--- | ||
apiVersion: x.getambassador.io/v3alpha1 | ||
kind: Mapping | ||
metadata: | ||
name: ambassador | ||
namespace: default | ||
spec: | ||
prefix: /test/ | ||
hostname: "*" | ||
service: test:9999 | ||
""" | ||
econf = _get_envoy_config(yaml) | ||
expected = 5242880 | ||
key_found = False | ||
|
||
conf = econf.as_dict() | ||
|
||
for listener in conf['static_resources']['listeners']: | ||
per_connection_buffer_limit_bytes = listener.get('per_connection_buffer_limit_bytes', None) | ||
assert per_connection_buffer_limit_bytes is not None, \ | ||
f"per_connection_buffer_limit_bytes not found on listener: {listener.name}" | ||
print(f"Found per_connection_buffer_limit_bytes = {per_connection_buffer_limit_bytes}") | ||
key_found = True | ||
assert expected == int(per_connection_buffer_limit_bytes), \ | ||
"per_connection_buffer_limit_bytes must equal the value set on the ambassador Module" | ||
assert key_found, 'per_connection_buffer_limit_bytes must be found in the envoy config' | ||
|
||
# Tests that the default value of per_connection_buffer_limit_bytes is disabled when there is not Module config for it. | ||
@pytest.mark.compilertest | ||
def test_default_buffer_limit(): | ||
yaml = """ | ||
--- | ||
apiVersion: x.getambassador.io/v3alpha1 | ||
kind: Mapping | ||
metadata: | ||
name: ambassador | ||
namespace: default | ||
spec: | ||
prefix: /test/ | ||
hostname: "*" | ||
service: test:9999 | ||
""" | ||
econf = _get_envoy_config(yaml, version='V2') | ||
|
||
conf = econf.as_dict() | ||
|
||
for listener in conf['static_resources']['listeners']: | ||
per_connection_buffer_limit_bytes = listener.get('per_connection_buffer_limit_bytes', None) | ||
assert per_connection_buffer_limit_bytes is None, \ | ||
f"per_connection_buffer_limit_bytes found on listener (should not exist unless configured in the module): {listener.name}" | ||
|
||
|
||
@pytest.mark.compilertest | ||
def test_default_buffer_limit_V3(): | ||
yaml = """ | ||
--- | ||
apiVersion: x.getambassador.io/v3alpha1 | ||
kind: Mapping | ||
metadata: | ||
name: ambassador | ||
namespace: default | ||
spec: | ||
prefix: /test/ | ||
hostname: "*" | ||
service: test:9999 | ||
""" | ||
econf = _get_envoy_config(yaml) | ||
|
||
conf = econf.as_dict() | ||
|
||
for listener in conf['static_resources']['listeners']: | ||
per_connection_buffer_limit_bytes = listener.get('per_connection_buffer_limit_bytes', None) | ||
assert per_connection_buffer_limit_bytes is None, \ | ||
f"per_connection_buffer_limit_bytes found on listener (should not exist unless configured in the module): {listener.name}" | ||
|
||
# Tests that the default value of per_connection_buffer_limit_bytes is disabled when there is not Module config for it (and that there are no issues when we dont make a listener). | ||
@pytest.mark.compilertest | ||
def test_buffer_limit_no_listener(): | ||
yaml = """ | ||
--- | ||
apiVersion: x.getambassador.io/v3alpha1 | ||
kind: Mapping | ||
metadata: | ||
name: ambassador | ||
namespace: default | ||
spec: | ||
prefix: /test/ | ||
hostname: "*" | ||
service: test:9999 | ||
""" | ||
econf = _get_envoy_config(yaml, version='V2') | ||
|
||
conf = econf.as_dict() | ||
|
||
for listener in conf['static_resources']['listeners']: | ||
per_connection_buffer_limit_bytes = listener.get('per_connection_buffer_limit_bytes', None) | ||
assert per_connection_buffer_limit_bytes is None, \ | ||
f"per_connection_buffer_limit_bytes found on listener (should not exist unless configured in the module): {listener.name}" | ||
|
||
|
||
@pytest.mark.compilertest | ||
def test_buffer_limit_no_listener_V3(): | ||
yaml = """ | ||
--- | ||
apiVersion: x.getambassador.io/v3alpha1 | ||
kind: Mapping | ||
metadata: | ||
name: ambassador | ||
namespace: default | ||
spec: | ||
prefix: /test/ | ||
hostname: "*" | ||
service: test:9999 | ||
""" | ||
econf = _get_envoy_config(yaml) | ||
|
||
conf = econf.as_dict() | ||
|
||
for listener in conf['static_resources']['listeners']: | ||
per_connection_buffer_limit_bytes = listener.get('per_connection_buffer_limit_bytes', None) | ||
assert per_connection_buffer_limit_bytes is None, \ | ||
f"per_connection_buffer_limit_bytes found on listener (should not exist unless configured in the module): {listener.name}" |