Skip to content

Commit 7c5bd56

Browse files
authored
Merge pull request #242 from splunk/tests/splunk-secret-env
Adding tests for splunk secret env
2 parents 059cf01 + e5a4c59 commit 7c5bd56

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

tests/test_docker_splunk.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,76 @@ def test_adhoc_1uf_change_tailed_files(self):
759759
if cid:
760760
self.client.remove_container(cid, v=True, force=True)
761761

762+
def test_adhoc_1so_splunk_secret_env(self):
763+
# Create a splunk container
764+
cid = None
765+
try:
766+
splunk_container_name = generate_random_string()
767+
cid = self.client.create_container(self.SPLUNK_IMAGE_NAME, tty=True, ports=[8089], name=splunk_container_name,
768+
environment={
769+
"DEBUG": "true",
770+
"SPLUNK_START_ARGS": "--accept-license",
771+
"SPLUNK_PASSWORD": self.password,
772+
"SPLUNK_SECRET": "wubbalubbadubdub"
773+
},
774+
host_config=self.client.create_host_config(port_bindings={8089: ("0.0.0.0",)})
775+
)
776+
cid = cid.get("Id")
777+
self.client.start(cid)
778+
# Poll for the container to be ready
779+
assert self.wait_for_containers(1, name=splunk_container_name)
780+
# Check splunkd
781+
splunkd_port = self.client.port(cid, 8089)[0]["HostPort"]
782+
url = "https://localhost:{}/services/server/info".format(splunkd_port)
783+
kwargs = {"auth": ("admin", self.password), "verify": False}
784+
status, content = self.handle_request_retry("GET", url, kwargs)
785+
assert status == 200
786+
# Check if the created file exists
787+
exec_command = self.client.exec_create(cid, "cat /opt/splunk/etc/auth/splunk.secret", user="splunk")
788+
std_out = self.client.exec_start(exec_command)
789+
assert "wubbalubbadubdub" in std_out
790+
except Exception as e:
791+
self.logger.error(e)
792+
raise e
793+
finally:
794+
if cid:
795+
self.client.remove_container(cid, v=True, force=True)
796+
797+
def test_adhoc_1uf_splunk_secret_env(self):
798+
# Create a uf container
799+
cid = None
800+
try:
801+
splunk_container_name = generate_random_string()
802+
cid = self.client.create_container(self.UF_IMAGE_NAME, tty=True, ports=[8089], name=splunk_container_name,
803+
environment={
804+
"DEBUG": "true",
805+
"SPLUNK_START_ARGS": "--accept-license",
806+
"SPLUNK_PASSWORD": self.password,
807+
"SPLUNK_SECRET": "wubbalubbadubdub"
808+
},
809+
host_config=self.client.create_host_config(port_bindings={8089: ("0.0.0.0",)})
810+
)
811+
cid = cid.get("Id")
812+
self.client.start(cid)
813+
# Poll for the container to be ready
814+
assert self.wait_for_containers(1, name=splunk_container_name)
815+
# Check splunkd
816+
splunkd_port = self.client.port(cid, 8089)[0]["HostPort"]
817+
url = "https://localhost:{}/services/server/info".format(splunkd_port)
818+
kwargs = {"auth": ("admin", self.password), "verify": False}
819+
status, content = self.handle_request_retry("GET", url, kwargs)
820+
assert status == 200
821+
# Check if the created file exists
822+
exec_command = self.client.exec_create(cid, "cat /opt/splunkforwarder/etc/auth/splunk.secret", user="splunk")
823+
std_out = self.client.exec_start(exec_command)
824+
assert "wubbalubbadubdub" in std_out
825+
except Exception as e:
826+
self.logger.error(e)
827+
raise e
828+
finally:
829+
if cid:
830+
self.client.remove_container(cid, v=True, force=True)
831+
762832
def test_adhoc_1so_preplaybook_with_sudo(self):
763833
# Create a splunk container
764834
cid = None

0 commit comments

Comments
 (0)