Skip to content
Merged
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
270 changes: 131 additions & 139 deletions t/configuration-loading-lazy.t
Original file line number Diff line number Diff line change
@@ -1,178 +1,170 @@
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();

__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
should just say service is not found
--- 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]