def test_group_msg(self): # Setup ts = datetime.datetime.now() apct_list = self.create_message_apct(ORIGIN_CONTACT_HEADER, b'testmessage', group_name=b'testgroup') contact_list = ContactList(nicks=['Alice', 'Bob', 'local']) key_list = KeyList(nicks=['Alice', 'Bob', 'local']) keyset = key_list.get_keyset('*****@*****.**') keyset.rx_harac = 1 keyset.rx_key = 32 * b'\x01' keyset.rx_hek = 32 * b'\x01' group_list = GroupList(groups=['testgroup']) group = group_list.get_group('testgroup') group.log_messages = True settings = Settings() packet_list = PacketList(contact_list=contact_list, settings=settings) window_list = WindowList(contact_list=contact_list, group_list=group_list, packet_list=packet_list, settings=settings) master_key = MasterKey() # Test for p in apct_list: self.assertIsNone( process_message(ts, p, window_list, packet_list, contact_list, key_list, group_list, settings, master_key)) # Teardown cleanup()
def test_file(self): # Setup ts = datetime.datetime.now() apct_list = self.create_file_apct() contact_list = ContactList(nicks=['Alice', 'Bob', 'local']) key_list = KeyList(nicks=['Alice', 'Bob', 'local']) keyset = key_list.get_keyset('*****@*****.**') keyset.rx_harac = 1 keyset.rx_key = 32 * b'\x01' keyset.rx_hek = 32 * b'\x01' group_list = GroupList(groups=['testgroup']) settings = Settings() packet_list = PacketList(contact_list=contact_list, settings=settings) window_list = WindowList(contact_list=contact_list, group_list=group_list, packet_list=packet_list, settings=settings) master_key = MasterKey() # Test for p in apct_list: self.assertIsNone( process_message(ts, p, window_list, packet_list, contact_list, key_list, group_list, settings, master_key)) # Teardown shutil.rmtree('received_files/')
def test_invalid_window_raises_fr(self): # Setup message = b'testgroup' ts = datetime.datetime.now() timestamp = double_to_bytes(time.time() * 1000) header = GROUP_MESSAGE_HEADER + timestamp + b'test_group' + US_BYTE apct_list = self.create_message_apct(ORIGIN_CONTACT_HEADER, message, header=header) contact_list = ContactList(nicks=['Alice', 'Bob', 'local']) key_list = KeyList(nicks=['Alice', 'Bob', 'local']) keyset = key_list.get_keyset('*****@*****.**') keyset.rx_harac = 1 keyset.rx_key = 32 * b'\x01' keyset.rx_hek = 32 * b'\x01' group_list = GroupList(groups=['testgroup']) settings = Settings() packet_list = PacketList(contact_list=contact_list, settings=settings) window_list = WindowList(contact_list=contact_list, group_list=group_list, packet_list=packet_list, settings=settings) master_key = MasterKey() # Test for p in apct_list: self.assertFR("Received message to unknown group.", process_message, ts, p, window_list, packet_list, contact_list, key_list, group_list, settings, master_key) # Teardown cleanup()
def test_group_remove_member_msg(self): # Setup message = b'testgroup' + US_BYTE + b'*****@*****.**' + US_BYTE + b'*****@*****.**' ts = datetime.datetime.now() apct_list = self.create_message_apct(ORIGIN_CONTACT_HEADER, message, header=GROUP_MSG_MEMBER_RM_HEADER) contact_list = ContactList(nicks=['Alice', 'Bob', 'local']) key_list = KeyList(nicks=['Alice', 'Bob', 'local']) keyset = key_list.get_keyset('*****@*****.**') keyset.rx_harac = 1 keyset.rx_key = 32 * b'\x01' keyset.rx_hek = 32 * b'\x01' group_list = GroupList(groups=['testgroup']) settings = Settings() packet_list = PacketList(contact_list=contact_list, settings=settings) window_list = WindowList(contact_list=contact_list, group_list=group_list, packet_list=packet_list, settings=settings) master_key = MasterKey() # Test for p in apct_list: self.assertIsNone( process_message(ts, p, window_list, packet_list, contact_list, key_list, group_list, settings, master_key)) # Teardown cleanup()
def test_invalid_group_message_header(self): # Setup message = b'testgroup' ts = datetime.datetime.now() apct_list = self.create_message_apct(ORIGIN_CONTACT_HEADER, message, header=GROUP_MESSAGE_HEADER) contact_list = ContactList(nicks=['Alice', 'Bob', 'local']) key_list = KeyList(nicks=['Alice', 'Bob', 'local']) keyset = key_list.get_keyset('*****@*****.**') keyset.rx_harac = 1 keyset.rx_key = 32 * b'\x01' keyset.rx_hek = 32 * b'\x01' group_list = GroupList(groups=['testgroup']) settings = Settings() packet_list = PacketList(contact_list=contact_list, settings=settings) window_list = WindowList(contact_list=contact_list, group_list=group_list, packet_list=packet_list, settings=settings) master_key = MasterKey() # Test for p in apct_list: self.assertFR("Received an invalid group message.", process_message, ts, p, window_list, packet_list, contact_list, key_list, group_list, settings, master_key)
def test_valid_psk(self): # Setup packet = b'*****@*****.**' contact_list = ContactList(nicks=['Alice', 'local']) key_list = KeyList(nicks=['Alice', 'local']) keyset = key_list.get_keyset('*****@*****.**') keyset.rx_key = bytes(32) keyset.rx_hek = bytes(32) window_list = WindowList(nicks=['Alice', 'local']) ts = datetime.datetime.now() settings = Settings(disable_gui_dialog=True) o_input = builtins.input o_getpass = getpass.getpass builtins.input = lambda x: 'ut_psk' getpass.getpass = lambda x: 'testpassword' password = '******' salt = os.urandom(32) rx_key = os.urandom(32) rx_hek = os.urandom(32) kek, _ = argon2_kdf(password, salt, rounds=16, memory=128000, parallelism=1) ct_tag = encrypt_and_sign(rx_key + rx_hek, key=kek) with open('ut_psk', 'wb+') as f: f.write(salt + ct_tag) # Test self.assertTrue(os.path.isfile('ut_psk')) self.assertIsNone(psk_import(packet, ts, window_list, contact_list, key_list, settings)) self.assertFalse(os.path.isfile('ut_psk')) self.assertEqual(keyset.rx_key, rx_key) self.assertEqual(keyset.rx_hek, rx_hek) # Teardown builtins.input = o_input getpass.getpass = o_getpass
def setUp(self): self.o_input = builtins.input self.window_list = WindowList( nicks=['Alice', LOCAL_ID]) self.contact_list = ContactList(nicks=['Alice', LOCAL_ID]) self.key_list = KeyList( nicks=['Alice', LOCAL_ID]) self.keyset = self.key_list.get_keyset('*****@*****.**') self.packet = None
def test_function(self): # Setup packet = 32 * b'\x01' + 32 * b'\x02' + b'*****@*****.**' + US_BYTE + b'Alice' ts = datetime.datetime.now() window_list = WindowList(nicks=['local']) settings = Settings() pubkey_buf = dict() contact_list = ContactList() key_list = KeyList() # Test self.assertIsNone(psk_command(packet, ts, window_list, contact_list, key_list, settings, pubkey_buf)) keyset = key_list.get_keyset('*****@*****.**') self.assertIsInstance(keyset, KeySet) self.assertEqual(keyset.rx_account, '*****@*****.**') self.assertEqual(keyset.tx_key, 32 * b'\x01') self.assertEqual(keyset.tx_hek, 32 * b'\x02') self.assertEqual(keyset.rx_key, bytes(32)) self.assertEqual(keyset.rx_hek, bytes(32)) contact = contact_list.get_contact('*****@*****.**') self.assertIsInstance(contact, Contact) self.assertEqual(contact.rx_account, '*****@*****.**') self.assertEqual(contact.nick, 'Alice') self.assertEqual(contact.rx_fingerprint, bytes(32)) self.assertEqual(contact.tx_fingerprint, bytes(32))
def setUp(self): self.msg = ("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean condimentum consectetur purus quis" " dapibus. Fusce venenatis lacus ut rhoncus faucibus. Cras sollicitudin commodo sapien, sed bibendu" "m velit maximus in. Aliquam ac metus risus. Sed cursus ornare luctus. Integer aliquet lectus id ma" "ssa blandit imperdiet. Ut sed massa eget quam facilisis rutrum. Mauris eget luctus nisl. Sed ut el" "it iaculis, faucibus lacus eget, sodales magna. Nunc sed commodo arcu. In hac habitasse platea dic" "tumst. Integer luctus aliquam justo, at vestibulum dolor iaculis ac. Etiam laoreet est eget odio r" "utrum, vel malesuada lorem rhoncus. Cras finibus in neque eu euismod. Nulla facilisi. Nunc nec ali" "quam quam, quis ullamcorper leo. Nunc egestas lectus eget est porttitor, in iaculis felis sceleris" "que. In sem elit, fringilla id viverra commodo, sagittis varius purus. Pellentesque rutrum loborti" "s neque a facilisis. Mauris id tortor placerat, aliquam dolor ac, venenatis arcu.").encode() self.ts = datetime.now() self.master_key = MasterKey() self.settings = Settings(logfile_masking=True) self.contact_list = ContactList(nicks=['Alice', 'Bob', 'Charlie', LOCAL_ID]) self.key_list = KeyList( nicks=['Alice', 'Bob', 'Charlie', LOCAL_ID]) self.group_list = GroupList( groups=['testgroup']) self.packet_list = PacketList(contact_list=self.contact_list, settings=self.settings) self.window_list = WindowList(contact_list=self.contact_list, settings=self.settings, group_list=self.group_list, packet_list=self.packet_list) self.group_list.get_group('testgroup').log_messages = True for account in self.contact_list.get_list_of_accounts(): keyset = self.key_list.get_keyset(account) keyset.tx_harac = 1 keyset.rx_harac = 1 keyset.tx_hek = KEY_LENGTH * b'\x01' keyset.rx_hek = KEY_LENGTH * b'\x01' keyset.tx_key = KEY_LENGTH * b'\x01' keyset.rx_key = KEY_LENGTH * b'\x01' self.message = b'testgroup' + US_BYTE + b'*****@*****.**' + US_BYTE + b'*****@*****.**'
def setUp(self): self.ts = datetime.datetime.now() self.window_list = WindowList(nicks=[LOCAL_ID]) self.contact_list = ContactList() self.key_list = KeyList() self.settings = Settings() self.pubkey_buf = {'*****@*****.**' : KEY_LENGTH*b'a'} self.packet = KEY_LENGTH * b'\x01' + KEY_LENGTH * b'\x02' + b'*****@*****.**' + US_BYTE + b'Alice'
def setUp(self): self.onion_pub_key = nick_to_pub_key("Alice") self.origin = ORIGIN_CONTACT_HEADER self.window_list = WindowList(nicks=['Alice', LOCAL_ID]) self.contact_list = ContactList(nicks=['Alice', LOCAL_ID]) self.key_list = KeyList(nicks=['Alice', LOCAL_ID]) self.keyset = self.key_list.get_keyset(nick_to_pub_key("Alice")) self.args = self.onion_pub_key, self.origin, self.window_list, self.contact_list, self.key_list
def setUp(self): self.unittest_dir = cd_unittest() self.packet = b'\x00' + nick_to_pub_key("Alice") self.ts = datetime.now() self.window_list = WindowList(nicks=['Alice', LOCAL_ID]) self.contact_list = ContactList(nicks=['Alice', LOCAL_ID]) self.key_list = KeyList(nicks=['Alice', LOCAL_ID]) self.settings = Settings(disable_gui_dialog=True) self.file_name = self.file_name self.args = self.packet, self.ts, self.window_list, self.contact_list, self.key_list, self.settings
def test_missing_rx_psk_raises_fr(self): # Setup packet = MESSAGE_PACKET_HEADER + 344 * b'a' + ORIGIN_CONTACT_HEADER + b'*****@*****.**' window_list = WindowList(nicks=['Alice', 'local']) contact_list = ContactList(nicks=['Alice', 'local']) key_list = KeyList(nicks=['Alice', 'local']) keyset = key_list.get_keyset('*****@*****.**') keyset.rx_hek = bytes(32) # Set to identify missing PSK # Test self.assertFR("Warning! Received packet from Alice but no PSK exists.", decrypt_assembly_packet, packet, window_list, contact_list, key_list)
def setUp(self): self.ts = datetime.fromtimestamp(1502750000) self.window_list = WindowList(nicks=[LOCAL_ID]) self.contact_list = ContactList() self.key_list = KeyList() self.settings = Settings() self.packet = (nick_to_pub_key("Alice") + SYMMETRIC_KEY_LENGTH * b'\x01' + bytes(SYMMETRIC_KEY_LENGTH) + SYMMETRIC_KEY_LENGTH * b'\x02' + bytes(SYMMETRIC_KEY_LENGTH) + str_to_bytes('Alice')) self.args = self.packet, self.ts, self.window_list, self.contact_list, self.key_list, self.settings
def test_invalid_harac_raises_raises_struct_error(self): # Check that in the case where an internal error caused bytestring (possible key material) to end up in hash # ratchet value, the system raises some error that prevents the output of packet. In this case the, error comes # from the unsuccessful encoding of hash ratchet counter. for l in range(1, 33): key_list = KeyList() key_list.keysets = [create_keyset('Alice', tx_key=SYMMETRIC_KEY_LENGTH * b'\x02', tx_harac=l * b'k')] with self.assertRaises(struct.error): send_packet(key_list, self.gateway, self.l_queue, bytes(ASSEMBLY_PACKET_LENGTH), nick_to_pub_key("Alice"), True)
def setUp(self): self.o_input = builtins.input self.o_getpass = getpass.getpass self.o_sp = subprocess.Popen self.packet = b'*****@*****.**' self.ts = datetime.datetime.now() self.window_list = WindowList( nicks=['Alice', LOCAL_ID]) self.contact_list = ContactList(nicks=['Alice', LOCAL_ID]) self.key_list = KeyList( nicks=['Alice', LOCAL_ID]) self.settings = Settings(disable_gui_dialog=True) builtins.input = lambda _: 'ut_psk'
def test_invalid_harac_raises_raises_struct_error(self): # Check that in case where internal error caused bytestring (possible key material) # to end up in hash ratchet value, system raises some error that prevents output of packet. # In this case the error comes from unsuccessful encoding of hash ratchet counter. for l in range(1, 33): key_list = KeyList() key_list.keysets = [ create_keyset(tx_key=KEY_LENGTH * b'\x02', tx_harac=l * b'k') ] with self.assertRaises(struct.error): send_packet(key_list, self.gateway, self.l_queue, bytes(ASSEMBLY_PACKET_LEN), self.settings, '*****@*****.**', '*****@*****.**', True)
def test_valid_message_packet(self): # Setup gateway = Gateway(serial_error_correction=5) key_list = KeyList(master_key=bytes(SYMMETRIC_KEY_LENGTH)) key_list.keysets = [create_keyset('Alice', tx_key=SYMMETRIC_KEY_LENGTH * b'\x02', tx_harac=8)] # Test self.assertIsNone(send_packet(key_list, gateway, self.l_queue, bytes(ASSEMBLY_PACKET_LENGTH), nick_to_pub_key("Alice"), True)) self.assertEqual(len(gateway.packets), 1) time.sleep(0.01) self.assertFalse(self.l_queue.empty())
def test_successful_removal(self): # Setup contact_list = ContactList(nicks=['Alice', 'Bob']) contact = contact_list.get_contact_by_address_or_nick("Bob") group_list = GroupList(groups=['test_group', 'test_group2']) key_list = KeyList(nicks=['Alice', 'Bob']) self.window_list.windows = [RxWindow(type=WIN_TYPE_GROUP)] # Test self.assert_fr("No log database available.", contact_rem, *self.args, contact_list, group_list, key_list, self.settings, self.master_key) self.assertFalse(contact_list.has_pub_key(nick_to_pub_key("Bob"))) self.assertFalse(key_list.has_keyset(nick_to_pub_key("Bob"))) for g in group_list: self.assertFalse(contact in g.members)
def test_expired_harac_raises_fr(self): # Setup encrypted_message = encrypt_and_sign(PRIVATE_MESSAGE_HEADER + byte_padding(b'test'), 32 * b'\x01') harac_in_bytes = int_to_bytes(1) encrypted_harac = encrypt_and_sign(harac_in_bytes, 32 * b'\x01') packet = MESSAGE_PACKET_HEADER + encrypted_harac + encrypted_message + ORIGIN_CONTACT_HEADER + b'*****@*****.**' window_list = WindowList(nicks=['Alice', 'local']) contact_list = ContactList(nicks=['Alice', 'local']) key_list = KeyList(nicks=['Alice', 'local']) keyset = key_list.get_keyset('*****@*****.**') keyset.rx_harac = 3 # Test self.assertFR("Warning! Received packet from Alice had an expired hash ratchet counter.", decrypt_assembly_packet, packet, window_list, contact_list, key_list)
class TestProcessCommand(TFCTestCase): def setUp(self): self.unittest_dir = cd_unittest() self.ts = datetime.now() self.settings = Settings() self.master_key = MasterKey() self.group_list = GroupList() self.exit_queue = Queue() self.gateway = Gateway() self.window_list = WindowList(nicks=[LOCAL_ID]) self.contact_list = ContactList(nicks=[LOCAL_ID]) self.packet_list = PacketList(self.settings, self.contact_list) self.key_list = KeyList(nicks=[LOCAL_ID]) self.key_set = self.key_list.get_keyset(LOCAL_PUBKEY) self.args = (self.window_list, self.packet_list, self.contact_list, self.key_list, self.group_list, self.settings, self.master_key, self.gateway, self.exit_queue) def tearDown(self): cleanup(self.unittest_dir) def test_incomplete_command_raises_fr(self): packet = assembly_packet_creator(COMMAND, b'test_command', s_header_override=C_L_HEADER, encrypt_packet=True)[0] self.assert_fr("Incomplete command.", process_command, self.ts, packet, *self.args) def test_invalid_command_header(self): packet = assembly_packet_creator(COMMAND, b'invalid_header', encrypt_packet=True)[0] self.assert_fr("Error: Received an invalid command.", process_command, self.ts, packet, *self.args) def test_process_command(self): packet = assembly_packet_creator(COMMAND, LOG_REMOVE, encrypt_packet=True)[0] self.assert_fr(f"No log database available.", process_command, self.ts, packet, *self.args)
def setUp(self): self.o_input = builtins.input self.contact_list = ContactList(nicks=[LOCAL_ID]) self.key_list = KeyList( nicks=[LOCAL_ID]) self.window_list = WindowList( nicks=[LOCAL_ID]) self.settings = Settings() self.ts = datetime.datetime.now()
def setUp(self): self.unittest_dir = cd_unittest() self.msg = ("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean condimentum consectetur purus quis" " dapibus. Fusce venenatis lacus ut rhoncus faucibus. Cras sollicitudin commodo sapien, sed bibendu" "m velit maximus in. Aliquam ac metus risus. Sed cursus ornare luctus. Integer aliquet lectus id ma" "ssa blandit imperdiet. Ut sed massa eget quam facilisis rutrum. Mauris eget luctus nisl. Sed ut el" "it iaculis, faucibus lacus eget, sodales magna. Nunc sed commodo arcu. In hac habitasse platea dic" "tumst. Integer luctus aliquam justo, at vestibulum dolor iaculis ac. Etiam laoreet est eget odio r" "utrum, vel malesuada lorem rhoncus. Cras finibus in neque eu euismod. Nulla facilisi. Nunc nec ali" "quam quam, quis ullamcorper leo. Nunc egestas lectus eget est porttitor, in iaculis felis sceleris" "que. In sem elit, fringilla id viverra commodo, sagittis varius purus. Pellentesque rutrum loborti" "s neque a facilisis. Mauris id tortor placerat, aliquam dolor ac, venenatis arcu.") self.ts = datetime.now() self.master_key = MasterKey() self.settings = Settings(log_file_masking=True) self.file_name = f'{DIR_USER_DATA}{self.settings.software_operation}_logs' self.contact_list = ContactList(nicks=['Alice', 'Bob', 'Charlie', LOCAL_ID]) self.key_list = KeyList( nicks=['Alice', 'Bob', 'Charlie', LOCAL_ID]) self.group_list = GroupList( groups=['test_group']) self.packet_list = PacketList(contact_list=self.contact_list, settings=self.settings) self.window_list = WindowList(contact_list=self.contact_list, settings=self.settings, group_list=self.group_list, packet_list=self.packet_list) self.group_id = group_name_to_group_id('test_group') self.file_keys = dict() self.group_list.get_group('test_group').log_messages = True self.args = (self.window_list, self.packet_list, self.contact_list, self.key_list, self.group_list, self.settings, self.master_key, self.file_keys) ensure_dir(DIR_USER_DATA)
def test_function(self): # Setup master_key = MasterKey() settings = Settings() ts = datetime.datetime.now() o_getpass = getpass.getpass window_list = WindowList() contact_list = ContactList() group_list = GroupList() key_list = KeyList() getpass.getpass = lambda x: 'a' write_log_entry(F_S_HEADER + bytes(255), '*****@*****.**', settings, master_key) # Test self.assertEqual(master_key.master_key, bytes(32)) self.assertIsNone( change_master_key(ts, window_list, contact_list, group_list, key_list, settings, master_key)) self.assertNotEqual(master_key.master_key, bytes(32)) # Teardown getpass.getpass = o_getpass cleanup()
class TestAddPSKTxKeys(unittest.TestCase): def setUp(self): self.ts = datetime.datetime.now() self.window_list = WindowList(nicks=[LOCAL_ID]) self.contact_list = ContactList() self.key_list = KeyList() self.settings = Settings() self.pubkey_buf = {'*****@*****.**' : KEY_LENGTH*b'a'} self.packet = KEY_LENGTH * b'\x01' + KEY_LENGTH * b'\x02' + b'*****@*****.**' + US_BYTE + b'Alice' def test_add_psk_tx_keys(self): self.assertIsNone(add_psk_tx_keys(self.packet, self.ts, self.window_list, self.contact_list, self.key_list, self.settings, self.pubkey_buf)) keyset = self.key_list.get_keyset('*****@*****.**') self.assertIsInstance(keyset, KeySet) self.assertEqual(keyset.rx_account, '*****@*****.**') self.assertEqual(keyset.tx_key, KEY_LENGTH * b'\x01') self.assertEqual(keyset.tx_hek, KEY_LENGTH * b'\x02') self.assertEqual(keyset.rx_key, bytes(KEY_LENGTH)) self.assertEqual(keyset.rx_hek, bytes(KEY_LENGTH)) contact = self.contact_list.get_contact('*****@*****.**') self.assertIsInstance(contact, Contact) self.assertEqual(contact.rx_account, '*****@*****.**') self.assertEqual(contact.nick, 'Alice') self.assertEqual(contact.rx_fingerprint, bytes(FINGERPRINT_LEN)) self.assertEqual(contact.tx_fingerprint, bytes(FINGERPRINT_LEN)) self.assertFalse('*****@*****.**' in self.pubkey_buf)
def test_loops(self): queues = gen_queue_dict() window = TxWindow(log_messages=True) settings = Settings(traffic_masking=True, tm_static_delay=0.001, tm_random_delay=0.001) gateway = Gateway() key_list = KeyList(nicks=['Bob', LOCAL_ID]) # Output Bob as existing contact queues[TM_NOISE_COMMAND_QUEUE].put( (C_N_HEADER + bytes(PADDING_LENGTH))) queues[TM_NOISE_PACKET_QUEUE].put( (P_N_HEADER + bytes(PADDING_LENGTH), True, True)) queues[WINDOW_SELECT_QUEUE].put(window.window_contacts) queues[SENDER_MODE_QUEUE].put(settings) queue_command(b'test', settings, queues) # Output command self.assertIsNone( sender_loop(queues, settings, gateway, key_list, unittest=True)) self.assertEqual(len(gateway.packets), 1) settings.traffic_masking = False queues[SENDER_MODE_QUEUE].put(settings) self.assertIsNone( sender_loop(queues, settings, gateway, key_list, unittest=True)) # Output Alice and Bob again self.assertEqual(len(gateway.packets), 1)
def test_loop(self): # Setup queues = gen_queue_dict() settings = Settings(traffic_masking=True, tm_static_delay=0.001, tm_random_delay=0.001) gateway = Gateway() key_list = KeyList(nicks=['Alice', LOCAL_ID]) window = TxWindow(log_messages=True) contact_list = ContactList(nicks=['Alice', LOCAL_ID]) window.contact_list = contact_list window.window_contacts = [contact_list.get_contact_by_address_or_nick('Alice')] user_input = UserInput(plaintext='test') def queue_delayer(): """Place packets to queue after delay.""" time.sleep(0.01) queues[WINDOW_SELECT_QUEUE].put(window.window_contacts) time.sleep(0.01) queue_command(b'test', settings, queues) # 1 queue_message(user_input, window, settings, queues) # 2 queue_message(user_input, window, settings, queues) # 3 queue_command(b'test', settings, queues) # 4 queues[TM_NOISE_COMMAND_QUEUE].put((C_N_HEADER + bytes(PADDING_LENGTH))) # 5 queue_to_nc(UNENCRYPTED_DATAGRAM_HEADER + UNENCRYPTED_EXIT_COMMAND, queues[RELAY_PACKET_QUEUE]) # 6 queue_to_nc(UNENCRYPTED_DATAGRAM_HEADER + UNENCRYPTED_WIPE_COMMAND, queues[RELAY_PACKET_QUEUE]) # 7 queues[SENDER_MODE_QUEUE].put(settings) # Test threading.Thread(target=queue_delayer).start() self.assertIsInstance(traffic_masking_loop(queues, settings, gateway, key_list), Settings) self.assertEqual(len(gateway.packets), 7) # Teardown tear_queues(queues)
def setUp(self) -> None: """Pre-test actions.""" self.l_queue = Queue() self.key_list = KeyList(nicks=['Alice']) self.settings = Settings() self.gateway = Gateway() self.onion_service = OnionService()
def setUp(self): self.unittest_dir = cd_unittest() self.ts = datetime.now() self.settings = Settings() self.master_key = MasterKey() self.group_list = GroupList() self.exit_queue = Queue() self.gateway = Gateway() self.window_list = WindowList(nicks=[LOCAL_ID]) self.contact_list = ContactList(nicks=[LOCAL_ID]) self.packet_list = PacketList(self.settings, self.contact_list) self.key_list = KeyList(nicks=[LOCAL_ID]) self.key_set = self.key_list.get_keyset(LOCAL_PUBKEY) self.args = (self.window_list, self.packet_list, self.contact_list, self.key_list, self.group_list, self.settings, self.master_key, self.gateway, self.exit_queue)
def test_successful_removal(self): # Setup contact_list = ContactList(nicks=['Alice', 'Bob']) contact = contact_list.get_contact('*****@*****.**') group_list = GroupList(groups=['testgroup', 'testgroup2']) key_list = KeyList(nicks=['Alice', 'Bob']) self.window_list.windows = [RxWindow(type=WIN_TYPE_GROUP)] # Test self.assertIsNone( remove_contact(self.cmd_data, self.ts, self.window_list, contact_list, group_list, key_list)) self.assertFalse(contact_list.has_contact('*****@*****.**')) self.assertFalse(key_list.has_keyset('*****@*****.**')) for g in group_list: self.assertFalse(contact in g.members)