def test_add_cert_from_file(self): """ Add cert from file """ from imzaci.cert.cert_tools import load_cert_from_dir #add one into the empty db cert_to_add = load_cert_from_dir(list_of_cert_dirs['0']) cert_to_add.store_to_file("foo.pem") assert self.db_handler.add_cert_from_file("foo.pem") == True assert self.db_handler.add_cert_from_file("foo.pem") == False import os os.remove("foo.pem")
def test_add_cert(self): """ Add cert object into db """ from imzaci.cert.cert_tools import load_cert_from_dir #add one into the empty db cert_to_add = load_cert_from_dir(list_of_cert_dirs['0']) assert self.db_handler.add_cert(cert_to_add) == True #should check if we have that in db tmp_cert=self.db_handler.search_and_get_cert(cert_to_add.cert_hash()) assert len(tmp_cert) == 1 assert tmp_cert[0] == cert_to_add #add one duplicate assert self.db_handler.add_cert(cert_to_add) == False #add another when have others another_cert = load_cert_from_dir(list_of_cert_dirs['1']) assert self.db_handler.add_cert(another_cert) == True #is it there? tmp_cert=self.db_handler.search_and_get_cert(another_cert.cert_hash()) assert len(tmp_cert) == 1 assert tmp_cert[0] == another_cert
def test_remove_cert(self): """ Remove a cert from db """ #first try to remove a cert that is not there assert self.db_handler.remove_cert("foo_cert")==False from imzaci.cert.cert_tools import load_cert_from_dir #add one into the empty db cert_to_add = load_cert_from_dir(list_of_cert_dirs['0']) self.db_handler.add_cert(cert_to_add) == True #now remove that cert from there assert self.db_handler.remove_cert(cert_to_add.cert_hash())==True #now search for it into db tmp_cert=self.db_handler.search_and_get_cert(cert_to_add.cert_hash()) assert tmp_cert == None
def test_search_cert_and_get_cert(self): """ Test the search operations for search_and_get_cert and search_cert """ #search an empty db tmp_result = self.db_handler.search_cert("*") tmp_cert_result = self.db_handler.search_and_get_cert("*") assert tmp_result == {} assert tmp_cert_result == None #search emtry db for sth that is not there tmp_result = self.db_handler.search_cert("foo_cert") tmp_cert_result = self.db_handler.search_and_get_cert("foo_cert") assert tmp_cert_result == None assert tmp_result == {} #add a cert and search for it from imzaci.cert.cert_tools import load_cert_from_dir #add one into the empty db cert_to_add = load_cert_from_dir(list_of_cert_dirs['0']) self.db_handler.add_cert(cert_to_add) search_fields = extract_subject_info(cert_to_add.person_info()) #search for every field it has ... for search_item in search_fields: tmp_result = self.db_handler.search_cert(search_item) tmp_cert_result = self.db_handler.search_and_get_cert(search_item) #check instance assert len(tmp_cert_result) == 1 assert tmp_cert_result[0] == cert_to_add #check dict assert len(tmp_result.keys()) == 1 assert tmp_result.has_key(cert_to_add.cert_hash())== True #search also the hash tmp_result = self.db_handler.search_cert(cert_to_add.cert_hash()) assert len(tmp_result.keys()) == 1 assert tmp_result.has_key(cert_to_add.cert_hash())== True #now make a full search again tmp_result = self.db_handler.search_cert("*") tmp_cert_result = self.db_handler.search_and_get_cert("*") #check instance assert len(tmp_cert_result) == 1 #check the dict assert len(tmp_result.keys()) == 1 tmp_cert_result = self.db_handler.search_and_get_cert("foo_cert") tmp_result = self.db_handler.search_cert("foo_cert") assert tmp_cert_result == None assert tmp_result == {} #add also a chain and make search for it from imzaci.cert.cert_tools import load_chain_from_dirs #add into an empty stuff chain_to_add = load_chain_from_dirs([list_of_cert_dirs['3'],list_of_cert_dirs['2'],list_of_cert_dirs['1']]) self.db_handler.add_cert_chain(chain_to_add) #search for the chain hash firstly tmp_result = self.db_handler.search_cert(chain_to_add.get_chain_hash()) tmp_cert_result = self.db_handler.search_and_get_cert(chain_to_add.get_chain_hash()) assert len(tmp_result) == 3 for cert_search in chain_to_add: assert tmp_result.has_key("".join([chain_to_add.get_chain_hash(),"-",cert_search.cert_hash()])) == True #also search for the cert in the chain tmp_result_inner = self.db_handler.search_cert(cert_search.cert_hash()) assert len(tmp_result_inner.keys()) == 1 #print tmp_result_inner assert tmp_result_inner.has_key("".join([chain_to_add.get_chain_hash(),"-",cert_search.cert_hash()]))== True