def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.master_key = MasterKey() self.settings = Settings() self.time = STATIC_TIMESTAMP self.contact_list = ContactList(self.master_key, self.settings) self.group_list = GroupList(groups=['test_group']) self.file_name = f'{DIR_USER_DATA}{self.settings.software_operation}_logs' self.tmp_file_name = self.file_name + "_temp" self.tfc_log_database = MessageLog(self.file_name, self.master_key.master_key) self.args = 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): """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.master_key = MasterKey() self.settings = Settings() self.file_name = f'{DIR_USER_DATA}{self.settings.software_operation}_groups' self.contact_list = ContactList(self.master_key, self.settings) self.group_list = GroupList(self.master_key, self.settings, self.contact_list) self.nicks = [ 'Alice', 'Bob', 'Charlie', 'David', 'Eric', 'Fido', 'Guido', 'Heidi', 'Ivan', 'Joana', 'Karol' ] self.group_names = [ 'test_group_1', 'test_group_2', 'test_group_3', 'test_group_4', 'test_group_5', 'test_group_6', 'test_group_7', 'test_group_8', 'test_group_9', 'test_group_10', 'test_group_11' ] members = list(map(create_contact, self.nicks)) self.contact_list.contacts = members self.group_list.groups = \ [Group(name =name, group_id =group_name_to_group_id(name), log_messages =False, notifications=False, members =members, settings =self.settings, store_groups =self.group_list.store_groups) for name in self.group_names] self.single_member_data_len = ( GROUP_STATIC_LENGTH + self.settings.max_number_of_group_members * ONION_SERVICE_PUBLIC_KEY_LENGTH)
def setUp(self): """Pre-test actions.""" self.unit_test_dir = cd_unit_test() 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) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.master_key = MasterKey() self.settings = Settings() self.log_file = f'{DIR_USER_DATA}{self.settings.software_operation}_logs' self.tfc_log_database = MessageLog(self.log_file, self.master_key.master_key)
def setUp(self) -> None: """Pre-test actions.""" self.short_msg = "Lorem ipsum dolor sit amet, consectetur adipiscing elit" 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.unit_test_dir = cd_unit_test() self.ts = datetime.now() self.contact = create_contact('Alice') self.settings = Settings(log_file_masking=True) self.onion_pub_key = nick_to_pub_key('Alice') self.window_list = WindowList() self.whisper_header = b'\x00' compressed = zlib.compress(b'file_data', level=COMPRESSION_LEVEL) file_key = os.urandom(SYMMETRIC_KEY_LENGTH) encrypted = encrypt_and_sign(compressed, key=file_key) encrypted += file_key self.short_f_data = (int_to_bytes(1) + int_to_bytes(2) + b'testfile.txt' + US_BYTE + encrypted)
def setUp(self): """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.old_key = MasterKey() self.new_key = MasterKey(master_key=os.urandom(SYMMETRIC_KEY_LENGTH)) self.settings = Settings() self.tmp_file_name = f"{DIR_USER_DATA}{self.settings.software_operation}_logs_temp" self.time = STATIC_TIMESTAMP
def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.file_name = f'{DIR_USER_DATA}ut_logs' self.temp_name = self.file_name + '_temp' self.settings = Settings() self.database_key = os.urandom(SYMMETRIC_KEY_LENGTH) self.message_log = MessageLog(self.file_name, self.database_key)
def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.win_name = nick_to_pub_key("Alice") self.contact_list = ContactList() self.group_list = GroupList() self.settings = Settings() self.master_key = MasterKey()
def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.contact_list = ContactList() self.settings = Settings(disable_gui_dialog=True) self.queues = gen_queue_dict() self.onion_service = OnionService() self.args = self.contact_list, self.settings, self.onion_service, self.queues
def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.master_key = MasterKey() self.settings = Settings() self.file_name = f'{DIR_USER_DATA}{self.settings.software_operation}_keys' self.keylist = KeyList(self.master_key, self.settings) self.full_contact_list = ['Alice', 'Bob', 'Charlie', LOCAL_ID] self.keylist.keysets = [create_keyset(n, store_f=self.keylist.store_keys) for n in self.full_contact_list]
def setUp(self): """Pre-test actions.""" self.settings = Settings() self.unit_test_dir = cd_unit_test() self.gateway = Gateway() self.rs = RSCodec(2 * self.gateway.settings.serial_error_correction) self.ts = datetime.now() self.queues = gen_queue_dict() self.args = self.queues, self.gateway
def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.settings = Settings() self.queues = gen_queue_dict() self.window = TxWindow() self.onion_service = OnionService() self.contact_list = ContactList(nicks=['Alice', 'Bob', 'Charlie']) self.args = self.settings, self.queues, self.window
def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.ts = datetime.now() self.window_list = WindowList() self.cmd_data = nick_to_pub_key("Bob") self.settings = Settings() self.master_key = MasterKey() self.args = self.cmd_data, self.ts, self.window_list
def setUp(self) -> None: """Pre-test actions.""" self.settings = Settings() self.unit_test_dir = cd_unit_test() self.gateway = Gateway() self.rs = RSCodec(2 * self.gateway.settings.serial_error_correction) self.ts = datetime.now() self.queues = gen_queue_dict() self.args = self.queues, self.gateway self.queues[TX_BUF_KEY_QUEUE].put(SYMMETRIC_KEY_LENGTH * b'a')
def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.old_master_key = MasterKey() self.new_master_key = MasterKey(master_key=os.urandom(SYMMETRIC_KEY_LENGTH)) self.settings = Settings() self.tmp_file_name = f"{DIR_USER_DATA}{self.settings.software_operation}_logs_temp" self.time = STATIC_TIMESTAMP self.log_file = f'{DIR_USER_DATA}{self.settings.software_operation}_logs' self.message_log = MessageLog(self.log_file, self.old_master_key.master_key)
def setUp(self): """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.contact_list = ContactList(nicks=['Alice']) self.group_list = GroupList(groups=['test_group']) self.settings = Settings() self.queues = gen_queue_dict() self.master_key = MasterKey() self.file_name = f'{DIR_USER_DATA}{self.settings.software_operation}_logs' self.args = self.contact_list, self.group_list, self.settings, self.queues, self.master_key
def setUp(self): """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.user_input = UserInput() self.contact_list = ContactList(nicks=['Alice', 'Bob']) self.group_list = GroupList(groups=['test_group']) 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
def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.contact_list = ContactList(nicks=['Alice']) self.group_list = GroupList(groups=['test_group']) self.settings = Settings() self.queues = gen_queue_dict() self.master_key = MasterKey() self.pub_key = nick_to_pub_key('Alice') self.args = self.contact_list, self.group_list, self.settings, self.queues, self.master_key
def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.ts = datetime.now() self.onion_pub_key = nick_to_pub_key('Alice') self.nick = 'Alice' self.settings = Settings() self.window_list = WindowList(nick=['Alice', 'Bob']) self.key = os.urandom(SYMMETRIC_KEY_LENGTH) self.args = self.onion_pub_key, self.nick, self.settings, self.window_list
def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.file_name = f"{DIR_USER_DATA}{TX}_settings" self.master_key = MasterKey() self.settings = Settings(self.master_key, operation=TX, local_test=False) self.contact_list = ContactList(nicks=[f'contact_{n}' for n in range(18)]) self.group_list = GroupList(groups=[f'group_{n}' for n in range(18)]) self.group_list.groups[0] = create_group('group_0', [f'contact_{n}' for n in range(18)]) self.args = self.contact_list, self.group_list
def setUp(self, _): """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.window = TxWindow(name='Alice', uid=nick_to_pub_key('Alice')) self.contact_list = ContactList() self.group_list = GroupList() self.settings = Settings() self.queues = gen_queue_dict() self.master_key = MasterKey() self.args = (self.window, self.contact_list, self.group_list, self.settings, self.queues, self.master_key)
def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.ts = datetime.now() self.account = nick_to_pub_key('Alice') self.file_key = SYMMETRIC_KEY_LENGTH*b'a' self.file_ct = encrypt_and_sign(50 * b'a', key=self.file_key) self.contact_list = ContactList(nicks=['Alice']) self.window_list = WindowList() self.settings = Settings() self.args = self.file_key, self.contact_list, self.window_list, self.settings
def setUp(self): """Pre-test actions.""" self.unit_test_dir = cd_unit_test() 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 setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.master_key = MasterKey() self.settings = Settings() self.file_name = f'{DIR_USER_DATA}{self.settings.software_operation}_contacts' self.contact_list = ContactList(self.master_key, self.settings) self.full_contact_list = ['Alice', 'Bob', 'Charlie', 'David', 'Eric', LOCAL_ID] self.contact_list.contacts = list(map(create_contact, self.full_contact_list)) self.real_contact_list = self.full_contact_list[:] self.real_contact_list.remove(LOCAL_ID)
def setUp(self): """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.contact_list = ContactList() self.group_list = GroupList() self.settings = Settings() self.queues = gen_queue_dict() self.master_key = MasterKey() self.onion_service = OnionService( master_key=self.master_key, file_name=f'{DIR_USER_DATA}/unittest') self.args = (self.contact_list, self.group_list, self.settings, self.queues, self.master_key, self.onion_service)
def setUp(self): """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.ts = datetime.now() self.master_key = MasterKey() self.settings = Settings() self.contact_list = ContactList(nicks=[LOCAL_ID]) self.window_list = WindowList(nicks=[LOCAL_ID]) self.group_list = GroupList() self.key_list = KeyList() self.args = (self.ts, self.window_list, self.contact_list, self.group_list, self.key_list, self.settings, self.master_key)
def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.ts = datetime.now() self.packet = b'' self.file_keys = dict() self.file_buf = dict() self.contact_list = ContactList(nicks=['Alice']) self.window_list = WindowList() self.file_key = SYMMETRIC_KEY_LENGTH*b'a' self.settings = Settings() self.compressed = zlib.compress(str_to_bytes("test_file.txt") + b'file_data', level=COMPRESSION_LEVEL) self.args = self.file_keys, self.file_buf, self.contact_list, self.window_list, self.settings
def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() kat_file_url = 'https://raw.githubusercontent.com/BLAKE2/BLAKE2/master/testvectors/blake2b-kat.txt' kat_file_name = 'blake2b-kat.txt' # Download the test vector file. subprocess.Popen(f'wget {kat_file_url} -O {kat_file_name}', shell=True).wait() # Read the test vector file. with open(kat_file_name) as f: file_data = f.read() # Verify the SHA256 hash of the test vector file. self.assertEqual( '82fcb3cabe8ff6e1452849e3b2a26a3631f1e2b51beb62ffb537892d2b3e364f', hashlib.sha256(file_data.encode()).hexdigest()) # Parse the test vectors to a list of tuples: [(message1, key1, digest1), (message2, key2, digest2), ...] self.test_vectors = [] trimmed_data = file_data[ 2: -1] # Remove empty lines from the start and the end of the read data. test_vectors = trimmed_data.split( '\n\n' ) # Each tuple of test vector values is separated by an empty line. for test_vector in test_vectors: # Each value is hex-encoded, and has a tab-separated name # (in, key, hash) prepended to it that must be separated. message, key, digest = [ bytes.fromhex(line.split('\t')[1]) for line in test_vector.split('\n') ] self.test_vectors.append((message, key, digest)) # Transpose the list of tuples to lists of messages, keys, and digests. messages, keys, digests = list(map(list, zip(*self.test_vectors))) # Verify that messages and digests are unique, and # that identical keys are used in every test vector. self.assertEqual(len(set(messages)), 256) self.assertEqual(len(keys), 256) self.assertEqual(len(set(keys)), 1) self.assertEqual(len(set(digests)), 256)
def setUp(self) -> None: """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.ts = datetime.now() self.master_key = MasterKey() self.settings = Settings() self.contact_list = ContactList(nicks=[LOCAL_ID]) self.window_list = WindowList(nicks=[LOCAL_ID]) self.group_list = GroupList() self.key_list = KeyList() self.args = (self.ts, self.window_list, self.contact_list, self.group_list, self.key_list, self.settings, self.master_key) self.log_file = f'{DIR_USER_DATA}{self.settings.software_operation}_logs' self.tfc_log_database = MessageLog(self.log_file, self.master_key.master_key)
def setUp(self): """Pre-test actions.""" self.unit_test_dir = cd_unit_test() self.nicks = ['Alice', 'Bob', 'Charlie'] members = list(map(create_contact, self.nicks)) self.settings = Settings() self.group = Group(name='test_group', group_id=group_name_to_group_id('test_group'), log_messages=False, notifications=False, members=members, settings=self.settings, store_groups=lambda: None) ensure_dir(DIR_USER_DATA)