mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-16 02:35:12 +00:00
test(load): machine jwt profile grant (#8482)
# Which Problems Are Solved Currently there was no load test present for machine jwt profile grant. This test is now added # How the Problems Are Solved K6 test implemented. # Additional Context - part of https://github.com/zitadel/zitadel/issues/8352
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { loginByUsernamePassword } from '../login_ui';
|
||||
import { createOrg, removeOrg } from '../org';
|
||||
import {createMachine, User, addMachineKey} from '../user';
|
||||
import {JWTProfileRequest, token, userinfo} from '../oidc';
|
||||
import { Config, MaxVUs } from '../config';
|
||||
import encoding from 'k6/encoding';
|
||||
|
||||
const publicKey = encoding.b64encode(open('../.keys/key.pem.pub'));
|
||||
|
||||
export async function setup() {
|
||||
const tokens = loginByUsernamePassword(Config.admin as User);
|
||||
console.info('setup: admin signed in');
|
||||
|
||||
const org = await createOrg(tokens.accessToken!);
|
||||
console.info(`setup: org (${org.organizationId}) created`);
|
||||
|
||||
let machines = (
|
||||
await Promise.all(
|
||||
Array.from({ length: MaxVUs() }, (_, i) => {
|
||||
return createMachine(`zitachine-${i}`, org, tokens.accessToken!);
|
||||
}),
|
||||
)
|
||||
).map((machine) => {
|
||||
return { userId: machine.userId, loginName: machine.loginNames[0] };
|
||||
});
|
||||
console.info(`setup: ${machines.length} machines created`);
|
||||
|
||||
let keys = (
|
||||
await Promise.all(
|
||||
machines.map((machine) => {
|
||||
return addMachineKey(
|
||||
machine.userId,
|
||||
org,
|
||||
tokens.accessToken!,
|
||||
publicKey,
|
||||
);
|
||||
}),
|
||||
)
|
||||
).map((key, i) => {
|
||||
return { userId: machines[i].userId, keyId: key.keyId };
|
||||
});
|
||||
console.info(`setup: ${keys.length} keys added`);
|
||||
|
||||
return { tokens, machines: keys, org };
|
||||
}
|
||||
|
||||
export default function (data: any) {
|
||||
token(new JWTProfileRequest(data.machines[__VU - 1].userId, data.machines[__VU - 1].keyId))
|
||||
.then((token) => {
|
||||
userinfo(token.accessToken!)
|
||||
})
|
||||
}
|
||||
|
||||
export function teardown(data: any) {
|
||||
removeOrg(data.org, data.tokens.accessToken);
|
||||
console.info('teardown: org removed');
|
||||
}
|
||||
Reference in New Issue
Block a user