def test_get_conkey_for_correct_data_type(self): self.keys=["password",78,5j,b"bin_data",0x13] for pass_key in self.keys: if type(pass_key)==str: self.assertEqual(SHA256.new(pass_key.encode()).digest(),Cipher("test.txt",pass_key).get_conkey()) else: self.assertEqual(TypeError,type(Cipher("test.txt",pass_key).get_conkey()))
def login(self): ''' Login User using the master password ''' try: if Cipher(self.crypt_file, self.master_pass).decrypt() == "successfully Decrypted": return True elif ValueError == type( Cipher(self.data_file, self.master_pass).decrypt()): return ValueError("Wrong Password Given") except: return False
def logout(self): ''' Log out user and encrypt ''' try: return Cipher(self.data_file, self.master_pass).encrypt() except: return False
def terminate_account(self): if crypto_extention + self.username + ".csv" in os.listdir(users_dir): if Cipher(self.crypt_file, self.master_pass).decrypt() == "successfully Decrypted": try: os.remove(self.data_file) return True except: return False elif ValueError == type( Cipher(self.data_file, self.master_pass).decrypt()): return ValueError("Wrong Password Given") else: return False elif self.username + ".csv" in os.listdir(users_dir): try: os.remove(self.data_file) return True except: return False
def create_account(self): '''Create a new user csv file and encrypt it with the master password''' Data_Operator(self.data_file).writeit() Cipher(self.data_file, self.master_pass).encrypt() return True
def test_decrypt_for_correct_password(self): #test for correct password with open(self.testFile,'w') as testFile: testFile.write("This is a Test File") Cipher(self.testFile,self.key).encrypt() self.assertEqual("successfully Decrypted",Cipher(self.crypted_file,self.key).decrypt())
def test_decrypt_for_wrong_password(self): #test for wrong password with open(self.testFile,'w') as testFile: testFile.write("This is a Test File") Cipher(self.testFile,self.key).encrypt() self.assertEqual(ValueError,type(Cipher(self.crypted_file,self.wrong_key).decrypt()))
def test_decrypt_for_invalid_file_path(self): #test for invalid file path or fileNotExist self.assertEqual(FileNotFoundError,type(Cipher(self.fileNotExist,self.key).decrypt()))
def test_encrypt_for_successful_enc(self): #test for successful encryption with open(self.testFile,'w') as testFile: testFile.write("This is a Test File") self.assertEqual("successfully Encrypted",Cipher(self.testFile,self.key).encrypt())