Skip to content

Commit

Permalink
add integration test for security json bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarroll1 committed Dec 13, 2024
1 parent 0e76152 commit c8e29db
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 0 deletions.
69 changes: 69 additions & 0 deletions tests/e2e/solrcloud_security_json_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package e2e

import (
"context"
solrv1beta1 "github.com/apache/solr-operator/api/v1beta1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/utils/pointer"
)

var _ = FDescribe("E2E - SolrCloud - Security JSON", func() {
var (
solrCloud *solrv1beta1.SolrCloud
)

BeforeEach(func() {
solrCloud = generateBaseSolrCloudWithSecurityJSON(1)
})

JustBeforeEach(func(ctx context.Context) {
By("generating the security.json secret")
generateSolrSecuritySecret(ctx, solrCloud)
generateSolrBasicAuthSecret(ctx, solrCloud)

By("creating the SolrCloud")
Expect(k8sClient.Create(ctx, solrCloud)).To(Succeed())

DeferCleanup(func(ctx context.Context) {
cleanupTest(ctx, solrCloud)
})

By("Waiting for the SolrCloud to come up healthy")
solrCloud = expectSolrCloudToBeReady(ctx, solrCloud)

By("creating a first Solr Collection")
createAndQueryCollection(ctx, solrCloud, "basic", 1, 1)
})

FContext("Provided Zookeeper", func() {
BeforeEach(func() {
solrCloud.Spec.ZookeeperRef = &solrv1beta1.ZookeeperRef{
ProvidedZookeeper: &solrv1beta1.ZookeeperSpec{
Replicas: pointer.Int32(1),
Ephemeral: &solrv1beta1.ZKEphemeral{},
},
}
})

// All testing will be done in the "JustBeforeEach" logic, no additional tests required here
FIt("Starts correctly", func(ctx context.Context) {})
})
})
85 changes: 85 additions & 0 deletions tests/e2e/test_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,91 @@ func generateBaseSolrCloud(replicas int) *solrv1beta1.SolrCloud {
}
}

func generateSolrSecuritySecret(ctx context.Context, solrCloud *solrv1beta1.SolrCloud) {
securityJsonSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: solrCloud.Name + "-security-secret",
Namespace: solrCloud.Namespace,
},
StringData: map[string]string{
"security.json": `{
"authentication": {
"blockUnknown": false,
"class": "solr.BasicAuthPlugin",
"credentials": {
"test-oper": "IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c="
},
"realm": "Solr Basic Auth",
"forwardCredentials": false
},
"authorization": {
"class": "solr.RuleBasedAuthorizationPlugin",
"user-role": {
"test-oper": "test-oper"
},
"permissions": [
{
"name": "cluster",
"role": null
},
{
"name": "collections",
"role": null,
"collection": "*"
}
]
}
}`,
},
Type: corev1.SecretTypeOpaque,
}
Expect(k8sClient.Create(ctx, securityJsonSecret)).To(Succeed(), "Failed to create secret for security json in namespace "+solrCloud.Namespace)

expectSecret(ctx, solrCloud, securityJsonSecret.Name)
return
}

func generateSolrBasicAuthSecret(ctx context.Context, solrCloud *solrv1beta1.SolrCloud) {
basicAuthSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: solrCloud.Name + "-basic-auth-secret",
Namespace: solrCloud.Namespace,
},
// Using default creds
StringData: map[string]string{
"username": "test-oper",
"password": "SolrRocks",
},
Type: corev1.SecretTypeBasicAuth,
}
Expect(k8sClient.Create(ctx, basicAuthSecret)).To(Succeed(), "Failed to create secret for basic auth in namespace "+solrCloud.Namespace)

expectSecret(ctx, solrCloud, basicAuthSecret.Name)
return
}

func generateBaseSolrCloudWithSecurityJSON(replicas int) *solrv1beta1.SolrCloud {
solrCloud := generateBaseSolrCloud(replicas)

// Ensure SolrSecurity is initialized
if solrCloud.Spec.SolrSecurity == nil {
solrCloud.Spec.SolrSecurity = &solrv1beta1.SolrSecurityOptions{}
}

solrCloud.Spec.SolrSecurity.BootstrapSecurityJson = &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: solrCloud.Name + "-security-secret",
},
Key: "security.json",
}

solrCloud.Spec.SolrSecurity.AuthenticationType = "Basic"

solrCloud.Spec.SolrSecurity.BasicAuthSecret = solrCloud.Name + "-basic-auth-secret"

return solrCloud
}

func generateBaseSolrCloudWithPlacementPolicy(replicas int, placementPlugin string) *solrv1beta1.SolrCloud {
solrCloud := generateBaseSolrCloud(replicas)
solrCloud.Spec.CustomSolrKubeOptions.PodOptions.EnvVariables = []corev1.EnvVar{
Expand Down

0 comments on commit c8e29db

Please sign in to comment.