From bb0fad800e3a445ce5d2d0b4f4e50efea7a3bc4c Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Fri, 27 May 2022 22:28:46 +0200 Subject: [PATCH 1/2] t/configuration-loading-lazy.t: convert to APIcast::Blackbox --- t/configuration-loading-lazy.t | 268 ++++++++++++++++----------------- 1 file changed, 130 insertions(+), 138 deletions(-) diff --git a/t/configuration-loading-lazy.t b/t/configuration-loading-lazy.t index 354e7b3c5..66289f78a 100644 --- a/t/configuration-loading-lazy.t +++ b/t/configuration-loading-lazy.t @@ -1,16 +1,11 @@ use lib 't'; -use Test::APIcast 'no_plan'; +use Test::APIcast::Blackbox 'no_plan'; $ENV{TEST_NGINX_HTTP_CONFIG} = "$Test::APIcast::path/http.d/init.conf"; - +$ENV{APICAST_ACCESS_LOG_FILE} = "$Test::Nginx::Util::ErrLogFile"; $ENV{APICAST_CONFIGURATION_LOADER} = 'lazy'; -env_to_nginx( - 'APICAST_CONFIGURATION_LOADER', - 'TEST_NGINX_APICAST_PATH', - 'THREESCALE_CONFIG_FILE', - 'THREESCALE_PORTAL_ENDPOINT' -); +repeat_each(1); run_tests(); @@ -18,161 +13,158 @@ __DATA__ === TEST 1: load empty configuration should just say service is not found ---- main_config -env THREESCALE_PORTAL_ENDPOINT=http://127.0.0.1:$TEST_NGINX_SERVER_PORT; ---- http_config - include $TEST_NGINX_HTTP_CONFIG; - lua_package_path "$TEST_NGINX_LUA_PATH"; ---- config - include $TEST_NGINX_APICAST_CONFIG; - - location = /admin/api/nginx/spec.json { - echo "{}"; - } ---- request -GET /t +--- env eval +( + 'APICAST_CONFIGURATION_LOADER' => 'lazy', + 'THREESCALE_PORTAL_ENDPOINT' => "http://test:$ENV{TEST_NGINX_SERVER_PORT}" +) +--- upstream +location /admin/api/services.json { + echo '{}'; +} +--- request: GET /t --- error_code: 404 --- error_log service not found for host localhost +using lazy configuration loader === TEST 2: load invalid configuration should fail with server error ---- main_config -env THREESCALE_PORTAL_ENDPOINT=http://127.0.0.1:$TEST_NGINX_SERVER_PORT; ---- http_config - include $TEST_NGINX_HTTP_CONFIG; - lua_package_path "$TEST_NGINX_LUA_PATH"; ---- config - include $TEST_NGINX_APICAST_CONFIG; - - location = /admin/api/nginx/spec.json { - echo ""; - } ---- request -GET /t +--- env eval +( + 'APICAST_CONFIGURATION_LOADER' => 'lazy', + 'THREESCALE_PORTAL_ENDPOINT' => "http://test:$ENV{TEST_NGINX_SERVER_PORT}" +) +--- upstream +location /admin/api/services.json { + echo ''; +} +--- request: GET /t --- error_code: 404 +--- error_log +service not found for host localhost +using lazy configuration loader === TEST 3: load valid configuration should correctly route the request ---- main_config -env THREESCALE_PORTAL_ENDPOINT=http://127.0.0.1:$TEST_NGINX_SERVER_PORT/; -env APICAST_CONFIGURATION_LOADER=lazy; ---- http_config - include $TEST_NGINX_HTTP_CONFIG; - include $TEST_NGINX_UPSTREAM_CONFIG; - lua_package_path "$TEST_NGINX_LUA_PATH"; ---- config - include $TEST_NGINX_APICAST_CONFIG; - include $TEST_NGINX_BACKEND_CONFIG; - - location = /admin/api/nginx/spec.json { - try_files /config.json =404; - } - - location /api/ { - echo "all ok"; - } +--- env eval +( + 'APICAST_CONFIGURATION_LOADER' => 'lazy', + 'THREESCALE_PORTAL_ENDPOINT' => "http://test:$ENV{TEST_NGINX_SERVER_PORT}" +) +--- upstream env + location = /admin/api/services.json { + echo ' + { + "services": [ + { "service": { "id":1 } } + ] + }'; + } + + location = /admin/api/services/1/proxy/configs/production/latest.json { + echo ' + { + "proxy_config": { + "content": { + "id": 1, + "backend_version": 1, + "proxy": { + "hosts": [ "localhost" ], + "api_backend": "http://test:$TEST_NGINX_SERVER_PORT/", + "proxy_rules": [ + { "pattern": "/t", "http_method": "GET", "metric_system_name": "test","delta": 1 } + ] + } + } + } + }'; + } + + location /t { + echo "all ok"; + } + +--- backend + location /transactions/authrep.xml { + content_by_lua_block { + ngx.exit(200) + } + } --- request GET /t?user_key=fake --- error_code: 200 ---- user_files eval -[ - [ 'config.json', qq| - { - "services": [{ - "id": 1, - "backend_version": 1, - "proxy": { - "api_backend": "http://127.0.0.1:$Test::Nginx::Util::ServerPortForClient/api/", - "backend": { - "endpoint": "http://127.0.0.1:$Test::Nginx::Util::ServerPortForClient" - }, - "proxy_rules": [ - { "pattern": "/t", "http_method": "GET", "metric_system_name": "test","delta": 1 } - ] - } - }] - } - | ] -] +--- error_log +using lazy configuration loader +--- no_error_log +[error] === TEST 4: load invalid json To validate that process does not died with invalid config ---- main_config -env THREESCALE_PORTAL_ENDPOINT=http://127.0.0.1:$TEST_NGINX_SERVER_PORT/; -env APICAST_CONFIGURATION_LOADER=lazy; ---- http_config - include $TEST_NGINX_UPSTREAM_CONFIG; - lua_package_path "$TEST_NGINX_LUA_PATH"; ---- config - include $TEST_NGINX_APICAST_CONFIG; - include $TEST_NGINX_BACKEND_CONFIG; - - location = /admin/api/nginx/spec.json { - try_files /config.json =404; - } - - location /api/ { - echo "all ok"; - } +--- env eval +( + 'APICAST_CONFIGURATION_LOADER' => 'lazy', + 'THREESCALE_PORTAL_ENDPOINT' => "http://test:$ENV{TEST_NGINX_SERVER_PORT}" +) +--- upstream +location ~ /admin/(.+) { + echo '{Hello, world}'; +} --- request GET /t?user_key=fake --- error_code: 404 ---- user_files ->>> config.json -{Hello, world} --- no_error_log [error] === TEST 5: load invalid oidc target url ---- main_config -env THREESCALE_PORTAL_ENDPOINT=http://127.0.0.1:$TEST_NGINX_SERVER_PORT/; -env APICAST_CONFIGURATION_LOADER=lazy; ---- http_config - include $TEST_NGINX_HTTP_CONFIG; - include $TEST_NGINX_UPSTREAM_CONFIG; - lua_package_path "$TEST_NGINX_LUA_PATH"; ---- config - include $TEST_NGINX_APICAST_CONFIG; - include $TEST_NGINX_BACKEND_CONFIG; - - location = /admin/api/nginx/spec.json { - try_files /config.json =404; - } - - location /api/ { - echo "all ok"; - } +--- env eval +( + 'APICAST_CONFIGURATION_LOADER' => 'lazy', + 'THREESCALE_PORTAL_ENDPOINT' => "http://test:$ENV{TEST_NGINX_SERVER_PORT}" +) +--- upstream env + location = /admin/api/services.json { + echo ' + { + "services": [ + { "service": { "id":1 } } + ] + }'; + } + + location = /admin/api/services/1/proxy/configs/production/latest.json { + echo ' + { + "proxy_config": { + "content": { + "id": 1, + "backend_version": "oauth", + "proxy": { + "hosts": [ "localhost" ], + "api_backend": "http://test:$TEST_NGINX_SERVER_PORT/", + "service_id": 2555417794444, + "oidc_issuer_endpoint": "www.fgoodl/adasd", + "authentication_method": "oidc", + "service_backend_version": "oauth", + "proxy_rules": [ + { "pattern": "/t", "http_method": "GET", "metric_system_name": "test","delta": 1 } + ] + } + } + } + }'; + } +--- backend + location /transactions/authrep.xml { + content_by_lua_block { + ngx.exit(200) + } + } --- request GET /t?user_key=fake --- error_code: 401 ---- user_files eval -[ - [ 'config.json', qq| - { - "services": [{ - "id": 1, - "backend_version": 1, - "backend_version": "oauth", - "proxy": { - "api_backend": "http://127.0.0.1:$Test::Nginx::Util::ServerPortForClient/api/", - "service_id": 2555417794444, - "oidc_issuer_endpoint": "www.fgoodl/adasd", - "authentication_method": "oidc", - "service_backend_version": "oauth", - "hosts": [ - "localhost" - ], - "backend": { - "endpoint": "http://127.0.0.1:$Test::Nginx::Util::ServerPortForClient" - }, - "proxy_rules": [ - { "pattern": "/t", "http_method": "GET", "metric_system_name": "test", "delta": 1} - ] - } - }] - } - | ] -] --- error_log +using lazy configuration loader OIDC url is not valid, uri: +--- no_error_log +[error] From 4aa8a60e76990a44cf297490c5b06021885e55c0 Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Wed, 1 Jun 2022 13:01:29 +0200 Subject: [PATCH 2/2] configuration-loading-lazy.t: little fix --- t/configuration-loading-lazy.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/configuration-loading-lazy.t b/t/configuration-loading-lazy.t index 66289f78a..177b98ada 100644 --- a/t/configuration-loading-lazy.t +++ b/t/configuration-loading-lazy.t @@ -29,7 +29,7 @@ service not found for host localhost using lazy configuration loader === TEST 2: load invalid configuration -should fail with server error +should just say service is not found --- env eval ( 'APICAST_CONFIGURATION_LOADER' => 'lazy',