From 8ea756921dc627934c520ef26c8d57008a6f3aee Mon Sep 17 00:00:00 2001 From: jusax23 Date: Sat, 18 Mar 2023 12:46:17 +0100 Subject: [PATCH] post test --- tests/post.js | 2 +- tests/tests/post.js | 46 +++++++++++++++++++++++++++++++++++++++++++++ tests/tests/ws.js | 2 +- tests/ws.js | 2 +- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/tests/post.js b/tests/post.js index 8bacc9a..c8e9700 100644 --- a/tests/post.js +++ b/tests/post.js @@ -62,7 +62,7 @@ async function postTester(url) { } if (typeof expData == "object" && expData != null) { if (!shallowEqual(expData, resp.data)) { - console.error(`Expected data: '${expData}', but got: '${resp.data}'`); + console.error(`Expected data: '${JSON.stringify(expData, null, 2)}', but got: '${JSON.stringify(resp.data, null, 2)}'`); kill(); process.exit(1); } diff --git a/tests/tests/post.js b/tests/tests/post.js index 6d787eb..f3fc8df 100644 --- a/tests/tests/post.js +++ b/tests/tests/post.js @@ -1,4 +1,5 @@ import { generateSigningKey, sign } from '../../dist/sys/crypto.js'; +import { PERMISSIONS } from '../../dist/server/permissions.js'; let name1 = "testUser1"; let name2 = "testUser2"; @@ -88,6 +89,51 @@ const list = [ sign: await sign(challenge, privateKey) }, "ok", ""); + }], ["account", async (req) => { + await req({ + "authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}` + }, "getMyAccount", {}, "ok", { + rights: PERMISSIONS.ALL, + name: name1, + viewable: true, + maxRooms: 3, + maxRoomSize: 10, + maxUsersPerRoom: 2, + }); + await req({ + "authorization": `Digest name=${name2} server=localhost:7224 accountKey=${accountKey}` + }, "getMyAccount", {}, "ok", { + rights: PERMISSIONS.DEFAULT, + name: name2, + viewable: true, + maxRooms: 3, + maxRoomSize: 10, + maxUsersPerRoom: 2, + }); + }], ["change account", async (req) => { + await req({ + "authorization": `Digest name=${name2} server=localhost:7224 accountKey=${accountKey}` + }, "changePassword", { + accountKey: accountKey + "lol" + }, "ok", ""); + await req({}, "signin", { + name: name2, + server: "localhost:7224", + accountKey + }, "error", "auth"); + await req({}, "signin", { + name: name2, + server: "localhost:7224", + accountKey: accountKey + "lol" + }, "ok", ""); + await req({ + "authorization": `Digest name=${name2} server=localhost:7224 accountKey=${accountKey + "lol"}` + }, "deleteAccount", {}, "ok", ""); + await req({}, "signin", { + name: name2, + server: "localhost:7224", + accountKey: accountKey + "lol" + }, "error", "auth"); }] ]; diff --git a/tests/tests/ws.js b/tests/tests/ws.js index beaded8..f93419b 100644 --- a/tests/tests/ws.js +++ b/tests/tests/ws.js @@ -104,7 +104,7 @@ const list = [ maxRoomSize: 10, maxUsersPerRoom: 2, }); - }], ["account", async (handler, req, newHandler) => { + }], ["change account", async (handler, req, newHandler) => { await req(handler, "signin", { name: name2, server: "localhost:7224", diff --git a/tests/ws.js b/tests/ws.js index 8dffe19..da62c28 100644 --- a/tests/ws.js +++ b/tests/ws.js @@ -110,7 +110,7 @@ async function wsTester(url) { } if (typeof expData == "object" && expData != null) { if (!shallowEqual(expData, resp.data)) { - console.error(`Expected data: '${expData}', but got: '${resp.data}'`); + console.error(`Expected data: '${JSON.stringify(expData, null, 2)}', but got: '${JSON.stringify(resp.data, null, 2)}'`); kill(); process.exit(1); }