Skip to content

Commit

Permalink
finish saml-uc
Browse files Browse the repository at this point in the history
  • Loading branch information
clauyan committed Oct 30, 2024
1 parent 31591a8 commit ac7cb51
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions loadtest/usecases/2_goto-sp-saml.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { check, fail, sleep } from "k6";
import { check, fail, group } from "k6";
import { get } from "k6/http";
import { getDefaultOptions } from "../util/config.ts";
import { prettyLog } from "../util/debug.ts";
import { loadPage, login } from "../util/page.ts";
Expand All @@ -15,18 +16,43 @@ export default wrapTestFunction(main);

function main(users = getDefaultAdminMix()) {
const { providers } = login(users.getLogin());
const target = providers.find((p) => p.name == serviceProviderName);
if (!target) fail(`could not find sp ${serviceProviderName}`);
const response = loadPage(target.url);
check(response, {
"found Anmeldung": (r) => {
try {

const response = group("follow link", () => {
const target = providers.find((p) => p.name == serviceProviderName);
if (!target) fail(`could not find sp ${serviceProviderName}`);
return loadPage(target.url);
});

group("finish saml", () => {
let submissionResponse = response.submitForm();
check(submissionResponse, {
"post to kc succeeded": (r) => r.status == 200,
});
submissionResponse = submissionResponse.submitForm();
check(submissionResponse, {
"post to school-sh succeeded": (r) => r.status == 200,
});

const stringifiedBody = submissionResponse.body?.toString();
if (!stringifiedBody) {
fail("no body returned");
}
const matches = RegExp(/URL='(\S+)'/).exec(stringifiedBody);
const redirectUrl = matches?.at(matches?.length - 1) ?? undefined;
const redirectUrlFound = check(redirectUrl, {
"redirect url found": (url) => url != undefined,
});
if (!redirectUrlFound) fail("redirect url not found");
const redirectResponse = get(redirectUrl!, {
headers: {
referer: submissionResponse.url,
},
tags: { name: "redirect to school-sh login" },
});
check(redirectResponse, {
"reached school-sh login": (r) => {
return r.html().find("#loginBox").text().includes("Anmeldung");
} catch (error) {
prettyLog(error);
return false;
}
},
},
});
});
sleep(1);
}

0 comments on commit ac7cb51

Please sign in to comment.