func TestEnableTLSOnExistingCluster(t *testing.T) {

	instance := buildTestSolrCloud()
	instance.Spec.SolrSecurity = &solr.SolrSecurityOptions{AuthenticationType: solr.Basic}

	changed := instance.WithDefaults()
	assert.True(t, changed, "WithDefaults should have changed the test SolrCloud instance")

	g := gomega.NewGomegaWithT(t)
	helper := NewTLSTestHelper(g)
	defer func() {
		helper.StopTest()
	}()

	ctx := context.TODO()
	helper.ReconcileSolrCloud(ctx, instance, 2)
	defer testClient.Delete(ctx, instance)

	// now, update the config to enable TLS
	tlsSecretName := "tls-cert-secret-from-user"
	keystorePassKey := "some-password-key-thingy"

	err := testClient.Get(ctx, types.NamespacedName{Name: instance.Name, Namespace: instance.Namespace}, instance)
	g.Expect(err).NotTo(gomega.HaveOccurred())
	instance.Spec.SolrTLS = createTLSOptions(tlsSecretName, keystorePassKey, true)
	foundTLSSecret := &corev1.Secret{}
	lookupErr := testClient.Get(ctx, types.NamespacedName{Name: instance.Spec.SolrTLS.PKCS12Secret.Name, Namespace: instance.Namespace}, foundTLSSecret)
	// TLS secret should not exist
	assert.True(t, errors.IsNotFound(lookupErr))

	// apply the update to trigger the upgrade to https
	err = testClient.Update(ctx, instance)
	g.Expect(err).NotTo(gomega.HaveOccurred())

	// Create a mock secret in the background so the isCert ready function returns
	var mockTLSSecret *corev1.Secret
	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		secret, _ := createMockTLSSecret(ctx, testClient, instance.Spec.SolrTLS.PKCS12Secret.Name, "keystore.p12", instance.Namespace, instance.Spec.SolrTLS.KeyStorePasswordSecret.Key)
		mockTLSSecret = &secret
		wg.Done()
	}()
	helper.WaitForReconcile(3)
	wg.Wait()

	expectStatefulSetTLSConfig(t, g, instance, false)
	expectIngressTLSConfig(t, g, tlsSecretName)

	defer testClient.Delete(ctx, mockTLSSecret)
}
// Test upgrade from non-TLS cluster to TLS enabled cluster
Test upgrade from non-TLS cluster to TLS enabled cluster
// Test upgrade from non - TLS cluster to TLS enabled cluster
func TestEnableTLSOnExistingCluster(t *testing.T) {
	instance := buildTestSolrCloud()
	instance.Spec.SolrSecurity = &solr.SolrSecurityOptions{AuthenticationType: solr.Basic}
	changed := instance.WithDefaults()
	assert.True(t, changed, "WithDefaults should have changed the test SolrCloud instance")
	g := gomega.NewGomegaWithT(t)
	helper := NewTLSTestHelper(g)
	defer func() {
		helper.StopTest()
	}()
	ctx := context.TODO()
	helper.ReconcileSolrCloud(ctx, instance, 2)
	defer testClient.Delete(ctx, instance)
	tlsSecretName := "tls-cert-secret-from-user"
	keystorePassKey := "some-password-key-thingy"
	err := testClient.Get(ctx, types.NamespacedName{Name: instance.Name, Namespace: instance.Namespace}, instance)
	g.Expect(err).NotTo(gomega.HaveOccurred())
	instance.Spec.SolrTLS = createTLSOptions(tlsSecretName, keystorePassKey, true)
	foundTLSSecret := &corev1.Secret{}
	lookupErr := testClient.Get(ctx, types.NamespacedName{Name: instance.Spec.SolrTLS.PKCS12Secret.Name, Namespace: instance.Namespace}, foundTLSSecret)
	assert.True(t, errors.IsNotFound(lookupErr))
	err = testClient.Update(ctx, instance)
	g.Expect(err).NotTo(gomega.HaveOccurred())
	var mockTLSSecret *corev1.Secret
	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		secret, _ := createMockTLSSecret(ctx, testClient, instance.Spec.SolrTLS.PKCS12Secret.Name, "keystore.p12", instance.Namespace, instance.Spec.SolrTLS.KeyStorePasswordSecret.Key)
		mockTLSSecret = &secret
		wg.Done()
	}()
	helper.WaitForReconcile(3)
	wg.Wait()
	expectStatefulSetTLSConfig(t, g, instance, false)
	expectIngressTLSConfig(t, g, tlsSecretName)
	defer testClient.Delete(ctx, mockTLSSecret)
}
func TestEnableTLSOnExistingCluster ( t * testing . T ) { instance := buildTestSolrCloud ( ) instance . Spec . SolrSecurity = & solr . SolrSecurityOptions { AuthenticationType : solr . Basic } changed := instance . WithDefaults ( ) assert . True ( t , changed , " " ) g := gomega . NewGomegaWithT ( t ) helper := NewTLSTestHelper ( g ) defer func ( ) { helper . StopTest ( ) } ( ) ctx := context . TODO ( ) helper . ReconcileSolrCloud ( ctx , instance , 2 ) defer testClient . Delete ( ctx , instance ) tlsSecretName := " " keystorePassKey := " " err := testClient . Get ( ctx , types . NamespacedName { Name : instance . Name , Namespace : instance . Namespace } , instance ) g . Expect ( err ) . NotTo ( gomega . HaveOccurred ( ) ) instance . Spec . SolrTLS = createTLSOptions ( tlsSecretName , keystorePassKey , true ) foundTLSSecret := & corev1 . Secret { } lookupErr := testClient . Get ( ctx , types . NamespacedName { Name : instance . Spec . SolrTLS . PKCS12Secret . Name , Namespace : instance . Namespace } , foundTLSSecret ) assert . True ( t , errors . IsNotFound ( lookupErr ) ) err = testClient . Update ( ctx , instance ) g . Expect ( err ) . NotTo ( gomega . HaveOccurred ( ) ) var mockTLSSecret * corev1 . Secret var wg sync . WaitGroup wg . Add ( 1 ) go func ( ) { secret , _ := createMockTLSSecret ( ctx , testClient , instance . Spec . SolrTLS . PKCS12Secret . Name , " " , instance . Namespace , instance . Spec . SolrTLS . KeyStorePasswordSecret . Key ) mockTLSSecret = & secret wg . Done ( ) } ( ) helper . WaitForReconcile ( 3 ) wg . Wait ( ) expectStatefulSetTLSConfig ( t , g , instance , false ) expectIngressTLSConfig ( t , g , tlsSecretName ) defer testClient . Delete ( ctx , mockTLSSecret ) }
Test upgrade from non-TLS cluster to TLS enabled cluster
Test upgrade from non - TLS cluster to TLS enabled cluster
// now, update the config to enable TLS // TLS secret should not exist // apply the update to trigger the upgrade to https // Create a mock secret in the background so the isCert ready function returns