From: Dmitry Volyntsev Date: Sat, 24 Oct 2026 05:45:29 +0000 (-0700) Subject: Tests: distinguish WebCrypto absence from probe failures X-Git-Url: https://git.kaiwu.me/http/%7B@url%7D?a=commitdiff_plain;h=260b437b0ab2d76a37873007ce56edcec50decf4;p=njs.git Tests: distinguish WebCrypto absence from probe failures The capability guards introduced in 4ea1356a skipped whenever the HTTP response did not contain "true". A startup error, HTTP 500 or malformed response could therefore hide a regression. Referencing an absent crypto global also raised ReferenceError instead of returning false. Use typeof to check the global and accept only a successful response with an exact boolean body. Probe WebCrypto through stream in the stream test, independently of HTTP engine selection. Treat startup and malformed probe responses as failures. Require WebCrypto when the existing CI_SSL setting is yes. Keep a capability skip for a valid false response outside SSL-enabled CI, so local builds without crypto remain supported. --- diff --git a/nginx/t/js_webcrypto.t b/nginx/t/js_webcrypto.t index 94f916a4..9ebcd241 100644 --- a/nginx/t/js_webcrypto.t +++ b/nginx/t/js_webcrypto.t @@ -59,7 +59,7 @@ EOF $t->write_file('test.js', <write_file('test.js', <try_run('no njs'); +$t->run(); -plan(skip_all => 'njs crypto module not available') - if http_get('/has_crypto') !~ /true/; +my $response = http_get('/has_crypto'); +my ($headers, $has_crypto) = split(/\x0d\x0a\x0d\x0a/, $response // '', 2); + +die "invalid WebCrypto capability response\n" + unless defined $has_crypto && $headers =~ /\AHTTP\/1\.[01] 200 / + && $has_crypto =~ /\A(?:true|false)\z/; + +if ($has_crypto eq 'false') { + die "WebCrypto is unavailable in an SSL-enabled CI job\n" + if defined $ENV{CI_SSL} && $ENV{CI_SSL} eq 'yes'; + + plan(skip_all => 'njs crypto module not available'); +} $t->plan(4); diff --git a/nginx/t/stream_js_webcrypto.t b/nginx/t/stream_js_webcrypto.t index 0d9272c7..286486de 100644 --- a/nginx/t/stream_js_webcrypto.t +++ b/nginx/t/stream_js_webcrypto.t @@ -23,7 +23,7 @@ use Test::Nginx::Stream qw/ stream /; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http stream stream_return/) +my $t = Test::Nginx->new()->has(qw/stream stream_return/) ->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% @@ -33,28 +33,19 @@ daemon off; events { } -http { - %%TEST_GLOBALS_HTTP%% - - js_import test.js; - - server { - listen 127.0.0.1:8080; - server_name localhost; - - location /has_crypto { - js_content test.has_crypto; - } - } -} - stream { %%TEST_GLOBALS_STREAM%% js_import test.js; + js_set $has_crypto test.has_crypto; js_set $test test.random_values_test; + server { + listen 127.0.0.1:8080; + return $has_crypto; + } + server { listen 127.0.0.1:8081; return $test; @@ -85,8 +76,8 @@ stream { EOF $t->write_file('test.js', <write_file('test.js', <try_run('no stream js_var'); +$t->run(); -plan(skip_all => 'njs crypto module not available') - if http_get('/has_crypto') !~ /true/; +my $has_crypto = stream('127.0.0.1:' . port(8080))->read(); + +die "invalid WebCrypto capability response\n" + unless defined $has_crypto && $has_crypto =~ /\A(true|false)\z/; + +if ($has_crypto eq 'false') { + die "WebCrypto is unavailable in an SSL-enabled CI job\n" + if defined $ENV{CI_SSL} && $ENV{CI_SSL} eq 'yes'; + + plan(skip_all => 'njs crypto module not available'); +} $t->plan(4);