diff --git a/utils.py b/utils.py index 2cb9cb00b33d5c36c005bc73de3f2e4b396d8311..2d9a4041bffe9b1f9be35f2c3731b8127e467274 100644 --- a/utils.py +++ b/utils.py @@ -238,6 +238,11 @@ def check_idp_response_selenium(sp,idp,test): store_page_source(page_source,idp,sp,test) 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: 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>" @@ -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>" store_page_source(page_source,idp,sp,test) return (idp['entityID'],wayfless_url,check_time,"(failed)","Connection-Error",webdriver_error) + ''' if (robots): 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): check_time = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S') + 'Z' driver.get(wayfless_url) - elem = WebDriverWait(driver, e2p.ECCS2SELENIUMPAGELOADTIMEOUT).until( - EC.presence_of_element_located((By.XPATH,'//form//input[@type="password"]')) - ) + # If meet <iframe> load it + 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 if (test): pgsrc = f"\n[WAYFLESS URL]{wayfless_url} - OK" @@ -294,6 +320,10 @@ def check_idp_response_selenium(sp,idp,test): except TimeoutException as e: 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) if (metadata_not_found): @@ -303,13 +333,13 @@ def check_idp_response_selenium(sp,idp,test): if (stored): return (idp['entityID'],wayfless_url,check_time,http_code,"No-eduGAIN-Metadata",webdriver_error) 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 stored = store_page_source(pgsrc,idp,sp,test) if (stored): return (idp['entityID'],wayfless_url,check_time,"(failed)","Timeout",webdriver_error) 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 stored = store_page_source(pgsrc,idp,sp,test) if (stored):