From 53f5af4afaa081428fb19c10810dcbfd38c8849c Mon Sep 17 00:00:00 2001 From: ikethecoder Date: Thu, 14 Nov 2024 16:38:30 -0800 Subject: [PATCH] remove problematic test --- .../routes/v2/test_v2_validate_upstream.py | 156 ------------------ microservices/gatewayApi/v2/routes/gateway.py | 12 +- 2 files changed, 3 insertions(+), 165 deletions(-) delete mode 100644 microservices/gatewayApi/tests/routes/v2/test_v2_validate_upstream.py diff --git a/microservices/gatewayApi/tests/routes/v2/test_v2_validate_upstream.py b/microservices/gatewayApi/tests/routes/v2/test_v2_validate_upstream.py deleted file mode 100644 index 21b61bc..0000000 --- a/microservices/gatewayApi/tests/routes/v2/test_v2_validate_upstream.py +++ /dev/null @@ -1,156 +0,0 @@ - - -# def test_index(client): -# response = client.get('/') -# assert response.data == b'["http://localhost/v1/status"]\n' - -import yaml -import pytest -from v2.routes.gateway import validate_upstream - -def test_upstream_good(app): - payload = ''' -services: - - name: my-service - tags: ["ns.mytest", "another"] - host: myservice -''' - y = yaml.load(payload, Loader=yaml.FullLoader) - validate_upstream (y, { }, []) - -def test_upstream_localhost(app): - payload = ''' -services: - - name: my-service - tags: ["ns.mytest", "another"] - host: localhost -''' - y = yaml.load(payload, Loader=yaml.FullLoader) - with pytest.raises(Exception, match=r"service upstream is invalid \(e1\)"): - validate_upstream (y, { }, []) - -def test_upstream_127(app): - payload = ''' -services: - - name: my-service - tags: ["ns.mytest", "another"] - host: 127.0.0.1 -''' - y = yaml.load(payload, Loader=yaml.FullLoader) - with pytest.raises(Exception, match=r"service upstream is invalid \(e1\)"): - validate_upstream (y, { "perm-project": ["ns.mytest"]}, []) - -def test_upstream_url(app): - payload = ''' -services: - - name: my-service - tags: ["ns.mytest", "another"] - url: http://localhost:4000 -''' - y = yaml.load(payload, Loader=yaml.FullLoader) - with pytest.raises(Exception, match=r"service upstream is invalid \(e1\)"): - validate_upstream (y, { "perm-project": ["ns.mytest"]}, []) - -def test_upstream_invalid_url(app): - payload = ''' -services: - - name: my-service - tags: ["ns.mytest", "another"] - url: localhost:4000 -''' - y = yaml.load(payload, Loader=yaml.FullLoader) - with pytest.raises(Exception, match=r"service upstream has invalid url specified \(e1\)"): - validate_upstream (y, { "perm-project": ["ns.mytest"]}, []) - - -def test_upstream_valid_service(app): - payload = ''' -services: - - name: my-service - tags: ["ns.mytest", "another"] - host: myapi.my-namespace.svc -''' - y = yaml.load(payload, Loader=yaml.FullLoader) - validate_upstream (y, { "perm-project": ["ns.mytest"]}, []) - -def test_upstream_protected_service_allow(app): - payload = ''' -services: - - name: my-service - tags: ["ns.mytest", "another"] - host: myapi.my-namespace.svc -''' - y = yaml.load(payload, Loader=yaml.FullLoader) - validate_upstream (y, { "perm-protected-ns": ["allow"]}, ['my-namespace']) - -def test_upstream_protected_service(app): - payload = ''' -services: - - name: my-service - tags: ["ns.mytest", "another"] - host: myapi.my-namespace.svc -''' - y = yaml.load(payload, Loader=yaml.FullLoader) - with pytest.raises(Exception, match=r"service upstream is invalid \(e3\)"): - validate_upstream (y, {}, ['my-namespace']) - -def test_upstream_protected_service_deny(app): - payload = ''' -services: - - name: my-service - tags: ["ns.mytest", "another"] - host: myapi.my-namespace.svc -''' - y = yaml.load(payload, Loader=yaml.FullLoader) - with pytest.raises(Exception, match=r"service upstream is invalid \(e3\)"): - validate_upstream (y, { "perm-protected-ns": ["deny"]}, ['my-namespace']) - -def test_upstream_invalid_host(app): - payload = ''' -services: - - name: my-service - tags: ["ns.mytest", "another"] - host: my-namespace.svc -''' - y = yaml.load(payload, Loader=yaml.FullLoader) - with pytest.raises(Exception, match=r"service upstream is invalid \(e2\)"): - validate_upstream (y, { "perm-protected-ns": ["deny"]}, ['my-namespace']) - -def test_upstream_protected_service_allow(app): - payload = ''' -services: - - name: my-service - tags: ["ns.mytest", "another"] - host: myapi.my-other-namespace.svc -''' - y = yaml.load(payload, Loader=yaml.FullLoader) - validate_upstream (y, { "perm-protected-ns": ["deny"]}, ['my-namespace']) - -def test_upstream_pass_validation(app): - payload = ''' -services: - - name: my-service - tags: ["ns.mytest", "another"] - host: myapi.my-namespace.svc -''' - y = yaml.load(payload, Loader=yaml.FullLoader) - - validate_upstream (y, { "perm-upstreams": ["my-namespace"]}, [], True) - -def test_upstream_fail_validation(app): - payload = ''' -services: - - name: my-service - tags: ["ns.mytest", "another"] - host: myapi.my-namespace.svc -''' - y = yaml.load(payload, Loader=yaml.FullLoader) - - with pytest.raises(Exception, match=r"service upstream is invalid \(e6\)"): - validate_upstream (y, {}, [], True) - - with pytest.raises(Exception, match=r"service upstream is invalid \(e6\)"): - validate_upstream (y, { "perm-upstreams": ["other-namespace"]}, [], True) - - with pytest.raises(Exception, match=r"service upstream is invalid \(e6\)"): - validate_upstream (y, { "perm-upstreams": [""]}, [], True) diff --git a/microservices/gatewayApi/v2/routes/gateway.py b/microservices/gatewayApi/v2/routes/gateway.py index ca6bb78..b3171fd 100644 --- a/microservices/gatewayApi/v2/routes/gateway.py +++ b/microservices/gatewayApi/v2/routes/gateway.py @@ -6,25 +6,19 @@ from urllib.parse import urlparse from subprocess import Popen, PIPE, STDOUT import uuid -import logging import json import requests import yaml -from werkzeug.exceptions import HTTPException, NotFound -from flask import Blueprint, config, jsonify, request, Response, make_response, abort, g, current_app as app -from io import TextIOWrapper +from werkzeug.exceptions import HTTPException +from flask import Blueprint, jsonify, request, make_response, abort, current_app as app from clients.ocp_routes import get_host_list, get_route_overrides from v2.auth.auth import admin_jwt, uma_enforce - from v2.services.namespaces import NamespaceService from clients.portal import record_gateway_event from clients.kong import get_routes, register_kong_certs -from clients.ocp_networksecuritypolicy import get_ocp_service_namespaces, check_nsp, apply_nsp, delete_nsp -from clients.ocp_routes import prepare_apply_routes, prepare_delete_routes, apply_routes, delete_routes -from clients.ocp_gateway_secret import prep_submitted_config, prep_and_apply_secret, write_submitted_config - +from clients.ocp_gateway_secret import prep_submitted_config from utils.validators import host_valid from utils.transforms import plugins_transformations from utils.masking import mask