Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions microservices/gatewayApi/tests/utils/test_validate_upstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ def test_upstream_pass_validation(app):

validate_upstream (y, { "perm-upstreams": ["my-namespace"]}, [], True)

def test_upstream_pass_validation_exact_match(app):
payload = '''
services:
- name: my-service
tags: ["ns.mytest", "another"]
host: 192.168.1.1
'''
y = yaml.load(payload, Loader=yaml.FullLoader)

validate_upstream (y, { "perm-upstreams": ["192.168.1.1"]}, [], True)

def test_upstream_fail_validation(app):
payload = '''
services:
Expand Down
6 changes: 3 additions & 3 deletions microservices/gatewayApi/utils/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def validate_upstream_host(_host, errors, allow_protected_ns, protected_kube_nam

if host in restricted:
errors.append("service upstream is invalid (e1)")
elif host.endswith('svc'):
elif host.endswith('.svc'):
partials = host.split('.')
# get the namespace, and make sure it is not in the protected_kube_namespaces list
if len(partials) != 3:
Expand All @@ -61,7 +61,7 @@ def validate_upstream_host(_host, errors, allow_protected_ns, protected_kube_nam
errors.append("service upstream is invalid (e3)")
elif do_validate_upstreams and (partials[1] in perm_upstreams) is False:
errors.append("service upstream is invalid (e6)")
elif host.endswith('svc.cluster.local'):
elif host.endswith('.svc.cluster.local'):
partials = host.split('.')
# get the namespace, and make sure it is not in the protected_kube_namespaces list
if len(partials) != 5:
Expand All @@ -70,5 +70,5 @@ def validate_upstream_host(_host, errors, allow_protected_ns, protected_kube_nam
errors.append("service upstream is invalid (e5)")
elif do_validate_upstreams and (partials[1] in perm_upstreams) is False:
errors.append("service upstream is invalid (e6)")
elif do_validate_upstreams:
elif do_validate_upstreams and (host in perm_upstreams) is False:
errors.append("service upstream is invalid (e6)")
Loading