Skip to content

Commit

Permalink
Merge pull request #302 from projektwahl/more-tests
Browse files Browse the repository at this point in the history
Test sudo
  • Loading branch information
mohe2015 authored Apr 16, 2022
2 parents 94344fc + 45fa757 commit 4d8cb23
Showing 1 changed file with 73 additions and 2 deletions.
75 changes: 73 additions & 2 deletions tests/e2e/api-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1138,14 +1138,85 @@ async function testChoices() {
});
}

async function testSudo() {
const session_id = await getAdminSessionId();

let headers;

let [r] = await request(
{
[constants.HTTP2_HEADER_METHOD]: constants.HTTP2_METHOD_POST,
[constants.HTTP2_HEADER_PATH]: `/api/v1/sudo`,
[constants.HTTP2_HEADER_COOKIE]: `strict_id=${session_id}`,
"x-csrf-protection": "projektwahl",
},
JSON.stringify({})
);
assert.deepEqual(JSON.parse(r), {
success: false,
error: {
issues: [
{
code: "invalid_type",
expected: "number",
received: "undefined",
path: ["id"],
message: "Pflichtfeld",
},
],
name: "ZodError",
},
});

[r, headers] = await request(
{
[constants.HTTP2_HEADER_METHOD]: constants.HTTP2_METHOD_POST,
[constants.HTTP2_HEADER_PATH]: `/api/v1/sudo`,
[constants.HTTP2_HEADER_COOKIE]: `strict_id=${session_id}`,
"x-csrf-protection": "projektwahl",
},
JSON.stringify({
id: 2,
})
);
const sudo_session_id = (headers["set-cookie"] || "")[0]
.split(";")[0]
.split("=")[1];
assert.deepEqual(JSON.parse(r), { success: true, data: {} });

[r, headers] = await request(
{
[constants.HTTP2_HEADER_METHOD]: constants.HTTP2_METHOD_POST,
[constants.HTTP2_HEADER_PATH]: `/api/v1/sudo`,
[constants.HTTP2_HEADER_COOKIE]: `strict_id=${sudo_session_id}`,
"x-csrf-protection": "projektwahl",
},
JSON.stringify({
id: 2,
})
);
assert.deepEqual(JSON.parse(r), {
success: false,
error: {
issues: [
{
code: "custom",
path: ["forbidden"],
message: "Unzureichende Berechtigung!",
},
],
},
});
}

await testSudo();

await testChoices();

await testCreateOrUpdateProjects();

await testCreateOrUpdateUsers();

console.log("done");

await testLogin();

await sleep(5000);
Expand Down

0 comments on commit 4d8cb23

Please sign in to comment.