コード例 #1
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()
コード例 #2
0
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())
コード例 #3
0
def base_test_app():
    """Setup & Teardown an app-restricted app for this api"""
    app = ApigeeApiDeveloperApps()
    loop = asyncio.new_event_loop()
    loop.run_until_complete(
        app.setup_app(
            api_products=[get_env("APIGEE_PRODUCT")],
            custom_attributes=_BASE_CUSTOM_ATTRIBUTES,
        ))
    app.oauth = OauthHelper(app.client_id, app.client_secret, app.callback_url)
    yield app
    loop.run_until_complete(app.destroy_app())
コード例 #4
0
def test_app():
    """Setup & Teardown an app-restricted app for this api"""
    app = ApigeeApiDeveloperApps()
    loop = asyncio.new_event_loop()
    loop.run_until_complete(
        app.setup_app(
            api_products=[get_env("APIGEE_PRODUCT")],
            custom_attributes={
                "jwks-resource-url": "https://raw.githubusercontent.com/NHSDigital/identity-service-jwks/main/jwks/internal-dev/9baed6f4-1361-4a8e-8531-1f8426e3aba8.json"  # noqa
            },
        )
    )
    app.oauth = OauthHelper(app.client_id, app.client_secret, app.callback_url)
    yield app
    loop.run_until_complete(app.destroy_app())
    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()
コード例 #6
0
    async def _setup_session(request):
        product = await _product_with_full_access()
        app = ApigeeApiDeveloperApps()

        print("\nCreating Default App..")
        await app.create_new_app(
            callback_url="https://nhsd-apim-testing-internal-dev.herokuapp.com/callback"
        )
        await app.add_api_product([product.name])

        # Set default JWT Testing resource url
        await 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"
            }
        )

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

        for item in request.node.items:
            setattr(item.cls, "oauth", oauth)

        return app, product
コード例 #7
0
 def app(self):
     """
     Import the test utils module to be able to:
         - Create apigee test application
             - Update custom attributes
             - Update custom ratelimits
             - Update products to the test application
     """
     return ApigeeApiDeveloperApps()
コード例 #8
0
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())
コード例 #9
0
def setup_session(request):
    """This fixture is automatically called once at the start of pytest execution.
    The default app created here should be modified by your tests.
    If your test requires specific app config then please create your own using
    the fixture test_app"""
    product = asyncio.run(_product_with_full_access())
    app = ApigeeApiDeveloperApps()

    print("\nCreating Default App..")
    asyncio.run(
        app.create_new_app(
            callback_url=
            "https://nhsd-apim-testing-internal-dev.herokuapp.com/callback"))
    asyncio.run(app.add_api_product([product.name]))

    # Set default JWT Testing resource url
    asyncio.run(
        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'
        }))

    oauth = OauthHelper(app.client_id, app.client_secret, app.callback_url)
    for item in request.node.items:
        setattr(item.cls, "oauth", oauth)

    yield

    # Teardown
    print("\nDestroying Default App..")
    asyncio.run(app.destroy_app())
    asyncio.run(product.destroy_product())
コード例 #10
0
def setup_session(request):
    """This fixture is called at a function level.
    The default app created here should be modified by your tests.
    """
    product = asyncio.run(_product_with_full_access())
    print("\nCreating Default App..")
    # Create a new app
    app = ApigeeApiDeveloperApps()

    asyncio.run(
        app.create_new_app(callback_url="https://example.org/callback"))
    # Assign the new product to the app
    asyncio.run(app.add_api_product([product.name]))

    # Set default JWT Testing resource url
    asyncio.run(
        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'
        }))

    asyncio.run(product.update_environments([config.ENVIRONMENT]))
    oauth = OauthHelper(app.client_id, app.client_secret, app.callback_url)
    resp = asyncio.run(
        oauth.get_token_response(grant_type="authorization_code"))
    token = resp["body"]["access_token"]

    yield product, app, token

    # Teardown
    print("\nDestroying Default App..")
    asyncio.run(app.destroy_app())
    asyncio.run(product.destroy_product())
コード例 #11
0
async def _api():
    """ Setup and Teardown, create an app at the start and then destroy it at the end """

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

    print("\nCreating Test App..")
    await api.create_new_app()

    yield api
    # teardown
    print("\nDestroying Test App..")
    await api.destroy_app()
コード例 #12
0
    async def test_app(self):
        """Testing App Setup"""
        apigee_app = ApigeeApiDeveloperApps()
        print("Creating Test App..")
        await apigee_app.create_new_app(
            callback_url=
            "https://nhsd-apim-testing-internal-dev.herokuapp.com/callback")

        # 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=[config.MOCK_PROXY_PATH])

        yield apigee_app
        print("Destroying Test App..")
        await apigee_app.destroy_app()
コード例 #13
0
async def _test_app():
    """ Setup and Teardown, create an app at the start and then destroy it at the end """

    test_app = ApigeeApiDeveloperApps()

    print("\nCreating Test App..")
    await test_app.create_new_app(
        callback_url=
        "https://nhsd-apim-testing-internal-dev.herokuapp.com/callback")
    await test_app.add_api_product(["internal-testing-internal-dev"])

    # Set JWT Testing resource url
    await test_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'
    })

    yield test_app
    # teardown
    print("\nDestroying Test App..")
    await test_app.destroy_app()
コード例 #14
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())
コード例 #15
0
async def test_app_no_jwks_url(apigee_organization, test_product):
    api = ApigeeApiDeveloperApps(org_name=apigee_organization)
    await api.create_new_app()
    yield api
    await api.destroy_app()
コード例 #16
0
async def test_app_other_environment(test_product_other_environment):
    api = ApigeeApiDeveloperApps(org_name="nhsd-nonprod")
    await api.create_new_app()
    yield api
    await api.destroy_app()
コード例 #17
0
async def test_app_no_product_subscriptions(apigee_organization):
    api = ApigeeApiDeveloperApps(org_name=apigee_organization)
    await api.create_new_app()
    yield api
    await api.destroy_app()
コード例 #18
0
def app():
    return ApigeeApiDeveloperApps()