Skip to content

Commit 26edfa8

Browse files
committed
Fix the batcher/oidc integration test
1 parent a4164a0 commit 26edfa8

File tree

1 file changed

+42
-10
lines changed

1 file changed

+42
-10
lines changed

t/apicast-policy-3scale-batcher.t

+42-10
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,10 @@ rewrite_by_lua_block {
484484
--- no_error_log
485485
[error]
486486
487-
488-
489487
=== TEST 6: caches successful authorizations with app_id only
490-
This test checks that the policy caches successful authorizations. To do that,
491-
we define a backend that makes sure that it's called only once.
488+
This test checks that the policy a) caches successful authorizations and b) reports correctly.
489+
For a) we define a backend that makes sure that it's called only once.
490+
For b) we force the batch reporting and check that transactions.xml receive it in the expected format.
492491
--- http_config
493492
include $TEST_NGINX_UPSTREAM_CONFIG;
494493
lua_shared_dict cached_auths 1m;
@@ -512,13 +511,14 @@ init_by_lua_block {
512511
backend_authentication_type = 'service_token',
513512
backend_authentication_value = 'token-value',
514513
proxy = {
515-
error_status_auth_missing = 403,
516514
authentication_method = 'oidc',
517515
oidc_issuer_endpoint = 'https://example.com/auth/realms/apicast',
518516
backend = { endpoint = "http://127.0.0.1:$TEST_NGINX_SERVER_PORT" },
519517
api_backend = "http://127.0.0.1:$TEST_NGINX_SERVER_PORT/api-backend/",
518+
error_auth_missing = 'credentials missing!',
519+
error_status_auth_missing = 401,
520520
proxy_rules = {
521-
{ pattern = '/', http_method = 'GET', metric_system_name = 'hits', delta = 2 }
521+
{ pattern = '/', http_method = 'GET', metric_system_name = 'hits', delta = 1 }
522522
},
523523
policy_chain = {
524524
{ name = 'apicast.policy.3scale_batcher', configuration = {} },
@@ -544,22 +544,54 @@ init_by_lua_block {
544544
end
545545
}
546546
}
547+
location /transactions.xml {
548+
content_by_lua_block {
549+
ngx.say('report OK')
550+
}
551+
}
552+
553+
location /force_report_to_backend {
554+
content_by_lua_block {
555+
local ReportsBatcher = require ('apicast.policy.3scale_batcher.reports_batcher')
556+
local reporter = require ('apicast.policy.3scale_batcher.reporter')
557+
local http_ng_resty = require('resty.http_ng.backend.resty')
558+
local backend_client = require('apicast.backend_client')
559+
560+
local service_id = 42
561+
562+
local reports_batcher = ReportsBatcher.new(
563+
ngx.shared.batched_reports, 'batched_reports_locks')
564+
565+
local reports = reports_batcher:get_all(service_id)
566+
567+
local backend = backend_client:new(
568+
{
569+
id = service_id,
570+
backend_authentication_type = 'service_token',
571+
backend_authentication_value = 'token-value',
572+
backend = { endpoint = "http://127.0.0.1:$TEST_NGINX_SERVER_PORT" }
573+
}, http_ng_resty)
574+
575+
reporter.report(reports, service_id, backend, reports_batcher)
576+
ngx.say('force report OK')
577+
}
578+
}
547579
location /api-backend {
548580
echo 'yay, api backend';
549581
}
550582
--- request eval
551-
[ "GET /test", "GET /test" ]
583+
[ "GET /test", "GET /test", "GET /force_report_to_backend", "GET /transactions.xml"]
552584
--- error_code eval
553-
[ 200, 200 ]
585+
[ 200, 200 , 200, 200 ]
554586
--- response_body eval
555-
["yay, api backend\x{0a}","yay, api backend\x{0a}"]
587+
["yay, api backend\x{0a}","yay, api backend\x{0a}","force report OK\x{0a}", "report OK\x{0a}"]
556588
--- more_headers eval
557589
use Crypt::JWT qw(encode_jwt);
558590
my $jwt = encode_jwt(payload => {
559591
aud => 'appid',
560592
sub => 'someone',
561593
iss => 'https://example.com/auth/realms/apicast',
562594
exp => time + 3600 }, key => \$::rsa, alg => 'RS256', extra_headers => { kid => 'somekid' });
563-
["Authorization: Bearer $jwt", "Authorization: Bearer $jwt"]
595+
["Authorization: Bearer $jwt", "Authorization: Bearer $jwt", "" , ""]
564596
--- no_error_log
565597
[error]

0 commit comments

Comments
 (0)