actions-test/tests/tests/ws.js
2023-03-20 21:48:44 +01:00

233 lines
No EOL
7.1 KiB
JavaScript

import { generateSigningKey, sign } from '../../dist/sys/crypto.js';
import { PERMISSIONS } from '../../dist/server/permissions.js';
let name1 = "testUser1";
let name2 = "testUser2";
let name3 = "testUser3";
let accountKey = "123456789";
let room1 = "r1";
let room2 = "r2";
let room3 = "r3";
let { privateKey, publicKey } = await generateSigningKey();
const list = [
["signup", async (handler, req, newHandler) => {
await req(handler, "signup", {
name: name1,
server: "localhost:7224",
accountKey
}, "ok", "");
await req(handler, "signup", {
name: name1,
server: "localhost:7224",
accountKey
}, "error", "wrongstate");
await req(await newHandler(), "signup", {
name: name1,
server: "localhost:7224",
accountKey
}, "error", "existence");
await req(await newHandler(), "signup", {
name: name2,
server: "localhost:7224",
accountKey
}, "ok", "");
await req(await newHandler(), "signup", {
name: name3,
server: "localhost:7224",
accountKey
}, "error", "config");
}], ["remote", async (handler, req, newHandler) => {
await req(handler, "signin", {
name: name1,
server: "localhost:7224",
accountKey
}, "ok", "");
let signature = (await req(handler, "createSignature", {
publicKey
}, "ok", null)).sign;
let falseSignature = await sign("lol", privateKey);
let h2 = await newHandler();
await req(h2, "remote1", {
name: name1,
server: "localhost:7223",
publicKey,
sign: signature
}, "error", "signature");
await req(h2, "remote1", {
name: name1,
server: "localhost:7224",
publicKey,
sign: falseSignature
}, "error", "signature");
let challenge = (await req(h2, "remote1", {
name: name1,
server: "localhost:7224",
publicKey,
sign: signature
}, "ok", null)).challenge;
await req(h2, "remote1", {
name: name1,
server: "localhost:7224",
publicKey,
sign: signature
}, "error", "wrongstate");
await req(h2, "remote2", {
sign: await sign(challenge + "lol", privateKey)
}, "error", "signature");
await req(h2, "remote2", {
sign: await sign(challenge, privateKey)
}, "ok", "");
}], ["account", async (handler, req, newHandler) => {
await req(handler, "signin", {
name: name1,
server: "localhost:7224",
accountKey
}, "ok", "");
await req(handler, "getMyAccount", {}, "ok", {
rights: PERMISSIONS.ALL,
name: name1,
viewable: true,
maxRooms: 2,
maxRoomSize: 10,
maxUsersPerRoom: 2,
});
let h2 = await newHandler();
await req(h2, "signin", {
name: name2,
server: "localhost:7224",
accountKey
}, "ok", "");
await req(h2, "getMyAccount", {}, "ok", {
rights: PERMISSIONS.DEFAULT,
name: name2,
viewable: true,
maxRooms: 2,
maxRoomSize: 10,
maxUsersPerRoom: 2,
});
}], ["change account", async (handler, req, newHandler) => {
await req(handler, "signin", {
name: name2,
server: "localhost:7224",
accountKey
}, "ok", "");
await req(handler, "changePassword", {
accountKey: accountKey + "lol"
}, "ok", "");
let h2 = await newHandler();
await req(h2, "signin", {
name: name2,
server: "localhost:7224",
accountKey
}, "error", "auth");
await req(h2, "signin", {
name: name2,
server: "localhost:7224",
accountKey: accountKey + "lol"
}, "ok", "");
await req(h2, "deleteAccount", {}, "ok", "");
let h3 = await newHandler();
await req(h3, "signin", {
name: name2,
server: "localhost:7224",
accountKey: accountKey + "lol"
}, "error", "auth");
}], ["room Owner", async (handler, req, newHandler) => {
await req(handler, "signin", {
name: name1,
server: "localhost:7224",
accountKey
}, "ok", "");
await req(handler, "createRoom", {
room: room1,
server: "localhost:7224",
title: "Test Room 1",
description: "some desc",
visibility: 0,
icon: "shopping"
}, "ok", "");
await req(handler, "createRoom", {
room: room1,
server: "localhost:7224",
title: "Test Room 1",
description: "some desc",
visibility: 0,
icon: "shopping"
}, "error", "existence");
await req(handler, "createRoom", {
room: room2,
server: "localhost:7224",
title: "Test Room 2",
description: "some desc 2",
visibility: 1,
icon: ""
}, "ok", "");
await req(handler, "createRoom", {
room: room3,
server: "localhost:7224",
title: "Test Room 2",
description: "some desc 2",
visibility: 1,
icon: ""
}, "error", "limit");
await req(handler, "listRooms", {}, "ok", [
{
name: room1,
server: "localhost:7224",
owner: name1,
rights: 0b11111,
title: "Test Room 1",
description: "some desc",
visibility: 0,
icon: "shopping",
debug: true
}, {
name: room2,
server: "localhost:7224",
owner: name1,
rights: 0b11111,
title: "Test Room 2",
description: "some desc 2",
visibility: 1,
icon: "",
debug: true
}
]);
await req(handler, "deleteRoom", {
room: room2 + "lol",
server: "localhost:7224"
}, "error", "existence");
await req(handler, "deleteRoom", {
room: room2,
server: "localhost:7224"
}, "ok", "");
await req(handler, "deleteRoom", {
room: room2,
server: "localhost:7224"
}, "error", "existence");
await req(handler, "listRooms", {}, "ok", [
{
name: room1,
server: "localhost:7224",
owner: name1,
rights: 0b11111,
title: "Test Room 1",
description: "some desc",
visibility: 0,
icon: "shopping",
debug: true
}
]);
}]
];
export default list;