Skip to content
Snippets Groups Projects
Commit cb5eeb66 authored by Marco Malavolti's avatar Marco Malavolti
Browse files

Changed Selenium check

parent f0c57716
Branches
No related tags found
No related merge requests found
...@@ -238,6 +238,11 @@ def check_idp_response_selenium(sp,idp,test): ...@@ -238,6 +238,11 @@ def check_idp_response_selenium(sp,idp,test):
store_page_source(page_source,idp,sp,test) store_page_source(page_source,idp,sp,test)
return (idp['entityID'],wayfless_url,check_time,"(failed)","SSL-Error",webdriver_error) return (idp['entityID'],wayfless_url,check_time,"(failed)","SSL-Error",webdriver_error)
# Do not consider any other Exception
except:
pass
'''
except requests.exceptions.ConnectionError as e: except requests.exceptions.ConnectionError as e:
if (test): page_source = f"\nA Connection error occurred while opening https://{fqdn_idp}/robots.txt:\n\n{e}" if (test): page_source = f"\nA Connection error occurred while opening https://{fqdn_idp}/robots.txt:\n\n{e}"
else: page_source = f"<h1>CONNECTION ERROR:</h1><h2>A Connection error occurred while opening <a href='https://{fqdn_idp}/robots.txt'>https://{fqdn_idp}/robots.txt</a>:</h2><p>{e}</p>" else: page_source = f"<h1>CONNECTION ERROR:</h1><h2>A Connection error occurred while opening <a href='https://{fqdn_idp}/robots.txt'>https://{fqdn_idp}/robots.txt</a>:</h2><p>{e}</p>"
...@@ -255,6 +260,7 @@ def check_idp_response_selenium(sp,idp,test): ...@@ -255,6 +260,7 @@ def check_idp_response_selenium(sp,idp,test):
else: page_source = f"<h1>TOO MANY REDIRECTS</h1><h2>Too many redirects occurred while opening: <a href='https://{fqdn_idp}/robots.txt'>https://{fqdn_idp}/robots.txt</a>:</h2><p>{e}</p>" else: page_source = f"<h1>TOO MANY REDIRECTS</h1><h2>Too many redirects occurred while opening: <a href='https://{fqdn_idp}/robots.txt'>https://{fqdn_idp}/robots.txt</a>:</h2><p>{e}</p>"
store_page_source(page_source,idp,sp,test) store_page_source(page_source,idp,sp,test)
return (idp['entityID'],wayfless_url,check_time,"(failed)","Connection-Error",webdriver_error) return (idp['entityID'],wayfless_url,check_time,"(failed)","Connection-Error",webdriver_error)
'''
if (robots): if (robots):
check_time = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S') + 'Z' check_time = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S') + 'Z'
...@@ -281,9 +287,29 @@ def check_idp_response_selenium(sp,idp,test): ...@@ -281,9 +287,29 @@ def check_idp_response_selenium(sp,idp,test):
check_time = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S') + 'Z' check_time = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S') + 'Z'
driver.get(wayfless_url) driver.get(wayfless_url)
elem = WebDriverWait(driver, e2p.ECCS2SELENIUMPAGELOADTIMEOUT).until( # If meet <iframe> load it
EC.presence_of_element_located((By.XPATH,'//form//input[@type="password"]')) if ("<iframe" in driver.page_source):
) seq = driver.find_elements_by_tag_name('iframe')
#switching between the iframes based on index
for index in range(len(seq)):
driver.switch_to_default_content
iframe = driver.find_elements_by_tag_name('iframe')[index]
driver.switch_to.frame(iframe)
# and search the <input type="password"> tag
if (EC.presence_of_element_located((By.XPATH,'//input[@type="password"]'))):
break # input password found
driver.switch_to.default_content
# else search only the <input type="password"> tag
else:
WebDriverWait(driver, e2p.ECCS2SELENIUMPAGELOADTIMEOUT).until(
EC.presence_of_element_located((By.XPATH,'//input[@type="password"]'))
)
page_source = driver.page_source page_source = driver.page_source
if (test): pgsrc = f"\n[WAYFLESS URL]{wayfless_url} - OK" if (test): pgsrc = f"\n[WAYFLESS URL]{wayfless_url} - OK"
...@@ -294,6 +320,10 @@ def check_idp_response_selenium(sp,idp,test): ...@@ -294,6 +320,10 @@ def check_idp_response_selenium(sp,idp,test):
except TimeoutException as e: except TimeoutException as e:
page_source = driver.page_source page_source = driver.page_source
if (test):
sys.stdout.write(f"\nPAGE_SOURCE: {page_source}")
metadata_not_found = re.search(e2p.METADATAPATTERN,page_source, re.I) metadata_not_found = re.search(e2p.METADATAPATTERN,page_source, re.I)
if (metadata_not_found): if (metadata_not_found):
...@@ -303,13 +333,13 @@ def check_idp_response_selenium(sp,idp,test): ...@@ -303,13 +333,13 @@ def check_idp_response_selenium(sp,idp,test):
if (stored): if (stored):
return (idp['entityID'],wayfless_url,check_time,http_code,"No-eduGAIN-Metadata",webdriver_error) return (idp['entityID'],wayfless_url,check_time,http_code,"No-eduGAIN-Metadata",webdriver_error)
elif(page_source == "<html><head></head><body></body></html>"): elif(page_source == "<html><head></head><body></body></html>"):
if (test): pgsrc = f"Timeout: No valid login form loaded in {e2p.ECCS2SELENIUMPAGELOADTIMEOUT} seconds" if (test): pgsrc = f"\nTimeout: No valid login form loaded in {e2p.ECCS2SELENIUMPAGELOADTIMEOUT} seconds"
else: pgsrc = page_source else: pgsrc = page_source
stored = store_page_source(pgsrc,idp,sp,test) stored = store_page_source(pgsrc,idp,sp,test)
if (stored): if (stored):
return (idp['entityID'],wayfless_url,check_time,"(failed)","Timeout",webdriver_error) return (idp['entityID'],wayfless_url,check_time,"(failed)","Timeout",webdriver_error)
else: else:
if (test): pgsrc = f"Invalid-Form: No valid login form found in {e2p.ECCS2SELENIUMPAGELOADTIMEOUT} seconds" if (test): pgsrc = f"\nInvalid-Form: No valid login form found in {e2p.ECCS2SELENIUMPAGELOADTIMEOUT} seconds"
else: pgsrc = page_source else: pgsrc = page_source
stored = store_page_source(pgsrc,idp,sp,test) stored = store_page_source(pgsrc,idp,sp,test)
if (stored): if (stored):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment