Skip to content

Commit 981aea6

Browse files
authored
Making password extraction more robust (#358)
1 parent 55d8a88 commit 981aea6

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

tests/test_docker_splunk.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@ def test_adhoc_1so_using_default_yml(self):
557557
output = self.get_container_logs(cid.get("Id"))
558558
self.client.remove_container(cid.get("Id"), v=True, force=True)
559559
# Get the password
560-
password = re.search(" password: (.*)", output).group(1).strip()
561-
assert password
560+
password = re.search(r"^ password: (.*?)\n", output, flags=re.MULTILINE|re.DOTALL).group(1).strip()
561+
assert password and password != "null"
562562
# Change the admin user
563563
output = re.sub(r' admin_user: admin', r' admin_user: chewbacca', output)
564564
# Write the default.yml to a file
@@ -602,8 +602,8 @@ def test_adhoc_1uf_using_default_yml(self):
602602
output = self.get_container_logs(cid.get("Id"))
603603
self.client.remove_container(cid.get("Id"), v=True, force=True)
604604
# Get the password
605-
password = re.search(" password: (.*)", output).group(1).strip()
606-
assert password
605+
password = re.search(r"^ password: (.*?)\n", output, flags=re.MULTILINE|re.DOTALL).group(1).strip()
606+
assert password and password != "null"
607607
# Change the admin user
608608
output = re.sub(r' admin_user: admin', r' admin_user: hansolo', output)
609609
# Write the default.yml to a file
@@ -647,8 +647,8 @@ def test_adhoc_1so_custom_conf(self):
647647
output = self.get_container_logs(cid.get("Id"))
648648
self.client.remove_container(cid.get("Id"), v=True, force=True)
649649
# Get the password
650-
password = re.search(" password: (.*)", output).group(1).strip()
651-
assert password
650+
password = re.search(r"^ password: (.*?)\n", output, flags=re.MULTILINE|re.DOTALL).group(1).strip()
651+
assert password and password != "null"
652652
# Add a custom conf file
653653
output = re.sub(r' group: splunk', r''' group: splunk
654654
conf:
@@ -705,8 +705,8 @@ def test_adhoc_1uf_custom_conf(self):
705705
output = self.get_container_logs(cid.get("Id"))
706706
self.client.remove_container(cid.get("Id"), v=True, force=True)
707707
# Get the password
708-
password = re.search(" password: (.*)", output).group(1).strip()
709-
assert password
708+
password = re.search(r"^ password: (.*?)\n", output, flags=re.MULTILINE|re.DOTALL).group(1).strip()
709+
assert password and password != "null"
710710
# Add a custom conf file
711711
output = re.sub(r' group: splunk', r''' group: splunk
712712
conf:
@@ -1291,8 +1291,8 @@ def test_adhoc_1so_apps_location_in_default_yml(self):
12911291
output = self.get_container_logs(cid.get("Id"))
12921292
self.client.remove_container(cid.get("Id"), v=True, force=True)
12931293
# Get the password
1294-
password = re.search(" password: (.*)", output).group(1).strip()
1295-
assert password
1294+
password = re.search(r"^ password: (.*?)\n", output, flags=re.MULTILINE|re.DOTALL).group(1).strip()
1295+
assert password and password != "null"
12961296
# Change repl factor & search factor
12971297
output = re.sub(r' user: splunk', r' user: splunk\n apps_location: /tmp/defaults/splunk_app_example.tgz', output)
12981298
# Write the default.yml to a file
@@ -1347,8 +1347,8 @@ def test_adhoc_1so_bind_mount_apps(self):
13471347
output = self.get_container_logs(cid.get("Id"))
13481348
self.client.remove_container(cid.get("Id"), v=True, force=True)
13491349
# Get the password
1350-
password = re.search(" password: (.*)", output).group(1).strip()
1351-
assert password
1350+
password = re.search(r"^ password: (.*?)\n", output, flags=re.MULTILINE|re.DOTALL).group(1).strip()
1351+
assert password and password != "null"
13521352
# Write the default.yml to a file
13531353
with open(os.path.join(FIXTURES_DIR, "default.yml"), "w") as f:
13541354
f.write(output)
@@ -1401,8 +1401,8 @@ def test_adhoc_1uf_bind_mount_apps(self):
14011401
output = self.get_container_logs(cid.get("Id"))
14021402
self.client.remove_container(cid.get("Id"), v=True, force=True)
14031403
# Get the password
1404-
password = re.search(" password: (.*)", output).group(1).strip()
1405-
assert password
1404+
password = re.search(r"^ password: (.*?)\n", output, flags=re.MULTILINE|re.DOTALL).group(1).strip()
1405+
assert password and password != "null"
14061406
# Write the default.yml to a file
14071407
with open(os.path.join(FIXTURES_DIR, "default.yml"), "w") as f:
14081408
f.write(output)
@@ -1680,8 +1680,8 @@ def test_adhoc_1so_splunktcp_ssl(self):
16801680
output = self.get_container_logs(cid.get("Id"))
16811681
self.client.remove_container(cid.get("Id"), v=True, force=True)
16821682
# Get the password
1683-
password = re.search(" password: (.*)", output).group(1).strip()
1684-
assert password
1683+
password = re.search(r"^ password: (.*?)\n", output, flags=re.MULTILINE|re.DOTALL).group(1).strip()
1684+
assert password and password != "null"
16851685
# Commands to generate self-signed certificates for Splunk here: https://docs.splunk.com/Documentation/Splunk/latest/Security/ConfigureSplunkforwardingtousesignedcertificates
16861686
passphrase = "abcd1234"
16871687
cmds = [
@@ -1754,8 +1754,8 @@ def test_adhoc_1uf_splunktcp_ssl(self):
17541754
output = self.get_container_logs(cid.get("Id"))
17551755
self.client.remove_container(cid.get("Id"), v=True, force=True)
17561756
# Get the password
1757-
password = re.search(" password: (.*)", output).group(1).strip()
1758-
assert password
1757+
password = re.search(r"^ password: (.*?)\n", output, flags=re.MULTILINE|re.DOTALL).group(1).strip()
1758+
assert password and password != "null"
17591759
# Commands to generate self-signed certificates for Splunk here: https://docs.splunk.com/Documentation/Splunk/latest/Security/ConfigureSplunkforwardingtousesignedcertificates
17601760
passphrase = "abcd1234"
17611761
cmds = [
@@ -2777,8 +2777,8 @@ def test_compose_3idx1cm_default_repl_factor(self):
27772777
output = self.get_container_logs(cid.get("Id"))
27782778
self.client.remove_container(cid.get("Id"), v=True, force=True)
27792779
# Get the password
2780-
password = re.search(" password: (.*)", output).group(1).strip()
2781-
assert password
2780+
password = re.search(r"^ password: (.*?)\n", output, flags=re.MULTILINE|re.DOTALL).group(1).strip()
2781+
assert password and password != "null"
27822782
# Write the default.yml to a file
27832783
with open(os.path.join(SCENARIOS_DIR, "defaults", "default.yml"), "w") as f:
27842784
f.write(output)
@@ -2837,8 +2837,8 @@ def test_compose_3idx1cm_custom_repl_factor(self):
28372837
output = self.get_container_logs(cid.get("Id"))
28382838
self.client.remove_container(cid.get("Id"), v=True, force=True)
28392839
# Get the password
2840-
password = re.search(" password: (.*)", output).group(1).strip()
2841-
assert password
2840+
password = re.search(r"^ password: (.*?)\n", output, flags=re.MULTILINE|re.DOTALL).group(1).strip()
2841+
assert password and password != "null"
28422842
# Change repl factor & search factor
28432843
output = re.sub(r' replication_factor: 3', r''' replication_factor: 2''', output)
28442844
output = re.sub(r' search_factor: 3', r''' search_factor: 1''', output)
@@ -3003,8 +3003,8 @@ def test_compose_1cm_smartstore(self):
30033003
output = self.get_container_logs(cid.get("Id"))
30043004
self.client.remove_container(cid.get("Id"), v=True, force=True)
30053005
# Get the password
3006-
password = re.search(" password: (.*)", output).group(1).strip()
3007-
assert password
3006+
password = re.search(r"^ password: (.*?)\n", output, flags=re.MULTILINE|re.DOTALL).group(1).strip()
3007+
assert password and password != "null"
30083008
# Add a custom conf file
30093009
output = re.sub(r' smartstore: null', r''' smartstore:
30103010
index:
@@ -3152,8 +3152,8 @@ def test_compose_1idx3sh1cm1dep(self):
31523152
output = self.get_container_logs(cid.get("Id"))
31533153
self.client.remove_container(cid.get("Id"), v=True, force=True)
31543154
# Get the password
3155-
password = re.search(" password: (.*)", output).group(1).strip()
3156-
assert password
3155+
password = re.search(r"^ password: (.*?)\n", output, flags=re.MULTILINE|re.DOTALL).group(1).strip()
3156+
assert password and password != "null"
31573157
# Write the default.yml to a file
31583158
with open(os.path.join(SCENARIOS_DIR, "defaults", "default.yml"), "w") as f:
31593159
f.write(output)

0 commit comments

Comments
 (0)