Beispiel #1
0
def test_get_oauth_uris():
    base_url = 'http://example.com/fhir/'
    conformance = fhir.get_conformance_statement(base_url)
    uris = fhir.get_oauth_uris(conformance)

    assert uris['token'] is not None
    assert uris['authorize'] is not None
Beispiel #2
0
def before_all(context):
    """ Runs once before all tests.

    Set up some global state necessary to the tests and test runner.

    * Get the vendor config and attach it to the context.
    * Authorize against the vendor FHIR server and store the authorization.
    * Get the test plan so that we can show a progress meter.
    * Load the conformance statement so we know which resources are supported.
    """
    # Get the vendor config and attach it to the context.
    vendor = getattr(context.config, 'vendor', os.getenv('VENDOR'))
    override = getattr(context.config, 'override', os.getenv('CONFIG_OVERRIDE', ''))
    vendor_config = get_config(vendor.lower(), override)
    context.vendor_config = vendor_config

    # Set the ElasticSearch logging endpoint
    context.config.es_url = os.getenv('ES_URL')

    # Authorize against the vendor FHIR server.
    context.oauth = factory(vendor_config)
    try:
        context.oauth.authorize()
        if getattr(context.oauth, 'patient', None) is not None:
            vendor_config['api']['patient'] = context.oauth.patient
    except AssertionError as error:
        logging.error(utils.bad_response_assert(error.args[0], ''))
    except authorize.AuthorizationException as err:
        error = oauth.ERROR_SELENIUM_SCREENSHOT.format(
            err.args[0],
            err.args[1],
            context.vendor_config['host'],
        )
        raise Exception(error)

    # Get the test plan so that we can show a progress meter.
    context.config.plan = []
    # There is no other way to get a feature list from the context.
    # Since this is for display purposes only, this should be safe.
    features = context._runner.features  # pylint: disable=protected-access
    for feature in features:
        scenariolist = []
        context.config.plan.append({
            'name': feature.name,
            'location': str(feature.location),
            'scenarios': scenariolist})
        for scenario in feature.scenarios:
            scenariolist.append({
                'name': scenario.name,
                'location': str(scenario.location)})

    # Download the conformance statement
    try:
        context.conformance = fhir.get_conformance_statement(vendor_config['api']['url'])
    except ValueError as error:
        context.conformance = None
        logging.error(utils.bad_response_assert(error.response, ''))

    # Define a global cache
    context.cache = Cache(redis.StrictRedis())
Beispiel #3
0
def before_all(context):
    """ Runs once before all tests.

    Set up some global state necessary to the tests and test runner.

    * Get the vendor config and attach it to the context.
    * Authorize against the vendor FHIR server and store the authorization.
    * Get the test plan so that we can show a progress meter.
    * Load the conformance statement so we know which resources are supported.
    """
    # Get the vendor config and attach it to the context.
    vendor = getattr(context.config, 'vendor', os.getenv('VENDOR'))
    vendor_config = get_config(vendor.lower())
    context.vendor_config = vendor_config

    # Authorize against the vendor FHIR server.
    context.oauth = factory(vendor_config)
    try:
        context.oauth.authorize()
        if getattr(context.oauth, 'patient', None) is not None:
            vendor_config['api']['patient'] = context.oauth.patient
    except AssertionError as error:
        logging.error(utils.bad_response_assert(error.args[0], ''))
    except authorize.AuthorizationException as err:
        error = oauth.ERROR_SELENIUM_SCREENSHOT.format(
            err.args[0],
            err.args[1],
            context.vendor_config['host'],
        )
        raise Exception(error)

    # Get the test plan so that we can show a progress meter.
    context.config.plan = []
    # There is no other way to get a feature list from the context.
    # Since this is for display purposes only, this should be safe.
    features = context._runner.features  # pylint: disable=protected-access
    for feature in features:
        scenariolist = []
        context.config.plan.append({
            'name': feature.name,
            'location': str(feature.location),
            'scenarios': scenariolist
        })
        for scenario in feature.scenarios:
            scenariolist.append({
                'name': scenario.name,
                'location': str(scenario.location)
            })

    # Download the conformance statement
    try:
        context.conformance = fhir.get_conformance_statement(
            vendor_config['api']['url'])
    except ValueError as error:
        context.conformance = None
        logging.error(utils.bad_response_assert(error.response, ''))
Beispiel #4
0
def authorization_code_factory(config):
    """ Build a AuthorizationCodeStrategy.

    Returns:
        authorization_code.AuthorizationCodeStrategy
    """
    auth_config = config['auth']
    conformance = fhir.get_conformance_statement(config['api']['url'])
    urls = fhir.get_oauth_uris(conformance)
    authorizer = authorize.Authorizer(config=auth_config,
                                      authorize_url=urls['authorize'])

    return authorization_code.AuthorizationCodeStrategy(
        auth_config, urls, authorizer)
Beispiel #5
0
def before_all(context):
    """ Runs once before all tests.

    Set up some global state necessary to the tests and test runner.

    * Get the vendor config and attach it to the context.
    * Authorize against the vendor FHIR server and store the authorization.
    * Get the test plan so that we can show a progress meter.
    * Load the conformance statement so we know which resources are supported.
    """
    # Get the vendor config and attach it to the context.
    vendor = getattr(context.config, 'vendor', os.getenv('VENDOR'))
    vendor_config = get_config(vendor.lower())
    context.vendor_config = vendor_config

    # Authorize against the vendor FHIR server.
    context.oauth = factory(vendor_config)
    try:
        context.oauth.authorize()
        if getattr(context.oauth, 'patient', None) is not None:
            vendor_config['api']['patient'] = context.oauth.patient
    except AssertionError as error:
        logging.error(utils.bad_response_assert(error.args[0], ''))

    # Get the test plan so that we can show a progress meter.
    context.config.plan = []
    # There is no other way to get a feature list from the context.
    # Since this is for display purposes only, this should be safe.
    features = context._runner.features  # pylint: disable=protected-access
    for feature in features:
        scenariolist = []
        context.config.plan.append({
            'name': feature.name,
            'location': str(feature.location),
            'scenarios': scenariolist})
        for scenario in feature.scenarios:
            scenariolist.append({
                'name': scenario.name,
                'location': str(scenario.location)})

    # Download the conformance statement
    try:
        context.conformance = fhir.get_conformance_statement(vendor_config['api']['url'])
    except ValueError as error:
        context.conformance = None
        logging.error(utils.bad_response_assert(error.response, ''))
def authorization_code_factory(config):
    """ Build a AuthorizationCodeStrategy.

    Returns:
        authorization_code.AuthorizationCodeStrategy
    """
    auth_config = config['versioned_auth']
    conformance = fhir.get_conformance_statement(config['versioned_api']['url'])
    urls = fhir.get_oauth_uris(conformance)
    authorizer = authorize.Authorizer(config=auth_config,
                                      authorize_url=urls['authorize'])

    return authorization_code.AuthorizationCodeStrategy(
        auth_config,
        urls,
        authorizer
    )
Beispiel #7
0
def before_all(context):
    """ Runs once before all tests.

    Set up some global state necessary to the tests and test runner.

    * Get the vendor config and attach it to the context.
    * Authorize against the vendor FHIR server and store the authorization.
    * Get the test plan so that we can show a progress meter.
    * Load the conformance statement so we know which resources are supported.
    """
    # Get the vendor config and attach it to the context.
    vendor = getattr(context.config, 'vendor', os.getenv('VENDOR'))
    override = getattr(context.config, 'override',
                       os.getenv('CONFIG_OVERRIDE', ''))

    vendor_config = get_vendor_config(vendor, override)

    # Get configuration from the test server's environment.
    env_config = get_env_config()

    # Attempt to retrieve the security URL for this version.
    vendor_config['versioned_auth']['aud'] = vendor_config['versioned_api'][
        'url']

    context.vendor_config = copy.deepcopy(vendor_config)
    context.env_config = copy.deepcopy(env_config)

    # Filter out any tagged vendor config steps
    steps = vendor_config['versioned_auth'].get('steps', [])
    steps = [step for step in steps if 'when' not in step]
    vendor_config['versioned_auth']['steps'] = steps

    # Set the ElasticSearch logging endpoint
    context.config.es_url = os.getenv('ES_URL')

    # Authorize against the vendor FHIR server.
    try:
        context.oauth = factory(vendor_config)
        context.oauth.authorize()
        if getattr(context.oauth, 'patient', None) is not None:
            context.vendor_config['versioned_api'][
                'patient'] = context.oauth.patient
    except AssertionError as error:
        logging.error(utils.bad_response_assert(error.args[0], ''))
        raise Exception(utils.bad_response_assert(error.args[0], ''))
    except authorize.AuthorizationException as err:
        error = oauth.ERROR_SELENIUM_SCREENSHOT.format(
            err.args[0],
            err.args[1],
            err.args[2],
            context.vendor_config['host'],
        )
        raise Exception(error)
    except ValueError as error:
        logging.error(utils.bad_response_assert(error.response, ''))
        raise Exception(utils.bad_response_assert(error.response, ''))

    # Get the test plan so that we can show a progress meter.
    context.config.plan = []
    # There is no other way to get a feature list from the context.
    # Since this is for display purposes only, this should be safe.
    features = context._runner.features  # pylint: disable=protected-access
    for feature in features:
        scenariolist = []
        context.config.plan.append({
            'name': feature.name,
            'location': str(feature.location),
            'scenarios': scenariolist
        })
        for scenario in feature.scenarios:
            scenariolist.append({
                'name': scenario.name,
                'location': str(scenario.location)
            })

    # Download the conformance statement
    try:
        context.conformance = fhir.get_conformance_statement(
            vendor_config['versioned_auth']['aud'])
    except ValueError as error:
        context.conformance = None
        logging.error(utils.bad_response_assert(error.response, ''))

    # Define a global cache
    context.cache = Cache(redis.StrictRedis())