def test_product():
    """Setup & Teardown an product for this api"""
    product = ApigeeApiProducts()
    loop = asyncio.new_event_loop()
    loop.run_until_complete(product.create_new_product())
    yield product
    loop.run_until_complete(product.destroy_product())
    async def test_app_and_product(self):
        apigee_product = ApigeeApiProducts()
        apigee_product2 = ApigeeApiProducts()
        await apigee_product.create_new_product()
        await apigee_product.update_proxies([config.SERVICE_NAME])
        await apigee_product2.create_new_product()
        await apigee_product2.update_proxies([config.SERVICE_NAME])

        apigee_app = ApigeeApiDeveloperApps()
        await apigee_app.create_new_app()

        # Set default JWT Testing resource url
        await apigee_app.set_custom_attributes({
            'jwks-resource-url':
            'https://raw.githubusercontent.com/NHSDigital/'
            'identity-service-jwks/main/jwks/internal-dev/'
            '9baed6f4-1361-4a8e-8531-1f8426e3aba8.json'
        })

        await apigee_app.add_api_product(
            api_products=[apigee_product.name, apigee_product2.name])

        [
            await product.update_ratelimits(quota=60000,
                                            quota_interval="1",
                                            quota_time_unit="minute",
                                            rate_limit="1000ps")
            for product in [apigee_product, apigee_product2]
        ]

        yield apigee_product, apigee_product2, apigee_app

        await apigee_app.destroy_app()
        await apigee_product.destroy_product()
        await apigee_product2.destroy_product()
def test_product_and_app():
    """Setup & Teardown an product and app for this api"""
    product = ApigeeApiProducts()
    app = ApigeeApiDeveloperApps()
    loop = asyncio.new_event_loop()
    loop.run_until_complete(product.create_new_product())
    loop.run_until_complete(app.setup_app())
    app.oauth = OauthHelper(app.client_id, app.client_secret, app.callback_url)
    yield product, app
    loop.run_until_complete(app.destroy_app())
    loop.run_until_complete(product.destroy_product())
Exemple #4
0
async def _product_with_full_access():
    product = ApigeeApiProducts()
    await product.create_new_product()
    _set_default_rate_limit(product)
    product.update_scopes([
        "personal-demographics-service:USER-RESTRICTED",
        "urn:nhsd:apim:app:level3:",
        "urn:nhsd:apim:user-nhs-id:aal3:personal-demographics-service"
    ])

    await product.update_paths(paths=["/", "/*"])
    return product
Exemple #5
0
async def test_product():
    """Create a test product which can be modified by the test"""
    product = ApigeeApiProducts()
    await product.create_new_product()
    _set_default_rate_limit(product)
    yield product
    await product.destroy_product()
Exemple #6
0
async def test_app():
    """Programatically create and destroy test app for each test"""
    apigee_product = ApigeeApiProducts()
    await apigee_product.create_new_product()
    await apigee_product.update_proxies([config.SERVICE_NAME])

    apigee_app = ApigeeApiDeveloperApps()

    await apigee_product.update_ratelimits(
        quota=60000,
        quota_interval="1",
        quota_time_unit="minute",
        rate_limit="1000ps",
    )

    await apigee_app.setup_app(
        api_products=[apigee_product.name],
        custom_attributes={
            "jwks-resource-url":
            "https://internal-dev.api.service.nhs.uk/mock-nhsid-jwks/identity-service/nhs-cis2-jwks"
        })

    apigee_app.oauth = OauthHelper(apigee_app.client_id,
                                   apigee_app.client_secret,
                                   apigee_app.callback_url)

    api_service_name = get_env("SERVICE_NAME")

    await apigee_product.update_scopes(
        ["urn:nhsd:apim:user-nhs-id:aal3:personal-demographics-service"])

    yield apigee_app

    await apigee_app.destroy_app()
 def product(self):
     """
     Import the test utils module to be able to:
         - Create apigee test product
             - Update custom scopes
             - Update environments
             - Update product paths
             - Update custom attributes
             - Update proxies to the product
             - Update custom ratelimits
     """
     return ApigeeApiProducts()
def test_product_and_app():
    """Setup & Teardown an product and app for this api"""
    product = ApigeeApiProducts()
    app = ApigeeApiDeveloperApps()
    loop = asyncio.new_event_loop()
    loop.run_until_complete(product.create_new_product())
    loop.run_until_complete(
        product.update_scopes([
            "urn:nhsd:apim:app:level3:immunisation-history",
            "urn:nhsd:apim:user-nhs-login:P9:immunisation-history",
            "urn:nhsd:apim:user-nhs-login:P5:immunisation-history"
        ]))
    loop.run_until_complete(
        app.setup_app(
            api_products=[product.name],
            custom_attributes=_BASE_CUSTOM_ATTRIBUTES,
        ))
    app.oauth = OauthHelper(app.client_id, app.client_secret, app.callback_url)
    yield product, app
    loop.run_until_complete(app.destroy_app())
    loop.run_until_complete(product.destroy_product())
Exemple #9
0
async def _api():
    """ Setup and Teardown, create an product at the start and then destroy it at the end """

    # create apigee instance & attach instance to class
    api = ApigeeApiProducts()

    print("\nCreating Test Product..")
    await api.create_new_product()

    yield api
    # teardown
    print("\nDestroying Test Product..")
    await api.destroy_product()
Exemple #10
0
def test_product_and_app(request):
    """Setup & Teardown an product and app for this api"""
    request_params = request.param
    product = ApigeeApiProducts()
    app = ApigeeApiDeveloperApps()
    loop = asyncio.new_event_loop()
    loop.run_until_complete(product.create_new_product())
    loop.run_until_complete(product.update_scopes(
        request_params['scopes']
    ))
    loop.run_until_complete(
        app.setup_app(
            api_products=[product.name],
            custom_attributes= {
                "jwks-resource-url": "https://raw.githubusercontent.com/NHSDigital/identity-service-jwks/main/jwks/internal-dev/9baed6f4-1361-4a8e-8531-1f8426e3aba8.json",
                "nhs-login-allowed-proofing-level": request_params.get('requested_proofing_level')
            },
        )
    )
    app.oauth = OauthHelper(app.client_id, app.client_secret, app.callback_url)
    app.request_params = request_params
    yield product, app
    loop.run_until_complete(app.destroy_app())
    loop.run_until_complete(product.destroy_product())
Exemple #11
0
async def _product_with_full_access():
    """Creates an apigee product with access to all proxy paths and scopes.

    Returns:
        product (ApigeeApiProducts): Apigee product.
    """
    product = ApigeeApiProducts()
    await product.create_new_product()
    await _set_default_rate_limit(product)
    await product.update_scopes([
        "personal-demographics-service:USER-RESTRICTED",
        "urn:nhsd:apim:app:level3:",
        "urn:nhsd:apim:user-nhs-id:aal3:personal-demographics-service"
    ])
    # Allows access to all proxy paths - so we don't have to specify the pr proxy explicitly
    await product.update_paths(paths=["/", "/*"])
    return product
def set_quota_and_rate_limit(
    product: ApigeeApiProducts,
    rate_limit: str = "1000ps",
    quota: int = 60000,
    quota_interval: str = "1",
    quota_time_unit: str = "minute"
) -> None:
    """Sets the quota and rate limit on an apigee product.

    Args:
        product (ApigeeApiProducts): Apigee product
        rate_limit (str): The rate limit to be set.
        quota (int): The amount of requests per quota interval.
        quoata_interval (str): The length of a quota interval in quota units.
        quota_time_unit (str): The quota unit length e.g. minute.
    """
    asyncio.run(product.update_ratelimits(quota=quota,
                                          quota_interval=quota_interval,
                                          quota_time_unit=quota_time_unit,
                                          rate_limit=rate_limit))
async def test_product(apigee_organization):
    api = ApigeeApiProducts(org_name=apigee_organization)
    await api.create_new_product()
    yield api
    await api.destroy_product()
async def test_product_other_environment():
    api = ApigeeApiProducts(org_name="nhsd-nonprod")
    await api.create_new_product()
    yield api
    await api.destroy_product()
Exemple #15
0
def _set_default_rate_limit(product: ApigeeApiProducts):
    product.update_ratelimits(quota=60000,
                              quota_interval="1",
                              quota_time_unit="minute",
                              rate_limit="1000ps")