func expectBasicAuthConfigOnPodTemplate(t *testing.T, instance *solr.SolrCloud, podTemplate *corev1.PodTemplateSpec, expectBootstrapSecret bool) *corev1.Container {

	// check the env vars needed for the probes to work with auth
	assert.NotNil(t, podTemplate.Spec.Containers)
	assert.True(t, len(podTemplate.Spec.Containers) > 0)
	mainContainer := podTemplate.Spec.Containers[0]
	assert.NotNil(t, mainContainer, "Didn't find the main solrcloud-node container in the sts!")
	assert.NotNil(t, mainContainer.Env, "Didn't find the main solrcloud-node container in the sts!")

	// probes with auth
	if instance.Spec.SolrSecurity.ProbesRequireAuth {
		assert.NotNil(t, podTemplate.Spec.Volumes)
		secretName := instance.BasicAuthSecretName()
		var basicAuthSecretVol *corev1.Volume = nil
		for _, vol := range podTemplate.Spec.Volumes {
			if vol.Name == secretName {
				basicAuthSecretVol = &vol
				break
			}
		}
		assert.NotNil(t, basicAuthSecretVol)
		assert.NotNil(t, basicAuthSecretVol.VolumeSource.Secret, "Didn't find the basic auth secret volume in sts config!")
		assert.Equal(t, instance.BasicAuthSecretName(), basicAuthSecretVol.VolumeSource.Secret.SecretName)

		var basicAuthSecretVolMount *corev1.VolumeMount = nil
		for _, m := range podTemplate.Spec.Containers[0].VolumeMounts {
			if m.Name == secretName {
				basicAuthSecretVolMount = &m
				break
			}
		}
		assert.NotNil(t, basicAuthSecretVolMount)
		assert.Equal(t, "/etc/secrets/"+secretName, basicAuthSecretVolMount.MountPath)

		expProbeCmd := "JAVA_TOOL_OPTIONS=\"-Dbasicauth=$(cat /etc/secrets/foo-tls-solrcloud-basic-auth/username):$(cat /etc/secrets/foo-tls-solrcloud-basic-auth/password)\" java -Dsolr.ssl.checkPeerName=false " +
			"-Dsolr.httpclient.builder.factory=org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory " +
			"-Dsolr.install.dir=\"/opt/solr\" -Dlog4j.configurationFile=\"/opt/solr/server/resources/log4j2-console.xml\" " +
			"-classpath \"/opt/solr/server/solr-webapp/webapp/WEB-INF/lib/*:/opt/solr/server/lib/ext/*:/opt/solr/server/lib/*\" " +
			"org.apache.solr.util.SolrCLI api -get http://localhost:8983/solr/admin/info/system"
		assert.NotNil(t, mainContainer.LivenessProbe, "main container should have a liveness probe defined")
		assert.NotNil(t, mainContainer.LivenessProbe.Exec, "liveness probe should have an exec when auth is enabled")
		assert.Equal(t, expProbeCmd, mainContainer.LivenessProbe.Exec.Command[2], "liveness probe should invoke java with auth opts")
		assert.NotNil(t, mainContainer.ReadinessProbe, "main container should have a readiness probe defined")
		assert.NotNil(t, mainContainer.ReadinessProbe.Exec, "readiness probe should have an exec when auth is enabled")
		assert.Equal(t, expProbeCmd, mainContainer.ReadinessProbe.Exec.Command[2], "readiness probe should invoke java with auth opts")
	}

	// if no user-provided auth secret, then check that security.json gets bootstrapped correctly
	if instance.Spec.SolrSecurity.BasicAuthSecret == "" {
		// initContainers
		assert.NotNil(t, podTemplate.Spec.InitContainers)
		var expInitContainer *corev1.Container = nil
		for _, cnt := range podTemplate.Spec.InitContainers {
			if cnt.Name == "setup-zk" {
				expInitContainer = &cnt
				break
			}
		}

		if expectBootstrapSecret {
			// if the zookeeperRef has ACLs set, verify the env vars were set correctly for this initContainer
			allACL, _ := instance.Spec.ZookeeperRef.GetACLs()
			if allACL != nil {
				assert.Equal(t, 10, len(expInitContainer.Env))
				assert.Equal(t, "SOLR_OPTS", expInitContainer.Env[len(expInitContainer.Env)-2].Name)
				assert.Equal(t, "SECURITY_JSON", expInitContainer.Env[len(expInitContainer.Env)-1].Name)
				testACLEnvVars(t, expInitContainer.Env[3:len(expInitContainer.Env)-2])
			} // else this ref not using ACLs

			assert.NotNil(t, expInitContainer, "Didn't find the setup-zk InitContainer in the sts!")
			expCmd := "ZK_SECURITY_JSON=$(/opt/solr/server/scripts/cloud-scripts/zkcli.sh -zkhost ${ZK_HOST} -cmd get /security.json); " +
				"if [ ${#ZK_SECURITY_JSON} -lt 3 ]; then " +
				"echo $SECURITY_JSON > /tmp/security.json; " +
				"/opt/solr/server/scripts/cloud-scripts/zkcli.sh -zkhost ${ZK_HOST} -cmd putfile /security.json /tmp/security.json; echo \"put security.json in ZK\"; fi"
			assert.True(t, strings.Contains(expInitContainer.Command[2], expCmd), "setup-zk initContainer not configured to bootstrap security.json!")
		} else {
			assert.True(t, expInitContainer == nil || !strings.Contains(expInitContainer.Command[2], "SECURITY_JSON"),
				"setup-zk initContainer not reconciled after bootstrap secret deleted")
		}

	}

	return &mainContainer // return as a convenience in case tests want to do more checking on the main container
}
// Ensures config is setup for basic-auth enabled Solr pods
Ensures config is setup for basic-auth enabled Solr pods
// Ensures config is setup for basic - auth enabled Solr pods
func expectBasicAuthConfigOnPodTemplate(t *testing.T, instance *solr.SolrCloud, podTemplate *corev1.PodTemplateSpec, expectBootstrapSecret bool) *corev1.Container {
	assert.NotNil(t, podTemplate.Spec.Containers)
	assert.True(t, len(podTemplate.Spec.Containers) > 0)
	mainContainer := podTemplate.Spec.Containers[0]
	assert.NotNil(t, mainContainer, "Didn't find the main solrcloud-node container in the sts!")
	assert.NotNil(t, mainContainer.Env, "Didn't find the main solrcloud-node container in the sts!")
	if instance.Spec.SolrSecurity.ProbesRequireAuth {
		assert.NotNil(t, podTemplate.Spec.Volumes)
		secretName := instance.BasicAuthSecretName()
		var basicAuthSecretVol *corev1.Volume = nil
		for _, vol := range podTemplate.Spec.Volumes {
			if vol.Name == secretName {
				basicAuthSecretVol = &vol
				break
			}
		}
		assert.NotNil(t, basicAuthSecretVol)
		assert.NotNil(t, basicAuthSecretVol.VolumeSource.Secret, "Didn't find the basic auth secret volume in sts config!")
		assert.Equal(t, instance.BasicAuthSecretName(), basicAuthSecretVol.VolumeSource.Secret.SecretName)
		var basicAuthSecretVolMount *corev1.VolumeMount = nil
		for _, m := range podTemplate.Spec.Containers[0].VolumeMounts {
			if m.Name == secretName {
				basicAuthSecretVolMount = &m
				break
			}
		}
		assert.NotNil(t, basicAuthSecretVolMount)
		assert.Equal(t, "/etc/secrets/"+secretName, basicAuthSecretVolMount.MountPath)
		expProbeCmd := "JAVA_TOOL_OPTIONS=\"-Dbasicauth=$(cat /etc/secrets/foo-tls-solrcloud-basic-auth/username):$(cat /etc/secrets/foo-tls-solrcloud-basic-auth/password)\" java -Dsolr.ssl.checkPeerName=false " +
			"-Dsolr.httpclient.builder.factory=org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory " +
			"-Dsolr.install.dir=\"/opt/solr\" -Dlog4j.configurationFile=\"/opt/solr/server/resources/log4j2-console.xml\" " +
			"-classpath \"/opt/solr/server/solr-webapp/webapp/WEB-INF/lib/*:/opt/solr/server/lib/ext/*:/opt/solr/server/lib/*\" " +
			"org.apache.solr.util.SolrCLI api -get http://localhost:8983/solr/admin/info/system"
		assert.NotNil(t, mainContainer.LivenessProbe, "main container should have a liveness probe defined")
		assert.NotNil(t, mainContainer.LivenessProbe.Exec, "liveness probe should have an exec when auth is enabled")
		assert.Equal(t, expProbeCmd, mainContainer.LivenessProbe.Exec.Command[2], "liveness probe should invoke java with auth opts")
		assert.NotNil(t, mainContainer.ReadinessProbe, "main container should have a readiness probe defined")
		assert.NotNil(t, mainContainer.ReadinessProbe.Exec, "readiness probe should have an exec when auth is enabled")
		assert.Equal(t, expProbeCmd, mainContainer.ReadinessProbe.Exec.Command[2], "readiness probe should invoke java with auth opts")
	}
	if instance.Spec.SolrSecurity.BasicAuthSecret == "" {
		assert.NotNil(t, podTemplate.Spec.InitContainers)
		var expInitContainer *corev1.Container = nil
		for _, cnt := range podTemplate.Spec.InitContainers {
			if cnt.Name == "setup-zk" {
				expInitContainer = &cnt
				break
			}
		}
		if expectBootstrapSecret {
			allACL, _ := instance.Spec.ZookeeperRef.GetACLs()
			if allACL != nil {
				assert.Equal(t, 10, len(expInitContainer.Env))
				assert.Equal(t, "SOLR_OPTS", expInitContainer.Env[len(expInitContainer.Env)-2].Name)
				assert.Equal(t, "SECURITY_JSON", expInitContainer.Env[len(expInitContainer.Env)-1].Name)
				testACLEnvVars(t, expInitContainer.Env[3:len(expInitContainer.Env)-2])
			} 
			assert.NotNil(t, expInitContainer, "Didn't find the setup-zk InitContainer in the sts!")
			expCmd := "ZK_SECURITY_JSON=$(/opt/solr/server/scripts/cloud-scripts/zkcli.sh -zkhost ${ZK_HOST} -cmd get /security.json); " +
				"if [ ${#ZK_SECURITY_JSON} -lt 3 ]; then " +
				"echo $SECURITY_JSON > /tmp/security.json; " +
				"/opt/solr/server/scripts/cloud-scripts/zkcli.sh -zkhost ${ZK_HOST} -cmd putfile /security.json /tmp/security.json; echo \"put security.json in ZK\"; fi"
			assert.True(t, strings.Contains(expInitContainer.Command[2], expCmd), "setup-zk initContainer not configured to bootstrap security.json!")
		} else {
			assert.True(t, expInitContainer == nil || !strings.Contains(expInitContainer.Command[2], "SECURITY_JSON"),
				"setup-zk initContainer not reconciled after bootstrap secret deleted")
		}
	}
	return &mainContainer 
}
func expectBasicAuthConfigOnPodTemplate ( t * testing . T , instance * solr . SolrCloud , podTemplate * corev1 . PodTemplateSpec , expectBootstrapSecret bool ) * corev1 . Container { assert . NotNil ( t , podTemplate . Spec . Containers ) assert . True ( t , len ( podTemplate . Spec . Containers ) > 0 ) mainContainer := podTemplate . Spec . Containers [ 0 ] assert . NotNil ( t , mainContainer , " " ) assert . NotNil ( t , mainContainer . Env , " " ) if instance . Spec . SolrSecurity . ProbesRequireAuth { assert . NotNil ( t , podTemplate . Spec . Volumes ) secretName := instance . BasicAuthSecretName ( ) var basicAuthSecretVol * corev1 . Volume = nil for _ , vol := range podTemplate . Spec . Volumes { if vol . Name == secretName { basicAuthSecretVol = & vol break } } assert . NotNil ( t , basicAuthSecretVol ) assert . NotNil ( t , basicAuthSecretVol . VolumeSource . Secret , " " ) assert . Equal ( t , instance . BasicAuthSecretName ( ) , basicAuthSecretVol . VolumeSource . Secret . SecretName ) var basicAuthSecretVolMount * corev1 . VolumeMount = nil for _ , m := range podTemplate . Spec . Containers [ 0 ] . VolumeMounts { if m . Name == secretName { basicAuthSecretVolMount = & m break } } assert . NotNil ( t , basicAuthSecretVolMount ) assert . Equal ( t , " " + secretName , basicAuthSecretVolMount . MountPath ) expProbeCmd := " \" \" " + " " + " \" \" \" \" " + " \" \" " + " " assert . NotNil ( t , mainContainer . LivenessProbe , " " ) assert . NotNil ( t , mainContainer . LivenessProbe . Exec , " " ) assert . Equal ( t , expProbeCmd , mainContainer . LivenessProbe . Exec . Command [ 2 ] , " " ) assert . NotNil ( t , mainContainer . ReadinessProbe , " " ) assert . NotNil ( t , mainContainer . ReadinessProbe . Exec , " " ) assert . Equal ( t , expProbeCmd , mainContainer . ReadinessProbe . Exec . Command [ 2 ] , " " ) } if instance . Spec . SolrSecurity . BasicAuthSecret == " " { assert . NotNil ( t , podTemplate . Spec . InitContainers ) var expInitContainer * corev1 . Container = nil for _ , cnt := range podTemplate . Spec . InitContainers { if cnt . Name == " " { expInitContainer = & cnt break } } if expectBootstrapSecret { allACL , _ := instance . Spec . ZookeeperRef . GetACLs ( ) if allACL != nil { assert . Equal ( t , 10 , len ( expInitContainer . Env ) ) assert . Equal ( t , " " , expInitContainer . Env [ len ( expInitContainer . Env ) - 2 ] . Name ) assert . Equal ( t , " " , expInitContainer . Env [ len ( expInitContainer . Env ) - 1 ] . Name ) testACLEnvVars ( t , expInitContainer . Env [ 3 : len ( expInitContainer . Env ) - 2 ] ) } assert . NotNil ( t , expInitContainer , " " ) expCmd := " " + " " + " " + " \" \" " assert . True ( t , strings . Contains ( expInitContainer . Command [ 2 ] , expCmd ) , " " ) } else { assert . True ( t , expInitContainer == nil || ! strings . Contains ( expInitContainer . Command [ 2 ] , " " ) , " " ) } } return & mainContainer }
Ensures config is setup for basic-auth enabled Solr pods
Ensures config is setup for basic - auth enabled Solr pods
// check the env vars needed for the probes to work with auth // probes with auth // if no user-provided auth secret, then check that security.json gets bootstrapped correctly // initContainers // if the zookeeperRef has ACLs set, verify the env vars were set correctly for this initContainer // else this ref not using ACLs // return as a convenience in case tests want to do more checking on the main container