| {{- /* |
| # ***************************************************************************** |
| # |
| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| # |
| # ****************************************************************************** |
| */ -}} |
| |
| {{- if .Values.test.enabled }} |
| apiVersion: v1 |
| kind: ConfigMap |
| metadata: |
| name: {{ include "keycloak.fullname" . }}-test |
| labels: |
| {{- include "keycloak.commonLabels" . | nindent 4 }} |
| data: |
| test.py: | |
| import os |
| from selenium import webdriver |
| from selenium.webdriver.common.by import By |
| from selenium.webdriver.support.ui import WebDriverWait |
| from selenium.webdriver.support import expected_conditions |
| from urllib.parse import urlparse |
| |
| print('Creating PhantomJS driver...') |
| driver = webdriver.PhantomJS(service_log_path='/tmp/ghostdriver.log') |
| |
| base_url = 'http://{{ include "keycloak.fullname" . }}-http{{ if ne 80 (int .Values.keycloak.service.httpPort) }}:{{ .Values.keycloak.service.httpPort }}{{ end }}' |
| |
| print('Opening Keycloak...') |
| driver.get('{0}/auth/admin/'.format(base_url)) |
| |
| username = os.environ['KEYCLOAK_USER'] |
| password = os.environ['KEYCLOAK_PASSWORD'] |
| |
| username_input = WebDriverWait(driver, 30).until(expected_conditions.presence_of_element_located((By.ID, "username"))) |
| password_input = WebDriverWait(driver, 30).until(expected_conditions.presence_of_element_located((By.ID, "password"))) |
| login_button = WebDriverWait(driver, 30).until(expected_conditions.presence_of_element_located((By.ID, "kc-login"))) |
| |
| print('Entering username...') |
| username_input.send_keys(username) |
| |
| print('Entering password...') |
| password_input.send_keys(password) |
| |
| print('Clicking login button...') |
| login_button.click() |
| |
| current_url = urlparse(driver.current_url) |
| expected_url = urlparse('{0}/auth/admin/master/console/'.format(base_url)) |
| |
| print('Current URL: {0}'.format(current_url)) |
| print('Expected URL: {0}'.format(expected_url)) |
| |
| if current_url.path != expected_url.path: |
| print('Login failed. Current url is not expected url') |
| exit(1) |
| |
| print('URLs match. Login successful.') |
| |
| driver.quit() |
| {{- end }} |