@@ -208,7 +208,7 @@ def handle_request_retry(self, method, url, kwargs):
208208 continue
209209 raise e
210210
211- def check_splunkd (self , username , password , name = None ):
211+ def check_splunkd (self , username , password , name = None , scheme = "https" ):
212212 '''
213213 NOTE: This helper method can only be used for `compose up` scenarios where self.project_name is defined
214214 '''
@@ -223,7 +223,7 @@ def check_splunkd(self, username, password, name=None):
223223 if "maintainer" not in container [
"Labels" ]
or container [
"Labels" ][
"maintainer" ]
!= "[email protected] " :
224224 continue
225225 splunkd_port = self .client .port (container ["Id" ], 8089 )[0 ]["HostPort" ]
226- url = "https ://localhost:{}/services/server/info" .format (splunkd_port )
226+ url = "{} ://localhost:{}/services/server/info" .format (scheme , splunkd_port )
227227 kwargs = {"auth" : (username , password ), "verify" : False }
228228 status , content = self .handle_request_retry ("GET" , url , kwargs )
229229 assert status == 200
@@ -2008,7 +2008,7 @@ def test_adhoc_1so_splunkd_custom_ssl(self):
20082008 ]
20092009 for cmd in cmds :
20102010 execute_cmd = subprocess .check_output (["/bin/sh" , "-c" , cmd ])
2011- # Update s2s ssl settings
2011+ # Update server ssl settings
20122012 output = re .sub (r'''^ ssl:.*?password: null''' , r''' ssl:
20132013 ca: /tmp/defaults/ca.pem
20142014 cert: /tmp/defaults/cert.pem
@@ -2038,7 +2038,6 @@ def test_adhoc_1so_splunkd_custom_ssl(self):
20382038 # Check if the created file exists
20392039 exec_command = self .client .exec_create (cid , "cat /opt/splunk/etc/system/local/server.conf" , user = "splunk" )
20402040 std_out = self .client .exec_start (exec_command )
2041- assert "enableSplunkdSSL = 1" in std_out
20422041 assert "sslRootCAPath = /tmp/defaults/ca.pem" in std_out
20432042 assert "serverCert = /tmp/defaults/cert.pem" in std_out
20442043 # Check splunkd using the custom certs
@@ -2089,7 +2088,7 @@ def test_adhoc_1uf_splunkd_custom_ssl(self):
20892088 ]
20902089 for cmd in cmds :
20912090 execute_cmd = subprocess .check_output (["/bin/sh" , "-c" , cmd ])
2092- # Update s2s ssl settings
2091+ # Update server ssl settings
20932092 output = re .sub (r'''^ ssl:.*?password: null''' , r''' ssl:
20942093 ca: /tmp/defaults/ca.pem
20952094 cert: /tmp/defaults/cert.pem
@@ -2119,7 +2118,6 @@ def test_adhoc_1uf_splunkd_custom_ssl(self):
21192118 # Check if the created file exists
21202119 exec_command = self .client .exec_create (cid , "cat /opt/splunkforwarder/etc/system/local/server.conf" , user = "splunk" )
21212120 std_out = self .client .exec_start (exec_command )
2122- assert "enableSplunkdSSL = 1" in std_out
21232121 assert "sslRootCAPath = /tmp/defaults/ca.pem" in std_out
21242122 assert "serverCert = /tmp/defaults/cert.pem" in std_out
21252123 # Check splunkd using the custom certs
@@ -2146,6 +2144,118 @@ def test_adhoc_1uf_splunkd_custom_ssl(self):
21462144 ]
21472145 self .cleanup_files (files )
21482146
2147+ def test_adhoc_1so_splunkd_no_ssl (self ):
2148+ # Generate default.yml
2149+ cid = self .client .create_container (self .SPLUNK_IMAGE_NAME , tty = True , command = "create-defaults" )
2150+ self .client .start (cid .get ("Id" ))
2151+ output = self .get_container_logs (cid .get ("Id" ))
2152+ self .client .remove_container (cid .get ("Id" ), v = True , force = True )
2153+ # Get the password
2154+ password = re .search (r"^ password: (.*?)\n" , output , flags = re .MULTILINE | re .DOTALL ).group (1 ).strip ()
2155+ assert password and password != "null"
2156+ # Update server ssl settings
2157+ output = re .sub (r'''^ ssl:.*?password: null''' , r''' ssl:
2158+ ca: null
2159+ cert: null
2160+ enable: false
2161+ password: null''' , output , flags = re .MULTILINE | re .DOTALL )
2162+ # Write the default.yml to a file
2163+ with open (os .path .join (FIXTURES_DIR , "default.yml" ), "w" ) as f :
2164+ f .write (output )
2165+ # Create the container and mount the default.yml
2166+ cid = None
2167+ try :
2168+ splunk_container_name = generate_random_string ()
2169+ cid = self .client .create_container (self .SPLUNK_IMAGE_NAME , tty = True , ports = [8000 , 8089 ],
2170+ volumes = ["/tmp/defaults/" ], name = splunk_container_name ,
2171+ environment = {"DEBUG" : "true" ,
2172+ "SPLUNK_START_ARGS" : "--accept-license" ,
2173+ "SPLUNK_CERT_PREFIX" : "http" ,
2174+ "SPLUNK_PASSWORD" : password },
2175+ host_config = self .client .create_host_config (binds = [FIXTURES_DIR + ":/tmp/defaults/" ],
2176+ port_bindings = {8089 : ("0.0.0.0" ,), 8000 : ("0.0.0.0" ,)})
2177+ )
2178+ cid = cid .get ("Id" )
2179+ self .client .start (cid )
2180+ # Poll for the container to be ready
2181+ assert self .wait_for_containers (1 , name = splunk_container_name )
2182+ # Check splunkd
2183+ assert self .check_splunkd ("admin" , password , scheme = "http" )
2184+ # Check if the created file exists
2185+ exec_command = self .client .exec_create (cid , "cat /opt/splunk/etc/system/local/server.conf" , user = "splunk" )
2186+ std_out = self .client .exec_start (exec_command )
2187+ assert "enableSplunkdSSL = false" in std_out
2188+ # Check splunkd using the custom certs
2189+ mgmt_port = self .client .port (cid , 8089 )[0 ]["HostPort" ]
2190+ url = "http://localhost:{}/services/server/info" .format (mgmt_port )
2191+ kwargs = {"auth" : ("admin" , password )}
2192+ status , content = self .handle_request_retry ("GET" , url , kwargs )
2193+ assert status == 200
2194+ except Exception as e :
2195+ self .logger .error (e )
2196+ raise e
2197+ finally :
2198+ if cid :
2199+ self .client .remove_container (cid , v = True , force = True )
2200+ files = [os .path .join (FIXTURES_DIR , "default.yml" )]
2201+ self .cleanup_files (files )
2202+
2203+ def test_adhoc_1uf_splunkd_no_ssl (self ):
2204+ # Generate default.yml
2205+ cid = self .client .create_container (self .UF_IMAGE_NAME , tty = True , command = "create-defaults" )
2206+ self .client .start (cid .get ("Id" ))
2207+ output = self .get_container_logs (cid .get ("Id" ))
2208+ self .client .remove_container (cid .get ("Id" ), v = True , force = True )
2209+ # Get the password
2210+ password = re .search (r"^ password: (.*?)\n" , output , flags = re .MULTILINE | re .DOTALL ).group (1 ).strip ()
2211+ assert password and password != "null"
2212+ # Update server ssl settings
2213+ output = re .sub (r'''^ ssl:.*?password: null''' , r''' ssl:
2214+ ca: null
2215+ cert: null
2216+ enable: false
2217+ password: null''' , output , flags = re .MULTILINE | re .DOTALL )
2218+ # Write the default.yml to a file
2219+ with open (os .path .join (FIXTURES_DIR , "default.yml" ), "w" ) as f :
2220+ f .write (output )
2221+ # Create the container and mount the default.yml
2222+ cid = None
2223+ try :
2224+ splunk_container_name = generate_random_string ()
2225+ cid = self .client .create_container (self .UF_IMAGE_NAME , tty = True , ports = [8000 , 8089 ],
2226+ volumes = ["/tmp/defaults/" ], name = splunk_container_name ,
2227+ environment = {"DEBUG" : "true" ,
2228+ "SPLUNK_START_ARGS" : "--accept-license" ,
2229+ "SPLUNK_CERT_PREFIX" : "http" ,
2230+ "SPLUNK_PASSWORD" : password },
2231+ host_config = self .client .create_host_config (binds = [FIXTURES_DIR + ":/tmp/defaults/" ],
2232+ port_bindings = {8089 : ("0.0.0.0" ,), 8000 : ("0.0.0.0" ,)})
2233+ )
2234+ cid = cid .get ("Id" )
2235+ self .client .start (cid )
2236+ # Poll for the container to be ready
2237+ assert self .wait_for_containers (1 , name = splunk_container_name )
2238+ # Check splunkd
2239+ assert self .check_splunkd ("admin" , password , scheme = "http" )
2240+ # Check if the created file exists
2241+ exec_command = self .client .exec_create (cid , "cat /opt/splunkforwarder/etc/system/local/server.conf" , user = "splunk" )
2242+ std_out = self .client .exec_start (exec_command )
2243+ assert "enableSplunkdSSL = false" in std_out
2244+ # Check splunkd using the custom certs
2245+ mgmt_port = self .client .port (cid , 8089 )[0 ]["HostPort" ]
2246+ url = "http://localhost:{}/services/server/info" .format (mgmt_port )
2247+ kwargs = {"auth" : ("admin" , password )}
2248+ status , content = self .handle_request_retry ("GET" , url , kwargs )
2249+ assert status == 200
2250+ except Exception as e :
2251+ self .logger .error (e )
2252+ raise e
2253+ finally :
2254+ if cid :
2255+ self .client .remove_container (cid , v = True , force = True )
2256+ files = [os .path .join (FIXTURES_DIR , "default.yml" )]
2257+ self .cleanup_files (files )
2258+
21492259 def test_adhoc_1so_web_ssl (self ):
21502260 # Generate a password
21512261 password = generate_random_string ()
0 commit comments