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

Used logging to separate results

parent 0fa338dd
Branches
Tags
No related merge requests found
...@@ -47,7 +47,7 @@ def getIdPs(): ...@@ -47,7 +47,7 @@ def getIdPs():
return idp_list return idp_list
def checkIdP(driver,sp,idp): def checkIdP(driver,sp,idp,logger):
import re import re
# Apro la URL contenente il Discovery Service, inserisco l'idp e vado alla pagina di login # Apro la URL contenente il Discovery Service, inserisco l'idp e vado alla pagina di login
...@@ -61,7 +61,7 @@ def checkIdP(driver,sp,idp): ...@@ -61,7 +61,7 @@ def checkIdP(driver,sp,idp):
except NoSuchElementException as e: except NoSuchElementException as e:
pass pass
except TimeoutException as e: except TimeoutException as e:
logging.info("%s;%s;TIMEOUT" % (idp,sp)) logger.info("%s;%s;TIMEOUT" % (idp,sp))
return "TIMEOUT" return "TIMEOUT"
pattern_metadata = "Unable.to.locate(\sissuer.in|).metadata(\sfor|)|no.metadata.found|profile.is.not.configured.for.relying.party|Cannot.locate.entity|fail.to.load.unknown.provider|does.not.recognise.the.service|unable.to.load.provider|Nous.n'avons.pas.pu.(charg|charger).le.fournisseur.de service|Metadata.not.found|application.you.have.accessed.is.not.registered.for.use.with.this.service|Message.did.not.meet.security.requirements" pattern_metadata = "Unable.to.locate(\sissuer.in|).metadata(\sfor|)|no.metadata.found|profile.is.not.configured.for.relying.party|Cannot.locate.entity|fail.to.load.unknown.provider|does.not.recognise.the.service|unable.to.load.provider|Nous.n'avons.pas.pu.(charg|charger).le.fournisseur.de service|Metadata.not.found|application.you.have.accessed.is.not.registered.for.use.with.this.service|Message.did.not.meet.security.requirements"
...@@ -74,13 +74,13 @@ def checkIdP(driver,sp,idp): ...@@ -74,13 +74,13 @@ def checkIdP(driver,sp,idp):
password_found = re.search(pattern_password,driver.page_source, re.I) password_found = re.search(pattern_password,driver.page_source, re.I)
if(metadata_not_found): if(metadata_not_found):
logging.info("%s;%s;No-eduGAIN-Metadata" % (idp,sp)) logger.info("%s;%s;No-eduGAIN-Metadata" % (idp,sp))
return "No-eduGAIN-Metadata" return "No-eduGAIN-Metadata"
elif not username_found and not password_found: elif not username_found and not password_found:
logging.info("%s;%s;Invalid-Form" % (idp,sp)) logger.info("%s;%s;Invalid-Form" % (idp,sp))
return "Invalid Form" return "Invalid Form"
else: else:
logging.info("%s;%s;OK" % (idp,sp)) logger.info("%s;%s;OK" % (idp,sp))
return "OK" return "OK"
def setup(): def setup():
...@@ -97,13 +97,39 @@ def setup(): ...@@ -97,13 +97,39 @@ def setup():
return driver return driver
# Use logger to produce files consumed by ECCS-2
def getLogger(filename,log_level="DEBUG",path="./"):
if __name__=="__main__": logger = logging.getLogger(filename)
ch = logging.FileHandler(path+filename,'w','utf-8')
if (log_level == "DEBUG"):
logger.setLevel(logging.DEBUG)
ch.setLevel(logging.DEBUG)
elif (log_level == "INFO"):
logger.setLevel(logging.INFO)
ch.setLevel(logging.INFO)
elif (log_level == "WARN"):
logger.setLevel(logging.WARN)
ch.setLevel(logging.WARN)
elif (log_level == "ERROR"):
logger.setLevel(logging.ERROR)
ch.setLevel(logging.ERROR)
elif (log_level == "CRITICAL"):
logger.setLevel(logging.CRITICAL)
ch.setLevel(logging.CRITICAL)
formatter = logging.Formatter('%(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
import os return logger
os.remove("eccs2.log")
if __name__=="__main__":
logging.basicConfig(format='%(message)s',filename='eccs2.log',level=logging.INFO) eccs2log = getLogger("logs/eccs2.log","INFO")
eccs2checks = getLogger("logs/eccs2checks.log","INFO")
driver = setup() driver = setup()
...@@ -122,12 +148,12 @@ if __name__=="__main__": ...@@ -122,12 +148,12 @@ if __name__=="__main__":
for idp in listIdPs: for idp in listIdPs:
result = [] result = []
for sp in sps: for sp in sps:
result.append(checkIdP(driver,sp,idp)) result.append(checkIdP(driver,sp,idp,eccs2checks))
# se tutti e 2 i check sono andati bene, allora l'IdP è OK, altrimenti no. # se tutti e 2 i check sono andati bene, allora l'IdP è OK, altrimenti no.
if (result[0] == result[1] == "OK"): if (result[0] == result[1] == "OK"):
print("IdP '%s' results into: OK" % (idp)) eccs2log.info("IdP '%s' results into: OK" % (idp))
else: else:
print("IdP '%s' results into: NOT OK" % (idp)) eccs2log.info("IdP '%s' results into: NOT OK" % (idp))
driver.close() driver.close()
# Ignore everything in this directory
*
# Except this file
!.gitignore
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment