Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: added --- sni Support TLS http2 and SNI #68

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions lib/Test/Nginx/Socket.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,11 @@ sub gen_curl_cmd_from_req ($$) {
push @args, '--http2', '--http2-prior-knowledge';
}

if (use_http2($block) && defined $block->tls) {
my $resolve = "$ServerName:$ServerPortForClient:$ServerAddr";
push @args, '-k', '--resolve', $resolve;
}

if ($meth eq 'HEAD') {
push @args, '-I';

Expand Down Expand Up @@ -2191,6 +2196,10 @@ sub gen_curl_cmd_from_req ($$) {
my $server = $ServerAddr;
my $port = $ServerPortForClient;
$link = "http://$server:$port$uri";
if (use_http2($block) && defined $block->tls) {
my $server_name = $ServerName;
$link = "https://$server_name:$port$uri";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in my previous round of review, the test scaffold should automatically generate self-signed server certificate and key files and automatically make use of them in the automatically generated nginx.conf. All such details should be transparent. Also, we can introduce a TEST_NGINX_USE_HTTP2_TLS=1 system environment to enable this for any existing tests without any edits in the tests themselves?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agentzh I think it can be split into two parts. Listening on HTTPS/2 and making HTTPS/2 requests from Test::Nginx.

I have tests that are using custom certificates and want to keep it that way, but would like to make HTTPS/2 request from Test::Nginx to verify them. IMO those are two different problems.

I see the workaround in ssl_certificate_by_lua tests (using cosockets), but having first class support in Test::Nginx would be nice.

}
}

push @args, $link;
Expand Down Expand Up @@ -2864,6 +2873,7 @@ The following sections are supported:
=head2 http2

Enforces the test scaffold to use the HTTP/2 wire protocol to send the test request.
Also, you can set tls section using the HTTP/2 over TLS protocol and SNI(Server Name Indication).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to mention SNI here? It can be implicit I think. The user cannot specify their own SNI names now anyway.


Under the hood, the test scaffold uses the `curl` command-line utility to do the wire communication
with the NGINX server. The `curl` utility must be recent enough to support both the C<--http2>
Expand Down Expand Up @@ -3991,6 +4001,10 @@ One can enable HTTP/2 mode for an individual test block by specifying the L<http

--- http2

Enable HTTP/2 over TLS mode for an individual test block by specifying the L<tls> section, as in

--- tls

=head2 TEST_NGINX_VERBOSE

Controls whether to output verbose debugging messages in Test::Nginx. Default to empty.
Expand Down
4 changes: 4 additions & 0 deletions lib/Test/Nginx/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,10 @@ _EOC_

my $listen_opts = '';

if (use_http2($block) && defined $block->tls) {
$listen_opts .= " ssl";
}

if (use_http2($block)) {
$listen_opts .= " http2";
}
Expand Down