예제 #1
0
 def test_aaa_initial_ask_to_register_no_response_fails(self):
     """Ensures that client throws if the user declines to register a user."""
     with server_process():
         se = InputSideEffect(["n", "exit"])
         with patch('builtins.input', side_effect=se.se):
             with self.assertRaises(RuntimeError):
                 client.main()
예제 #2
0
 def test_aan_add_contact_invalid_email(self):
     """Ensures that client does not add a new contact if the input is an invalid email."""
     invalid_emails = [
         "Abc.example.com", "A@b@[email protected]", "a\"b(c)d,e:f;g<h>i[j\\k][email protected]",
         "just\"not\"*****@*****.**", "this is\"not\\[email protected]",
         "this\\ still\\\"not\\\\[email protected]",
         "*****@*****.**",
         "i_like_underscore@but_its_not_allow_in_this_part.example.com"
     ]
     with server_process():
         for i in invalid_emails:
             se_list = ["*****@*****.**", "add", "name_v_2", i, "exit"]
             se_list[3] = i
             se1 = InputSideEffect(se_list)
             se2 = InputSideEffect(["password_v12"])
             with patch('builtins.input', side_effect=se1.se):
                 with patch('getpass.getpass', side_effect=se2.se):
                     client.main()
                     with open(DEFAULT_filename, 'r') as f:
                         jdict = json.load(f)
                         contacts = json.loads(
                             AESWrapper("*****@*****.**").decrypt(
                                 jdict["e908de13f0f86b9c15f70d34cc1a5696280b3fbf822ae09343a779b19a3214b7"]
                                 ["contacts"]))
                         self.assertEqual(dict(), contacts)
예제 #3
0
 def test_aal_login_correct_password(self):
     """Ensures that client logs in successfully with correct email/password."""
     with server_process():
         se1 = InputSideEffect(["*****@*****.**", "exit"])
         se2 = InputSideEffect(["password_v12"])
         with patch('builtins.input', side_effect=se1.se):
             with patch('getpass.getpass', side_effect=se2.se):
                 client.main()
예제 #4
0
 def test_aag_initial_registration_succeeds(self):
     """Ensures that client doesn't throw during valid registration."""
     with server_process():
         se1 = InputSideEffect(["y", "name_v", "*****@*****.**", "exit"])
         se2 = InputSideEffect(["password_v12", "password_v12"])
         with patch('builtins.input', side_effect=se1.se):
             with patch('getpass.getpass', side_effect=se2.se):
                 client.main()
예제 #5
0
 def test_aae_initial_ask_to_register_password_too_short(self):
     """Ensures that client throws if the user inputs a password that is too short during registration."""
     with server_process():
         se1 = InputSideEffect(["y", "name_v", "email_v", "exit"])
         se2 = InputSideEffect(["password_v1", "password_v1"])
         with patch('builtins.input', side_effect=se1.se):
             with patch('getpass.getpass', side_effect=se2.se):
                 with self.assertRaises(RuntimeError):
                     client.main()
예제 #6
0
 def test_aak_login_wrong_password(self):
     """Ensures that client throws if trying to login with an incorrect password."""
     with server_process():
         se1 = InputSideEffect(["*****@*****.**"])
         se2 = InputSideEffect(["password_v12_"])
         with patch('builtins.input', side_effect=se1.se):
             with patch('getpass.getpass', side_effect=se2.se):
                 with self.assertRaises(RuntimeError):
                     client.main()
예제 #7
0
 def test_aaj_login_unknown_email(self):
     """Ensures that client throws if trying to login with an unknown email."""
     with server_process():
         se1 = InputSideEffect(["*****@*****.**"])
         se2 = InputSideEffect(["password_v12"])
         with patch('builtins.input', side_effect=se1.se):
             with patch('getpass.getpass', side_effect=se2.se):
                 with self.assertRaises(RuntimeError):
                     client.main()
예제 #8
0
 def test_aap_list_contacts_empty_dictionary(self):
     """Ensures that does not list users if no users have been added"""
     with server_process():
         se1 = InputSideEffect(["*****@*****.**", "list", "exit"])
         se2 = InputSideEffect(["password_v12"])
         with patch('builtins.input', side_effect=se1.se):
             with patch('getpass.getpass', side_effect=se2.se):
                 client.main(None, None, None, True)
                 with open(LIST_CONTACTS_TEST_FILENAME, 'r') as f:
                     jdict = json.load(f)
                     is_empty = not bool(jdict)
                     self.assertTrue(is_empty)
예제 #9
0
 def test_aac_initial_ask_to_register_empty_input(self):
     """Ensures that client throws if the user inputs an empty string during registration."""
     with server_process():
         for i in range(0, 2):
             for j in range(0, 2):
                 se_lists = [["y", "name_v", "*****@*****.**", "exit"], ["password_v12", "password_v12"]]
                 se_lists[i][j + int(i == 0)] = ""
                 se1 = InputSideEffect(se_lists[0])
                 se2 = InputSideEffect(se_lists[1])
                 with patch('builtins.input', side_effect=se1.se):
                     with patch('getpass.getpass', side_effect=se2.se):
                         with self.assertRaises(RuntimeError):
                             client.main()
예제 #10
0
 def test_aad_initial_ask_to_register_invalid_email(self):
     """Ensures that client throws if the user inputs invalid email during registration."""
     with server_process():
         invalid_emails = [
             "Abc.example.com", "A@b@[email protected]", "a\"b(c)d,e:f;g<h>i[j\\k][email protected]",
             "just\"not\"*****@*****.**", "this is\"not\\[email protected]",
             "this\\ still\\\"not\\\\[email protected]",
             "*****@*****.**",
             "i_like_underscore@but_its_not_allow_in_this_part.example.com"
         ]
         for i in invalid_emails:
             se1 = InputSideEffect(["y", "name_v", i, "exit"])
             se2 = InputSideEffect(["password_v12", "password_v12"])
             with patch('builtins.input', side_effect=se1.se):
                 with self.assertRaises(RuntimeError):
                     with patch('getpass.getpass', side_effect=se2.se):
                         client.main()
예제 #11
0
 def test_aaf_initial_registration_succeeds(self):
     """Ensures that client doesn't throw during some wild, yet valid user registrations."""
     valid_emails = [
         "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**",
         "[email protected]", "*****@*****.**", "*****@*****.**",
         "*****@*****.**", "*****@*****.**",
         "*****@*****.**"
     ]
     with server_process():
         for i in valid_emails:
             se1 = InputSideEffect(["y", "name_v", i, "exit"])
             se2 = InputSideEffect(["password_v12", "password_v12"])
             with patch('builtins.input', side_effect=se1.se):
                 with patch('getpass.getpass', side_effect=se2.se):
                     client.main()
                     os.remove(client.DEFAULT_FILENAME)
                     os.remove(DEFAULT_filename)
예제 #12
0
 def test_aao_add_contact(self):
     """Ensures that client adds valid contacts successfully."""
     with server_process():
         se1 = InputSideEffect([
             "*****@*****.**", "add", "name_v_2", "*****@*****.**", "add", "name_v_3", "*****@*****.**",
             "exit"
         ])
         se2 = InputSideEffect(["password_v12"])
         with patch('builtins.input', side_effect=se1.se):
             with patch('getpass.getpass', side_effect=se2.se):
                 client.main()
                 with open(DEFAULT_filename, 'r') as f:
                     jdict = json.load(f)
                     contacts = json.loads(
                         AESWrapper("*****@*****.**").decrypt(
                             jdict["e908de13f0f86b9c15f70d34cc1a5696280b3fbf822ae09343a779b19a3214b7"]["contacts"]))
                     self.assertEqual("name_v_2", contacts["*****@*****.**"])
                     self.assertEqual("name_v_3", contacts["*****@*****.**"])
예제 #13
0
 def test_aam_add_contact_empty_input(self):
     """Ensures that client does not add a new contact if the input is an empty string."""
     with server_process():
         for i in range(0, 2):
             se_list = ["*****@*****.**", "add", "name_v_2", "*****@*****.**", "exit"]
             se_list[2 + i] = ""
             se1 = InputSideEffect(se_list)
             se2 = InputSideEffect(["password_v12"])
             with patch('builtins.input', side_effect=se1.se):
                 with patch('getpass.getpass', side_effect=se2.se):
                     client.main()
                     with open(DEFAULT_filename, 'r') as f:
                         jdict = json.load(f)
                         contacts = json.loads(
                             AESWrapper("*****@*****.**").decrypt(
                                 jdict["e908de13f0f86b9c15f70d34cc1a5696280b3fbf822ae09343a779b19a3214b7"]
                                 ["contacts"]))
                         self.assertEqual(dict(), contacts)