Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
test(chart): add tests for the case basic auth is enabled
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
  • Loading branch information
VietND96 committed Feb 21, 2024
1 parent 438ec42 commit 5670b28
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,12 @@ chart_test_autoscaling_deployment:
./tests/charts/make/chart_test.sh DeploymentAutoscaling

chart_test_autoscaling_job_https:
SELENIUM_GRID_TEST_HEADLESS=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_PORT=443 \
SELENIUM_GRID_TEST_HEADLESS=true SELENIUM_GRID_PROTOCOL=https CHART_ENABLE_BASIC_AUTH=true SELENIUM_GRID_PORT=443 \
VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) NAMESPACE=$(NAMESPACE) \
./tests/charts/make/chart_test.sh JobAutoscaling

chart_test_autoscaling_job_hostname:
SE_ENABLE_TRACING=true SE_ENABLE_INGRESS_HOSTNAME=true \
SE_ENABLE_TRACING=true SE_ENABLE_INGRESS_HOSTNAME=true CHART_ENABLE_BASIC_AUTH=true \
VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) NAMESPACE=$(NAMESPACE) \
./tests/charts/make/chart_test.sh JobAutoscaling

Expand Down
4 changes: 2 additions & 2 deletions charts/selenium-grid/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ All related testing to this helm chart will be documented in this file.
| Features | TC Description | Coverage | Test via |
|------------------------|----------------------------------------------------------------------|----------|----------|
| Basic Auth | Basic Auth is disabled | &check; | Cluster |
| | Basic Auth is enabled | &cross; | |
| | Basic Auth is enabled | &check; | Cluster |
| Auto scaling | Auto scaling with `enableWithExistingKEDA` is `true` | &check; | Cluster |
| | Auto scaling with `scalingType` is `job` | &check; | Cluster |
| | Auto scaling with `scalingType` is `deployment` | &check; | Cluster |
Expand All @@ -21,7 +21,7 @@ All related testing to this helm chart will be documented in this file.
| | `isolateComponents` is disabled | &check; | Cluster |
| Browser Nodes | Node `nameOverride` is set | &check; | Cluster |
| | Sanity tests in node | &check; | Cluster |
| | Video recorder is enabled in node | &cross; | |
| | Video recorder is enabled in node | &check; | Cluster |
| | Node `extraEnvironmentVariables` is set value | &check; | Cluster |
| General | Set new image registry via `global.seleniumGrid.imageRegistry` | &check; | Cluster |
| | Components are able to set `.affinity` | &check; | Template |
Expand Down
5 changes: 5 additions & 0 deletions tests/SeleniumTests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
SELENIUM_GRID_PROTOCOL = os.environ.get('SELENIUM_GRID_PROTOCOL', 'http')
SELENIUM_GRID_HOST = os.environ.get('SELENIUM_GRID_HOST', 'localhost')
SELENIUM_GRID_PORT = os.environ.get('SELENIUM_GRID_PORT', '4444')
SELENIUM_GRID_USERNAME = os.environ.get('SELENIUM_GRID_USERNAME', '')
SELENIUM_GRID_PASSWORD = os.environ.get('SELENIUM_GRID_PASSWORD', '')
SELENIUM_GRID_TEST_HEADLESS = os.environ.get('SELENIUM_GRID_TEST_HEADLESS', 'false').lower() == 'true'
WEB_DRIVER_WAIT_TIMEOUT = int(os.environ.get('WEB_DRIVER_WAIT_TIMEOUT', 60))

if SELENIUM_GRID_USERNAME and SELENIUM_GRID_PASSWORD:
SELENIUM_GRID_HOST = f"{SELENIUM_GRID_USERNAME}:{SELENIUM_GRID_PASSWORD}@{SELENIUM_GRID_HOST}"

class SeleniumGenericTests(unittest.TestCase):

def test_title(self):
Expand Down
16 changes: 10 additions & 6 deletions tests/SmokeTests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import time
import json
from ssl import _create_unverified_context
try:
from urllib2 import urlopen
except ImportError:
from urllib.request import urlopen
import requests
from requests.auth import HTTPBasicAuth

SELENIUM_GRID_PROTOCOL = os.environ.get('SELENIUM_GRID_PROTOCOL', 'http')
SELENIUM_GRID_HOST = os.environ.get('SELENIUM_GRID_HOST', 'localhost')
SELENIUM_GRID_PORT = os.environ.get('SELENIUM_GRID_PORT', '4444')
SELENIUM_GRID_USERNAME = os.environ.get('SELENIUM_GRID_USERNAME', '')
SELENIUM_GRID_PASSWORD = os.environ.get('SELENIUM_GRID_PASSWORD', '')
SELENIUM_GRID_AUTOSCALING = os.environ.get('SELENIUM_GRID_AUTOSCALING', 'false')
SELENIUM_GRID_AUTOSCALING_MIN_REPLICA = os.environ.get('SELENIUM_GRID_AUTOSCALING_MIN_REPLICA', 0)
HUB_CHECKS_MAX_ATTEMPTS = os.environ.get('HUB_CHECKS_MAX_ATTEMPTS', 3)
Expand All @@ -29,8 +29,12 @@ def smoke_test_container(self, port):
while current_attempts < max_attempts:
current_attempts = current_attempts + 1
try:
response = urlopen('%s://%s:%s/status' % (SELENIUM_GRID_PROTOCOL, SELENIUM_GRID_HOST, port), context=_create_unverified_context())
status_json = json.loads(response.read())
grid_url_status = '%s://%s:%s/status' % (SELENIUM_GRID_PROTOCOL, SELENIUM_GRID_HOST, port)
if SELENIUM_GRID_USERNAME and SELENIUM_GRID_PASSWORD:
response = requests.get(grid_url_status, auth=HTTPBasicAuth(SELENIUM_GRID_USERNAME, SELENIUM_GRID_PASSWORD))
else:
response = requests.get(grid_url_status)
status_json = response.json()
if not auto_scaling or (auto_scaling and auto_scaling_min_replica > 0):
self.assertTrue(status_json['value']['ready'], "Container is not ready on port %s" % port)
else:
Expand Down
13 changes: 13 additions & 0 deletions tests/charts/make/chart_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ SE_ENABLE_TRACING=${SE_ENABLE_TRACING:-"false"}
SE_FULL_DISTRIBUTED_MODE=${SE_FULL_DISTRIBUTED_MODE:-"false"}
HOSTNAME_ADDRESS=${HOSTNAME_ADDRESS:-"selenium-grid.local"}
SE_ENABLE_INGRESS_HOSTNAME=${SE_ENABLE_INGRESS_HOSTNAME:-"false"}
CHART_ENABLE_BASIC_AUTH=${CHART_ENABLE_BASIC_AUTH:-"false"}
BASIC_AUTH_USERNAME=${BASIC_AUTH_USERNAME:-"sysAdminUser"}
BASIC_AUTH_PASSWORD=${BASIC_AUTH_PASSWORD:-"myStrongPassword"}

cleanup() {
if [ "${SKIP_CLEANUP}" = "false" ]; then
Expand Down Expand Up @@ -91,6 +94,16 @@ else
"
fi

if [ "${CHART_ENABLE_BASIC_AUTH}" = "true" ]; then
HELM_COMMAND_SET_IMAGES="${HELM_COMMAND_SET_IMAGES} \
--set basicAuth.enabled=${CHART_ENABLE_BASIC_AUTH} \
--set basicAuth.username=${BASIC_AUTH_USERNAME} \
--set basicAuth.password=${BASIC_AUTH_PASSWORD} \
"
export SELENIUM_GRID_USERNAME=${BASIC_AUTH_USERNAME}
export SELENIUM_GRID_PASSWORD=${BASIC_AUTH_PASSWORD}
fi

if [ "${SELENIUM_GRID_AUTOSCALING}" = "true" ]; then
HELM_COMMAND_SET_AUTOSCALING=" \
--set autoscaling.enableWithExistingKEDA=${SELENIUM_GRID_AUTOSCALING} \
Expand Down

0 comments on commit 5670b28

Please sign in to comment.