Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
fix: do not crash on failed login + clear cookiejar before logging in
Browse files Browse the repository at this point in the history
  • Loading branch information
juniorode committed May 16, 2024
1 parent 51a9f67 commit 126c455
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 47 deletions.
92 changes: 48 additions & 44 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ var T = Object.defineProperty;
var U = (o, e, r) => e in o ? T(o, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : o[e] = r;
var m = (o, e, r) => (U(o, typeof e != "symbol" ? e + "" : e, r), r);
import c from "k6/http";
import { check as u, fail as f } from "k6";
import { check as u, fail as g } from "k6";
import { FormData as O } from "https://jslib.k6.io/formdata/0.0.2/index.js";
import { URL as D } from "https://jslib.k6.io/url/1.0.0/index.js";
import { URL as I } from "https://jslib.k6.io/url/1.0.0/index.js";
const h = {
COOKIE: 0,
OAUTH2: 1
Expand All @@ -28,7 +28,7 @@ class C {
return this.cookies ? this.cookies.filter((r) => r.name === e).map((r) => r.value)[0] : null;
}
}
const E = __ENV.BASE_URL, I = 30 * 60, k = __ENV.ROOT_URL, l = function(o) {
const D = __ENV.BASE_URL, E = 30 * 60, k = __ENV.ROOT_URL, l = function(o) {
let e;
return o ? o.mode === h.COOKIE ? e = { "x-xsrf-token": o.getCookie("XSRF-TOKEN") || "" } : o.mode === h.OAUTH2 ? e = { Authorization: `Bearer ${o.token}` } : e = {} : e = {}, e;
}, X = function(o, e) {
Expand All @@ -47,24 +47,28 @@ const E = __ENV.BASE_URL, I = 30 * 60, k = __ENV.ROOT_URL, l = function(o) {
"should get a valid userId": (r) => !!r.json("userId")
}), e.json("userId");
}, A = function(o, e) {
let r = {
const r = c.cookieJar();
r.clear(k);
let t = {
email: o,
password: e,
callBack: "",
detail: ""
};
const t = c.post(`${k}/auth/login`, r, {
const s = c.post(`${k}/auth/login`, t, {
redirects: 0
});
u(t, {
if (u(s, {
"should redirect connected user to login page": (a) => a.status === 302,
"should have set an auth cookie": (a) => a.cookies.oneSessionId !== null && a.cookies.oneSessionId !== void 0
}), c.cookieJar().set(k, "oneSessionId", t.cookies.oneSessionId[0].value);
const n = Object.keys(t.cookies).map((a) => ({ name: a, value: t.cookies[a][0].value }));
}), !s.cookies.oneSessionId)
return console.error(`Could not get oneSessionId for ${o}`), null;
r.set(k, "oneSessionId", s.cookies.oneSessionId[0].value);
const n = Object.keys(s.cookies).map((a) => ({ name: a, value: s.cookies[a][0].value }));
return new C(
t.cookies.oneSessionId[0].value,
s.cookies.oneSessionId[0].value,
h.COOKIE,
I,
E,
n
);
}, Y = function(o) {
Expand Down Expand Up @@ -112,7 +116,7 @@ function ee(o, e, r) {
return s || console.error(e, o), s;
}
const oe = function(o, e) {
const r = c.get(`${E}/metrics`, {
const r = c.get(`${D}/metrics`, {
headers: l(e)
});
u(r, {
Expand All @@ -124,7 +128,7 @@ const oe = function(o, e) {
if (s.indexOf(`${o} `) === 0)
return parseFloat(s.substring(o.length + 1).trim());
return console.error("Metric", o, "not found"), null;
}, d = __ENV.ROOT_URL, N = new D(d).hostname;
}, d = __ENV.ROOT_URL, N = new I(d).hostname;
function y(o, e) {
let r = c.get(`${d}/directory/structure/admin/list`, {
headers: l(e)
Expand All @@ -145,7 +149,7 @@ function te(o, e) {
let r = c.get(`${d}/directory/structure/${o.id}/users`, {
headers: l(e)
});
r.status != 200 && f(`Cannot fetch users of structure ${o.id} : ${r}`);
r.status != 200 && g(`Cannot fetch users of structure ${o.id} : ${r}`);
const t = JSON.parse(r.body);
for (let s = 0; s < t.length; s++) {
const n = t[s];
Expand All @@ -160,7 +164,7 @@ function J(o) {
redirects: 0,
headers: { Host: N }
});
r.status !== 302 && (console.error(r), f(
r.status !== 302 && (console.error(r), g(
`Could not activate user ${o.login} : ${r.status} - ${r.body}`
));
}
Expand All @@ -175,15 +179,15 @@ function se(o, e, r, t) {
else {
const i = l(t);
i["content-type"] = "application/json";
const g = { headers: i }, p = JSON.stringify({
const f = { headers: i }, p = JSON.stringify({
groupId: a.id,
roleIds: (a.roles || []).concat([e.id])
}), S = c.post(
}), b = c.post(
`${d}/appregistry/authorize/group?schoolId=${o.id}`,
p,
g
f
);
u(S, {
u(b, {
"link role to structure": (_) => _.status == 200
});
}
Expand All @@ -200,7 +204,7 @@ function ne(o, e, r) {
name: o
});
let a = c.post(`${d}/directory/school`, n, s);
a.status !== 201 && (console.error(a.body), f(`Could not create structure ${o}`)), t = y(o, r);
a.status !== 201 && (console.error(a.body), g(`Could not create structure ${o}`)), t = y(o, r);
}
return t;
}
Expand All @@ -225,14 +229,14 @@ function j(o, e, r) {
s.append("type", "CSV"), s.append("structureName", o);
let n, a, i;
"teachers" in e ? (n = e.teachers, a = e.students, i = e.responsables) : n = e, s.append("Teacher", c.file(n, "enseignants.csv")), a && s.append("Student", c.file(a, "eleves.csv")), i && s.append("Relative", c.file(i, "responsables.csv"));
const g = l(r);
g["Content-Type"] = "multipart/form-data; boundary=" + s.boundary;
const p = { headers: g };
const f = l(r);
f["Content-Type"] = "multipart/form-data; boundary=" + s.boundary;
const p = { headers: f };
c.post(
`${d}/directory/wizard/import`,
s.body(),
p
).status != 200 && f(`Could not create structure ${o}`), t = y(o, r);
).status != 200 && g(`Could not create structure ${o}`), t = y(o, r);
}
return t;
}
Expand All @@ -247,7 +251,7 @@ function ae(o, e, r) {
n["content-type"] = "application/json", c.put(
`${d}/directory/structure/${e.id}/parent/${o.id}`,
"{}"
).status !== 200 && f(
).status !== 200 && g(
`Could not attach structure ${e.name} as a child of ${o.name}`
), t = !0;
}
Expand All @@ -260,11 +264,11 @@ function le(o, e, r) {
"teachers" in e ? (s = e.teachers, n = e.students, a = e.responsables) : s = e, t.append("Teacher", c.file(s, "enseignants.csv")), n && t.append("Student", c.file(n, "eleves.csv")), a && t.append("Relative", c.file(a, "responsables.csv"));
const i = l(r);
i["Content-Type"] = "multipart/form-data; boundary=" + t.boundary;
const g = { headers: i };
const f = { headers: i };
return c.post(
`${d}/directory/wizard/import`,
t.body(),
g
f
);
}
function ie(o) {
Expand Down Expand Up @@ -293,11 +297,11 @@ function pe(o, e) {
(p) => p.name === o
)[0].actions.map((p) => p[0]), i = l(e);
i["content-type"] = "application/json";
const g = {
const f = {
role: r,
actions: a
};
s = c.post(`${w}/appregistry/role`, JSON.stringify(g), {
s = c.post(`${w}/appregistry/role`, JSON.stringify(f), {
headers: i
}), console.log(s), u(s, { "save role ok": (p) => p.status == 201 }), t = v(r, e);
}
Expand Down Expand Up @@ -359,7 +363,7 @@ const F = __ENV.ROOT_URL, ue = [
"org-entcore-workspace-controllers-WorkspaceController|commentFolder",
"org-entcore-workspace-controllers-WorkspaceController|commentDocument"
];
function ge(o, e) {
function fe(o, e) {
let r = l(e);
const t = new O();
t.append("file", c.file(o, "file.txt")), r["Content-Type"] = "multipart/form-data; boundary=" + t.boundary;
Expand All @@ -369,7 +373,7 @@ function ge(o, e) {
}), JSON.parse(s.body);
}
const G = __ENV.ROOT_URL;
function fe(o, e, r) {
function ge(o, e, r) {
const t = l(r);
t["content-type"] = "application/json";
const s = JSON.stringify(e);
Expand All @@ -386,7 +390,7 @@ function ke(o, e, r) {
);
return t.status !== 200 && (console.error(
`Error while adding communication between ${o} -> ${e}`
), console.error(t), f(`could not add communication between ${o} -> ${e}`)), t;
), console.error(t), g(`could not add communication between ${o} -> ${e}`)), t;
}
const $ = __ENV.ROOT_URL;
function me(o, e, r) {
Expand Down Expand Up @@ -414,8 +418,8 @@ function me(o, e, r) {
}), a = c.put(`${$}/directory/group/${i}`, n, { headers: s }), u(a, {
"set broadcast group for teachers": (p) => p.status === 200
});
const g = V(e, r).id;
L(i, [g], r), t = R(o, e, r);
const f = V(e, r).id;
L(i, [f], r), t = R(o, e, r);
}
return t;
}
Expand All @@ -428,19 +432,19 @@ function L(o, e, r) {
"{}",
{ headers: t }
);
n.status !== 200 && (console.error(n), f(`Cannot open comm rule from ${s} to ${o}`));
n.status !== 200 && (console.error(n), g(`Cannot open comm rule from ${s} to ${o}`));
}
}
function V(o, e) {
return b("teachers", o, e);
return S("teachers", o, e);
}
function he(o, e) {
return b("students", o, e);
return S("students", o, e);
}
function ye(o, e) {
return b("relatives", o, e);
return S("relatives", o, e);
}
function b(o, e, r) {
function S(o, e, r) {
return W(e.id, r).filter((s) => {
const n = s.name.toLowerCase();
return n === `${e.name} group ${o}.`.toLowerCase() || n === `${o} from group ${e.name}.`.toLowerCase();
Expand All @@ -459,14 +463,14 @@ function R(o, e, r) {
}
function we(o, e, r = 200) {
const t = r || 200;
o.status != t && (console.error(`ko - ${e}. Expecting ${t} but got ${o.status}`), console.error(o), f(e + " ko"));
o.status != t && (console.error(`ko - ${e}. Expecting ${t} but got ${o.status}`), console.error(o), g(e + " ko"));
}
function $e(o, e) {
const r = {};
r[e] = () => o, u({}, r) || f(e);
r[e] = () => o, u({}, r) || g(e);
}
export {
E as BASE_URL,
D as BASE_URL,
C as Session,
h as SessionMode,
ue as WS_MANAGER_SHARE,
Expand All @@ -491,7 +495,7 @@ export {
l as getHeaders,
oe as getMetricValue,
ye as getParentRole,
b as getProfileGroupOfStructure,
S as getProfileGroupOfStructure,
x as getRandomUser,
Z as getRandomUserWithProfile,
v as getRoleByName,
Expand All @@ -503,8 +507,8 @@ export {
le as importUsers,
se as linkRoleToUsers,
X as searchUser,
fe as shareFile,
ge as shareFile,
Y as switchSession,
ie as triggerImport,
ge as uploadFile
fe as uploadFile
};
Loading

0 comments on commit 126c455

Please sign in to comment.