def test_parse_url_with_fqdn_and_port(mocker):
    from JARM import parse_hostname

    MOCK_HOSTNAME = 'google.com'
    MOCK_PORT = 443

    hostname = f'https://{MOCK_HOSTNAME}:{MOCK_PORT}'
    port = None

    assert parse_hostname(hostname=hostname, port=port) == {
        'target_type': 'fqdn',
        'target_host': MOCK_HOSTNAME,
        'port': MOCK_PORT
    }
def test_parse_fqdn_explicit_port_wins_over_implicit(mocker):
    from JARM import parse_hostname

    MOCK_HOSTNAME = 'google.com'
    MOCK_PORT = 443

    hostname = f'{MOCK_HOSTNAME}:999'
    port = MOCK_PORT

    assert parse_hostname(hostname=hostname, port=port) == {
        'target_type': 'fqdn',
        'target_host': MOCK_HOSTNAME,
        'port': MOCK_PORT
    }
def test_parse_ipv4_explicit_port(mocker):
    from JARM import parse_hostname

    MOCK_HOSTNAME = '1.2.3.4'
    MOCK_PORT = 443

    hostname = f'{MOCK_HOSTNAME}'
    port = MOCK_PORT

    assert parse_hostname(hostname=hostname, port=port) == {
        'target_type': 'ip',
        'target_host': MOCK_HOSTNAME,
        'port': MOCK_PORT
    }
def test_parse_fqdn_noport(mocker):
    from JARM import parse_hostname

    MOCK_HOSTNAME = 'google.com'
    MOCK_PORT = 443

    hostname = f'{MOCK_HOSTNAME}'
    port = None

    assert parse_hostname(hostname=hostname, port=port) == {
        'target_type': 'fqdn',
        'target_host': MOCK_HOSTNAME,
        'port': MOCK_PORT
    }