Load test secured endpoints with Azure Load Testing

In this article, you learn how to load test secured applications with Azure Load Testing. Secured applications require authentication to access the endpoint. Azure Load Testing enables you to authenticate with endpoints by using shared secrets or credentials, or to authenticate with client certificates.

Prerequisites

Authenticate with a shared secret or credentials

In this scenario, the application endpoint requires that you use a shared secret, such as an access token, an API key, or user credentials to authenticate. In the JMeter script, you have to provide this security information with each application request. For example, to load test a web endpoint that uses OAuth 2.0, you add an Authorization header, which contains the access token, to the HTTP request.

The following diagram shows how to use shared secrets or credentials to authenticate with an application endpoint in your load test. To avoid storing, and disclosing, security information in the JMeter script, you can securely store secrets in Azure Key Vault or in the CI/CD secrets store. In the JMeter script, you then use a custom JMeter function GetSecret to retrieve the secret value. Finally, you specify the secret value in the JMeter request to the application endpoint.

Diagram that shows how to use shared-secret authentication with Azure Load Testing.

  1. Add the security information in a secrets store in either of two ways:

  2. Add the secret to the load test configuration:

    To add a secret to your load test in the Azure portal:

    1. Navigate to your load testing resource in the Azure portal. If you don't have a load test yet, create a new load test using a JMeter script.

    2. On the left pane, select Tests to view the list of load tests.

    3. Select your test from the list, and then select Edit, to edit the load test configuration.

      Screenshot that shows how to edit a load test in the Azure portal.

    4. On the Parameters tab, enter the details of the secret.

      Field Value
      Name Name of the secret. You'll provide this name to the GetSecret function to retrieve the secret value in the JMeter script.
      Value Matches the Azure Key Vault Secret identifier.

      Screenshot that shows how to add secrets to a load test in the Azure portal.

    5. Select Apply, to save the load test configuration changes.

  3. Update the JMeter script to retrieve the secret value:

    1. Create a user-defined variable that retrieves the secret value with the GetSecret custom function:

      Screenshot that shows how to add a user-defined variable that uses the GetSecret function in JMeter.

    2. Update the JMeter sampler component to pass the secret in the request. For example, to provide an OAuth2 access token, you configure the Authorization HTTP header:

      Screenshot that shows how to add an authorization header to a request in JMeter.

When you now run your load test, the JMeter script can retrieve the secret information from the secrets store and authenticate with the application endpoint.

Authenticate with client certificates

In this scenario, the application endpoint requires that you use a client certificate to authenticate. Azure Load Testing supports Public Key Certificate Standard #12 (PKCS12) type of certificates. You can use only one client certificate in a load test.

The following diagram shows how to use a client certificate to authenticate with an application endpoint in your load test. To avoid storing, and disclosing, the client certificate alongside the JMeter script, you store the certificate in Azure Key Vault. When you run the load test, Azure Load Testing reads the certificate from the key vault, and automatically passes it to JMeter. JMeter then transparently passes the certificate in all application requests. You don't have to update the JMeter script to use the client certificate.

Diagram that shows how to use client-certificate authentication with Azure Load Testing.

  1. Follow the steps in Import a certificate to store your certificate in Azure Key Vault.

    Important

    Azure Load Testing only supports PKCS12 certificates. Upload the client certificate in PFX file format.

  2. Verify that your load testing resource has permissions to retrieve the certificate from your key vault.

    Azure Load Testing retrieves the certificate as a secret to ensure that the private key for the certificate is available. Assign the Get secret permission to your load testing resource in Azure Key Vault.

  3. Add the certificate to the load test configuration:

    To add a client certificate to your load test in the Azure portal:

    1. Navigate to your load testing resource in the Azure portal. If you don't have a load test yet, create a new load test using a JMeter script.

    2. On the left pane, select Tests to view the list of load tests.

    3. Select your test from the list, and then select Edit, to edit the load test configuration.

      Screenshot that shows how to edit a load test in the Azure portal.

    4. On the Parameters tab, enter the details of the certificate.

      Field Value
      Name Name of the certificate.
      Value Matches the Azure Key Vault Secret identifier of the certificate.

      Screenshot that shows how to add a certificate to a load test in the Azure portal.

    5. Select Apply, to save the load test configuration changes.

When you now run your load test, Azure Load Testing retrieves the client certificate from Azure Key Vault, and injects it in the JMeter web requests.

Next steps