core - Update allowed_methods test method to GET

This commit is contained in:
Théophile Diot 2023-05-18 17:04:55 -04:00
parent 62cb85453a
commit dbb8840992
No known key found for this signature in database
GPG Key ID: E752C80DB72BB014
2 changed files with 8 additions and 8 deletions

View File

@ -1,6 +1,6 @@
from os import getenv
from subprocess import run
from requests import ConnectionError, head, options, post
from requests import ConnectionError, get, head, post
from socket import create_connection
from ssl import CERT_NONE, create_default_context
from time import sleep
@ -141,20 +141,20 @@ try:
allowed_methods = getenv("ALLOWED_METHODS", "GET|POST|HEAD")
print(
f" Sending a OPTIONS request to http{'s' if ssl_generated else ''}://www.example.com to test ALLOWED_METHODS",
f" Sending a GET request to http{'s' if ssl_generated else ''}://www.example.com to test ALLOWED_METHODS",
flush=True,
)
response = options(
response = get(
f"http{'s' if ssl_generated else ''}://www.example.com",
headers={"Host": "www.example.com"},
verify=False,
)
if response.status_code == 405:
if "OPTIONS" in allowed_methods:
if "GET" in allowed_methods:
print(
"❌ Request got rejected, even if OPTIONS is in allowed methods, exiting ...",
"❌ Request got rejected, even if GET is in allowed methods, exiting ...",
flush=True,
)
exit(1)
@ -164,9 +164,9 @@ try:
if response.status_code != 404:
response.raise_for_status()
if "OPTIONS" not in allowed_methods:
if "GET" not in allowed_methods:
print(
"❌ Request didn't get rejected, even if OPTIONS is not in allowed methods, exiting ...",
"❌ Request didn't get rejected, even if GET is not in allowed methods, exiting ...",
flush=True,
)
exit(1)

View File

@ -59,7 +59,7 @@ do
echo "🗃️ Running tests when misc settings have tweaked values ..."
echo " Keeping the ssl generated in self signed ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@DISABLE_DEFAULT_SERVER: "no"@DISABLE_DEFAULT_SERVER: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@ALLOWED_METHODS: ".*"$@ALLOWED_METHODS: "GET|POST|HEAD|OPTIONS"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@ALLOWED_METHODS: ".*"$@ALLOWED_METHODS: "POST|HEAD"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@MAX_CLIENT_SIZE: "5m"@MAX_CLIENT_SIZE: "10m"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@SERVE_FILES: "yes"@SERVE_FILES: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@HTTP2: "yes"@HTTP2: "no"@' {} \;