@signalapp/mock-server
Advanced tools
Comparing version 6.6.0 to 6.7.0
{ | ||
"name": "@signalapp/mock-server", | ||
"version": "6.6.0", | ||
"version": "6.7.0", | ||
"description": "Mock Signal Server for writing tests", | ||
@@ -44,2 +44,4 @@ "main": "src/index.js", | ||
"@signalapp/libsignal-client": "^0.45.0", | ||
"@tus/file-store": "^1.4.0", | ||
"@tus/server": "^1.7.0", | ||
"debug": "^4.3.2", | ||
@@ -46,0 +48,0 @@ "long": "^4.0.0", |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import Long from 'long'; | ||
import { ServerOptions } from 'https'; | ||
import { AddressInfo } from 'net'; | ||
import { ProvisionIdString, ServiceIdKind, ServiceIdString } from '../types'; | ||
@@ -29,2 +27,3 @@ import { Group as GroupData } from '../data/group'; | ||
maxStorageReadKeys?: number; | ||
cdn3Path?: string; | ||
}>; | ||
@@ -52,3 +51,2 @@ export type CreatePrimaryDeviceOptions = Readonly<{ | ||
private readonly knownNumbers; | ||
private https; | ||
private emptyAttachment; | ||
@@ -65,3 +63,2 @@ private provisionQueue; | ||
close(): Promise<void>; | ||
address(): AddressInfo; | ||
waitForProvision(): Promise<PendingProvision>; | ||
@@ -76,2 +73,3 @@ private waitForStorageManifest; | ||
stopRateLimiting({ source, target, }: RateLimitOptions): number | undefined; | ||
storeAttachmentOnCdn(cdnNumber: number, cdnKey: string, data: Uint8Array): void; | ||
getProvisioningResponse(id: ProvisionIdString): Promise<ProvisioningResponse>; | ||
@@ -78,0 +76,0 @@ handleMessage(source: Device | undefined, serviceIdKind: ServiceIdKind, envelopeType: EnvelopeType, target: Device, encrypted: Buffer): Promise<void>; |
@@ -42,3 +42,2 @@ "use strict"; | ||
knownNumbers = new Set(); | ||
https; | ||
emptyAttachment; | ||
@@ -81,3 +80,3 @@ provisionQueue; | ||
this.emptyAttachment = (0, attachment_1.attachmentToPointer)(emptyCDNKey, emptyData); | ||
const httpHandler = (0, http_1.createHandler)(this); | ||
const httpHandler = (0, http_1.createHandler)(this, { cdn3Path: this.config.cdn3Path }); | ||
const server = https_1.default.createServer(this.config.https || {}, (req, res) => { | ||
@@ -107,12 +106,2 @@ (0, micro_1.run)(req, res, httpHandler); | ||
} | ||
address() { | ||
if (!this.https) { | ||
throw new Error('Not listening'); | ||
} | ||
const result = this.https.address(); | ||
if (!result || typeof result !== 'object') { | ||
throw new Error('Invalid .address() result'); | ||
} | ||
return result; | ||
} | ||
// | ||
@@ -227,2 +216,8 @@ // Various queues | ||
} | ||
storeAttachmentOnCdn(cdnNumber, cdnKey, data) { | ||
assert_1.default.strictEqual(cdnNumber, 3, 'Only cdn 3 currently supported'); | ||
const { cdn3Path } = this.config; | ||
(0, assert_1.default)(cdn3Path, 'cdn3Path must be provided to store attachments'); | ||
fs_1.default.writeFileSync(path_1.default.join(cdn3Path, cdnKey), data); | ||
} | ||
// | ||
@@ -229,0 +224,0 @@ // Implement Server's abstract methods |
@@ -13,7 +13,7 @@ import z from 'zod'; | ||
}, "strip", z.ZodTypeAny, { | ||
keyId: number; | ||
publicKey: string; | ||
}, { | ||
keyId: number; | ||
}, { | ||
publicKey: string; | ||
keyId: number; | ||
}>; | ||
@@ -26,8 +26,8 @@ export type ServerPreKey = z.infer<typeof PreKeySchema>; | ||
}, "strip", z.ZodTypeAny, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
@@ -41,7 +41,7 @@ }>; | ||
}, "strip", z.ZodTypeAny, { | ||
keyId: number; | ||
publicKey: string; | ||
}, { | ||
keyId: number; | ||
}, { | ||
publicKey: string; | ||
keyId: number; | ||
}>, "many">; | ||
@@ -53,8 +53,8 @@ pqPreKeys: z.ZodOptional<z.ZodArray<z.ZodObject<{ | ||
}, "strip", z.ZodTypeAny, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
@@ -67,8 +67,8 @@ }>, "many">>; | ||
}, "strip", z.ZodTypeAny, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
@@ -81,8 +81,8 @@ }>>; | ||
}, "strip", z.ZodTypeAny, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
@@ -92,18 +92,18 @@ }>>; | ||
preKeys: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
}[]; | ||
pqPreKeys?: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}[] | undefined; | ||
pqLastResortPreKey?: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
} | undefined; | ||
signedPreKey?: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
@@ -113,18 +113,18 @@ } | undefined; | ||
preKeys: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
}[]; | ||
pqPreKeys?: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}[] | undefined; | ||
pqLastResortPreKey?: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
} | undefined; | ||
signedPreKey?: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
@@ -207,2 +207,3 @@ } | undefined; | ||
}, "strip", z.ZodTypeAny, { | ||
fetchesMessages: boolean; | ||
registrationId: number & { | ||
@@ -215,8 +216,7 @@ __reg_id: never; | ||
name: string; | ||
}, { | ||
fetchesMessages: boolean; | ||
}, { | ||
registrationId: number; | ||
pniRegistrationId: number; | ||
name: string; | ||
fetchesMessages: boolean; | ||
}>; | ||
@@ -228,8 +228,8 @@ aciSignedPreKey: z.ZodObject<{ | ||
}, "strip", z.ZodTypeAny, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
@@ -242,8 +242,8 @@ }>; | ||
}, "strip", z.ZodTypeAny, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
@@ -256,8 +256,8 @@ }>; | ||
}, "strip", z.ZodTypeAny, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
@@ -270,8 +270,8 @@ }>; | ||
}, "strip", z.ZodTypeAny, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}, { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
@@ -282,2 +282,3 @@ }>; | ||
accountAttributes: { | ||
fetchesMessages: boolean; | ||
registrationId: number & { | ||
@@ -290,22 +291,21 @@ __reg_id: never; | ||
name: string; | ||
fetchesMessages: boolean; | ||
}; | ||
aciSignedPreKey: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}; | ||
pniSignedPreKey: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}; | ||
aciPqLastResortPreKey: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}; | ||
pniPqLastResortPreKey: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
@@ -316,25 +316,25 @@ }; | ||
accountAttributes: { | ||
fetchesMessages: boolean; | ||
registrationId: number; | ||
pniRegistrationId: number; | ||
name: string; | ||
fetchesMessages: boolean; | ||
}; | ||
aciSignedPreKey: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}; | ||
pniSignedPreKey: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}; | ||
aciPqLastResortPreKey: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
}; | ||
pniPqLastResortPreKey: { | ||
keyId: number; | ||
publicKey: string; | ||
keyId: number; | ||
signature: string; | ||
@@ -351,8 +351,8 @@ }; | ||
}, "strip", z.ZodTypeAny, { | ||
attributes: number; | ||
members: number; | ||
attributes: number; | ||
addFromInviteLink: number; | ||
}, { | ||
attributes: number; | ||
members: number; | ||
attributes: number; | ||
addFromInviteLink: number; | ||
@@ -363,17 +363,17 @@ }>; | ||
publicKey: Uint8Array; | ||
version: 0; | ||
accessControl: { | ||
attributes: number; | ||
members: number; | ||
attributes: number; | ||
addFromInviteLink: number; | ||
}; | ||
version: 0; | ||
members: unknown[]; | ||
}, { | ||
publicKey: Uint8Array; | ||
version: 0; | ||
accessControl: { | ||
attributes: number; | ||
members: number; | ||
attributes: number; | ||
addFromInviteLink: number; | ||
}; | ||
version: 0; | ||
members: unknown[]; | ||
@@ -380,0 +380,0 @@ }>; |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { SenderCertificate } from '@signalapp/libsignal-client'; | ||
import { AuthCredentialPresentation, CreateCallLinkCredentialRequest, CreateCallLinkCredentialResponse, GenericServerSecretParams, ProfileKeyCredentialRequest, ServerSecretParams } from '@signalapp/libsignal-client/zkgroup'; | ||
import https from 'https'; | ||
import Long from 'long'; | ||
import { AddressInfo } from 'net'; | ||
import { signalservice as Proto } from '../../protos/compiled'; | ||
@@ -140,2 +144,4 @@ import { ServerCertificate } from '../crypto'; | ||
protected privGenericServerSecret: GenericServerSecretParams | undefined; | ||
protected https: https.Server | undefined; | ||
address(): AddressInfo; | ||
generateAci(): Promise<AciString>; | ||
@@ -142,0 +148,0 @@ generatePni(): Promise<PniString>; |
@@ -57,2 +57,13 @@ "use strict"; | ||
privGenericServerSecret; | ||
https; | ||
address() { | ||
if (!this.https) { | ||
throw new Error('Not listening'); | ||
} | ||
const result = this.https.address(); | ||
if (!result || typeof result !== 'object') { | ||
throw new Error('Invalid .address() result'); | ||
} | ||
return result; | ||
} | ||
// | ||
@@ -59,0 +70,0 @@ // Service Ids |
import { RequestHandler } from 'micro'; | ||
import { Server } from './base'; | ||
export declare const createHandler: (server: Server) => RequestHandler; | ||
export declare const createHandler: (server: Server, { cdn3Path }: { | ||
cdn3Path: string | undefined; | ||
}) => RequestHandler; |
"use strict"; | ||
// Copyright 2022 Signal Messenger, LLC | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -16,2 +39,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const microrouter_1 = require("microrouter"); | ||
const fs = __importStar(require("fs")); | ||
const server_1 = require("@tus/server"); | ||
const file_store_1 = require("@tus/file-store"); | ||
const compiled_1 = require("../../protos/compiled"); | ||
@@ -22,2 +48,3 @@ const crypto_1 = require("../crypto"); | ||
const util_1 = require("../util"); | ||
const path_1 = require("path"); | ||
const debug = (0, debug_1.default)('mock:http'); | ||
@@ -51,3 +78,3 @@ const parsePassword = (req) => { | ||
}; | ||
const createHandler = (server) => { | ||
const createHandler = (server, { cdn3Path }) => { | ||
// | ||
@@ -85,2 +112,24 @@ // Unauthorized requests | ||
// | ||
const tusServer = new server_1.Server({ | ||
path: '/cdn3', | ||
datastore: new file_store_1.FileStore({ directory: cdn3Path ?? '' }), | ||
namingFunction: (req) => { | ||
(0, assert_1.default)(req.url); | ||
return req.url.split('/').at(-1); | ||
}, | ||
}); | ||
const getCdn3Attachment = (0, microrouter_1.get)('/cdn3/attachments/:key', async (req, res) => { | ||
(0, assert_1.default)(cdn3Path, 'cdn3Path must be set'); | ||
try { | ||
const data = fs.readFileSync((0, path_1.join)(cdn3Path, req.params.key)); | ||
return (0, micro_1.send)(res, 200, data); | ||
} | ||
catch (e) { | ||
(0, assert_1.default)(e instanceof Error); | ||
if ('code' in e && e.code === 'ENOENT') { | ||
return (0, micro_1.send)(res, 404); | ||
} | ||
return (0, micro_1.send)(res, 500, e.message); | ||
} | ||
}); | ||
const getAttachment = (0, microrouter_1.get)('/attachments/:key/:subkey', async (req, res) => { | ||
@@ -638,5 +687,7 @@ const { key, subkey } = req.params; | ||
// Technically these should live on a separate server, but who cares | ||
getGroupV1, getGroup, getGroupVersion, getGroupLogsV1, getGroupLogs, createGroupV1, createGroup, modifyGroupV1, modifyGroup, getStorageManifest, getStorageManifestByVersion, putStorage, putStorageRead, getCallLink, createOrUpdateCallLink, deleteCallLink, | ||
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) => { | ||
await tusServer.handle(req, res); | ||
})), getCdn3Attachment, | ||
// TODO(indutny): support this | ||
(0, microrouter_1.get)('/v1/groups/token', notFound), (0, microrouter_1.get)('/stickers/', notFound), (0, microrouter_1.get)('/*', notFoundAfterAuth), (0, microrouter_1.put)('/*', notFoundAfterAuth)); | ||
(0, microrouter_1.get)('/v1/groups/token', notFound), (0, microrouter_1.get)('/stickers/', notFound), (0, microrouter_1.get)('/*', notFoundAfterAuth), (0, microrouter_1.put)('/*', notFoundAfterAuth), (0, microrouter_1.post)('/*', notFoundAfterAuth)); | ||
return (req, res) => { | ||
@@ -643,0 +694,0 @@ debug('got request %s %s', req.method, req.url); |
@@ -16,2 +16,3 @@ "use strict"; | ||
const SealedSenderMultiRecipientMessage_1 = __importDefault(require("@signalapp/libsignal-client/dist/SealedSenderMultiRecipientMessage")); | ||
const uuid_1 = require("uuid"); | ||
const compiled_1 = require("../../../protos/compiled"); | ||
@@ -315,2 +316,12 @@ const schemas_1 = require("../../data/schemas"); | ||
}); | ||
// | ||
// Attachment upload forms | ||
// | ||
this.router.get('/v4/attachments/form/upload', async () => { | ||
const key = (0, uuid_1.v4)(); | ||
const headers = { expectedHeaders: (0, uuid_1.v4)() }; | ||
const address = this.server.address(); | ||
const signedUploadLocation = `https://127.0.0.1:${address.port}/cdn3/${key}`; | ||
return [200, { cdn: 3, key, headers, signedUploadLocation }]; | ||
}); | ||
} | ||
@@ -317,0 +328,0 @@ async start() { |
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
3663701
67833
12
64
5
+ Added@tus/file-store@^1.4.0
+ Added@tus/server@^1.7.0
+ Added@redis/client@1.6.0(transitive)
+ Added@tus/file-store@1.5.0(transitive)
+ Added@tus/server@1.8.0(transitive)
+ Added@tus/utils@0.4.0(transitive)
+ Added@types/node@22.5.5(transitive)
+ Addedcluster-key-slot@1.1.2(transitive)
+ Addedgeneric-pool@3.9.0(transitive)
+ Addedlodash.throttle@4.1.1(transitive)
+ Addedyallist@4.0.0(transitive)
- Removed@types/node@22.5.4(transitive)