chg: [diagnostic] Fixed to support auth

authImprovements
mokaddem 2019-10-11 09:35:03 +02:00
parent eaf3ad30d1
commit 8da3d509cd
1 changed files with 18 additions and 10 deletions

View File

@ -387,27 +387,35 @@ def check_server_listening(spinner):
@add_spinner @add_spinner
def check_server_dynamic_enpoint(spinner): def check_server_dynamic_enpoint(spinner):
payload = {
'username': 'admin@admin.test',
'password': 'Password1234',
'submit': 'Sign In'
}
sleep_max = 15 sleep_max = 15
start_time = time.time() start_time = time.time()
url_login = '{}:{}/login'.format(HOST, PORT)
url = '{}:{}/_logs'.format(HOST, PORT) url = '{}:{}/_logs'.format(HOST, PORT)
p = subprocess.Popen( session = requests.Session()
['curl', '-sfN', '--header', 'Accept: text/event-stream', url], session.verify = False
stdout=subprocess.PIPE, r_login = session.post(url_login, data=payload)
bufsize=1) if '/login' in r_login.url:
signal.alarm(sleep_max) return_text = 'Invalid credential. Use valid credential to proceed.'
return (False, return_text)
r = session.get(url, stream=True, timeout=sleep_max, headers={'Accept': 'text/event-stream'})
return_flag = False return_flag = False
return_text = 'Dynamic endpoint returned data but not in the correct format.' return_text = 'Dynamic endpoint returned data but not in the correct format.'
try: try:
for line in iter(p.stdout.readline, b''): for line in r.iter_lines():
if line.startswith(b'data: '): if line.startswith(b'data: '):
data = line[6:] data = line[6:]
try: try:
j = json.loads(data) json.loads(data)
return_flag = True return_flag = True
return_text = 'Dynamic endpoint returned data (took {:.2f}s)'.format(time.time()-start_time) return_text = 'Dynamic endpoint returned data (took {:.2f}s)\n\t{}...'.format(time.time()-start_time, line[6:20])
signal.alarm(0)
break break
except Exception as e: except Exception:
return_flag = False return_flag = False
return_text = 'Something went wrong. Output {}'.format(line) return_text = 'Something went wrong. Output {}'.format(line)
break break