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

Commit 5670b28

Browse files
committed
test(chart): add tests for the case basic auth is enabled
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 438ec42 commit 5670b28

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,12 @@ chart_test_autoscaling_deployment:
457457
./tests/charts/make/chart_test.sh DeploymentAutoscaling
458458

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

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

charts/selenium-grid/TESTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ All related testing to this helm chart will be documented in this file.
77
| Features | TC Description | Coverage | Test via |
88
|------------------------|----------------------------------------------------------------------|----------|----------|
99
| Basic Auth | Basic Auth is disabled | &check; | Cluster |
10-
| | Basic Auth is enabled | &cross; | |
10+
| | Basic Auth is enabled | &check; | Cluster |
1111
| Auto scaling | Auto scaling with `enableWithExistingKEDA` is `true` | &check; | Cluster |
1212
| | Auto scaling with `scalingType` is `job` | &check; | Cluster |
1313
| | Auto scaling with `scalingType` is `deployment` | &check; | Cluster |
@@ -21,7 +21,7 @@ All related testing to this helm chart will be documented in this file.
2121
| | `isolateComponents` is disabled | &check; | Cluster |
2222
| Browser Nodes | Node `nameOverride` is set | &check; | Cluster |
2323
| | Sanity tests in node | &check; | Cluster |
24-
| | Video recorder is enabled in node | &cross; | |
24+
| | Video recorder is enabled in node | &check; | Cluster |
2525
| | Node `extraEnvironmentVariables` is set value | &check; | Cluster |
2626
| General | Set new image registry via `global.seleniumGrid.imageRegistry` | &check; | Cluster |
2727
| | Components are able to set `.affinity` | &check; | Template |

tests/SeleniumTests/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
SELENIUM_GRID_PROTOCOL = os.environ.get('SELENIUM_GRID_PROTOCOL', 'http')
1515
SELENIUM_GRID_HOST = os.environ.get('SELENIUM_GRID_HOST', 'localhost')
1616
SELENIUM_GRID_PORT = os.environ.get('SELENIUM_GRID_PORT', '4444')
17+
SELENIUM_GRID_USERNAME = os.environ.get('SELENIUM_GRID_USERNAME', '')
18+
SELENIUM_GRID_PASSWORD = os.environ.get('SELENIUM_GRID_PASSWORD', '')
1719
SELENIUM_GRID_TEST_HEADLESS = os.environ.get('SELENIUM_GRID_TEST_HEADLESS', 'false').lower() == 'true'
1820
WEB_DRIVER_WAIT_TIMEOUT = int(os.environ.get('WEB_DRIVER_WAIT_TIMEOUT', 60))
1921

22+
if SELENIUM_GRID_USERNAME and SELENIUM_GRID_PASSWORD:
23+
SELENIUM_GRID_HOST = f"{SELENIUM_GRID_USERNAME}:{SELENIUM_GRID_PASSWORD}@{SELENIUM_GRID_HOST}"
24+
2025
class SeleniumGenericTests(unittest.TestCase):
2126

2227
def test_title(self):

tests/SmokeTests/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import time
44
import json
55
from ssl import _create_unverified_context
6-
try:
7-
from urllib2 import urlopen
8-
except ImportError:
9-
from urllib.request import urlopen
6+
import requests
7+
from requests.auth import HTTPBasicAuth
108

119
SELENIUM_GRID_PROTOCOL = os.environ.get('SELENIUM_GRID_PROTOCOL', 'http')
1210
SELENIUM_GRID_HOST = os.environ.get('SELENIUM_GRID_HOST', 'localhost')
1311
SELENIUM_GRID_PORT = os.environ.get('SELENIUM_GRID_PORT', '4444')
12+
SELENIUM_GRID_USERNAME = os.environ.get('SELENIUM_GRID_USERNAME', '')
13+
SELENIUM_GRID_PASSWORD = os.environ.get('SELENIUM_GRID_PASSWORD', '')
1414
SELENIUM_GRID_AUTOSCALING = os.environ.get('SELENIUM_GRID_AUTOSCALING', 'false')
1515
SELENIUM_GRID_AUTOSCALING_MIN_REPLICA = os.environ.get('SELENIUM_GRID_AUTOSCALING_MIN_REPLICA', 0)
1616
HUB_CHECKS_MAX_ATTEMPTS = os.environ.get('HUB_CHECKS_MAX_ATTEMPTS', 3)
@@ -29,8 +29,12 @@ def smoke_test_container(self, port):
2929
while current_attempts < max_attempts:
3030
current_attempts = current_attempts + 1
3131
try:
32-
response = urlopen('%s://%s:%s/status' % (SELENIUM_GRID_PROTOCOL, SELENIUM_GRID_HOST, port), context=_create_unverified_context())
33-
status_json = json.loads(response.read())
32+
grid_url_status = '%s://%s:%s/status' % (SELENIUM_GRID_PROTOCOL, SELENIUM_GRID_HOST, port)
33+
if SELENIUM_GRID_USERNAME and SELENIUM_GRID_PASSWORD:
34+
response = requests.get(grid_url_status, auth=HTTPBasicAuth(SELENIUM_GRID_USERNAME, SELENIUM_GRID_PASSWORD))
35+
else:
36+
response = requests.get(grid_url_status)
37+
status_json = response.json()
3438
if not auto_scaling or (auto_scaling and auto_scaling_min_replica > 0):
3539
self.assertTrue(status_json['value']['ready'], "Container is not ready on port %s" % port)
3640
else:

tests/charts/make/chart_test.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ SE_ENABLE_TRACING=${SE_ENABLE_TRACING:-"false"}
3030
SE_FULL_DISTRIBUTED_MODE=${SE_FULL_DISTRIBUTED_MODE:-"false"}
3131
HOSTNAME_ADDRESS=${HOSTNAME_ADDRESS:-"selenium-grid.local"}
3232
SE_ENABLE_INGRESS_HOSTNAME=${SE_ENABLE_INGRESS_HOSTNAME:-"false"}
33+
CHART_ENABLE_BASIC_AUTH=${CHART_ENABLE_BASIC_AUTH:-"false"}
34+
BASIC_AUTH_USERNAME=${BASIC_AUTH_USERNAME:-"sysAdminUser"}
35+
BASIC_AUTH_PASSWORD=${BASIC_AUTH_PASSWORD:-"myStrongPassword"}
3336

3437
cleanup() {
3538
if [ "${SKIP_CLEANUP}" = "false" ]; then
@@ -91,6 +94,16 @@ else
9194
"
9295
fi
9396

97+
if [ "${CHART_ENABLE_BASIC_AUTH}" = "true" ]; then
98+
HELM_COMMAND_SET_IMAGES="${HELM_COMMAND_SET_IMAGES} \
99+
--set basicAuth.enabled=${CHART_ENABLE_BASIC_AUTH} \
100+
--set basicAuth.username=${BASIC_AUTH_USERNAME} \
101+
--set basicAuth.password=${BASIC_AUTH_PASSWORD} \
102+
"
103+
export SELENIUM_GRID_USERNAME=${BASIC_AUTH_USERNAME}
104+
export SELENIUM_GRID_PASSWORD=${BASIC_AUTH_PASSWORD}
105+
fi
106+
94107
if [ "${SELENIUM_GRID_AUTOSCALING}" = "true" ]; then
95108
HELM_COMMAND_SET_AUTOSCALING=" \
96109
--set autoscaling.enableWithExistingKEDA=${SELENIUM_GRID_AUTOSCALING} \

0 commit comments

Comments
 (0)