Skip to content

Commit

Permalink
[#133] fix cookies global vars
Browse files Browse the repository at this point in the history
  • Loading branch information
ablatov committed Sep 14, 2018
1 parent c3ca38c commit 5245da4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 34 deletions.
17 changes: 12 additions & 5 deletions legion_test/legion_test/profiler_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,28 @@ def get_variables(arg=None):
if cookies:
try:
with open(cookies, 'r') as stream:
print('Start reading cookies.dat file')
lines = stream.readlines()
data['jenkins_user'] = lines[0]
data['jenkins_password'] = lines[1]
data['cookies'] = lines[2]
print('Loaded cookies :{},'
'\nJenkins creds: {}, {}'.format(data['cookies'], data['jenkins_user'], data['jenkins_password']))
data['jenkins_user'] = lines[0].rstrip()
data['jenkins_password'] = lines[1].rstrip()
data['cookies'] = lines[2].rstrip()
print('Complete reading cookies.dat file no errors')
except IOError:
pass

if not data.get('cookies', ''):
if 'dex' in data and data['dex']['enabled'] and 'staticPasswords' in data['dex']['config'] and \
data['dex']['config']['staticPasswords']:
print('Start init dex session cookies')
static_user = data['dex']['config']['staticPasswords'][0]
init_session_id(static_user['email'], static_user['password'], data.get('test_base_domain', data['base_domain']))
variables['STATIC_USER_EMAIL'] = static_user['email']
variables['STATIC_USER_PASS'] = static_user['password']
else:
variables['STATIC_USER_EMAIL'] = ''
variables['STATIC_USER_PASS'] = ''
else:
print('Init dex session cookies from cookies.dat')
init_session_id_from_data(data)

return variables
5 changes: 3 additions & 2 deletions legion_test/legion_test/robot/dex_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@


def init_session_id_from_data(data: dict):
global _session_cookies, _jenkins_credentials
cookies = data['cookies'].split(';')
for cookie in cookies:
_session_cookies[cookie.split('=')[0].rstrip()] = cookie.split('=')[1].rstrip()
_jenkins_credentials = (data['jenkins_user'].rstrip(), data['jenkins_password'].rstrip())
_session_cookies[cookie.split('=')[0]] = cookie.split('=')[1]
_jenkins_credentials = (data['jenkins_user'], data['jenkins_password'])
print('Cookies:{}'.format(_session_cookies))
print('Jenkins_creds:{}'.format(_jenkins_credentials))

Expand Down
26 changes: 0 additions & 26 deletions legion_test/legion_test/robot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,29 +227,3 @@ def post_credentials_to_auth(component_url, cluster_host, creds, jenkins=False):
else:
response = session.post(AUTHENTICATION_PATH.format(cluster_host, request_id), creds)
return {"response_code": response.status_code, "response_text": response.text}

@staticmethod
def get_static_user_data():
"""
Get static user email and password form secrets
:return: user email and password
:rtype: dict
"""
import os

import yaml
from legion_test.profiler_loader import CREDENTIAL_SECRETS_ENVIRONMENT_KEY
secrets = os.getenv(CREDENTIAL_SECRETS_ENVIRONMENT_KEY)
if not secrets:
raise Exception(
'Cannot get secrets - {} env variable is not set'.format(CREDENTIAL_SECRETS_ENVIRONMENT_KEY))

if not os.path.exists(secrets):
raise Exception('Cannot get secrets - file not found {}'.format(secrets))

with open(secrets, 'r') as stream:
data = yaml.load(stream)

static_user = data['dex']['config']['staticPasswords'][0]
return {"login": static_user['email'], "password": static_user['password']}
2 changes: 1 addition & 1 deletion tests/robot/resources/keywords.robot
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Secured component domain should be accessible by valid credentials
${jenkins} = Run Keyword If '${component}' == 'jenkins' Set Variable True
... ELSE Set Variable False
${boolean} = Convert To Boolean ${jenkins}
&{creds} = Get static user data
&{creds} = Create Dictionary login=${STATIC_USER_EMAIL} password=${STATIC_USER_PASS}
&{response} = Run Keyword If '${enclave}' == '${EMPTY}' Post credentials to auth ${HOST_PROTOCOL}://${component} ${HOST_BASE_DOMAIN} ${creds} ${boolean}
... ELSE Post credentials to auth ${HOST_PROTOCOL}://${component}-${enclave} ${HOST_BASE_DOMAIN} ${creds} ${boolean}
Log Bad auth page for ${component} is ${response}
Expand Down

0 comments on commit 5245da4

Please sign in to comment.