Unanswered question

How can i assign a client certificate per user? In NeoLoad it seems to be only globally set in the project settings.

I have some user profiles that use certificate and some not. Plus the user profiles do not share the same certificate. Is there a way to use those certificates only for some user profiles?

Nouredine A.
Nouredine A.

Nouredine A.

Level
4
5000 / 5000
points
Team

Answers

Nouredine A.
Nouredine A.

Nouredine A.

Level
4
5000 / 5000
points
Team

There's an enhancement request opened to be able to configure the use of client certificate per user profile or at server level. Currently there's a workaround that can be adjusted based on the needs but basically here is how it works.
The goal is to use a NeoLoad Javascript variable and use for example for that content:

 // This function evaluates the variable value.
// Use either the syntax ${<variable name>.col_<field number>} or ${<variable name>.<field name>} to access the value of the variable field.
function evaluate() {
 var vuname = context.currentVU.name;
 return new function() {
  this.vuname = vuname;
 };
}

This type of variable is initialized very soon in the user process. That's why you can't use a Javascript inside your user profile.


Here this JS will get the name of the virtual user profile. Save that JS variable with that name "VUNAME". Then the idea is to name your private key file with the name of your virtual user profiles.

in the NeoLoad preferences, under certificate manager, you can use that variable for the runtime certificate field: ${VUNAME.col_0}.pfx
If the password is the same for both certificate then you can use an hardcoded value in the password field or from a NeoLoad variable. If it's different depending on the user profile, you can use the same kind of tricks.


For instance, let's say your virtual user profile names are  VUA and VUB. Create a VUA.pfx and VUB.pfx certificate keys and copy them under your project folder under "client-certificates" folder.

Now if you run a check virtual user or even a test with your 3 virtual user profiles, each profile will use its own certificate whatever the virtual user instances.

Marcin B.
Marcin B.

Marcin B.

Level
0
15 / 100
points

Our solution based on answer from Nouredine.
.
.
All certificate files "certificate*.p12" are stored in directory: "client-certificates"

User Paths:
TC-001 - test case 001
TC-002 - test case 002

File variables, with value change policy: "On each iteration"
TC-001
user;certificate
user001_001;certificate_001_001.p12
user001_002;certificate_001_002.p12
...

TC-002
user;certificate
user002_001;certificate_002_001.p12
user002_002;certificate_002_002.p12
...

Variable "customer_certificate", type JavaScript, with value change policy: "On each iteration" and following script:
<code>
function evaluate() {
var token = " - ";
var pos = context.currentVU.id.indexOf(token);
if (pos < 1) {
context.fail("token '" + token + "' not found in user path: '" + context.currentVU.id.indexOf(token) + "'.");
}

var testCaseId = context.currentVU.id.substring(0, pos);
var name = testCaseId + ".certificate";
var certificate = context.variableManager.getValue(name);

return new function() {
this.certificate = certificate;
};
}
</code>

In Preferences -> Project settings -> Certificate Manager -> Runtime -> Use a different certificate for each user: ${customer_certificate.col_0}

@Nouredine thanks for the Idea :-)