Skip to content

Commit

Permalink
fix security integ test
Browse files Browse the repository at this point in the history
Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
  • Loading branch information
Jakob3xD committed Mar 11, 2024
1 parent 2a3e6f4 commit 198261c
Showing 1 changed file with 21 additions and 34 deletions.
55 changes: 21 additions & 34 deletions opensearch_secure_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ package opensearch_test
import (
"context"
"crypto/tls"
"errors"
"log"
"net/http"
"os"
"strconv"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -40,40 +38,29 @@ import (
)

func getSecuredClient() (*opensearchapi.Client, error) {
version := os.Getenv("OPENSEARCH_VERSION")
parts := strings.Split(version, ".")
first, _ := strconv.Atoi(parts[0])
second, _ := strconv.Atoi(parts[1])
var password string
if first > 2 || (first == 2 && second >= 12) {
password = "myStrongPassword123!"
} else {
password = "admin"
}

return opensearchapi.NewClient(
opensearchapi.Config{
Client: opensearch.Config{
Username: "admin",
Password: password,
Addresses: []string{"https://localhost:9200"},
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
errs := make([]error, 0)
for _, password := range []string{"admin", "myStrongPassword123!"} {
client, _ := opensearchapi.NewClient(
opensearchapi.Config{
Client: opensearch.Config{
Username: "admin",
Password: password,
Addresses: []string{"https://localhost:9200"},
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
},
},
},
)
}

type clusterVersion struct {
Number string `json:"number"`
BuildFlavor string `json:"build_flavor"`
Distribution string `json:"distribution"`
}
)
_, err := client.Info(nil, nil)
if err != nil {
errs = append(errs, err)
continue
}
return client, nil
}
return nil, errors.Join(errs...)

type Info struct {
Version clusterVersion `json:"version"`
Tagline string `json:"tagline"`
}

func TestSecuredClientAPI(t *testing.T) {
Expand Down

0 comments on commit 198261c

Please sign in to comment.