mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Added K6 tests, Added Lighthouse test result
This commit is contained in:
37
tests/k6/loadtest.js
Normal file
37
tests/k6/loadtest.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import http from 'k6/http';
|
||||
import { check } from 'k6';
|
||||
|
||||
export let options = {
|
||||
vus: 16, // number of virtual users
|
||||
duration: '30s', // test duration
|
||||
};
|
||||
export default function () {
|
||||
let environment = "http://localhost:5275";
|
||||
let username = "admin";
|
||||
let password = "admin";
|
||||
// Step 1: login, disable redirect following
|
||||
let loginRes = http.post(
|
||||
environment + '/Home/Login',
|
||||
{ Username: username, Password: password },
|
||||
{ redirects: 0 }
|
||||
);
|
||||
|
||||
// Step 2: extract the auth cookie manually
|
||||
const setCookieHeader = loginRes.headers['Set-Cookie'];
|
||||
|
||||
// Use a regex to extract the cookie value
|
||||
const match = setCookieHeader.match(/\.AspNetCore\.Cookies=([^;]+)/);
|
||||
const authCookie = match ? match[1] : null;
|
||||
|
||||
if (!authCookie) {
|
||||
throw new Error('Login failed: no auth cookie found');
|
||||
}
|
||||
|
||||
// Step 3: use it on a protected page
|
||||
const headers = { Cookie: `.AspNetCore.Cookies=${authCookie}` };
|
||||
const res = http.get(environment + '/Home/Assets', { headers });
|
||||
|
||||
check(res, {
|
||||
'authorized request succeeded': (r) => r.status === 200,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user