openresty / test-nginx

Data-driven test scaffold for Nginx C module and OpenResty Lua library development
http://search.cpan.org/dist/Test-Nginx
438 stars 105 forks source link

https seems not be supported #123

Open yi-guo-546 opened 3 years ago

yi-guo-546 commented 3 years ago

I want to use https to request, but I find it seems not be supported. Is there any plans to support. Thank you.

woodgear commented 2 years ago

you may take a look at https://github.com/openresty/test-nginx/pull/125 ,since that you could build a https request via

--- http2
--- curl_options: -k
--- curl_protocol: https
--- request
    GET /ping
ezzye commented 1 year ago

I have tried this with a macbook but does not work due to:`Could not open /proc/net/tcp. No such file or directory at /Users/xxxxxx/perl5/lib/perl5/Test/Nginx/Util.pm line 265.

Looks like your test exited with 2 before it could output anything.

` I think this only works with linux due to use of /proc/net/tcp.

I replaced

sub is_tcp_port_used($) {
    my $port = shift;
    my $filename = "/proc/net/tcp";

    open my $fh, $filename or die "Could not open $filename. $!";
    while (<$fh>) {
        my $line = $_;
        if ($line =~ /^ *\d+: [0-9A-F]+:([0-9A-F]+) /) {
            if ($port == hex($1)) {
                close $fh;
                return 1;
            }
        }
    }

    close $fh;
    return 0;
}

with

sub is_tcp_port_used($) {
    my $port = shift;
    my $cmd = "lsof -i tcp:$port";
    my $output = `$cmd`;

    if ($output) {
        return 1;
    } else {
        return 0;
    }
}

in Util.pm

and it works.

Tell me how you distinguish between macos, linux etc and I will submit a PR. Updated code per zhuizhuhaomeng comment.

zhuizhuhaomeng commented 1 year ago

Here is an example. you can change VMS to linux and so on.

        if ($^O eq 'VMS') {
                require ExtUtils::CBuilder;
                my $builder = ExtUtils::CBuilder->new(
                quiet => 1,
                );
                return $builder->have_compiler;
        }
zhuizhuhaomeng commented 1 year ago

by the way, "lsof -i tcp:$port -sTCP:LISTEN" is not correct. We want to test if the port is in used. So you should use "lsof -i tcp:$port"