Exemplo n.º 1
0
def test_sync_server_side_client_ip():
    port_config = get_port_config([Port(80, 80, 'TCP'), Port(81, 81, 'TCP')])
    port_drill = PortDrill(port_config, MockPortMapper(external_ip='10.1.1.1'), MockPortProber())

    responses.add(responses.POST,
                  "http://api.domain.com/domain/update",
                  status=200,
                  body="{'message': 'Domain was updated'}",
                  content_type="application/json")

    user_platform_config = get_user_platform_config()
    user_platform_config.update_redirect('domain.com', 'http://api.domain.com')
    user_platform_config.update_domain('boris', 'some_update_token')
    dns = RedirectService(user_platform_config, test_version)
    dns.sync(port_drill, 'some_update_token', 'http', False, 'TCP')

    expected_request = '''
{
    "web_local_port": 80,
    "web_port": 80,
    "web_protocol": "http",
    "platform_version": "test",
    "token": "some_update_token",
    "map_local_address": true,
    "local_ip": "127.0.0.1"
}
'''
    assertSingleRequest(expected_request)
Exemplo n.º 2
0
def test_link_success():
    device_id = id.id()

    responses.add(responses.POST,
                  "http://api.domain.com/domain/acquire",
                  status=200,
                  body='{"user_domain": "boris", "update_token": "some_update_token"}',
                  content_type="application/json")

    user_platform_config = get_user_platform_config()
    user_platform_config.update_redirect('domain.com', 'http://api.domain.com')
    dns = RedirectService(user_platform_config, test_version)
    result = dns.acquire('*****@*****.**', 'pass1234', 'boris')

    assert result is not None
    assert result.user_domain == "boris"
    assert result.update_token == "some_update_token"

    expected_request_data = {
        "password": "******",
        "email": "*****@*****.**",
        "user_domain": "boris",
        'device_mac_address': device_id.mac_address,
        'device_name': device_id.name,
        'device_title': device_id.title,
    }
    # Need to assert all passed POST parameters
    # self.assertSingleRequest(convertible.to_json(expected_request_data))

    assert result.user_domain == "boris"
    assert result.update_token == "some_update_token"
Exemplo n.º 3
0
def test_sync_server_side_client_ip():
    port_config = get_port_config([Port(80, 80, 'TCP'), Port(81, 81, 'TCP')])
    port_drill = PortDrill(port_config, MockPortMapper(external_ip='10.1.1.1'),
                           MockPortProber())

    responses.add(responses.POST,
                  "http://api.domain.com/domain/update",
                  status=200,
                  body="{'message': 'Domain was updated'}",
                  content_type="application/json")

    user_platform_config = get_user_platform_config()
    user_platform_config.update_redirect('domain.com', 'http://api.domain.com')
    user_platform_config.update_domain('boris', 'some_update_token')
    dns = RedirectService(user_platform_config, test_version)
    dns.sync(port_drill, 'some_update_token', 'http', False, 'TCP')

    expected_request = '''
{
    "web_local_port": 80,
    "web_port": 80,
    "web_protocol": "http",
    "platform_version": "test",
    "token": "some_update_token",
    "map_local_address": true,
    "local_ip": "127.0.0.1"
}
'''
    assertSingleRequest(expected_request)
Exemplo n.º 4
0
def test_link_success():
    device_id = id.id()

    responses.add(
        responses.POST,
        "http://api.domain.com/domain/acquire",
        status=200,
        body='{"user_domain": "boris", "update_token": "some_update_token"}',
        content_type="application/json")

    user_platform_config = get_user_platform_config()
    user_platform_config.update_redirect('domain.com', 'http://api.domain.com')
    dns = RedirectService(user_platform_config, test_version)
    result = dns.acquire('*****@*****.**', 'pass1234', 'boris')

    assert result is not None
    assert result.user_domain == "boris"
    assert result.update_token == "some_update_token"

    expected_request_data = {
        "password": "******",
        "email": "*****@*****.**",
        "user_domain": "boris",
        'device_mac_address': device_id.mac_address,
        'device_name': device_id.name,
        'device_title': device_id.title,
    }
    # Need to assert all passed POST parameters
    # self.assertSingleRequest(convertible.to_json(expected_request_data))

    assert result.user_domain == "boris"
    assert result.update_token == "some_update_token"
Exemplo n.º 5
0
def test_url_with_external_access():

    user_platform_config = get_user_platform_config()
    user_platform_config.update_domain('device', 'token')
    user_platform_config.update_redirect('syncloud.it', 'api.url')
    user_platform_config.update_device_access(False, False, True, '1.1.1.1')

    port_config = get_port_config([Port(80, 10000, 'TCP')])

    device_info = DeviceInfo(user_platform_config, port_config)

    assert device_info.url('app') == 'http://app.device.syncloud.it:10000'
Exemplo n.º 6
0
def test_url_with_external_access():

    user_platform_config = get_user_platform_config()
    user_platform_config.update_domain('device', 'token')
    user_platform_config.update_redirect('syncloud.it', 'api.url')
    user_platform_config.update_device_access(True, 'http')

    port_config = get_port_config([Port(80, 10000, 'TCP')])

    device_info = DeviceInfo(user_platform_config, port_config)

    assert device_info.url('app') == 'http://app.device.syncloud.it:10000'
Exemplo n.º 7
0
def test_link_server_error():
    responses.add(responses.POST,
                  "http://api.domain.com/domain/acquire",
                  status=403,
                  body='{"message": "Authentication failed"}',
                  content_type="application/json")

    user_platform_config = get_user_platform_config()
    user_platform_config.update_redirect('domain.com', 'http://api.domain.com')
    dns = RedirectService(user_platform_config, test_version)

    with pytest.raises(PassthroughJsonError) as context:
        result = dns.acquire('*****@*****.**', 'pass1234', 'boris')

    assert context.value.message == "Authentication failed"

    assert user_platform_config.get_user_domain() is None
Exemplo n.º 8
0
def test_link_server_error():
    responses.add(responses.POST,
                  "http://api.domain.com/domain/acquire",
                  status=403,
                  body='{"message": "Authentication failed"}',
                  content_type="application/json")

    user_platform_config = get_user_platform_config()
    user_platform_config.update_redirect('domain.com', 'http://api.domain.com')
    dns = RedirectService(user_platform_config, test_version)

    with pytest.raises(PassthroughJsonError) as context:
        result = dns.acquire('*****@*****.**', 'pass1234', 'boris')

    assert context.value.message == "Authentication failed"

    assert user_platform_config.get_user_domain() is None
Exemplo n.º 9
0
def test_sync_server_error():
    port_config = get_port_config([Port(80, 10000, 'TCP')])
    port_drill = PortDrill(port_config, MockPortMapper(external_ip='192.167.44.52'), MockPortProber())

    responses.add(responses.POST,
                  "http://api.domain.com/domain/update",
                  status=400,
                  body='{"message": "Unknown update token"}',
                  content_type="application/json")

    user_platform_config = get_user_platform_config()
    user_platform_config.update_redirect('domain.com', 'http://api.domain.com')
    user_platform_config.update_domain('boris', 'some_update_token')
    dns = RedirectService(user_platform_config, test_version)

    with pytest.raises(PassthroughJsonError) as context:
        dns.sync(port_drill, 'some_update_token', 'http', False, 'TCP')

    assert context.value.message == "Unknown update token"
Exemplo n.º 10
0
def test_sync_server_error():
    port_config = get_port_config([Port(80, 10000, 'TCP')])
    port_drill = PortDrill(port_config,
                           MockPortMapper(external_ip='192.167.44.52'),
                           MockPortProber())

    responses.add(responses.POST,
                  "http://api.domain.com/domain/update",
                  status=400,
                  body='{"message": "Unknown update token"}',
                  content_type="application/json")

    user_platform_config = get_user_platform_config()
    user_platform_config.update_redirect('domain.com', 'http://api.domain.com')
    user_platform_config.update_domain('boris', 'some_update_token')
    dns = RedirectService(user_platform_config, test_version)

    with pytest.raises(PassthroughJsonError) as context:
        dns.sync(port_drill, 'some_update_token', 'http', False, 'TCP')

    assert context.value.message == "Unknown update token"