template-monorepo/test/k6/journeys/change_password_full.js

51 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2026-05-27 09:28:13 +00:00
// Journey: enroll TOTP → step-up → change password → login with new password
2026-05-26 17:10:32 +00:00
import { post, checkError } from '../lib/http.js';
import { cfg } from '../lib/config.js';
2026-05-27 09:28:13 +00:00
import { registerAndConfirm, login } from '../lib/auth.js';
import {
changePassword,
enrollTOTP,
verifyTOTPForPasswordChange,
} from '../lib/member.js';
2026-05-26 17:10:32 +00:00
export const options = {
vus: 1,
iterations: 1,
thresholds: { checks: ['rate==1.0'] },
};
export default function () {
const { identity, tokens } = registerAndConfirm();
const bearer = { Authorization: `Bearer ${tokens.access_token}` };
const newPassword = 'K6-ChangePass-8!';
2026-05-27 09:28:13 +00:00
const { otpauthUrl } = enrollTOTP(bearer);
const stepUpToken = verifyTOTPForPasswordChange(bearer, otpauthUrl);
const data = changePassword(identity.password, newPassword, bearer, {
stepUpToken,
});
2026-05-26 17:10:32 +00:00
if (!data.ok) {
throw new Error('change password journey: expected ok=true');
}
2026-05-27 09:28:13 +00:00
const session = login({
2026-05-26 17:10:32 +00:00
email: identity.email,
password: newPassword,
2026-05-27 09:28:13 +00:00
otpauthUrl,
2026-05-26 17:10:32 +00:00
});
2026-05-27 09:28:13 +00:00
if (!session.access_token) {
2026-05-26 17:10:32 +00:00
throw new Error('change password journey: login with new password failed');
}
checkError(
post('/api/v1/auth/login', {
tenant_slug: cfg.tenantSlug,
email: identity.email,
password: identity.password,
}),
'POST /auth/login (old password after change)',
401,
28501000,
);
}