Skip to content

Commit adc99a8

Browse files
committed
fix tests
Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
1 parent da86565 commit adc99a8

41 files changed

Lines changed: 851 additions & 228 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.ci/opensearch/Dockerfile.opensearch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG OPENSEARCH_VERSION
1+
ARG OPENSEARCH_VERSION=latest
22
FROM opensearchproject/opensearch:${OPENSEARCH_VERSION}
33

44
ARG opensearch_path=/usr/share/opensearch

.ci/opensearch/docker-compose.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ services:
1313
environment:
1414
- cluster.name=opensearch-cluster
1515
- node.name=opensearch-node1
16-
- node.roles=cluster_manager,data,ingest
16+
- node.roles=${OPENSEARCH_MANAGER_ROLE:-cluster_manager},data,ingest
1717
- discovery.seed_hosts=opensearch-node1,opensearch-node2,opensearch-node3
18-
- cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2,opensearch-node3
18+
- cluster.initial_${OPENSEARCH_MANAGER_SETTING:-cluster_manager}_nodes=opensearch-node1,opensearch-node2,opensearch-node3
1919
- bootstrap.memory_lock=false # Disable memory locking for development
2020
- path.repo=/usr/share/opensearch/mnt
2121
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123!
@@ -57,9 +57,9 @@ services:
5757
environment:
5858
- cluster.name=opensearch-cluster
5959
- node.name=opensearch-node2
60-
- node.roles=cluster_manager,data,ingest
60+
- node.roles=${OPENSEARCH_MANAGER_ROLE:-cluster_manager},data,ingest
6161
- discovery.seed_hosts=opensearch-node1,opensearch-node2,opensearch-node3
62-
- cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2,opensearch-node3
62+
- cluster.initial_${OPENSEARCH_MANAGER_SETTING:-cluster_manager}_nodes=opensearch-node1,opensearch-node2,opensearch-node3
6363
- bootstrap.memory_lock=false # Disable memory locking for development
6464
- path.repo=/usr/share/opensearch/mnt
6565
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123!
@@ -101,9 +101,9 @@ services:
101101
environment:
102102
- cluster.name=opensearch-cluster
103103
- node.name=opensearch-node3
104-
- node.roles=cluster_manager,data,ingest
104+
- node.roles=${OPENSEARCH_MANAGER_ROLE:-cluster_manager},data,ingest
105105
- discovery.seed_hosts=opensearch-node1,opensearch-node2,opensearch-node3
106-
- cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2,opensearch-node3
106+
- cluster.initial_${OPENSEARCH_MANAGER_SETTING:-cluster_manager}_nodes=opensearch-node1,opensearch-node2,opensearch-node3
107107
- bootstrap.memory_lock=false # Disable memory locking for development
108108
- path.repo=/usr/share/opensearch/mnt
109109
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123!

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ tmp/
66
.vscode
77
bin/
88

9-
.DS_Store
9+
.DS_Store
10+
# Admin certificates for testing
11+
admin.pem
12+
admin.key

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
4343
### Fixed
4444

4545
- Fix flaky connection integration test by replacing arbitrary sleep times with proper server readiness polling
46+
- Fix OpenSearch 2.8.0+ Tasks API compatibility by adding cancellation_time_millis field to TasksListTask struct
4647
- Fix OpenSearch 3.1.0+ API compatibility by adding phase_results_processors field to nodes API and time_in_execution fields to cluster pending tasks API
4748
- Fix OpenSearch 3.2.0+ API compatibility by adding max_last_index_request_timestamp and startree query fields across nodes stats, indices stats, and cat APIs, plus settings field to security plugin health API
4849
- Fix OpenSearch 3.3.0+ API compatibility by adding neural_search breaker, query_failed and startree_query_failed search fields, search pipeline system_generated fields across multiple APIs, plus ingestion_status field to cluster state API and jwks_uri field to security config API

Makefile

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ endif
3333
ifdef race
3434
$(eval testintegargs += "-race")
3535
endif
36-
$(eval testintegargs += "-cover" "-tags=$(testintegtags)" "-timeout=1h" "./..." "-args" "-test.gocoverdir=$(PWD)/tmp/integration")
36+
$(eval testintegargs += "-cover" "-tags=$(testintegtags)" "-timeout=5m" "./..." "-args" "-test.gocoverdir=$(PWD)/tmp/integration")
3737
@mkdir -p $(PWD)/tmp/integration
3838
@echo "go test -v" $(testintegargs); \
3939
go test -v $(testintegargs);
@@ -126,10 +126,10 @@ lint.markdown:
126126
npm install -g $(package) --no-shrinkwrap; \
127127
fi
128128
@printf "\033[2m-> Running markdown lint...\033[0m\n"
129-
if npx $(package) --prose-wrap never --check **/*.md; [[ $$? -ne 0 ]]; then \
129+
if npx $(package) --prose-wrap never --check **/*.md; [ $$? -ne 0 ]; then \
130130
echo -e "\033[32m-> Found invalid files. Want to auto-format invalid files? (y/n) \033[0m"; \
131131
read RESP; \
132-
if [[ $$RESP = "y" || $$RESP = "Y" ]]; then \
132+
if [ "$$RESP" = "y" ] || [ "$$RESP" = "Y" ]; then \
133133
echo -e "\033[33m Formatting...\033[0m"; \
134134
npx $(package) --prose-wrap never --write **/*.md; \
135135
echo -e "\033[34m \nAll invalid files are formatted\033[0m"; \
@@ -197,7 +197,7 @@ endif
197197
set -e -o pipefail; \
198198
printf "\033[2m-> Commit and create Git tag? (y/n): \033[0m\c"; \
199199
read continue; \
200-
if [[ $$continue == "y" ]]; then \
200+
if [ "$$continue" = "y" ]; then \
201201
git add internal/version/version.go && \
202202
git commit --no-status --quiet --message "Release $(version)" && \
203203
git tag --annotate v$(version) --message 'Release $(version)'; \
@@ -225,14 +225,57 @@ godoc: ## Display documentation for the package
225225
godoc --http=localhost:6060 --play
226226

227227
cluster.build:
228-
docker compose --project-directory .ci/opensearch build --pull;
228+
@$(MAKE) cluster.docker-build
229229

230230
cluster.start:
231-
docker compose --project-directory .ci/opensearch up -d;
231+
@$(MAKE) cluster.docker-up
232+
@$(MAKE) cluster.get-cert
232233

233234
cluster.stop:
234235
docker compose --project-directory .ci/opensearch down;
235236

237+
cluster.docker-build:
238+
@# Determine version-specific settings
239+
$(eval OPENSEARCH_VERSION ?= latest)
240+
$(eval version_major := $(shell \
241+
if [ "$(OPENSEARCH_VERSION)" = "latest" ]; then \
242+
echo "2"; \
243+
else \
244+
echo "$(OPENSEARCH_VERSION)" | awk -F. '{print $$1}'; \
245+
fi \
246+
))
247+
$(eval manager_role := $(shell \
248+
if [ "$(version_major)" = "1" ]; then \
249+
echo "master"; \
250+
else \
251+
echo "cluster_manager"; \
252+
fi \
253+
))
254+
@echo "Building OpenSearch $(OPENSEARCH_VERSION) with role: $(manager_role)"
255+
OPENSEARCH_MANAGER_ROLE=$(manager_role) OPENSEARCH_MANAGER_SETTING=$(manager_role) \
256+
docker compose --project-directory .ci/opensearch build --pull
257+
258+
cluster.docker-up:
259+
@# Determine version-specific settings
260+
$(eval OPENSEARCH_VERSION ?= latest)
261+
$(eval version_major := $(shell \
262+
if [ "$(OPENSEARCH_VERSION)" = "latest" ]; then \
263+
echo "2"; \
264+
else \
265+
echo "$(OPENSEARCH_VERSION)" | awk -F. '{print $$1}'; \
266+
fi \
267+
))
268+
$(eval manager_role := $(shell \
269+
if [ "$(version_major)" = "1" ]; then \
270+
echo "master"; \
271+
else \
272+
echo "cluster_manager"; \
273+
fi \
274+
))
275+
@echo "Starting OpenSearch $(OPENSEARCH_VERSION) with role: $(manager_role)"
276+
OPENSEARCH_MANAGER_ROLE=$(manager_role) OPENSEARCH_MANAGER_SETTING=$(manager_role) \
277+
docker compose --project-directory .ci/opensearch up -d
278+
236279
cluster.scale.1: ## Start single-node cluster
237280
docker compose --project-directory .ci/opensearch up -d --scale opensearch-node2=0 --scale opensearch-node3=0;
238281

@@ -243,9 +286,14 @@ cluster.scale.3: ## Start full 3-node cluster
243286
docker compose --project-directory .ci/opensearch up -d --scale opensearch-node1=1 --scale opensearch-node2=1 --scale opensearch-node3=1;
244287

245288
cluster.get-cert:
246-
@if [[ -v SECURE_INTEGRATION ]] && [[ $$SECURE_INTEGRATION == "true" ]]; then \
247-
docker cp $$(docker compose --project-directory .ci/opensearch ps --format '{{.Name}}' | head -1):/usr/share/opensearch/config/kirk.pem admin.pem && \
248-
docker cp $$(docker compose --project-directory .ci/opensearch ps --format '{{.Name}}' | head -1):/usr/share/opensearch/config/kirk-key.pem admin.key; \
289+
@if [ -n "$${SECURE_INTEGRATION}" ] && [ "$${SECURE_INTEGRATION}" = "true" ]; then \
290+
CONTAINER=$$(docker compose --project-directory .ci/opensearch ps --format '{{.Name}}' | head -1); \
291+
if [ -z "$$CONTAINER" ]; then \
292+
echo "Error: No OpenSearch containers running. Start cluster first with 'make cluster.start'"; \
293+
exit 1; \
294+
fi; \
295+
docker cp $$CONTAINER:/usr/share/opensearch/config/kirk.pem admin.pem && \
296+
docker cp $$CONTAINER:/usr/share/opensearch/config/kirk-key.pem admin.key; \
249297
fi
250298

251299

@@ -281,5 +329,5 @@ help: ## Display help
281329
#------------- <https://suva.sh/posts/well-documented-makefiles> --------------
282330

283331
.DEFAULT_GOAL := help
284-
.PHONY: help backport cluster cluster.clean coverage godoc lint lint.local release test test-all test-race test-bench test-integ test-unit linters linters.install
332+
.PHONY: help backport cluster.build cluster.start cluster.stop cluster.docker-build cluster.docker-up cluster.clean coverage godoc lint lint.local release test test-all test-race test-bench test-integ test-unit linters linters.install
285333
.SILENT: lint.markdown

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ require (
3030
github.com/tidwall/match v1.1.1 // indirect
3131
github.com/tidwall/pretty v1.2.1 // indirect
3232
github.com/tidwall/sjson v1.2.5 // indirect
33+
golang.org/x/mod v0.33.0 // indirect
3334
gopkg.in/yaml.v3 v3.0.1 // indirect
3435
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
5252
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
5353
github.com/wI2L/jsondiff v0.7.0 h1:1lH1G37GhBPqCfp/lrs91rf/2j3DktX6qYAKZkLuCQQ=
5454
github.com/wI2L/jsondiff v0.7.0/go.mod h1:KAEIojdQq66oJiHhDyQez2x+sRit0vIzC9KeK0yizxM=
55+
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
56+
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
5557
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
5658
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5759
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=

internal/test/config.go

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,25 @@ package ostest
88

99
import (
1010
"crypto/tls"
11+
"fmt"
1112
"net/http"
1213
"os"
1314

15+
"golang.org/x/mod/semver"
16+
1417
"github.com/opensearch-project/opensearch-go/v4"
1518
"github.com/opensearch-project/opensearch-go/v4/opensearchapi"
1619
)
1720

21+
const (
22+
// OpenSearch default admin passwords
23+
defaultPasswordPre212 = "admin" // Default admin password in OpenSearch < 2.12.0
24+
defaultPasswordPost212 = "myStrongPassword123!" // Default admin password in OpenSearch >= 2.12.0
25+
26+
// Version where default admin password changed
27+
defaultPasswordChangeVersion = "v2.12.0"
28+
)
29+
1830
// IsSecure returns true when SECURE_INTEGRATION env is set to true
1931
func IsSecure() bool {
2032
return os.Getenv("SECURE_INTEGRATION") == "true"
@@ -48,25 +60,61 @@ func ClientConfig() (*opensearchapi.Config, error) {
4860
}, nil
4961
}
5062

51-
// GetPassword returns the password suited for the opensearch version
63+
// GetPassword returns the admin password for the opensearch version.
64+
// OpenSearch 2.12.0+ changed the default admin password from "admin" to "myStrongPassword123!".
65+
//
66+
// Note: This function tries to determine the correct password based on OPENSEARCH_VERSION env var.
67+
// If the env var doesn't match the actual running cluster, authentication may fail.
5268
func GetPassword() (string, error) {
53-
var (
54-
major, minor int64
55-
err error
56-
)
57-
password := "admin"
5869
version := os.Getenv("OPENSEARCH_VERSION")
5970

60-
if version != "latest" && version != "" {
61-
major, minor, _, err = opensearch.ParseVersion(version)
62-
if err != nil {
63-
return "", err
71+
// Default to pre-2.12 password for empty version or versions < 2.12.0
72+
password := defaultPasswordPre212
73+
74+
if version == "latest" {
75+
// Latest uses the post-2.12 default password
76+
password = defaultPasswordPost212
77+
} else if version != "" {
78+
// Normalize version to semver format (v2.12.0)
79+
if version[0] != 'v' {
80+
version = "v" + version
81+
}
82+
83+
// Validate semver format
84+
if !semver.IsValid(version) {
85+
return "", fmt.Errorf("invalid version format: %s", version)
6486
}
65-
if version == "latest" || major > 2 || (major == 2 && minor >= 12) {
66-
password = "myStrongPassword123!"
87+
88+
// OpenSearch 2.12.0+ uses the new default password
89+
if semver.Compare(version, defaultPasswordChangeVersion) >= 0 {
90+
password = defaultPasswordPost212
6791
}
68-
} else {
69-
password = "myStrongPassword123!"
7092
}
93+
7194
return password, nil
7295
}
96+
97+
// GetPasswordForCluster returns the admin password by trying to detect the actual cluster version.
98+
// This is more reliable than GetPassword() when OPENSEARCH_VERSION env var might not match reality.
99+
// It returns both possible passwords to try in order.
100+
func GetPasswordForCluster() []string {
101+
version := os.Getenv("OPENSEARCH_VERSION")
102+
103+
// If version is set and valid, trust it
104+
if version != "" && version != "latest" {
105+
if version[0] != 'v' {
106+
version = "v" + version
107+
}
108+
if semver.IsValid(version) {
109+
if semver.Compare(version, defaultPasswordChangeVersion) >= 0 {
110+
// For 2.12+, try post-2.12 password first, then fallback to pre-2.12
111+
return []string{defaultPasswordPost212, defaultPasswordPre212}
112+
}
113+
// For < 2.12, try pre-2.12 password first, then fallback to post-2.12
114+
return []string{defaultPasswordPre212, defaultPasswordPost212}
115+
}
116+
}
117+
118+
// Unknown or latest version: try pre-2.12 password first (most common), then post-2.12
119+
return []string{defaultPasswordPre212, defaultPasswordPost212}
120+
}

0 commit comments

Comments
 (0)