def setUp(self) -> None: """Pre-test actions.""" self.window_list = WindowList() self.window_list.windows = [ RxWindow(uid=nick_to_pub_key("Alice"), name='Alice'), RxWindow(uid=nick_to_pub_key("Bob"), name='Bob') ]
def setUp(self): self.cmd_data = nick_to_pub_key("Alice") self.window_list = WindowList() self.window_list.windows = [RxWindow(uid=nick_to_pub_key("Alice"), name='Alice'), RxWindow(uid=nick_to_pub_key("Bob"), name='Bob')] self.window = self.window_list.get_window(nick_to_pub_key("Alice")) self.window.message_log = [(datetime.now(), 'Hi Bob', nick_to_pub_key("Alice"), ORIGIN_CONTACT_HEADER)]
def setUp(self) -> None: """Pre-test actions.""" self.window_list = WindowList() self.window_list.windows = [ RxWindow(name='Alice', unread_messages=4), RxWindow(name='Bob', unread_messages=15) ]
def setUp(self): self.cmd_data = b'*****@*****.**' self.window_list = WindowList() self.window_list.windows = [ RxWindow(uid='*****@*****.**', name='Alice'), RxWindow(uid='*****@*****.**', name='Bob') ] self.window = self.window_list.get_window('*****@*****.**') self.window.message_log = [(datetime.now(), 'Hi Bob', '*****@*****.**', ORIGIN_CONTACT_HEADER)]
def setUp(self): self.unittest_dir = cd_unittest() self.master_key = MasterKey() self.settings = Settings() self.window = RxWindow(type=WIN_TYPE_CONTACT, uid=nick_to_pub_key('Alice'), name='Alice', type_print='contact') self.contact_list = ContactList(self.master_key, self.settings) self.contact_list.contacts = list( map(create_contact, ['Alice', 'Charlie'])) self.time = STATIC_TIMESTAMP self.group_list = GroupList(groups=['test_group']) self.group = self.group_list.get_group('test_group') self.group.members = self.contact_list.contacts self.args = self.window, self.contact_list, self.group_list, self.settings, self.master_key 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." )
def setUp(self): self.masterkey = MasterKey() self.settings = Settings() self.window = RxWindow(type=WIN_TYPE_CONTACT, uid='*****@*****.**', name='Alice') self.contact_list = ContactList(self.masterkey, self.settings) self.contact_list.contacts = list(map(create_contact, ['Alice', 'Charlie'])) self.time = datetime.fromtimestamp(struct.unpack('<L', binascii.unhexlify('08ceae02'))[0]).strftime('%H:%M') self.group_list = GroupList(groups=['test_group']) group = self.group_list.get_group('test_group') group.members = self.contact_list.contacts self.o_struct = struct.pack struct.pack = lambda *_: binascii.unhexlify('08ceae02') 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()
def test_short_group_message(self, _): # Setup self.window = RxWindow(type=WIN_TYPE_GROUP, uid=group_name_to_group_id('test_group'), name='test_group', group=self.group, type_print='group', group_list=self.group_list) # Add messages to Alice and Charlie. Add duplicate of outgoing message that should be skipped by access_logs. for p in assembly_packet_creator(MESSAGE, 'This is a short message', group_id=self.window.uid): write_log_entry(p, nick_to_pub_key('Alice'), self.settings, self.master_key) write_log_entry(p, nick_to_pub_key('Alice'), self.settings, self.master_key, origin=ORIGIN_CONTACT_HEADER) write_log_entry(p, nick_to_pub_key('Charlie'), self.settings, self.master_key) write_log_entry(p, nick_to_pub_key('Charlie'), self.settings, self.master_key, origin=ORIGIN_CONTACT_HEADER) # Test self.assert_prints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + f"""\ Log file of message(s) sent to group test_group ════════════════════════════════════════════════════════════════════════════════ {self.time} Me: This is a short message {self.time} Alice: This is a short message {self.time} Charlie: This is a short message <End of log file> """), access_logs, self.window, self.contact_list, self.group_list, self.settings, self.master_key)
def setUp(self): self.ts = datetime.datetime.now() self.group_list = GroupList(groups=['test_group']) self.window_list = WindowList() self.window = RxWindow() self.window_list.windows = [self.window] self.contact_list = ContactList(nicks=['alice']) self.args = self.ts, self.window_list, self.contact_list, self.group_list
def test_function_return(self): error = FunctionReturn('test message') self.assertEqual(error.message, 'test message') error = FunctionReturn('test message', head_clear=True) self.assertEqual(error.message, 'test message') error = FunctionReturn('test message', tail_clear=True) self.assertEqual(error.message, 'test message') error = FunctionReturn('test message', window=RxWindow()) self.assertEqual(error.message, 'test message')
def test_database_encryption_with_another_key(self, _: Any) -> None: # Setup window = RxWindow(type=WIN_TYPE_CONTACT, uid=nick_to_pub_key('Alice'), name='Alice', type_print='contact') contact_list = ContactList(self.old_master_key, self.settings) contact_list.contacts = [create_contact('Alice')] group_list = GroupList() # Create temp file that must be removed. temp_file_data = os.urandom(LOG_ENTRY_LENGTH) with open(self.tmp_file_name, 'wb+') as f: f.write(temp_file_data) # Add a message from contact Alice to user (Bob). for p in assembly_packet_creator(MESSAGE, 'This is a short message'): write_log_entry(p, nick_to_pub_key('Alice'), self.message_log, origin=ORIGIN_CONTACT_HEADER) # Add a message from user (Bob) to Alice. for p in assembly_packet_creator(MESSAGE, 'This is a short message'): write_log_entry(p, nick_to_pub_key('Alice'), self.message_log) # Check logfile content. message = (CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + f"""\ Log file of message(s) sent to contact Alice ════════════════════════════════════════════════════════════════════════════════ {self.time} Alice: This is a short message {self.time} Me: This is a short message <End of log file> """) self.assertIsNone( change_log_db_key(self.old_master_key.master_key, self.new_master_key.master_key, self.settings)) with open(self.tmp_file_name, 'rb') as f: purp_temp_data = f.read() self.assertNotEqual(purp_temp_data, temp_file_data) # Test that decryption with new key is identical. replace_log_db(self.settings) self.assert_prints(message, access_logs, window, contact_list, group_list, self.settings, self.new_master_key) # Test that temp file is removed. self.assertFalse(os.path.isfile(self.tmp_file_name))
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_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)
def test_short_group_message(self): # Setup self.window = RxWindow(type=WIN_TYPE_GROUP, uid='test_group', name='test_group') for p in assembly_packet_creator(MESSAGE, b'This is a short message', group_name='test_group'): write_log_entry(p, '*****@*****.**', self.settings, self.masterkey) write_log_entry(p, '*****@*****.**', self.settings, self.masterkey, origin=ORIGIN_CONTACT_HEADER) write_log_entry(p, '*****@*****.**', self.settings, self.masterkey) write_log_entry(p, '*****@*****.**', self.settings, self.masterkey, origin=ORIGIN_CONTACT_HEADER) # Test self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + f"""\ Logfile of messages to/from test_group ════════════════════════════════════════════════════════════════════════════════ {self.time} Me: This is a short message {self.time} Alice: This is a short message {self.time} Charlie: This is a short message <End of logfile> """), access_logs, self.window, self.contact_list, self.group_list, self.settings, self.masterkey)
def test_database_encryption_with_another_key(self): # Setup window = RxWindow(type=WIN_TYPE_CONTACT, uid='*****@*****.**', name='Alice') contact_list = ContactList(self.old_key, self.settings) contact_list.contacts = [create_contact()] group_list = GroupList() # Create temp file that must be removed with open("user_data/ut_logs_temp", 'wb+') as f: f.write(os.urandom(LOG_ENTRY_LENGTH)) for p in assembly_packet_creator(MESSAGE, b'This is a short message'): write_log_entry(p, '*****@*****.**', self.settings, self.old_key, origin=ORIGIN_CONTACT_HEADER) for p in assembly_packet_creator(MESSAGE, b'This is a short message'): write_log_entry(p, '*****@*****.**', self.settings, self.old_key) # Test self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + f"""\ Logfile of messages to/from Alice ════════════════════════════════════════════════════════════════════════════════ {self.time} Alice: This is a short message {self.time} Me: This is a short message <End of logfile> """), access_logs, window, contact_list, group_list, self.settings, self.old_key) self.assertIsNone(re_encrypt(self.old_key.master_key, self.new_key.master_key, self.settings)) # Test that decryption works with new key self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + f"""\ Logfile of messages to/from Alice ════════════════════════════════════════════════════════════════════════════════ {self.time} Alice: This is a short message {self.time} Me: This is a short message <End of logfile> """), access_logs, window, contact_list, group_list, self.settings, self.new_key) # Test that temp file is removed self.assertFalse(os.path.isfile("user_data/ut_logs_temp"))
def setUp(self): self.window_list = WindowList() self.window_list.windows = [RxWindow(uid=nick_to_pub_key("Alice"), name='Alice'), RxWindow(uid=nick_to_pub_key("Bob"), name='Bob')]
def setUp(self): self.window_list = WindowList() self.window_list.windows = [RxWindow(name='Alice', unread_messages=4), RxWindow(name='Bob', unread_messages=15)]
def test_long_group_message(self, _): # Setup # Test title displayed by the Receiver program. self.settings.software_operation = RX self.window = RxWindow(type=WIN_TYPE_GROUP, uid=group_name_to_group_id('test_group'), name='test_group', group=self.group, type_print='group') # Add an assembly packet sequence sent to contact Alice in group containing cancel packet. # Access_logs should skip this. packets = assembly_packet_creator( MESSAGE, self.msg, group_id=group_name_to_group_id('test_group')) packets = packets[2:] + [M_C_HEADER + bytes(PADDING_LENGTH)] for p in packets: write_log_entry(p, nick_to_pub_key('Alice'), self.settings, self.master_key) # Add an orphaned 'append' assembly packet. access_logs should skip this. write_log_entry(M_A_HEADER + bytes(PADDING_LENGTH), nick_to_pub_key('Alice'), self.settings, self.master_key) # Add a private message. access_logs should skip this. for p in assembly_packet_creator(MESSAGE, 'This is a short private message'): write_log_entry(p, nick_to_pub_key('Alice'), self.settings, self.master_key) # Add a group message for a different group. access_logs should skip this. for p in assembly_packet_creator(MESSAGE, 'This is a short group message', group_id=GROUP_ID_LENGTH * b'1'): write_log_entry(p, nick_to_pub_key('Alice'), self.settings, self.master_key) # Add messages to Alice and Charlie in group. # Add duplicate of outgoing message that should be skipped by access_logs. for p in assembly_packet_creator( MESSAGE, self.msg, group_id=group_name_to_group_id('test_group')): write_log_entry(p, nick_to_pub_key('Alice'), self.settings, self.master_key) write_log_entry(p, nick_to_pub_key('Alice'), self.settings, self.master_key, origin=ORIGIN_CONTACT_HEADER) write_log_entry(p, nick_to_pub_key('Charlie'), self.settings, self.master_key) write_log_entry(p, nick_to_pub_key('Charlie'), self.settings, self.master_key, origin=ORIGIN_CONTACT_HEADER) # Test self.assert_prints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + f"""\ Log file of message(s) to/from group test_group ════════════════════════════════════════════════════════════════════════════════ {self.time} Me: 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 bibendum velit maximus in. Aliquam ac metus risus. Sed cursus ornare luctus. Integer aliquet lectus id massa blandit imperdiet. Ut sed massa eget quam facilisis rutrum. Mauris eget luctus nisl. Sed ut elit iaculis, faucibus lacus eget, sodales magna. Nunc sed commodo arcu. In hac habitasse platea dictumst. Integer luctus aliquam justo, at vestibulum dolor iaculis ac. Etiam laoreet est eget odio rutrum, vel malesuada lorem rhoncus. Cras finibus in neque eu euismod. Nulla facilisi. Nunc nec aliquam quam, quis ullamcorper leo. Nunc egestas lectus eget est porttitor, in iaculis felis scelerisque. In sem elit, fringilla id viverra commodo, sagittis varius purus. Pellentesque rutrum lobortis neque a facilisis. Mauris id tortor placerat, aliquam dolor ac, venenatis arcu. {self.time} Alice: 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 bibendum velit maximus in. Aliquam ac metus risus. Sed cursus ornare luctus. Integer aliquet lectus id massa blandit imperdiet. Ut sed massa eget quam facilisis rutrum. Mauris eget luctus nisl. Sed ut elit iaculis, faucibus lacus eget, sodales magna. Nunc sed commodo arcu. In hac habitasse platea dictumst. Integer luctus aliquam justo, at vestibulum dolor iaculis ac. Etiam laoreet est eget odio rutrum, vel malesuada lorem rhoncus. Cras finibus in neque eu euismod. Nulla facilisi. Nunc nec aliquam quam, quis ullamcorper leo. Nunc egestas lectus eget est porttitor, in iaculis felis scelerisque. In sem elit, fringilla id viverra commodo, sagittis varius purus. Pellentesque rutrum lobortis neque a facilisis. Mauris id tortor placerat, aliquam dolor ac, venenatis arcu. {self.time} Charlie: 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 bibendum velit maximus in. Aliquam ac metus risus. Sed cursus ornare luctus. Integer aliquet lectus id massa blandit imperdiet. Ut sed massa eget quam facilisis rutrum. Mauris eget luctus nisl. Sed ut elit iaculis, faucibus lacus eget, sodales magna. Nunc sed commodo arcu. In hac habitasse platea dictumst. Integer luctus aliquam justo, at vestibulum dolor iaculis ac. Etiam laoreet est eget odio rutrum, vel malesuada lorem rhoncus. Cras finibus in neque eu euismod. Nulla facilisi. Nunc nec aliquam quam, quis ullamcorper leo. Nunc egestas lectus eget est porttitor, in iaculis felis scelerisque. In sem elit, fringilla id viverra commodo, sagittis varius purus. Pellentesque rutrum lobortis neque a facilisis. Mauris id tortor placerat, aliquam dolor ac, venenatis arcu. <End of log file> """), access_logs, self.window, self.contact_list, self.group_list, self.settings, self.master_key)
def test_long_group_message(self): # Setup self.window = RxWindow(type=WIN_TYPE_GROUP, uid='test_group', name='test_group') # Add an assembly packet sequence for contact containing cancel packet that the function should skip packets = assembly_packet_creator(MESSAGE, self.msg) packets = packets[2:] + [M_C_HEADER + bytes(PADDING_LEN)] for p in packets: write_log_entry(p, '*****@*****.**', self.settings, self.masterkey) # Add an orphaned 'append' assembly packet that the function should skip write_log_entry(M_A_HEADER + bytes(PADDING_LEN), '*****@*****.**', self.settings, self.masterkey) # Add a private message that the function should skip for p in assembly_packet_creator(MESSAGE, b'This is a short message'): write_log_entry(p, '*****@*****.**', self.settings, self.masterkey) # Add a group management message that the function should skip message = US_BYTE.join([b'test_group', b'*****@*****.**']) for p in assembly_packet_creator(MESSAGE, message, header=GROUP_MSG_INVITEJOIN_HEADER): write_log_entry(p, '*****@*****.**', self.settings, self.masterkey) # Add a group message that the function should skip for p in assembly_packet_creator(MESSAGE, b'This is a short message', group_name='different_group'): write_log_entry(p, '*****@*****.**', self.settings, self.masterkey) for p in assembly_packet_creator(MESSAGE, self.msg, group_name='test_group'): write_log_entry(p, '*****@*****.**', self.settings, self.masterkey) write_log_entry(p, '*****@*****.**', self.settings, self.masterkey, origin=ORIGIN_CONTACT_HEADER) write_log_entry(p, '*****@*****.**', self.settings, self.masterkey) write_log_entry(p, '*****@*****.**', self.settings, self.masterkey, origin=ORIGIN_CONTACT_HEADER) # Test access_logs(self.window, self.contact_list, self.group_list, self.settings, self.masterkey) self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + f"""\ Logfile of messages to/from test_group ════════════════════════════════════════════════════════════════════════════════ {self.time} Me: 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 bibendum velit maximus in. Aliquam ac metus risus. Sed cursus ornare luctus. Integer aliquet lectus id massa blandit imperdiet. Ut sed massa eget quam facilisis rutrum. Mauris eget luctus nisl. Sed ut elit iaculis, faucibus lacus eget, sodales magna. Nunc sed commodo arcu. In hac habitasse platea dictumst. Integer luctus aliquam justo, at vestibulum dolor iaculis ac. Etiam laoreet est eget odio rutrum, vel malesuada lorem rhoncus. Cras finibus in neque eu euismod. Nulla facilisi. Nunc nec aliquam quam, quis ullamcorper leo. Nunc egestas lectus eget est porttitor, in iaculis felis scelerisque. In sem elit, fringilla id viverra commodo, sagittis varius purus. Pellentesque rutrum lobortis neque a facilisis. Mauris id tortor placerat, aliquam dolor ac, venenatis arcu. {self.time} Alice: 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 bibendum velit maximus in. Aliquam ac metus risus. Sed cursus ornare luctus. Integer aliquet lectus id massa blandit imperdiet. Ut sed massa eget quam facilisis rutrum. Mauris eget luctus nisl. Sed ut elit iaculis, faucibus lacus eget, sodales magna. Nunc sed commodo arcu. In hac habitasse platea dictumst. Integer luctus aliquam justo, at vestibulum dolor iaculis ac. Etiam laoreet est eget odio rutrum, vel malesuada lorem rhoncus. Cras finibus in neque eu euismod. Nulla facilisi. Nunc nec aliquam quam, quis ullamcorper leo. Nunc egestas lectus eget est porttitor, in iaculis felis scelerisque. In sem elit, fringilla id viverra commodo, sagittis varius purus. Pellentesque rutrum lobortis neque a facilisis. Mauris id tortor placerat, aliquam dolor ac, venenatis arcu. {self.time} Charlie: 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 bibendum velit maximus in. Aliquam ac metus risus. Sed cursus ornare luctus. Integer aliquet lectus id massa blandit imperdiet. Ut sed massa eget quam facilisis rutrum. Mauris eget luctus nisl. Sed ut elit iaculis, faucibus lacus eget, sodales magna. Nunc sed commodo arcu. In hac habitasse platea dictumst. Integer luctus aliquam justo, at vestibulum dolor iaculis ac. Etiam laoreet est eget odio rutrum, vel malesuada lorem rhoncus. Cras finibus in neque eu euismod. Nulla facilisi. Nunc nec aliquam quam, quis ullamcorper leo. Nunc egestas lectus eget est porttitor, in iaculis felis scelerisque. In sem elit, fringilla id viverra commodo, sagittis varius purus. Pellentesque rutrum lobortis neque a facilisis. Mauris id tortor placerat, aliquam dolor ac, venenatis arcu. <End of logfile> """), access_logs, self.window, self.contact_list, self.group_list, self.settings, self.masterkey)
def setUp(self): self.window_list = WindowList() self.window_list.windows = [ RxWindow(uid='*****@*****.**', name='Alice'), RxWindow(uid='*****@*****.**', name='Bob') ]