@signalapp/mock-server
Advanced tools
Comparing version 9.1.0 to 10.0.0
{ | ||
"name": "@signalapp/mock-server", | ||
"version": "9.1.0", | ||
"version": "10.0.0", | ||
"description": "Mock Signal Server for writing tests", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -9,3 +9,2 @@ "use strict"; | ||
exports.createHandler = void 0; | ||
const zkgroup_1 = require("@signalapp/libsignal-client/zkgroup"); | ||
const assert_1 = __importDefault(require("assert")); | ||
@@ -22,3 +21,2 @@ const buffer_1 = require("buffer"); | ||
const compiled_1 = require("../../protos/compiled"); | ||
const crypto_1 = require("../crypto"); | ||
const schemas_1 = require("../data/schemas"); | ||
@@ -33,31 +31,2 @@ const util_1 = require("../util"); | ||
// | ||
// Unauthorized requests | ||
// | ||
// TODO: DESKTOP-5821 | ||
const getDeviceKeys = (0, microrouter_1.get)('/v2/keys/:serviceId/:deviceId', async (req, res) => { | ||
const serviceId = req.params.serviceId; | ||
const deviceId = parseInt(req.params.deviceId || '', 10); | ||
if (!serviceId || deviceId.toString() !== req.params.deviceId) { | ||
return (0, micro_1.send)(res, 400, { error: 'Invalid request parameters' }); | ||
} | ||
const device = await server.getDeviceByServiceId(serviceId, deviceId); | ||
if (!device) { | ||
return (0, micro_1.send)(res, 404, { error: 'Device not found' }); | ||
} | ||
const serviceIdKind = device.getServiceIdKind(serviceId); | ||
return (0, micro_1.send)(res, 200, await (0, util_1.getDevicesKeysResult)(serviceIdKind, [device])); | ||
}); | ||
const getAllDeviceKeys = (0, microrouter_1.get)('/v2/keys/:serviceId(/\\*)', async (req, res) => { | ||
const serviceId = req.params.serviceId; | ||
if (!serviceId) { | ||
return (0, micro_1.send)(res, 400, { error: 'Invalid request parameters' }); | ||
} | ||
const devices = await server.getAllDevicesByServiceId(serviceId); | ||
if (devices.length === 0) { | ||
return (0, micro_1.send)(res, 404, { error: 'Account not found' }); | ||
} | ||
const serviceIdKind = devices[0].getServiceIdKind(serviceId); | ||
return (0, micro_1.send)(res, 200, await (0, util_1.getDevicesKeysResult)(serviceIdKind, devices)); | ||
}); | ||
// | ||
// CDN | ||
@@ -262,137 +231,3 @@ // | ||
} | ||
const putKeys = (0, microrouter_1.put)('/v2/keys', async (req, res) => { | ||
const device = await auth(req, res); | ||
if (!device) { | ||
return; | ||
} | ||
const serviceIdKind = (0, util_1.serviceIdKindFromQuery)(req.query); | ||
const body = schemas_1.DeviceKeysSchema.parse(await (0, micro_1.json)(req)); | ||
try { | ||
await server.updateDeviceKeys(device, serviceIdKind, { | ||
preKeys: body.preKeys?.map(crypto_1.decodePreKey), | ||
kyberPreKeys: body.pqPreKeys?.map(crypto_1.decodeKyberPreKey), | ||
lastResortKey: body.pqLastResortPreKey | ||
? (0, crypto_1.decodeKyberPreKey)(body.pqLastResortPreKey) | ||
: undefined, | ||
signedPreKey: body.signedPreKey | ||
? (0, crypto_1.decodeSignedPreKey)(body.signedPreKey) | ||
: undefined, | ||
}); | ||
} | ||
catch (error) { | ||
(0, assert_1.default)(error instanceof Error); | ||
debug('updateDeviceKeys error', error.stack); | ||
return (0, micro_1.send)(res, 400, { error: error.message }); | ||
} | ||
return { ok: true }; | ||
}); | ||
const getKeys = (0, microrouter_1.get)('/v2/keys', async (req, res) => { | ||
const device = await auth(req, res); | ||
if (!device) { | ||
return; | ||
} | ||
const serviceIdKind = (0, util_1.serviceIdKindFromQuery)(req.query); | ||
return { | ||
count: await device.getPreKeyCount(serviceIdKind), | ||
pqCount: await device.getKyberPreKeyCount(serviceIdKind), | ||
}; | ||
}); | ||
// | ||
// Accounts | ||
// | ||
const whoami = (0, microrouter_1.get)('/v1/accounts/whoami', async (req, res) => { | ||
const device = await auth(req, res); | ||
if (!device) { | ||
return; | ||
} | ||
return { uuid: device.aci, pni: device.pni, number: device.number }; | ||
}); | ||
const reserveUsername = (0, microrouter_1.put)('/v1/accounts/username_hash/reserve', async (req, res) => { | ||
const device = await auth(req, res); | ||
if (!device) { | ||
return; | ||
} | ||
const body = schemas_1.UsernameReservationSchema.parse(await (0, micro_1.json)(req)); | ||
const usernameHash = await server.reserveUsername(device.aci, body); | ||
if (!usernameHash) { | ||
return (0, micro_1.send)(res, 409); | ||
} | ||
return { usernameHash: (0, util_1.toURLSafeBase64)(usernameHash) }; | ||
}); | ||
const confirmUsername = (0, microrouter_1.put)('/v1/accounts/username_hash/confirm', async (req, res) => { | ||
const device = await auth(req, res); | ||
if (!device) { | ||
return; | ||
} | ||
const body = schemas_1.UsernameConfirmationSchema.parse(await (0, micro_1.json)(req)); | ||
const result = await server.confirmUsername(device.aci, body); | ||
if (!result) { | ||
return (0, micro_1.send)(res, 409); | ||
} | ||
return result; | ||
}); | ||
const deleteUsername = (0, microrouter_1.del)('/v1/accounts/username_hash', async (req, res) => { | ||
const device = await auth(req, res); | ||
if (!device) { | ||
return; | ||
} | ||
await server.deleteUsername(device.aci); | ||
return (0, micro_1.send)(res, 204); | ||
}); | ||
const lookupByUsernameHash = (0, microrouter_1.get)('/v1/accounts/username_hash/:hash', async (req, res) => { | ||
const { hash = '' } = req.params; | ||
const uuid = await server.lookupByUsernameHash((0, util_1.fromURLSafeBase64)(hash)); | ||
if (!uuid) { | ||
return (0, micro_1.send)(res, 404); | ||
} | ||
return { uuid }; | ||
}); | ||
const lookupByUsernameLink = (0, microrouter_1.get)('/v1/accounts/username_link/:uuid', async (req, res) => { | ||
const { uuid: linkUuid = '' } = req.params; | ||
const encryptedValue = await server.lookupByUsernameLink(linkUuid); | ||
if (!encryptedValue) { | ||
return (0, micro_1.send)(res, 404); | ||
} | ||
return { usernameLinkEncryptedValue: (0, util_1.toURLSafeBase64)(encryptedValue) }; | ||
}); | ||
const replaceUsernameLink = (0, microrouter_1.put)('/v1/accounts/username_link', async (req, res) => { | ||
const device = await auth(req, res); | ||
if (!device) { | ||
return; | ||
} | ||
const { usernameLinkEncryptedValue } = schemas_1.PutUsernameLinkSchema.parse(await (0, micro_1.json)(req)); | ||
const usernameLinkHandle = await server.replaceUsernameLink(device.aci, usernameLinkEncryptedValue); | ||
return { usernameLinkHandle }; | ||
}); | ||
// | ||
// Call links | ||
// | ||
const createCallLinkAuth = (0, microrouter_1.post)('/v1/call-link/create-auth', async (req, res) => { | ||
const device = await auth(req, res); | ||
if (!device) { | ||
return; | ||
} | ||
const body = schemas_1.CreateCallLinkAuthSchema.parse(await (0, micro_1.json)(req)); | ||
const request = new zkgroup_1.CreateCallLinkCredentialRequest(body.createCallLinkCredentialRequest); | ||
const response = await server.createCallLinkAuth(device, request); | ||
return { | ||
redemptionTime: -Date.now(), | ||
credential: (0, util_1.toBase64)(response.serialize()), | ||
}; | ||
}); | ||
// | ||
// Captcha | ||
// | ||
const putChallenge = (0, microrouter_1.put)('/v1/challenge', async (req, res) => { | ||
const device = await auth(req, res); | ||
if (!device) { | ||
return; | ||
} | ||
const response = server.getResponseForChallenges(); | ||
if (response) { | ||
return (0, micro_1.send)(res, response.code, response.data); | ||
} | ||
return { ok: true }; | ||
}); | ||
// | ||
// GV2 | ||
@@ -657,5 +492,3 @@ // | ||
// Sure, why not | ||
(0, microrouter_1.get)('/v1/config', dummyAuth({ config: [] })), | ||
// TODO(indutny): support nameless devices? They use different route | ||
getDeviceKeys, getAllDeviceKeys, getAttachment, getStickerPack, getSticker, putKeys, getKeys, whoami, reserveUsername, confirmUsername, deleteUsername, lookupByUsernameHash, lookupByUsernameLink, replaceUsernameLink, createCallLinkAuth, putChallenge, | ||
(0, microrouter_1.get)('/v1/config', dummyAuth({ config: [] })), getAttachment, getStickerPack, getSticker, | ||
// Technically these should live on a separate server, but who cares | ||
@@ -662,0 +495,0 @@ getGroupV1, getGroup, getGroupVersion, getGroupLogsV1, getGroupLogs, createGroupV1, createGroup, modifyGroupV1, modifyGroup, getStorageManifest, getStorageManifestByVersion, putStorage, putStorageRead, getCallLink, createOrUpdateCallLink, deleteCallLink, ...[microrouter_1.head, microrouter_1.patch, microrouter_1.post].map((method) => method('/cdn3/*', async (req, res) => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3946798
72792