diff --git a/proxy/integration-tests/features/discovered_endpoint_metrics.feature b/proxy/integration-tests/features/discovered_endpoint_metrics.feature index 12b06c1..7d71e00 100644 --- a/proxy/integration-tests/features/discovered_endpoint_metrics.feature +++ b/proxy/integration-tests/features/discovered_endpoint_metrics.feature @@ -10,10 +10,10 @@ Feature: Lunar Proxy - Discovered Endpoint Metrics And 1 requests to GET http:// mox :8888 /status are made through Lunar Proxy with headers {"lunar-interceptor": "lunar-aiohttp-interceptor/2.1.3", "x-lunar-consumer-tag": "tagB"} And mox is set to return status code 200 on POST /status And 5 requests to POST http:// mox :8888 /status are made through Lunar Proxy with headers {"x-lunar-interceptor": "lunar-aiohttp-interceptor:2.1.2", "x-lunar-consumer-tag": "tagA"} - Then Discovered endpoint metrics for GET mox /status has 4 requests ({"201": 3, "402": 1}) - And Discovered endpoint metrics for POST mox /status has 5 requests ({"200": 5}) + Then Discovered endpoint metrics for GET mox:8888 /status has 4 requests ({"201": 3, "402": 1}) + And Discovered endpoint metrics for POST mox:8888 /status has 5 requests ({"200": 5}) And Discovered interceptor metrics has 3 interceptors ({"lunar-aiohttp-interceptor": "2.1.2", "unknown": "unknown", "lunar-direct": "0"}) - And Discovered consumer metrics for GET mox /status has consumer tagA with requests ({"201": 3}) - And Discovered consumer metrics for POST mox /status has consumer tagA with requests ({"200": 5}) - And Discovered consumer metrics for GET mox /status has consumer tagB with requests ({"402": 1}) + And Discovered consumer metrics for GET mox:8888 /status has consumer tagA with requests ({"201": 3}) + And Discovered consumer metrics for POST mox:8888 /status has consumer tagA with requests ({"200": 5}) + And Discovered consumer metrics for GET mox:8888 /status has consumer tagB with requests ({"402": 1}) diff --git a/proxy/integration-tests/features/policies_reload.feature b/proxy/integration-tests/features/policies_reload.feature index 15045c8..9dee3ac 100644 --- a/proxy/integration-tests/features/policies_reload.feature +++ b/proxy/integration-tests/features/policies_reload.feature @@ -4,7 +4,7 @@ Feature: Policies Reload Given Lunar Proxy is up And API Provider is up When policies.yaml file is updated - And policies.yaml includes a fixed_response remedy for GET mox /json requests with status code 202 + And policies.yaml includes a fixed_response remedy for GET mox:8888 /json requests with status code 202 And policies.yaml file is saved And apply_policies command is run without waiting for Fluent to reload And A request to http:// mox :8888 /json is made through Lunar Proxy with header 'Early-Response: true' @@ -17,7 +17,7 @@ Feature: Policies Reload And Lunar Proxy is up And mox is set to respond to GET /json with status 201 When policies.yaml file is updated - And policies.yaml includes a fixed_response remedy for GET mox /json requests with invalid config + And policies.yaml includes a fixed_response remedy for GET mox:8888 /json requests with invalid config And policies.yaml file is saved And A local POST request (id apply_policies) is made to port 8081 at path /apply_policies And A request to http:// mox :8888 /json is made through Lunar Proxy with header 'Early-Response: true' diff --git a/proxy/integration-tests/features/remedy_fixed_early_response.feature b/proxy/integration-tests/features/remedy_fixed_early_response.feature index dfc2c5d..b2395f6 100644 --- a/proxy/integration-tests/features/remedy_fixed_early_response.feature +++ b/proxy/integration-tests/features/remedy_fixed_early_response.feature @@ -4,9 +4,9 @@ Feature: Lunar Proxy fixed early response remedy Given API Provider is up And Lunar Proxy is up When policies.yaml file is updated - And policies.yaml includes a fixed_response remedy for GET mox /uuid/* requests with status code - And policies.yaml includes a fixed_response remedy for GET mox /uuid/{someID} requests with status code - And policies.yaml includes a fixed_response remedy for GET mox /test/* requests with status code + And policies.yaml includes a fixed_response remedy for GET mox:8888 /uuid/* requests with status code + And policies.yaml includes a fixed_response remedy for GET mox:8888 /uuid/{someID} requests with status code + And policies.yaml includes a fixed_response remedy for GET mox:8888 /test/* requests with status code And policies.yaml file is saved And apply_policies command is run without waiting for Fluent to reload When A request to :// : is made through Lunar Proxy with header 'Early-Response: true' @@ -23,8 +23,8 @@ Feature: Lunar Proxy fixed early response remedy And Lunar Proxy is up When policies.yaml file is updated And policies.yaml includes an accounts section with 2 accounts - And policies.yaml includes a fixed_response remedy for GET mox /uuid requests with status code 418 - And policies.yaml includes a disabled account_orchestration remedy for GET mox /uuid requests + And policies.yaml includes a fixed_response remedy for GET mox:8888 /uuid requests with status code 418 + And policies.yaml includes a disabled account_orchestration remedy for GET mox:8888 /uuid requests And policies.yaml file is saved And apply_policies command is run without waiting for Fluent to reload When A request to http:// mox :8888 /uuid is made through Lunar Proxy with header 'Early-Response: true' diff --git a/proxy/integration-tests/features/remedy_response_based_throttling.feature b/proxy/integration-tests/features/remedy_response_based_throttling.feature index 6093fc8..a8e56bf 100644 --- a/proxy/integration-tests/features/remedy_response_based_throttling.feature +++ b/proxy/integration-tests/features/remedy_response_based_throttling.feature @@ -5,7 +5,7 @@ Feature: Lunar Proxy response-based throttling remedy And Lunar Proxy is up And 2 remaining requests until rate limit threshold is reached When policies.yaml file is updated - And policies.yaml includes a response_based_throttling remedy for GET mox /throttle requests for 429 status using retry-after header as relative_seconds + And policies.yaml includes a response_based_throttling remedy for GET mox:8888 /throttle requests for 429 status using retry-after header as relative_seconds And policies.yaml file is saved And apply_policies command is run without waiting for Fluent to reload And 4 requests to rate limited endpoint http:// mox :8888 /throttle are made via Lunar Proxy diff --git a/proxy/integration-tests/features/remedy_stats.feature b/proxy/integration-tests/features/remedy_stats.feature index de8bf4b..15da848 100644 --- a/proxy/integration-tests/features/remedy_stats.feature +++ b/proxy/integration-tests/features/remedy_stats.feature @@ -11,7 +11,7 @@ Feature: Lunar Proxy - Remedy Stats Given API Provider is up When policies.yaml file is updated - And policies.yaml includes a fixed_response remedy for GET mox /status/* requests with status code 400 + And policies.yaml includes a fixed_response remedy for GET mox:8888 /status/* requests with status code 400 And policies.yaml file is saved And apply_policies command is run @@ -29,7 +29,7 @@ Feature: Lunar Proxy - Remedy Stats And item remedy_stat affected_count is 2 And item remedy_stat has field affected_stats_by_endpoint (marked endpoint_stats) - And item endpoint_stats is an array with item that matches {"method": "GET", "url": "mox/status"} (marked as endpoint_stat) + And item endpoint_stats is an array with item that matches {"method": "GET", "url": "mox:8888/status"} (marked as endpoint_stat) And item endpoint_stat count is 2 And item endpoint_stat count_by_status_code json is {"400": 2} diff --git a/proxy/integration-tests/features/steps/proxy_mode.py b/proxy/integration-tests/features/steps/proxy_mode.py index a973a45..c62cfee 100644 --- a/proxy/integration-tests/features/steps/proxy_mode.py +++ b/proxy/integration-tests/features/steps/proxy_mode.py @@ -234,7 +234,7 @@ async def step_impl( @when( - "A request to {scheme}:// {host} :{port} {path:Path} is made {is_proxified:IsProxified} with previously returned sequence id" + "A request to {scheme}:// {host} :{port:Int} {path:Path} is made {is_proxified:IsProxified} with previously returned sequence id" ) @async_run_until_complete async def step_impl( @@ -263,7 +263,7 @@ async def step_impl( @when( - "A request to {scheme}:// {host} :{port} {path:Path} is made {is_proxified:IsProxified}" + "A request to {scheme}:// {host} :{port:Int} {path:Path} is made {is_proxified:IsProxified}" ) @async_run_until_complete async def step_impl( diff --git a/proxy/integration-tests/features/validate_lunar_generated_header.feature b/proxy/integration-tests/features/validate_lunar_generated_header.feature index ca2f433..02c9ee2 100644 --- a/proxy/integration-tests/features/validate_lunar_generated_header.feature +++ b/proxy/integration-tests/features/validate_lunar_generated_header.feature @@ -6,9 +6,9 @@ Feature: Validate Lunar Proxy add the x-lunar-generated on modified responses Scenario Outline: Lunar returns a fixed early response when policy is matched and x-lunar-generated header is true When policies.yaml file is updated - And policies.yaml includes a fixed_response remedy for GET mox /uuid/* requests with status code - And policies.yaml includes a fixed_response remedy for GET mox /uuid/{someID} requests with status code - And policies.yaml includes a fixed_response remedy for GET mox /test/* requests with status code + And policies.yaml includes a fixed_response remedy for GET mox:8888 /uuid/* requests with status code + And policies.yaml includes a fixed_response remedy for GET mox:8888 /uuid/{someID} requests with status code + And policies.yaml includes a fixed_response remedy for GET mox:8888 /test/* requests with status code And policies.yaml file is saved And apply_policies command is run without waiting for Fluent to reload When A request to :// : is made through Lunar Proxy with header 'Early-Response: true' diff --git a/proxy/integration-tests/utils/client.py b/proxy/integration-tests/utils/client.py index 99d29b8..dd97390 100644 --- a/proxy/integration-tests/utils/client.py +++ b/proxy/integration-tests/utils/client.py @@ -1,5 +1,6 @@ from typing import Optional, Tuple +from toolkit_testing.integration_tests import routing from toolkit_testing.integration_tests.routing import ( Routing, RoutingType, @@ -56,7 +57,7 @@ async def make_request( with_routing_type: bool = True, ) -> ClientResponse: headers = {header_key: header_value} if header_key and header_value else None - + host = host.replace(":80", "").replace(":443", "") requested_host, requested_port = (host, port) if is_proxified else _mock_host(host) routing_type = ( ( @@ -70,11 +71,12 @@ async def make_request( routing = Routing( requested_host=requested_host, - requested_port=requested_port, requested_scheme=extract_scheme(scheme), type=routing_type, use_x_lunar_host=use_x_lunar_host and header_based_redirection, ) + if requested_port not in [80, 443]: + routing.requested_port = requested_port if is_proxified: client = _proxy_clients[proxy_id] @@ -115,12 +117,9 @@ async def request( proxy_id: str = "0", ) -> ClientResponse: client = _proxy_clients[proxy_id] - response = await client.make_request( - routing=Routing( - requested_host=host, - requested_scheme=extract_scheme(scheme), - requested_port=port, - ), - path=path, - ) + routing = Routing(requested_host=host, requested_scheme=extract_scheme(scheme)) + if port not in [80, 443]: + routing.requested_port = port + + response = await client.make_request(routing=routing, path=path) return response diff --git a/proxy/rootfs/etc/haproxy/haproxy.cfg b/proxy/rootfs/etc/haproxy/haproxy.cfg index 9ea4428..43af4a3 100644 --- a/proxy/rootfs/etc/haproxy/haproxy.cfg +++ b/proxy/rootfs/etc/haproxy/haproxy.cfg @@ -103,7 +103,7 @@ frontend http-in # txn.url is set to the full URL excluding scheme, port and query params (e.g. domain.com/path/to/resource) http-request set-var(txn.path) path - http-request set-var(txn.url) var(txn.host),host_only,concat(,txn.path) + http-request set-var(txn.url) var(txn.host),concat(,txn.path) # txn.lunar_interceptor http-request set-var(txn.interceptor) str("lunar-direct/0") unless { req.hdr(x-lunar-interceptor) -m found } @@ -136,8 +136,11 @@ frontend http-in http-request set-var(txn.error_in_body) str("Could not resolve port") if { var(txn.dst_port) -m int 0 } http-request deny status 503 content-type text/plain lf-string "Could not resolve port" hdr x-lunar-error 5 if { var(txn.dst_port) -m int 0 } - http-request do-resolve(req.host_ip,resolv-conf,ipv4) var(txn.host),host_only - + # Check if the host is an IPv4 address and resolve it if it is not + acl is_host_ipv4 var(txn.host),host_only -i -m reg (\d+)\.(\d+)\.(\d+)\.(\d+) + http-request do-resolve(req.host_ip,resolv-conf,ipv4) var(txn.host),host_only if !is_host_ipv4 + http-request set-var(req.host_ip) var(txn.host),host_only if is_host_ipv4 + http-request set-var(txn.x_lunar_error) str(5) unless { var(req.host_ip) -m found } http-request set-var(txn.error_in_body) str("Could not resolve host") unless { var(req.host_ip) -m found } http-request deny status 503 content-type text/plain lf-string "Could not resolve host" hdr x-lunar-error 5 unless { var(req.host_ip) -m found }