aperezdc / ngx-fancyindex

Fancy indexes module for the Nginx web server
Other
857 stars 127 forks source link

Test suite: ss: command not found #139

Closed ryandesign closed 2 years ago

ryandesign commented 2 years ago

The test suite says it passed on my Mac:

t/01-smoke-hasindex ... passed
t/04-hasindex-html ... passed
t/12-local-footer-nested ... passed
t/has-index ... passed
t/07-show_dotfiles ... passed
t/03-exact_size_off ... passed
t/08-local-footer ... passed
t/11-local-footer-nested ... passed
t/10-local-headerfooter ... passed
t/02-smoke-indexisfancy ... passed
t/00-build-artifacts ... passed
t/bug95-square-brackets ... passed
t/07-directory-first ... passed
t/bug61-empty-file-segfault ... passed
t/09-local-header ... passed
t/05-sort-by-size ... passed
t/06-hide_parent ... passed
=== passed/skipped/failed/total: 17/0/0/17

However, I'm not sure whether these results can be trusted since in each test's .err file it says:

ss: command not found

This is of course coming from the preamble which says:

NGINX_PORT=$(ss -4Htnl | awk '{ sub("[^:]+:", "", $4) ; seen[$4]=1 }
END { p=1025 ; while (seen[p]) p++; print p}')

I wasn't familiar with ss but found the ss manpage and reading your code it looks like you're trying to use it to find a port that's not in use which the test copy of nginx will use. Is that right? Maybe there is a different command that can give us that information on macOS.

It looks like since it could not run ss it used port 1025, which I think is free on my system, so maybe the test results are correct.

ryandesign commented 2 years ago

On an Ubuntu 20 VM, I see the output from ss -4Htnl looks like this:

LISTEN    0         4096          127.0.0.53%lo:53         0.0.0.0:*
LISTEN    0         128                 0.0.0.0:22         0.0.0.0:*

This is presumably a list of all the listening sockets. The awk command then looks at the 4th column and stores what's after the colon (the port) in the seen array. At the END, it starts from 1025 looking for a port number that was not recorded in the seen array and prints the first found available port.

On macOS (I tested on 10.15) it looks like netstat -a -n -finet -ptcp can provide similar information. Here's a subset of that output:

Active Internet connections (including servers)
Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)
tcp4       0      0  192.168.1.2.61098      17.57.144.89.5223      ESTABLISHED
tcp4       0      0  192.168.1.2.50207      192.168.1.103.49972    CLOSE_WAIT
tcp4       0      0  *.445                  *.*                    LISTEN
tcp4       0      0  192.168.1.2.54690      192.168.1.8.58483      CLOSE_WAIT
tcp4       0      0  192.168.1.2.54438      192.168.1.103.51678    CLOSE_WAIT
tcp46      0      0  *.5055                 *.*                    LISTEN
tcp4       0      0  *.5055                 *.*                    LISTEN

It doesn't appear to have a way to output only listening sockets, but that's easy enough to achieve with post-processing.