@@ -484,11 +484,10 @@ rewrite_by_lua_block {
484
484
--- no_error_log
485
485
[error]
486
486
487
-
488
-
489
487
=== 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.
492
491
--- http_config
493
492
include $TEST_NGINX_UPSTREAM_CONFIG;
494
493
lua_shared_dict cached_auths 1m;
@@ -512,13 +511,14 @@ init_by_lua_block {
512
511
backend_authentication_type = 'service_token',
513
512
backend_authentication_value = 'token-value',
514
513
proxy = {
515
- error_status_auth_missing = 403,
516
514
authentication_method = 'oidc',
517
515
oidc_issuer_endpoint = 'https://example.com/auth/realms/apicast',
518
516
backend = { endpoint = "http://127.0.0.1:$TEST_NGINX_SERVER_PORT" },
519
517
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,
520
520
proxy_rules = {
521
- { pattern = '/', http_method = 'GET', metric_system_name = 'hits', delta = 2 }
521
+ { pattern = '/', http_method = 'GET', metric_system_name = 'hits', delta = 1 }
522
522
},
523
523
policy_chain = {
524
524
{ name = 'apicast.policy.3scale_batcher', configuration = {} },
@@ -544,22 +544,54 @@ init_by_lua_block {
544
544
end
545
545
}
546
546
}
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
+ }
547
579
location /api-backend {
548
580
echo 'yay, api backend';
549
581
}
550
582
--- request eval
551
- [ "GET /test", "GET /test" ]
583
+ [ "GET /test", "GET /test", "GET /force_report_to_backend", "GET /transactions.xml" ]
552
584
--- error_code eval
553
- [ 200, 200 ]
585
+ [ 200, 200 , 200, 200 ]
554
586
--- 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}" ]
556
588
--- more_headers eval
557
589
use Crypt::JWT qw(encode_jwt);
558
590
my $jwt = encode_jwt(payload => {
559
591
aud => 'appid',
560
592
sub => 'someone',
561
593
iss => 'https://example.com/auth/realms/apicast',
562
594
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", "" , "" ]
564
596
--- no_error_log
565
597
[error]
0 commit comments