forked from testcontainers/testcontainers-java
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix internal port check when other ports are opened as well on the ta…
…rget container (testcontainers#2363) * Remove redundant execCreateCmd call This one is never used and probably causes some garbage on the docker side. * Allow leading zeros in /proc/net/tcp* when doing internal port listen check When at least one process is listening for a port that is significantly higher then the port we're checking, this check will fail as the checked port will contain leading zeros in the output of "cat /proc/net/tcp". This commit fixes this by changing the grep to ":0*XXX". * Surround grep parameter with ' Otherwise unnecessary shell expansion is tried * Refactor/Rewrite InternalCommandPortListeningCheckTest to test all possible checks This commit refactors InternalCommandPortListeningCheckTest to work with 3 different nginx based containers, each being able to only succeed one of the 3 tests performed in InternalCommandPortListeningCheck. Each test is now executed agains all 3 containers to ensure that all tests work as expected. * Add test for low+high ports This test should fail without the leading zeros fix found a few commits before this one. * Check for bash existence instead of only mentioning it in a comment * Rename nginx_on_8080.conf to nginx.conf It's not only port 8080 anymore, so better not have it in the name. * Make container a @rule again by moving initialization into contructor * Wait a few seconds for InternalCommandPortListeningCheck to pass
- Loading branch information
Showing
8 changed files
with
86 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
core/src/test/resources/internal-port-check-dockerfile/Dockerfile-bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM nginx:1.17-alpine | ||
|
||
RUN apk add bash | ||
|
||
# Make sure the /proc/net/tcp* check fails in this container | ||
RUN rm /usr/bin/awk | ||
|
||
# Make sure the nc check fails in this container | ||
RUN rm /usr/bin/nc | ||
|
||
ADD nginx.conf /etc/nginx/conf.d/default.conf |
9 changes: 9 additions & 0 deletions
9
core/src/test/resources/internal-port-check-dockerfile/Dockerfile-nc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM nginx:1.17-alpine | ||
|
||
# If this fails, you ended up using a base image with bash installed. Consider removing /bin/bash in this case | ||
RUN if bash -c true &> /dev/null; then exit 1; fi | ||
|
||
# Make sure the /proc/net/tcp* check fails in this container | ||
RUN rm /usr/bin/awk | ||
|
||
ADD nginx.conf /etc/nginx/conf.d/default.conf |
9 changes: 9 additions & 0 deletions
9
core/src/test/resources/internal-port-check-dockerfile/Dockerfile-tcp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM nginx:1.17-alpine | ||
|
||
# If this fails, you ended up using a base image with bash installed. Consider removing /bin/bash in this case | ||
RUN if bash -c true &> /dev/null; then exit 1; fi | ||
|
||
# Make sure the nc check fails in this container | ||
RUN rm /usr/bin/nc | ||
|
||
ADD nginx.conf /etc/nginx/conf.d/default.conf |
8 changes: 8 additions & 0 deletions
8
core/src/test/resources/internal-port-check-dockerfile/nginx.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# This configuration makes Nginx listen on port port 8080 | ||
|
||
server { | ||
# Port 8080 is necessary to prove that the command formatting in the /proc/net/tcp* check uses the correct casing for hexadecimal numbers (i.e. 1F90 and not 1f90) | ||
listen 8080; | ||
# Port 100 is necessary to ensure that the /proc/net/tcp* check also succeeds with trailing zeros in the hexadecimal port | ||
listen 100; | ||
} |
This file was deleted.
Oops, something went wrong.