Search code examples
oauth-2.0jmeterazure-secretsazure-load-testing

JMeter and Azure Load Testing using AD Authentication - unable to read Key Vault Secrets


I have a JMeter test that uses Azure AD authentication using username/password. The JMeter test works fine when the Username and Password are read from Excel or hard coded.

I need to run this test in Azure Load Test and have created a Key Vault in Azure with the credentials but unable to get my test to read the secrets.

I have posted snippets of my JMeter test below if anyone can have a look please, I think there is maybe something missing in one of the sections? If this looks correct then probably an issue with the Azure set up. I've stripped out the client_id, tenant_id, etc. in the below code.

The secrets in Azure Key Vault are named LoadTestUsername and LoadTestPassword.

User Defined Variables

<Arguments guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
  <collectionProp name="Arguments.arguments">
    <elementProp name="username" elementType="Argument">
      <stringProp name="Argument.name">username</stringProp>
      <stringProp name="Argument.value">${__GetSecret(LoadTestUsername)} </stringProp>
      <stringProp name="Argument.metadata">=</stringProp>
    </elementProp>
    <elementProp name="password" elementType="Argument">
      <stringProp name="Argument.name">password</stringProp>
      <stringProp name="Argument.value">${__GetSecret(LoadTestPassword)} </stringProp>
      <stringProp name="Argument.metadata">=</stringProp>
    </elementProp>
  </collectionProp>
</Arguments>

Get Token HTTP Sampler

<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Get Token" enabled="true">
          <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
            <collectionProp name="Arguments.arguments">
              <elementProp name="username" elementType="HTTPArgument">
                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                <stringProp name="Argument.value">${username}</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                <stringProp name="Argument.name">username</stringProp>
              </elementProp>
              <elementProp name="password" elementType="HTTPArgument">
                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                <stringProp name="Argument.metadata">=</stringProp>
                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                <stringProp name="Argument.name">password</stringProp>
                <stringProp name="Argument.value">${password}</stringProp>
              </elementProp>
              <elementProp name="grant_type" elementType="HTTPArgument">
                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                <stringProp name="Argument.value">password</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                <stringProp name="Argument.name">grant_type</stringProp>
              </elementProp>

HTTP Header Manager

 <HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager" enabled="true">
          <collectionProp name="HeaderManager.headers">
            <elementProp name="" elementType="Header">
              <stringProp name="Header.name">Authorization</stringProp>
              <stringProp name="Header.value">Bearer ${__property(access_token)}</stringProp>
            </elementProp>
          </collectionProp>
        </HeaderManager>

Solution

  • As per the plugin documentation:

    How to install

    Download jmeter-plugins-azure-load-testing-stub-?.?.?.jar file from latest release and put it into lib/ext directory of JMeter (e.g. /usr/local/jmeter/lib/ext), then restart JMeter.

    It will allow you to use Functions Helper Dialog to generate __GetSecret() function syntax however I doubt you will be able to use it locally but it will run successfully in Azure.

    More information: