Пример #1
0
def test_identity_rotate_customer_1():
    if os.environ.get('RUN_TESTS', '1') == '0':
        return pytest.skip()  # @UndefinedVariable

    sys.stderr.write('\ntest_identity_rotate_customer_1\n')

    service_info_v1('customer-1', 'service_customer', 'ON')

    supplier_list_v1('customer-1',
                     expected_min_suppliers=2,
                     expected_max_suppliers=2)

    service_info_v1('customer-1', 'service_shared_data', 'ON')

    # remember current ID sources
    r = identity_get_v1('customer-1')
    old_sources = r['result']['sources']
    old_global_id = r['result']['global_id']
    old_idurl = r['result']['idurl']

    # test other nodes able to talk to customer-1 before identity get rotated
    user_ping_v1('customer-3', old_global_id)
    user_ping_v1('supplier-1', old_global_id)
    user_ping_v1('supplier-2', old_global_id)

    # test customer-3 can chat with customer-1 before identity get rotated
    service_info_v1('customer-3', 'service_private_messages', 'ON')
    service_info_v1('customer-1', 'service_private_messages', 'ON')
    random_string = base64.b32encode(os.urandom(20)).decode()
    random_message = {
        'random_message': random_string,
    }
    t = threading.Timer(2.0, message_send_v1, [
        'customer-3',
        'master$%s' % old_global_id,
        random_message,
    ])
    t.start()
    message_receive_v1('customer-1', expected_data=random_message)

    # create one share and upload one file for customer-1
    share_id_customer_1 = share_create_v1('customer-1')
    filename = 'cat.txt'
    virtual_filename = filename
    volume_customer_1 = '/customer_1'
    filepath_customer_1 = f'{volume_customer_1}/{filename}'
    run_ssh_command_and_wait('customer-1',
                             f'echo customer_1 > {filepath_customer_1}')

    remote_path_customer_1 = f'{share_id_customer_1}:{virtual_filename}'
    downloaded_filepath = f'/tmp/{filename}'
    local_file_src = run_ssh_command_and_wait('customer-1', 'cat %s' %
                                              filepath_customer_1)[0].strip()

    service_info_v1('customer-1', 'service_shared_data', 'ON')

    packet_list_v1('customer-1', wait_all_finish=True)
    transfer_list_v1('customer-1', wait_all_finish=True)

    file_create_v1('customer-1', remote_path=remote_path_customer_1)
    file_upload_start_v1('customer-1',
                         remote_path=remote_path_customer_1,
                         local_path=filepath_customer_1)

    time.sleep(3)

    service_info_v1('customer-1', 'service_shared_data', 'ON')

    # make sure file is available before identity rotate
    share_open_v1('customer-1', share_id_customer_1)
    file_download_start_v1('customer-1',
                           remote_path=remote_path_customer_1,
                           destination='/tmp')

    # and make sure this is the same file
    downloaded_file_src = run_ssh_command_and_wait(
        'customer-1', 'cat %s' % downloaded_filepath)[0].strip()
    assert local_file_src == downloaded_file_src, "source file and received file content is not equal"

    # remember list of existing keys
    old_keys = [k['key_id'] for k in key_list_v1('customer-1')['result']]
    assert f'master${old_global_id}' in old_keys
    assert f'messages${old_global_id}' in old_keys
    assert f'customer${old_global_id}' in old_keys

    # make customer-1 and customer-3 friends to each other
    friend_add_v1('customer-1', 'http://id-a:8084/customer-3.xml', 'friend2')
    friend_add_v1('customer-3', old_idurl, 'friend1')
    old_friends = friend_list_v1('customer-3', extract_idurls=True)
    assert old_idurl in old_friends

    # rotate identity sources
    identity_rotate_v1('customer-1')

    time.sleep(1)

    # and make sure ID sources were changed
    r = identity_get_v1('customer-1')
    new_sources = r['result']['sources']
    new_global_id = r['result']['global_id']
    new_idurl = r['result']['idurl']
    assert new_sources != old_sources
    assert new_global_id != old_global_id
    assert new_idurl != old_idurl

    service_info_v1('customer-1', 'service_gateway', 'ON')
    service_info_v1('customer-1', 'service_customer', 'ON')

    # remember current suppliers of customer-1
    customer_1_suppliers = supplier_list_v1('customer-1',
                                            expected_min_suppliers=2,
                                            expected_max_suppliers=2,
                                            extract_suppliers=True)
    first_supplier = customer_1_suppliers[0].replace(
        'http://id-a:8084/', '').replace('http://id-b:8084/',
                                         '').replace('.xml', '')
    second_supplier = customer_1_suppliers[1].replace(
        'http://id-a:8084/', '').replace('http://id-b:8084/',
                                         '').replace('.xml', '')

    service_info_v1('customer-1', 'service_shared_data', 'ON')

    # test other nodes able to talk to customer-1 again on new IDURL
    user_ping_v1('customer-3', new_global_id)
    user_ping_v1('supplier-1', new_global_id)
    user_ping_v1('supplier-2', new_global_id)

    # make sure keys are renamed on customer-1
    new_keys = [k['key_id'] for k in key_list_v1('customer-1')['result']]
    assert len(old_keys) == len(new_keys)
    assert f'master${new_global_id}' in new_keys
    assert f'messages${new_global_id}' in new_keys
    assert f'customer${new_global_id}' in new_keys
    assert f'master${old_global_id}' not in new_keys
    assert f'messages${old_global_id}' not in new_keys
    assert f'customer${old_global_id}' not in new_keys

    # make sure file is still available after identity rotate
    new_share_id_customer_1 = share_id_customer_1.replace(
        old_global_id, new_global_id)
    share_open_v1('customer-1', new_share_id_customer_1)
    new_remote_path_customer_1 = remote_path_customer_1.replace(
        old_global_id, new_global_id)
    run_ssh_command_and_wait('customer-1',
                             'rm -rfv %s' % downloaded_filepath)[0].strip()
    file_download_start_v1('customer-1',
                           remote_path=new_remote_path_customer_1,
                           destination='/tmp')

    # and make sure this is still the same file
    new_downloaded_file_src = run_ssh_command_and_wait(
        'customer-1', 'cat %s' % downloaded_filepath)[0].strip()
    assert local_file_src == downloaded_file_src, "source file and received file content is not equal after identity rotate"
    assert new_downloaded_file_src == downloaded_file_src, "received file content before identity rotate is not equal to received file after identity rotate"

    # check again current suppliers of customer-1
    customer_1_suppliers = supplier_list_v1('customer-1',
                                            expected_min_suppliers=2,
                                            expected_max_suppliers=2,
                                            extract_suppliers=True)
    first_supplier = customer_1_suppliers[0].replace(
        'http://id-a:8084/', '').replace('http://id-b:8084/',
                                         '').replace('.xml', '')
    second_supplier = customer_1_suppliers[1].replace(
        'http://id-a:8084/', '').replace('http://id-b:8084/',
                                         '').replace('.xml', '')

    # verify files on first supplier were moved to correct sub folder
    print(f'checking customer-1 files on {first_supplier}')
    old_folder_first_supplier = run_ssh_command_and_wait(
        first_supplier,
        f'ls -la ~/.bitdust/customers/{old_global_id}/')[0].strip()
    new_folder_first_supplier = run_ssh_command_and_wait(
        first_supplier,
        f'ls -la ~/.bitdust/customers/{new_global_id}/')[0].strip()
    assert old_folder_first_supplier == ''
    assert new_folder_first_supplier != ''
    print(f'first supplier {first_supplier} :\n', new_folder_first_supplier)

    # verify files on second supplier were moved to correct sub folder
    print(f'checking customer-1 files on {second_supplier}')
    old_folder_second_supplier = run_ssh_command_and_wait(
        second_supplier,
        f'ls -la ~/.bitdust/customers/{old_global_id}/')[0].strip()
    new_folder_second_supplier = run_ssh_command_and_wait(
        second_supplier,
        f'ls -la ~/.bitdust/customers/{new_global_id}/')[0].strip()
    assert old_folder_second_supplier == ''
    assert new_folder_second_supplier != ''
    print(f'second supplier {second_supplier} :\n', new_folder_second_supplier)

    # test that friend1 idurl changed for customer-3
    new_friends = friend_list_v1('customer-3', extract_idurls=True)
    assert new_idurl in new_friends
    assert old_idurl not in new_friends

    # test customer-3 can still chat with customer-1 after identity rotated
    service_info_v1('customer-3', 'service_private_messages', 'ON')
    service_info_v1('customer-1', 'service_private_messages', 'ON')
    random_string = base64.b32encode(os.urandom(20)).decode()
    random_message = {
        'random_message': random_string,
    }
    t = threading.Timer(1.0, message_send_v1, [
        'customer-3',
        'master$%s' % new_global_id,
        random_message,
    ])
    t.start()
    message_receive_v1('customer-1', expected_data=random_message)
Пример #2
0
def test_ping_customer_1_towards_proxy_3():
    if os.environ.get('RUN_TESTS', '1') == '0':
        return pytest.skip()  # @UndefinedVariable

    user_ping_v1('customer-1', 'proxy-3@id-b_8084')
Пример #3
0
def test_ping_supplier_2_towards_customer_2():
    if os.environ.get('RUN_TESTS', '1') == '0':
        return pytest.skip()  # @UndefinedVariable

    user_ping_v1('supplier-2', 'customer-2@id-a_8084')
Пример #4
0
def test_ping_proxy_3_towards_proxy_1():
    if os.environ.get('RUN_TESTS', '1') == '0':
        return pytest.skip()  # @UndefinedVariable

    user_ping_v1('proxy-3', 'proxy-1@id-a_8084')