From ed8194afb0849526a1b4b4a7b4ff50574ed0a03d Mon Sep 17 00:00:00 2001 From: Tanner Shaw Date: Wed, 25 Oct 2023 12:58:29 -0500 Subject: [PATCH 1/8] feat(jest): added tests for Ethereum gateways --- src/endpoints/gateways/ethereumGroup.ts | 34 +++--- tests/discreetly.test.ts | 148 ++++++++++++++++++++++-- 2 files changed, 157 insertions(+), 25 deletions(-) diff --git a/src/endpoints/gateways/ethereumGroup.ts b/src/endpoints/gateways/ethereumGroup.ts index 85c5f96..9649c23 100644 --- a/src/endpoints/gateways/ethereumGroup.ts +++ b/src/endpoints/gateways/ethereumGroup.ts @@ -25,9 +25,11 @@ const adminAuth = basicAuth({ } }); + const router = express.Router(); const prisma = new PrismaClient(); + // Fetches all ethereum groups that exist in the database router.get('/groups/all', adminAuth, (req: Request, res: Response) => { prisma.ethereumGroup @@ -67,7 +69,7 @@ router.get('/group/:address', limiter, (req, res) => { } }) .then((groups) => { - res.status(200).json(groups); + res.status(200).json({status: 'valid', groups: groups}); }) .catch((err) => { console.error(err); @@ -95,15 +97,21 @@ router.post( name: string; roomIds: string[]; }; - const ethereumGroup = await prisma.ethereumGroup.create({ - data: { - name: name, - rooms: { - connect: roomIds.map((roomId) => ({ roomId })) + if (!name) res.status(400).json({ success: false, message: 'Missing name' }); + try { + const ethereumGroup = await prisma.ethereumGroup.create({ + data: { + name: name, + rooms: { + connect: roomIds.map((roomId) => ({ roomId })) + } } - } - }); - res.json({ success: true, ethereumGroup }); + }); + res.status(200).json({ success: true, message: 'Ethereum group created', ethereumGroup }); + } catch (err) { + console.error(err); + res.status(500).json({ success: false, error: 'Internal Server Error' }); + } }) ); @@ -119,7 +127,7 @@ router.post( names: string[]; ethAddresses: string[]; }; - if (!names) return; + if (!names) res.status(400).json({ success: false, message: 'Missing group names' }); const groups = await prisma.ethereumGroup.updateMany({ where: { name: { @@ -132,7 +140,7 @@ router.post( } } }); - res.json({ success: true, groups }); + res.status(200).json({ success: true, groups }); }) ); @@ -210,7 +218,7 @@ router.post('/group/delete', adminAuth, (req, res) => { } }) .then((group) => { - res.status(200).json(group); + res.status(200).json({ success: true, group }); }) .catch((err) => { console.error(err); @@ -231,7 +239,7 @@ router.post('/group/delete', adminAuth, (req, res) => { * } */ router.post( - '/join', + '/message/sign', limiter, asyncHandler(async (req: Request, res: Response) => { const { message, signature } = req.body as { diff --git a/tests/discreetly.test.ts b/tests/discreetly.test.ts index ab1c382..c02472c 100644 --- a/tests/discreetly.test.ts +++ b/tests/discreetly.test.ts @@ -7,7 +7,6 @@ import { beforeAll, afterAll, describe, expect, test } from '@jest/globals'; import { randomRoomName } from './utils'; import { generateIdentityProof } from '../src/crypto/idcVerifier/verifier'; import { Identity } from '@semaphore-protocol/identity'; -import { doesNotReject } from 'assert'; process.env.DATABASE_URL = process.env.DATABASE_URL_TEST; process.env.PORT = '3001'; @@ -33,6 +32,8 @@ const messageTestRoom = { roomId: CUSTOM_ID }; +let testEthAddress = '0x123123123'; + let roomByIdTest: string; let testCode: string; const testIdentity = new Identity(); @@ -44,6 +45,8 @@ beforeAll(async () => { await prismaTest.messages.deleteMany(); await prismaTest.rooms.deleteMany(); await prismaTest.claimCodes.deleteMany(); + await prismaTest.ethereumGroup.deleteMany(); + }); afterAll(async () => { @@ -57,14 +60,18 @@ describe('Endpoints', () => { .get('/') .then((res) => { expect(res.status).toBe(200); - expect(res.header['content-type']).toBe('application/json; charset=utf-8'); + expect(res.header['content-type']).toBe( + 'application/json; charset=utf-8' + ); expect(res.body.id).toBe(serverConfig.id); }) .catch((error) => console.error("GET '/' - " + error)); }); test('It should add a new room to the database', async () => { - const base64Credentials = Buffer.from(`${username}:${password}`).toString('base64'); + const base64Credentials = Buffer.from(`${username}:${password}`).toString( + 'base64' + ); await request(_app) .post('/room/add') .set('Authorization', `Basic ${base64Credentials}`) @@ -84,11 +91,19 @@ describe('Endpoints', () => { .catch((error) => console.warn('POST /room/add - ' + error)); }); test('It should create claimCode for the new room', async () => { - const base64Credentials = Buffer.from(`${username}:${password}`).toString('base64'); + const base64Credentials = Buffer.from(`${username}:${password}`).toString( + 'base64' + ); await request(_app) .post(`/admin/addcode`) .set('Authorization', `Basic ${base64Credentials}`) - .send({ numCodes: 1, rooms: [roomByIdTest], all: false, expiresAt: 0, usesLeft: -1 }) + .send({ + numCodes: 1, + rooms: [roomByIdTest], + all: false, + expiresAt: 0, + usesLeft: -1 + }) .then((res) => { try { console.log(res.body); @@ -102,7 +117,9 @@ describe('Endpoints', () => { }); test('It should add a new room with a custom id to the database', async () => { - const base64Credentials = Buffer.from(`${username}:${password}`).toString('base64'); + const base64Credentials = Buffer.from(`${username}:${password}`).toString( + 'base64' + ); await request(_app) .post('/room/add') .set('Authorization', `Basic ${base64Credentials}`) @@ -122,7 +139,9 @@ describe('Endpoints', () => { }); test('It shouldnt add a new room with the same ID', async () => { - const base64Credentials = Buffer.from(`${username}:${password}`).toString('base64'); + const base64Credentials = Buffer.from(`${username}:${password}`).toString( + 'base64' + ); await request(_app) .post('/room/add') .set('Authorization', `Basic ${base64Credentials}`) @@ -130,10 +149,8 @@ describe('Endpoints', () => { .then((res) => { try { - console.log(res.status); expect(res.status).toEqual(400); const result = res.body; - console.warn(result); } catch (error) { console.warn('POST /room/add - ' + error); } @@ -170,7 +187,9 @@ describe('Endpoints', () => { }); test('It should return all rooms', async () => { - const base64Credentials = Buffer.from(`${username}:${password}`).toString('base64'); + const base64Credentials = Buffer.from(`${username}:${password}`).toString( + 'base64' + ); await request(_app) .get('/admin/rooms') @@ -188,7 +207,9 @@ describe('Endpoints', () => { }); test("It should return all claim codes and add a user's identity to the rooms the claim code is associated with", async () => { - const base64Credentials = Buffer.from(`${username}:${password}`).toString('base64'); + const base64Credentials = Buffer.from(`${username}:${password}`).toString( + 'base64' + ); await request(_app) .get('/admin/logclaimcodes') @@ -240,7 +261,9 @@ describe('Endpoints', () => { const message = { message: 'Test message' }; - const base64Credentials = Buffer.from(`${username}:${password}`).toString('base64'); + const base64Credentials = Buffer.from(`${username}:${password}`).toString( + 'base64' + ); await request(_app) .post('/admin/message') .set('Authorization', `Basic ${base64Credentials}`) @@ -269,6 +292,107 @@ describe('Endpoints', () => { .catch((error) => console.error('GET /api/messages/:roomId - ' + error)); }); + test('It should create a new Ethereum group', async () => { + const base64Credentials = Buffer.from(`${username}:${password}`).toString( + 'base64' + ); + await request(_app) + .post('/gateway/eth/group/create') + .set('Authorization', `Basic ${base64Credentials}`) + .send({ name: 'EthGroup-Test', roomIds: [roomByIdTest] }) + .then((res) => { + try { + expect(res.statusCode).toEqual(200); + expect(res.body.message).toEqual('Ethereum group created'); + } catch (error) { + console.error('POST /gateway/eth/group/create - ' + error); + } + }); + }); + + test('It should return all of the Ethereum Groups', async () => { + const base64Credentials = Buffer.from(`${username}:${password}`).toString( + 'base64' + ); + await request(_app) + .get(`/gateway/eth/groups/all`) + .set('Authorization', `Basic ${base64Credentials}`) + .then((res) => { + try { + expect(res.statusCode).toEqual(200); + expect(res.body.length).toBeGreaterThan(0); + } catch (error) { + console.error('GET /gateway/eth/groups/all - ' + error); + } + }); + }); + + test('It should add Eth addresses to a group', async () => { + const base64Credentials = Buffer.from(`${username}:${password}`).toString( + 'base64' + ); + await request(_app) + .post(`/gateway/eth/group/add`) + .set('Authorization', `Basic ${base64Credentials}`) + .send({ names: ['EthGroup-Test'], ethAddresses: [testEthAddress] }) + .then((res) => { + try { + expect(res.statusCode).toEqual(200); + expect(res.body.success).toEqual(true) + } catch (err) { + console.error('POST /gateway/eth/group/add - ' + err); + } + }); + }); + test('It should return return the Groups the Ethereum Address is in', async () => { + await request(_app) + .get(`/gateway/eth/group/${testEthAddress}`) + .then((res) => { + try { + expect(res.statusCode).toEqual(200); + expect(res.body.status).toEqual('valid'); + } catch (err) { + console.error('GET /gateway/eth/group/:address -' + err) + } + }) + }) + test('It should edit an Ethereum Group to add Eth addresses and roomIds', async () => { + const base64Credentials = Buffer.from(`${username}:${password}`).toString( + 'base64' + ); + await request(_app) + .post('/gateway/eth/group/edit') + .set('Authorization', `Basic ${base64Credentials}`) + .send({name: 'EthGroup-Test', ethAddresses: ['0x321321321'], roomIds: []}) + .then((res) => { + try { + expect(res.statusCode).toEqual(200) + expect(res.body.success).toEqual(true) + expect(res.body.updatedGroup.ethereumAddresses.length).toBeGreaterThan(1) + } catch (err) { + console.error('POST /gateway/eth/group/edit - ' + err) + } + }) + }) + + test('It should delete an Ethereum Group', async () => { + const base64Credentials = Buffer.from(`${username}:${password}`).toString( + 'base64' + ); + await request(_app) + .post('/gateway/eth/group/delete') + .set('Authorization', `Basic ${base64Credentials}`) + .send({ name: 'EthGroup-Test' }) + .then((res) => { + try { + expect(res.statusCode).toEqual(200) + expect(res.body.success).toEqual(true) + } catch (err) { + console.error('DELETE /gateway/eth/group/delete - ' + err) + } + }) + }) + describe('Messages', () => { let testRoom: RoomI; From 6e695297080a8fa6ae9bd43e6b115645cbd2df71 Mon Sep 17 00:00:00 2001 From: Tanner Shaw Date: Wed, 8 Nov 2023 12:04:56 -0600 Subject: [PATCH 2/8] feat(jest) additional tests to make sure rooms are being created correctly --- tests/discreetly.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/discreetly.test.ts b/tests/discreetly.test.ts index c02472c..60991a1 100644 --- a/tests/discreetly.test.ts +++ b/tests/discreetly.test.ts @@ -8,6 +8,7 @@ import { randomRoomName } from './utils'; import { generateIdentityProof } from '../src/crypto/idcVerifier/verifier'; import { Identity } from '@semaphore-protocol/identity'; + process.env.DATABASE_URL = process.env.DATABASE_URL_TEST; process.env.PORT = '3001'; @@ -165,6 +166,13 @@ describe('Endpoints', () => { try { expect(res.status).toEqual(200); expect(res.body.name).toEqual(room.roomName); + expect(res.body.roomId).toEqual(roomByIdTest); + expect(res.body.rateLimit).toEqual(1000); + expect(res.body.userMessageLimit).toEqual(1); + expect(res.body.membershipType).toEqual('IDENTITY_LIST') + expect(res.body.ephemeral).toEqual('PERSISTENT') + expect(res.body.encrypted).toEqual('PLAINTEXT'); + expect(res.body.identities.length).toBeGreaterThan(0); } catch (error) { console.error(`GET /api/room/:roomId - + ${error}`); } From 974d0928c4566a8c927e60b45f99e8511ed533da Mon Sep 17 00:00:00 2001 From: Tanner Shaw Date: Wed, 8 Nov 2023 12:28:26 -0600 Subject: [PATCH 3/8] fix(jest) fixing /identity/:idc route and test --- src/endpoints/identity/idc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/endpoints/identity/idc.ts b/src/endpoints/identity/idc.ts index 4723671..50bd19d 100644 --- a/src/endpoints/identity/idc.ts +++ b/src/endpoints/identity/idc.ts @@ -14,7 +14,7 @@ const router = express.Router(); * @param {idcProof} proof - The proof of the identity to get rooms for. * @returns {void} */ -router.post( +router.get( '/:idc', limiter, asyncHandler(async (req: Request, res: Response) => { From f225e58cb11d5c41b5ef5343349d9ab5c1fb4762 Mon Sep 17 00:00:00 2001 From: Tanner Shaw Date: Wed, 8 Nov 2023 13:54:15 -0600 Subject: [PATCH 4/8] feat(jest) jest tests for discord gateway endpoints --- src/endpoints/gateways/discord.ts | 4 +- tests/discreetly.test.ts | 85 ++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 5 deletions(-) diff --git a/src/endpoints/gateways/discord.ts b/src/endpoints/gateways/discord.ts index 8c6a51d..1955e23 100644 --- a/src/endpoints/gateways/discord.ts +++ b/src/endpoints/gateways/discord.ts @@ -16,7 +16,7 @@ const discordPassword = process.env.DISCORD_PASSWORD const adminAuth = basicAuth({ users: { - discordAdmin: discordPassword + admin: discordPassword } }); @@ -152,7 +152,6 @@ router.post( filteredRooms.push(...newRooms); filteredNames.push(...(newRoomNames as string[])); } - console.log(filteredRooms); res.status(200).json({ rooms: filteredRooms, roomNames: filteredNames }); } else { const roomIds: string[] = []; @@ -193,7 +192,6 @@ router.post( */ router.post('/rooms', limiter, adminAuth, (req, res) => { const { discordUserId } = req.body as { discordUserId: string }; - console.log('here'); prisma.gateWayIdentity .findFirst({ where: { diff --git a/tests/discreetly.test.ts b/tests/discreetly.test.ts index 60991a1..73f6ae1 100644 --- a/tests/discreetly.test.ts +++ b/tests/discreetly.test.ts @@ -40,6 +40,7 @@ let testCode: string; const testIdentity = new Identity(); const username = 'admin'; const password = process.env.PASSWORD; +const discordPassword = process.env.DISCORD_PASSWORD beforeAll(async () => { const prismaTest = new PrismaClient(); @@ -47,7 +48,7 @@ beforeAll(async () => { await prismaTest.rooms.deleteMany(); await prismaTest.claimCodes.deleteMany(); await prismaTest.ethereumGroup.deleteMany(); - + await prismaTest.gateWayIdentity.deleteMany(); }); afterAll(async () => { @@ -103,7 +104,8 @@ describe('Endpoints', () => { rooms: [roomByIdTest], all: false, expiresAt: 0, - usesLeft: -1 + usesLeft: -1, + discordId: '53125497960' }) .then((res) => { try { @@ -419,4 +421,83 @@ describe('Endpoints', () => { expect(1).toBe(1); }); }); + + describe('Discord', () => { + test('It should add roles to a Discord Role mapping', async () => { + const base64Credentials = Buffer.from(`${username}:${discordPassword}`).toString('base64') + await request(_app) + .post('/gateway/discord/addrole') + .set('Authorization', `Basic ${base64Credentials}`) + .send({ + roles: ['12345', '67890'], + roomId: roomByIdTest, + guildId: '87128718167878' + }) + .then((res) => { + try { + expect(res.body.message).toEqual('Discord roles added successfully') + } catch (error) { + console.error(`POST /gateway/discord/addrole - ${error}`) + } + }) + }) + test('It should add a Discord Server to the database', async () => { + const base64Credentials = Buffer.from(`${username}:${discordPassword}`).toString('base64') + await request(_app) + .post('/gateway/discord/addguild') + .set('Authorization', `Basic ${base64Credentials}`) + .send({guildId: '87128718167878'}) + .then((res) => { + try { + expect(res.body.message).toEqual('Discord guild added successfully') + } catch (error) { + console.error(`POST /gateway/discord/addguild - ${error}`) + } + }) + }) + test('It should get the rooms associated with a Discord Role mapping', async () => { + const base64Credentials = Buffer.from(`${username}:${discordPassword}`).toString('base64') + await request(_app) + .post('/gateway/discord/getrooms') + .set('Authorization', `Basic ${base64Credentials}`) + .send({roles: ['12345', '67890'], discordId: '53125497960'}) + .then((res) => { + try { + expect(res.body.rooms.length).toBeGreaterThan(0) + } catch (error) { + console.error(`GET /gateway/discord/getrooms - ${error}`) + } + }) + }) + + test('It should get the rooms associated with the discordId', async () => { + const base64Credentials = Buffer.from(`${username}:${discordPassword}`).toString('base64') + await request(_app) + .post('/gateway/discord/rooms') + .set('Authorization', `Basic ${base64Credentials}`) + .send({discordUserId: '53125497960'}) + .then((res) => { + try { + expect(res.body.rooms.length).toBeGreaterThan(0) + } catch (error) { + console.error(`POST /gateway/discord/rooms - ${error}`) + } + }) + }) + + test('It should get the room mappings for a Discord Server ID', async () => { + const base64Credentials = Buffer.from(`${username}:${discordPassword}`).toString('base64') + await request(_app) + .post('/gateway/discord/checkrooms') + .set('Authorization', `Basic ${base64Credentials}`) + .send({ discordId: '87128718167878' }) + .then((res) => { + try { + expect(res.body.length).toBeGreaterThan(0) + } catch (error) { + console.error(`POST /gateway/discord/checkrooms - ${error}`) + } + }) + }) + }) }); From fe27d5281e500241b5e1bf63ab3321d2b0c45222 Mon Sep 17 00:00:00 2001 From: Tanner Shaw Date: Thu, 9 Nov 2023 13:13:28 -0600 Subject: [PATCH 5/8] feat(jsdocs) adding js docs to find functions --- src/data/db/find.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/data/db/find.ts b/src/data/db/find.ts index 8ca1f6c..75417fb 100644 --- a/src/data/db/find.ts +++ b/src/data/db/find.ts @@ -93,6 +93,12 @@ export async function findClaimCode(code: string): Promise { }); } + +/** + * This function finds a gateway identity in the database + * @param {string} identity - The identity of the user to find + * @returns {Promise} - The gateway identity, if found + */ export async function findGatewayByIdentity(identity: string): Promise { return await prisma.gateWayIdentity.findFirst({ where: { @@ -120,6 +126,12 @@ export async function findUpdatedRooms(roomIds: string[]): Promise { }); } +/** + * This function finds a room with a message id + * @param {string} roomId - The id of the room to find + * @param {MessageI} message - The message id to find + * @returns {Promise} - A promise that resolves to a message + */ export async function findRoomWithMessageId( roomId: string, message: MessageI @@ -154,7 +166,12 @@ export async function findRoomWithMessageId( } } -export async function findAllJubmojiNullifiers() { + +/** + * This function finds all the used jubmoji nullifiers in the db + * @returns {Promise} - A promise that resolves to a list of used sig nullifiers + */ +export async function findAllJubmojiNullifiers(): Promise { const jubmojiNullifiers: Jubmojis[] = await prisma.gateWayIdentity.findMany({ select: { jubmoji: true From 74236eab49306f35c0bba0047981d4277076801c Mon Sep 17 00:00:00 2001 From: Tanner Shaw Date: Thu, 9 Nov 2023 13:28:19 -0600 Subject: [PATCH 6/8] feat(jsdocs) adding js docs to remove/update/theword functions --- src/data/db/remove.ts | 2 -- src/data/db/update.ts | 1 - src/data/messages.ts | 18 ++++++++++++++++++ src/gateways/theWord/verifier.ts | 6 +++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/data/db/remove.ts b/src/data/db/remove.ts index 8aff204..0d1141d 100644 --- a/src/data/db/remove.ts +++ b/src/data/db/remove.ts @@ -49,7 +49,6 @@ export function removeIdentityFromRoom( * @param {string} roomId - The id of the room to remove * @returns {Promise} - A promise that resolves to true if the room was removed and false otherwise * */ - export function removeRoom(roomId: string): Promise { return prisma.messages .deleteMany({ @@ -82,7 +81,6 @@ export function removeRoom(roomId: string): Promise { * @param {string} messageId - The id of the message to remove * @returns {Promise} - A promise that resolves to true if the message was removed and false otherwise */ - export function removeMessage(roomId: string, messageId: string) { return prisma.messages .deleteMany({ diff --git a/src/data/db/update.ts b/src/data/db/update.ts index 0c1a358..3f9b4c5 100644 --- a/src/data/db/update.ts +++ b/src/data/db/update.ts @@ -303,7 +303,6 @@ export async function addIdentityToBandadaRooms( * @param {string} roomId - The ID of the room * @param {string[]} ethAddresses - The list of Ethereum addresses to add to the group */ - export async function createEthGroup( name: string, roomId: string, diff --git a/src/data/messages.ts b/src/data/messages.ts index cd7f15e..114f21b 100644 --- a/src/data/messages.ts +++ b/src/data/messages.ts @@ -19,6 +19,12 @@ type EphemeralMessagesI = Record; const ephemeralMessageStore: EphemeralMessagesI = {}; +/** + * This code checks the ephemeral message store for a collision. + * @param {string} roomId - The ID of the room to check for collisions in + * @param {MessageI} message - The message to be added to the room + * @returns {MessageI | null} - Returns the old message if there is a collision, and null otherwise + */ function checkEmphemeralStore(roomId: string, message: MessageI): MessageI | null { // Check ephemeralMessages const epoch = message.epoch?.toString(); @@ -34,6 +40,11 @@ function checkEmphemeralStore(roomId: string, message: MessageI): MessageI | nul return null; } +/** + * This code adds a message to the ephemeral message store. + * @param {string} roomId - The ID of the room to add the message to + * @param {MessageI} message - The message to add to the room + */ function addMessageToEphemeralStore(roomId: string, message: MessageI) { const currentEpoch = String(message.epoch); @@ -137,6 +148,13 @@ export interface validateMessageResult { idc?: string | bigint; } +/** + * This code handles the collision check result and adds the message to the room if there is no collision. + * @param {RoomI} room - The room which the message will be added + * @param {MessageI} message - The message to be created + * @param {CollisionCheckResult} collisionResult - The result of the collision check + * @returns {Promise} - A result object which contains a boolean indicating whether the operation was successful + */ async function handleCollision( room: RoomI, message: MessageI, diff --git a/src/gateways/theWord/verifier.ts b/src/gateways/theWord/verifier.ts index 5414209..13c951d 100644 --- a/src/gateways/theWord/verifier.ts +++ b/src/gateways/theWord/verifier.ts @@ -2,7 +2,11 @@ import { groth16 } from 'snarkjs'; import vkey from './vkey'; import { SNARKProof } from 'idc-nullifier'; - +/** + * This function verifies a proof generated by theWord. + * @param {SNARKProof} proof - The proof to verify + * @returns {Promise} - A promise that resolves to true if the proof is valid and false otherwise + */ export async function verifyTheWordProof(proof: SNARKProof): Promise { const isValid = groth16.verify(vkey, proof.publicSignals, proof.proof); From 01b94aeb9db208b1d481cf4a1a10e8f5503b8982 Mon Sep 17 00:00:00 2001 From: Tanner Shaw Date: Fri, 10 Nov 2023 14:03:17 -0600 Subject: [PATCH 7/8] minor fix --- src/endpoints/identity/idc.ts | 2 +- tests/discreetly.test.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/endpoints/identity/idc.ts b/src/endpoints/identity/idc.ts index 50bd19d..4723671 100644 --- a/src/endpoints/identity/idc.ts +++ b/src/endpoints/identity/idc.ts @@ -14,7 +14,7 @@ const router = express.Router(); * @param {idcProof} proof - The proof of the identity to get rooms for. * @returns {void} */ -router.get( +router.post( '/:idc', limiter, asyncHandler(async (req: Request, res: Response) => { diff --git a/tests/discreetly.test.ts b/tests/discreetly.test.ts index 73f6ae1..51f5e5e 100644 --- a/tests/discreetly.test.ts +++ b/tests/discreetly.test.ts @@ -38,6 +38,7 @@ let testEthAddress = '0x123123123'; let roomByIdTest: string; let testCode: string; const testIdentity = new Identity(); +console.log('identity', testIdentity); const username = 'admin'; const password = process.env.PASSWORD; const discordPassword = process.env.DISCORD_PASSWORD @@ -255,7 +256,7 @@ describe('Endpoints', () => { let proof = await generateIdentityProof(testIdentity, BigInt(Date.now())); await request(_app) - .get(`/identity/${testIdentity.getCommitment().toString()}`) + .post(`/identity/${testIdentity.getCommitment().toString()}`) .send(proof) .then((res) => { try { @@ -475,7 +476,7 @@ describe('Endpoints', () => { await request(_app) .post('/gateway/discord/rooms') .set('Authorization', `Basic ${base64Credentials}`) - .send({discordUserId: '53125497960'}) + .send({ discordUserId: '53125497960' }) .then((res) => { try { expect(res.body.rooms.length).toBeGreaterThan(0) From c913bd31351212a32ee329f77b0c08c3e1e52d30 Mon Sep 17 00:00:00 2001 From: AtHeartEngineer <1675654+AtHeartEngineer@users.noreply.github.com> Date: Sat, 11 Nov 2023 14:58:13 +0300 Subject: [PATCH 8/8] change the-word room id --- src/endpoints/gateways/theWord.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/endpoints/gateways/theWord.ts b/src/endpoints/gateways/theWord.ts index 6d7ad72..969df5d 100644 --- a/src/endpoints/gateways/theWord.ts +++ b/src/endpoints/gateways/theWord.ts @@ -23,14 +23,14 @@ router.post( '/join', limiter, asyncHandler(async (req: Request, res: Response) => { - const { proof, idc } = req.body as { proof: SNARKProof, idc: string }; + const { proof, idc } = req.body as { proof: SNARKProof; idc: string }; const isValid = await verifyTheWordProof(proof); if (isValid) { - const room = await prisma.rooms.findUnique({ + const room = (await prisma.rooms.findUnique({ where: { - roomId: '007' + process.env.THEWORD_ITERATION + roomId: '700' + process.env.THEWORD_ITERATION } - }) as RoomI; + })) as RoomI; const addedRoom = await addIdentityToIdentityListRooms([room], idc); if (addedRoom.length === 0) { res.status(500).json({