コード例 #1
0
    def test_invalid_nick_raises_fr(self):
        # Setup
        window = TxWindow(type=WIN_TYPE_CONTACT, contact=create_contact('Bob'))

        # Test
        self.assert_fr("Error: Nick must be printable.", change_nick,
                       UserInput("nick Alice\x01"), window, *self.args)
コード例 #2
0
    def test_user_abort_raises_fr(self, *_):
        # Setup
        user_input = UserInput(f'rm {nick_to_onion_address("Alice")}')

        # Test
        self.assert_fr("Removal of contact aborted.", remove_contact,
                       user_input, None, *self.args)
コード例 #3
0
    def test_successful_removal_of_last_member_of_active_group(self, _):
        # Setup
        user_input = UserInput('rm Alice')
        window = TxWindow(window_contacts=[
            self.contact_list.get_contact_by_address_or_nick("Alice")
        ],
                          type=WIN_TYPE_GROUP,
                          name='test_group')
        group = self.group_list.get_group('test_group')
        group.members = [
            self.contact_list.get_contact_by_address_or_nick("Alice")
        ]
        pub_key = nick_to_pub_key('Alice')

        # Test
        for g in self.group_list:
            self.assertIsInstance(g, Group)
            self.assertTrue(g.has_member(pub_key))
        self.assertEqual(len(group), 1)

        self.assertIsNone(remove_contact(user_input, window, *self.args))

        for g in self.group_list:
            self.assertIsInstance(g, Group)
            self.assertFalse(g.has_member(pub_key))

        self.assertFalse(self.contact_list.has_pub_key(pub_key))
        self.assertEqual(self.queues[COMMAND_PACKET_QUEUE].qsize(), 1)

        km_data = self.queues[KEY_MANAGEMENT_QUEUE].get()
        self.assertEqual(km_data, (KDB_REMOVE_ENTRY_HEADER, pub_key))
コード例 #4
0
    def test_contact_removal_during_traffic_masking_raises_fr(self):
        # Setup
        self.settings.traffic_masking = True

        # Test
        self.assert_fr("Error: Command is disabled during traffic masking.",
                       remove_contact, UserInput(), None, *self.args)
コード例 #5
0
ファイル: test_packet.py プロジェクト: AJMartel/tfc
    def test_cancel_message_during_normal(self):
        # Setup
        user_input = UserInput('cm')
        settings = Settings()
        window = TxWindow(name='Alice',
                          type=WIN_TYPE_CONTACT,
                          type_print='contact',
                          uid='*****@*****.**')
        window.window_contacts = [create_contact()]

        self.queues[MESSAGE_PACKET_QUEUE].put(
            ('testmessage1', settings, '*****@*****.**', '*****@*****.**',
             False, False, '*****@*****.**'))
        self.queues[MESSAGE_PACKET_QUEUE].put(
            ('testmessage2', settings, '*****@*****.**', '*****@*****.**',
             False, False, '*****@*****.**'))
        self.queues[MESSAGE_PACKET_QUEUE].put(
            ('testmessage3', settings, '*****@*****.**', '*****@*****.**',
             False, False, '*****@*****.**'))
        time.sleep(0.1)

        # Test
        self.assertIsNone(
            cancel_packet(user_input, window, settings, self.queues))
        time.sleep(0.1)

        self.assertEqual(self.queues[MESSAGE_PACKET_QUEUE].qsize(), 2)
コード例 #6
0
    def test_raises_fr_when_traffic_masking_is_enabled(self):
        # Setup
        self.settings.traffic_masking = True

        # Test
        self.assert_fr("Error: Command is disabled during traffic masking.",
                       process_group_command, UserInput(), *self.args)
コード例 #7
0
ファイル: test_packet.py プロジェクト: todun/tfc
    def test_cancel_message_during_normal(self):
        # Setup
        user_input = UserInput('cm')
        settings = Settings()
        window = TxWindow(name='Alice',
                          type=WIN_TYPE_CONTACT,
                          type_print='contact',
                          uid=nick_to_pub_key("Alice"))
        window.window_contacts = [create_contact('Alice')]

        self.queues[MESSAGE_PACKET_QUEUE].put(
            ('test_message1', nick_to_pub_key("Alice"), False, False,
             nick_to_pub_key("Alice")))
        self.queues[MESSAGE_PACKET_QUEUE].put(
            ('test_message2', nick_to_pub_key("Charlie"), False, False,
             nick_to_pub_key("Charlie")))
        self.queues[MESSAGE_PACKET_QUEUE].put(
            ('test_message3', nick_to_pub_key("Alice"), False, False,
             nick_to_pub_key("Alice")))

        # Test
        self.assert_fr("Cancelled queued messages to contact Alice.",
                       cancel_packet, user_input, window, settings,
                       self.queues)
        self.assertEqual(self.queues[MESSAGE_PACKET_QUEUE].qsize(), 2)
コード例 #8
0
    def test_missing_nick_raises_fr(self):
        # Setup
        user_input = UserInput("nick ")
        window = TxWindow(type=WIN_TYPE_CONTACT)

        # Test
        self.assertFR("Error: No nick specified.", change_nick, user_input,
                      window, None, None, None, None)
コード例 #9
0
ファイル: test_commands_g.py プロジェクト: barleyj/tfc
    def test_missing_name_raises_fr(self):
        # Setup
        user_input = UserInput('group create ')
        settings = Settings()

        # Test
        self.assertFR('No group name specified.', process_group_command,
                      user_input, None, None, settings, None)
コード例 #10
0
ファイル: test_commands_g.py プロジェクト: barleyj/tfc
    def test_invalid_command_parameters_raises_fr(self):
        # Setup
        user_input = UserInput('group bad')
        settings = Settings()

        # Test
        self.assertFR('Invalid group command.', process_group_command,
                      user_input, None, None, settings, None)
コード例 #11
0
    def test_log_printing_when_no_password_is_asked(self):
        # Setup
        self.settings.ask_password_for_log_access = False

        # Test
        self.assert_fr(f"No log database available.", log_command,
                       UserInput("history 4"), *self.args)
        self.assertEqual(self.queues[COMMAND_PACKET_QUEUE].qsize(), 1)
コード例 #12
0
    def test_invalid_nick_raises_fr(self):
        # Setup
        user_input = UserInput("nick Alice\x01")
        window = TxWindow(type=WIN_TYPE_CONTACT, contact=create_contact('Bob'))

        # Test
        self.assertFR("Nick must be printable.", change_nick, user_input,
                      window, self.contact_list, self.group_list, None, None)
コード例 #13
0
ファイル: test_commands.py プロジェクト: barleyj/tfc
    def test_invalid_setting_raises_fr(self):
        # Setup
        user_input = UserInput('set e_correction_ratia true')
        settings = Settings(key_list=['e_correction_ratio'])

        # Test
        self.assertFR('Invalid setting e_correction_ratia.', change_setting,
                      user_input, None, None, settings, None, None)
コード例 #14
0
ファイル: test_commands.py プロジェクト: barleyj/tfc
    def test_missing_target_sys_raises_fr(self):
        # Setup
        user_input = UserInput("passwd ")
        settings = Settings()

        # Test
        self.assertFR("No target system specified.", change_master_key,
                      user_input, None, None, settings, None, None)
コード例 #15
0
ファイル: test_commands.py プロジェクト: barleyj/tfc
    def test_invalid_target_sys_raises_fr(self):
        # Setup
        user_input = UserInput("passwd t")
        settings = Settings()

        # Test
        self.assertFR("Invalid target system.", change_master_key, user_input,
                      None, None, settings, None, None)
コード例 #16
0
ファイル: test_contact.py プロジェクト: barleyj/tfc
    def test_missing_nick_raises_fr(self):
        # Setup
        user_input = UserInput("nick ")
        window = Window(type='contact')

        # Test
        self.assertFR("Error: No nick specified.", change_nick, user_input,
                      window, None, None, None, None)
コード例 #17
0
ファイル: test_contact.py プロジェクト: xprog12/tfc
    def test_no_contact_raises_se(self) -> None:
        # Setup
        window = TxWindow(type=WIN_TYPE_CONTACT, contact=create_contact('Bob'))
        window.contact = None

        # Test
        self.assert_se("Error: Window does not have contact.", change_nick,
                       UserInput("nick Alice\x01"), window, *self.args)
コード例 #18
0
ファイル: test_commands.py プロジェクト: AJMartel/tfc
    def test_log_printing_all(self):
        self.assertFR(f"Error: Could not find log database.", log_command,
                      UserInput("history"), self.window, self.contact_list,
                      self.group_list, self.settings, self.c_queue,
                      self.master_key)
        time.sleep(0.1)

        self.assertEqual(self.c_queue.qsize(), 1)
コード例 #19
0
ファイル: test_contact.py プロジェクト: barleyj/tfc
    def test_missing_account_raises_fr(self):
        # Setup
        user_input = UserInput('rm ')
        settings = Settings()

        # Test
        self.assertFR("Error: No account specified.", remove_contact,
                      user_input, None, None, None, settings, None)
コード例 #20
0
 def setUp(self):
     self.user_input = UserInput()
     self.contact_list = ContactList(nicks=['Alice', 'Bob'])
     self.group_list = GroupList()
     self.settings = Settings()
     self.queues = gen_queue_dict()
     self.master_key = MasterKey()
     self.args = self.contact_list, self.group_list, self.settings, self.queues, self.settings
コード例 #21
0
ファイル: test_commands.py プロジェクト: barleyj/tfc
    def test_missing_value_raises_fr(self):
        # Setup
        user_input = UserInput('set e_correction_ratio')
        settings = Settings(key_list=['e_correction_ratio'])

        # Test
        self.assertFR('No value for setting specified.', change_setting,
                      user_input, None, None, settings, None, None)
コード例 #22
0
    def test_no_relay_clear_cmd_when_traffic_masking_is_enabled(self, _):
        # Setup
        self.settings.traffic_masking = True

        # Test
        self.assertIsNone(clear_screens(UserInput('clear'), *self.args))
        self.assertEqual(self.queues[TM_COMMAND_PACKET_QUEUE].qsize(), 1)
        self.assertEqual(self.queues[RELAY_PACKET_QUEUE].qsize(), 0)
コード例 #23
0
ファイル: test_contact.py プロジェクト: savg110/tfc
    def test_successful_nick_change(self) -> None:
        # Setup
        window = TxWindow(name='Alice',
                          type=WIN_TYPE_CONTACT,
                          contact=self.contact_list.get_contact_by_address_or_nick('Alice'))

        # Test
        self.assertIsNone(change_nick(UserInput("nick Alice_"), window, *self.args))
        self.assertEqual(self.contact_list.get_contact_by_pub_key(nick_to_pub_key('Alice')).nick, 'Alice_')
コード例 #24
0
ファイル: test_contact.py プロジェクト: savg110/tfc
    def test_invalid_account_raises_soft_error(self, *_: Any) -> None:
        # Setup
        user_input = UserInput(f'rm {nick_to_onion_address("Alice")[:-1]}')
        window     = TxWindow(window_contacts=[self.contact_list.get_contact_by_address_or_nick('Alice')],
                              type=WIN_TYPE_CONTACT,
                              uid=self.pub_key)

        # Test
        self.assert_se("Error: Invalid selection.", remove_contact, user_input, window, *self.args)
コード例 #25
0
ファイル: test_commands.py プロジェクト: AJMartel/tfc
    def test_missing_value_raises_fr(self):
        # Setup
        user_input = UserInput("set serial_error_correction")
        settings = Settings(key_list=['serial_error_correction'])

        # Test
        self.assertFR("Error: No value for setting specified.", change_setting,
                      user_input, self.contact_list, self.group_list, settings,
                      self.queues)
コード例 #26
0
    def test_nick_from_account(self):
        self.assert_prints(
            f"""\
{BOLD_ON}     Nick of 'hpcrayuxhrcy2wtpfwgwjibderrvjll6azfr4tqat3eka2m2gbb55bid' is      {NORMAL_TEXT}
{BOLD_ON}                                     Alice                                      {NORMAL_TEXT}\n""",
            whois,
            UserInput(
                "whois hpcrayuxhrcy2wtpfwgwjibderrvjll6azfr4tqat3eka2m2gbb55bid"
            ), *self.args)
コード例 #27
0
ファイル: test_commands.py プロジェクト: AJMartel/tfc
    def test_user_abort_raises_fr(self):
        # Setup
        builtins.input = lambda _: 'No'

        # Test
        self.assertFR("Logfile export aborted.", log_command,
                      UserInput('export'), self.window, self.contact_list,
                      self.group_list, self.settings, self.c_queue,
                      self.master_key)
コード例 #28
0
ファイル: test_packet.py プロジェクト: tannercollin/tfc
    def test_group_management_message_header(self):
        # Setup
        user_input = UserInput(plaintext='Test message', type=MESSAGE)
        window     = TxWindow(log_messages=True)
        window.window_contacts = [create_contact('Alice')]

        # Test
        self.assertIsNone(queue_message(user_input, window, *self.args, header=GROUP_MSG_INVITE_HEADER))
        self.assertEqual(self.queues[MESSAGE_PACKET_QUEUE].qsize(), 1)
コード例 #29
0
ファイル: test_commands.py プロジェクト: AJMartel/tfc
    def test_invalid_setting_raises_fr(self):
        # Setup
        user_input = UserInput("set e_correction_ratia true")
        settings = Settings(key_list=['serial_error_correction'])

        # Test
        self.assertFR("Error: Invalid setting 'e_correction_ratia'",
                      change_setting, user_input, self.contact_list,
                      self.group_list, settings, self.queues)
コード例 #30
0
    def test_private_message_header(self) -> None:
        # Setup
        user_input = UserInput(plaintext='Test message', type=MESSAGE)
        window     = TxWindow(log_messages=True)
        window.window_contacts = [create_contact('Alice')]

        # Test
        self.assertIsNone(queue_message(user_input, window, *self.args))
        self.assertEqual(self.queues[MESSAGE_PACKET_QUEUE].qsize(), 1)