Skip to content

Commit b5d00a1

Browse files
committed
Validate host contains scheme if it's passed
1 parent 9875e89 commit b5d00a1

File tree

2 files changed

+3
-27
lines changed

2 files changed

+3
-27
lines changed

Diff for: locust/main.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import sys
1414
import time
1515
import traceback
16+
from urllib.parse import urlparse
1617

1718
import gevent
1819

@@ -512,11 +513,7 @@ def assign_equal_weights(environment, **kwargs):
512513
if options.equal_weights:
513514
environment.events.init.add_listener(assign_equal_weights)
514515

515-
if options.headless and not options.host:
516-
logger.error("The --host option is required when running in headless mode")
517-
sys.exit(1)
518-
519-
if options.host and not (options.host.startswith("http://") or options.host.startswith("https://")):
516+
if options.host and not (urlparse(options.host).scheme):
520517
logger.error(f"Invalid --host option: {options.host}. Did you mean https://{options.host}?")
521518
sys.exit(1)
522519

Diff for: locust/test/test_main.py

+1-22
Original file line numberDiff line numberDiff line change
@@ -1381,28 +1381,7 @@ def my_task(self):
13811381
# ensure stats printer printed at least one report before shutting down and that there was a final report printed as well
13821382
self.assertRegex(stderr, r".*Aggregated[\S\s]*Shutting down[\S\s]*Aggregated.*")
13831383

1384-
def test_headless_wo_host(self):
1385-
with mock_locustfile() as mocked:
1386-
proc = subprocess.Popen(
1387-
[
1388-
"locust",
1389-
"-f",
1390-
mocked.file_path,
1391-
"--run-time",
1392-
"1s",
1393-
"--headless",
1394-
"--loglevel",
1395-
"DEBUG",
1396-
],
1397-
stdout=PIPE,
1398-
stderr=PIPE,
1399-
text=True,
1400-
)
1401-
stdout, stderr = proc.communicate(timeout=4)
1402-
self.assertIn("The --host option is required when running in headless mode", stderr)
1403-
self.assertEqual(1, proc.returncode)
1404-
1405-
def test_headless_wo_protocol(self):
1384+
def test_host_wo_protocol(self):
14061385
with mock_locustfile() as mocked:
14071386
proc = subprocess.Popen(
14081387
[

0 commit comments

Comments
 (0)