Coverage for test_encryption_util.py: 96%

25 statements  

« prev     ^ index     » next       coverage.py v7.2.6, created at 2023-05-30 12:56 +0530

1import unittest 

2import encryption_util 

3import key_util 

4 

5 

6class TestEnc(unittest.TestCase): 

7 

8 def test_generate_shared_key(self): 

9 keypair1=key_util.generate_key_pair() 

10 keypair2=key_util.generate_key_pair() 

11 

12 # positive testcases 

13 shared_key1=key_util.generate_shared_key(keypair1.private_key,keypair2.public_key) 

14 shared_key2=key_util.generate_shared_key(keypair2.private_key,keypair1.public_key) 

15 self.assertEqual(shared_key1,shared_key2,"must be same") 

16 

17 #negative testcase 

18 shared_key2=key_util.generate_shared_key(keypair1.private_key,keypair1.public_key) 

19 self.assertNotEqual(shared_key1,shared_key2,"should be different") 

20 

21 def test_encrypt_decrypt(self): 

22 keypair1=key_util.generate_key_pair() 

23 keypair2=key_util.generate_key_pair() 

24 

25 shared_key=key_util.generate_shared_key(keypair1.private_key,keypair2.public_key) 

26 

27 # positive testcases 

28 raw_data = "Hello This is ONDC Test data" 

29 encrypted_data=encryption_util.encrypt_data(shared_key,raw_data) 

30 decrypted_data=encryption_util.decrypt_data(shared_key,encrypted_data) 

31 self.assertEqual(decrypted_data,raw_data,"decrypted text and raw tax must be same") 

32 

33 #negative testcase 

34 invalid_shared_key='YR7XT2fAQR2WSQGf/G/JSLZ+LDuULMdYJI7ZDLGa3H4=' 

35 decrypted_data=encryption_util.decrypt_data(invalid_shared_key,encrypted_data) 

36 self.assertNotEqual(decrypted_data,raw_data,'should be different') 

37 

38if __name__=='__main__': 

39 unittest.main()