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 (req) => { await req({}, "signup", { name: name1, server: "localhost:7224", accountKey }, "ok", ""); await req({}, "signup", { name: name1, server: "localhost:7224", accountKey }, "error", "existence"); await req({}, "signup", { name: name2, server: "localhost:7224", accountKey }, "ok", ""); await req({}, "signup", { name: name2, server: "localhost:7224", accountKey }, "error", "config"); }], ["remote", async (req) => { let signature = (await req({ "authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}` }, "createSignature", { publicKey }, "ok", null)).sign; let falseSignature = await sign("lol", privateKey); let token = (await req({}, "requestTempToken", {}, "ok", { token: null })).token; await req({ "authorization": `Bearer ${token}` }, "remote1", { name: name1, server: "localhost:7223", publicKey, sign: signature }, "error", "signature"); await req({ "authorization": `Bearer ${token}` }, "remote1", { name: name1, server: "localhost:7224", publicKey, sign: falseSignature }, "error", "signature"); let challenge = (await req({ "authorization": `Bearer ${token}` }, "remote1", { name: name1, server: "localhost:7224", publicKey, sign: signature }, "ok", null)).challenge; await req({ "authorization": `Bearer ${token}` }, "remote1", { name: name1, server: "localhost:7224", publicKey, sign: signature }, "error", "wrongstate"); await req({ "authorization": `Bearer ${token}` }, "remote2", { sign: await sign(challenge + "lol", privateKey) }, "error", "signature"); await req({ "authorization": `Bearer ${token}` }, "remote2", { 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: 2, 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: 2, 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"); }], ["room Owner", async (req) => { await req({ "authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}` }, "createRoom", { room: room1, server: "localhost:7224", title: "Test Room 1", description: "some desc", visibility: 0, icon: "shopping" }, "ok", ""); await req({ "authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}` }, "createRoom", { room: room1, server: "localhost:7224", title: "Test Room 1", description: "some desc", visibility: 0, icon: "shopping" }, "error", "existence"); await req({ "authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}` }, "createRoom", { room: room2, server: "localhost:7224", title: "Test Room 2", description: "some desc 2", visibility: 1, icon: "" }, "ok", ""); await req({ "authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}` }, "createRoom", { room: room3, server: "localhost:7224", title: "Test Room 2", description: "some desc 2", visibility: 1, icon: "" }, "error", "limit"); await req({ "authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}` }, "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({ "authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}` }, "deleteRoom", { room: room2 + "lol", server: "localhost:7224" }, "error", "existence"); await req({ "authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}` }, "deleteRoom", { room: room2, server: "localhost:7224" }, "ok", ""); await req({ "authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}` }, "deleteRoom", { room: room2, server: "localhost:7224" }, "error", "existence"); await req({ "authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}` }, "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;