From 15c9f71bee1fa8d297d3fac7c6d04bc728265938 Mon Sep 17 00:00:00 2001 From: Silvan Date: Wed, 11 Sep 2024 11:23:24 +0200 Subject: [PATCH] test(load): add machine jwt profile test for a single user (#8593) # How the Problems Are Solved Adds a new load test to use the token endpoint with a single user by multiple threads. --- load-test/Makefile | 6 ++++ load-test/README.md | 5 ++- .../machine_jwt_profile_grant_single_user.ts | 35 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 load-test/src/use_cases/machine_jwt_profile_grant_single_user.ts diff --git a/load-test/Makefile b/load-test/Makefile index c0fdbb673c..bbd5ebf538 100644 --- a/load-test/Makefile +++ b/load-test/Makefile @@ -42,6 +42,12 @@ machine_jwt_profile_grant: ensure_modules ensure_key_pair bundle cd ../../xk6-modules && xk6 build --with xk6-zitadel=. ${K6} run --summary-trend-stats "min,avg,max,p(50),p(95),p(99)" dist/machine_jwt_profile_grant.js --vus ${VUS} --duration ${DURATION} +.PHONY: machine_jwt_profile_grant_single_user +machine_jwt_profile_grant_single_user: ensure_modules ensure_key_pair bundle + go install go.k6.io/xk6/cmd/xk6@latest + cd ../../xk6-modules && xk6 build --with xk6-zitadel=. + ${K6} run --summary-trend-stats "min,avg,max,p(50),p(95),p(99)" dist/machine_jwt_profile_grant_single_user.js --vus ${VUS} --duration ${DURATION} + .PHONY: lint lint: npm i diff --git a/load-test/README.md b/load-test/README.md index e046372ee0..b4b2a6cae9 100644 --- a/load-test/README.md +++ b/load-test/README.md @@ -52,4 +52,7 @@ Before you run the tests you need an initialized user. The tests don't implement test: creates new sessions with user id check * `make machine_jwt_profile_grant` setup: generates private/public key, creates machine users, adds a key - test: creates a token and calls user info \ No newline at end of file + test: creates a token and calls user info +* `make machine_jwt_profile_grant_single_user` + setup: generates private/public key, creates machine user, adds a key + test: creates a token and calls user info in parallel for the same user \ No newline at end of file diff --git a/load-test/src/use_cases/machine_jwt_profile_grant_single_user.ts b/load-test/src/use_cases/machine_jwt_profile_grant_single_user.ts new file mode 100644 index 0000000000..c654fb9492 --- /dev/null +++ b/load-test/src/use_cases/machine_jwt_profile_grant_single_user.ts @@ -0,0 +1,35 @@ +import { loginByUsernamePassword } from '../login_ui'; +import { createOrg, removeOrg } from '../org'; +import {createMachine, User, addMachineKey} from '../user'; +import {JWTProfileRequest, token, userinfo} from '../oidc'; +import { Config } 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`); + + const machine = await createMachine(`zitachine`, org, tokens.accessToken!); + console.info(`setup: machine ${machine.userId} created`); + const key = await addMachineKey(machine.userId, org, tokens.accessToken!, publicKey); + console.info(`setup: key ${key.keyId} added`); + + return { tokens, machine: {userId: machine.userId, keyId: key.keyId}, org }; +} + +export default function (data: any) { + token(new JWTProfileRequest(data.machine.userId, data.machine.keyId)) + .then((token) => { + userinfo(token.accessToken!) + }) +} + +export function teardown(data: any) { + removeOrg(data.org, data.tokens.accessToken); + console.info('teardown: org removed'); +}