Skip to content

Commit

Permalink
Pass in strong password to OSD integ test if version >= 2.12.0 (#4334)
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho authored Jan 10, 2024
1 parent 6eb6f8b commit eb1d8fe
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/test_workflow/integ_test/service_opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from test_workflow.integ_test.distribution import Distribution
from test_workflow.integ_test.distributions import Distributions
from test_workflow.integ_test.service import Service
from test_workflow.integ_test.utils import get_password


class ServiceOpenSearch(Service):
Expand All @@ -40,7 +41,6 @@ def __init__(
self.dist = Distributions.get_distribution("opensearch", distribution, version, work_dir)
self.dependency_installer = dependency_installer
self.install_dir = self.dist.install_dir
self.password = 'myStrongPassword123!' if float('.'.join(self.version.split('.')[:2])) >= 2.12 else 'admin'

def start(self) -> None:
self.dist.install(self.download())
Expand All @@ -66,7 +66,7 @@ def url(self, path: str = "") -> str:
def get_service_response(self) -> Response:
url = self.url("/_cluster/health")
logging.info(f"Pinging {url}")
return requests.get(url, verify=False, auth=("admin", self.password))
return requests.get(url, verify=False, auth=("admin", get_password(self.version)))

def __add_plugin_specific_config(self, additional_config: dict) -> None:
with open(self.opensearch_yml_path, "a") as yamlfile:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from test_workflow.integ_test.distribution import Distribution
from test_workflow.integ_test.distributions import Distributions
from test_workflow.integ_test.service import Service
from test_workflow.integ_test.utils import get_password


class ServiceOpenSearchDashboards(Service):
Expand Down Expand Up @@ -86,7 +87,7 @@ def url(self, path: str = "") -> str:
def get_service_response(self) -> Response:
url = self.url("/api/status")
logging.info(f"Pinging {url}")
return requests.get(url, verify=False, auth=("admin", "admin") if self.security_enabled else None)
return requests.get(url, verify=False, auth=("admin", get_password(self.version)) if self.security_enabled else None)

def __add_plugin_specific_config(self, additional_config: dict) -> None:
with open(self.opensearch_dashboards_yml_path, "a") as yamlfile:
Expand Down
16 changes: 16 additions & 0 deletions src/test_workflow/integ_test/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

import semver


def get_password(version: str) -> str:
# Starting in 2.12.0, demo configuration setup script requires a strong password
if semver.compare(version, '2.12.0') != -1:
return "myStrongPassword123!"
else:
return "admin"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

import unittest

from test_workflow.integ_test.utils import get_password


class TestUtils(unittest.TestCase):
def test_strong_password(self) -> None:
self.assertEqual("admin", get_password("2.11.1"))
self.assertEqual("myStrongPassword123!", get_password("3.0.0"))

0 comments on commit eb1d8fe

Please sign in to comment.