tests Room Owner

This commit is contained in:
jusax23 2023-03-18 15:34:19 +01:00
parent 4128155189
commit e640d325f1
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41
8 changed files with 236 additions and 35 deletions

View file

@ -1,3 +1,4 @@
export * from "./acts/login.js";
export * from "./acts/client.js"
export * from "./acts/admin.js"
export * from "./acts/rooms.js"

View file

@ -99,34 +99,38 @@ export const createRoom = {
server: "string", // Unused/Ignored at the Moment
title: "string-255",
description: "string-255",
isPublic: "number",
public: "number",
icon: "string-255"
},
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
if (!await canCreateRoom(client.accID))
return void aws("error", "limit");
let req = await insert(
rooms.name,
rooms.owner,
rooms.public,
rooms.title,
rooms.description,
rooms.icon
).add(
data.room,
client.accID,
data.isPublic,
data.title,
data.description,
data.icon
).query(db);
if (req.affectedRows > 0) {
await insert(roomMembers.roomID, roomMembers.name, roomMembers.server, roomMembers.admin)
.add(req.insertId, client.name, "local", true)
.query(db);
aws("ok", "");
} else {
try {
let req = await insert(
rooms.name,
rooms.owner,
rooms.public,
rooms.title,
rooms.description,
rooms.icon
).add(
data.room,
client.accID,
data.public,
data.title,
data.description,
data.icon
).query(db);
if (req.affectedRows > 0) {
await insert(roomMembers.roomID, roomMembers.name, roomMembers.server, roomMembers.admin)
.add(req.insertId, client.name, "local", true)
.query(db);
aws("ok", "");
} else {
aws("error", "existence");
}
} catch (error) {
client.suspect();
aws("error", "existence");
}
}
@ -158,7 +162,6 @@ export const listPublicRooms = {
right: PERMISSIONS.CAN_USE_API,
data: {},
func: async (client: Client, data: any, aws: (code: string, data: any) => void) => {
let req = await select([
rooms.name,
rooms.public,

View file

@ -1,4 +1,4 @@
import { alias, and, eq, exists, innerJoinOn, insert, le, minus, naturalJoin, not, or, remove, select, update } from "dblang";
import { alias, and, eq, exists, innerJoinOn, innerJoinUsing, insert, le, minus, naturalJoin, not, or, remove, select, update } from "dblang";
import { ROOM_RIGHTS } from "../../server/permissions.js";
import { accounts, db, roomMembers, roomOTAs, rooms } from "../../sys/db.js";
import { uts } from "../../sys/tools.js";
@ -22,7 +22,7 @@ export const listLocalRooms: Act = {
rooms.title,
rooms.description,
rooms.icon
], naturalJoin(rooms, roomMembers))
], innerJoinUsing(rooms, roomMembers, rooms.roomID, roomMembers.roomID))
.where(and(
eq(roomMembers.name, client.name),
eq(roomMembers.server, client.state == STATE.client ? "local" : client.server.tag)

View file

@ -22,6 +22,6 @@ database=outbag
[Settings]
maxUsers=2
defaultMaxRooms=3
defaultMaxRooms=2
defaultMaxRoomSize=10
defaultMaxUsersPerRoom=2

View file

@ -31,7 +31,10 @@ function shallowEqual(object1, object2) {
return false;
}
for (let key of keys1) {
if (object1[key] != null && object1[key] != object2[key]) {
if (typeof object1[key] == "object" && object1[key] != null) {
if(typeof object2[key] != "object") return false;
if(!shallowEqual(object1[key], object2[key])) return false;
} else if (object1[key] != null && object1[key] != object2[key]) {
return false;
}
}

View file

@ -6,6 +6,10 @@ 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 = [
@ -96,7 +100,7 @@ const list = [
rights: PERMISSIONS.ALL,
name: name1,
viewable: true,
maxRooms: 3,
maxRooms: 2,
maxRoomSize: 10,
maxUsersPerRoom: 2,
});
@ -106,7 +110,7 @@ const list = [
rights: PERMISSIONS.DEFAULT,
name: name2,
viewable: true,
maxRooms: 3,
maxRooms: 2,
maxRoomSize: 10,
maxUsersPerRoom: 2,
});
@ -134,6 +138,104 @@ const list = [
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",
public: 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",
public: 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",
public: 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",
public: 1,
icon: ""
}, "error", "limit");
await req({
"authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}`
}, "listLocalRooms", {}, "ok", [
{
name: room1,
owner: name1,
rights: 0b11111,
title: "Test Room 1",
description: "some desc",
public: 0,
icon: "shopping"
}, {
name: room2,
owner: name1,
rights: 0b11111,
title: "Test Room 2",
description: "some desc 2",
public: 1,
icon: ""
}
]);
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}`
}, "listLocalRooms", {}, "ok", [
{
name: room1,
owner: name1,
rights: 0b11111,
title: "Test Room 1",
description: "some desc",
public: 0,
icon: "shopping"
}
]);
}]
];

View file

@ -6,6 +6,10 @@ 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 = [
@ -86,7 +90,7 @@ const list = [
rights: PERMISSIONS.ALL,
name: name1,
viewable: true,
maxRooms: 3,
maxRooms: 2,
maxRoomSize: 10,
maxUsersPerRoom: 2,
});
@ -100,7 +104,7 @@ const list = [
rights: PERMISSIONS.DEFAULT,
name: name2,
viewable: true,
maxRooms: 3,
maxRooms: 2,
maxRoomSize: 10,
maxUsersPerRoom: 2,
});
@ -132,6 +136,91 @@ const list = [
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",
public: 0,
icon: "shopping"
}, "ok", "");
await req(handler, "createRoom", {
room: room1,
server: "localhost:7224",
title: "Test Room 1",
description: "some desc",
public: 0,
icon: "shopping"
}, "error", "existence");
await req(handler, "createRoom", {
room: room2,
server: "localhost:7224",
title: "Test Room 2",
description: "some desc 2",
public: 1,
icon: ""
}, "ok", "");
await req(handler, "createRoom", {
room: room3,
server: "localhost:7224",
title: "Test Room 2",
description: "some desc 2",
public: 1,
icon: ""
}, "error", "limit");
await req(handler, "listLocalRooms", {}, "ok", [
{
name: room1,
owner: name1,
rights: 0b11111,
title: "Test Room 1",
description: "some desc",
public: 0,
icon: "shopping"
}, {
name: room2,
owner: name1,
rights: 0b11111,
title: "Test Room 2",
description: "some desc 2",
public: 1,
icon: ""
}
]);
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, "listLocalRooms", {}, "ok", [
{
name: room1,
owner: name1,
rights: 0b11111,
title: "Test Room 1",
description: "some desc",
public: 0,
icon: "shopping"
}
]);
}]
];

View file

@ -90,7 +90,10 @@ function shallowEqual(object1, object2) {
return false;
}
for (let key of keys1) {
if (object1[key] != null && object1[key] != object2[key]) {
if (typeof object1[key] == "object" && object1[key] != null) {
if(typeof object2[key] != "object") return false;
if(!shallowEqual(object1[key], object2[key])) return false;
} else if (object1[key] != null && object1[key] != object2[key]) {
return false;
}
}
@ -104,7 +107,7 @@ async function wsTester(url) {
console.log("Testing Act:", act, "with Data:", data);
let resp = await conn.req(act, data);
if (resp.state != expState) {
console.error(`Expected state: '${expState}', but got: '${resp.state}'`);
console.error(`Expected state: '${expState}', but got: '${resp.state}' (Data: ${typeof resp.data == "object" ? JSON.stringify(resp.data) : resp.data})`);
kill();
process.exit(1);
}