@signalapp/mock-server
Advanced tools
Comparing version 2.12.1 to 2.13.0
{ | ||
"name": "@signalapp/mock-server", | ||
"version": "2.12.1", | ||
"version": "2.13.0", | ||
"description": "Mock Signal Server for writing tests", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -56,2 +56,3 @@ /// <reference types="node" /> | ||
private rateLimitCountByPair; | ||
private unregisteredUuids; | ||
constructor(config?: Config); | ||
@@ -66,2 +67,4 @@ listen(port: number, host?: string): Promise<void>; | ||
createSecondaryDevice(primary: PrimaryDevice): Promise<Device>; | ||
unregister(primary: PrimaryDevice, uuidKind?: UUIDKind): void; | ||
register(primary: PrimaryDevice, uuidKind?: UUIDKind): void; | ||
rateLimit({ source, target }: RateLimitOptions): void; | ||
@@ -71,2 +74,3 @@ stopRateLimiting({ source, target, }: RateLimitOptions): number | undefined; | ||
handleMessage(source: Device | undefined, uuidKind: UUIDKind, envelopeType: EnvelopeType, target: Device, encrypted: Buffer): Promise<void>; | ||
isUnregistered(uuid: UUID): boolean; | ||
isSendRateLimited({ source, target, }: IsSendRateLimitedOptions): boolean; | ||
@@ -73,0 +77,0 @@ updateDeviceKeys(device: Device, uuidKind: UUIDKind, keys: DeviceKeys): Promise<void>; |
@@ -47,2 +47,3 @@ "use strict"; | ||
this.rateLimitCountByPair = new Map(); | ||
this.unregisteredUuids = new Set(); | ||
this.config = { | ||
@@ -210,2 +211,8 @@ timeout: DEFAULT_API_TIMEOUT, | ||
} | ||
unregister(primary, uuidKind = types_1.UUIDKind.ACI) { | ||
this.unregisteredUuids.add(primary.device.getUUIDByKind(uuidKind)); | ||
} | ||
register(primary, uuidKind = types_1.UUIDKind.ACI) { | ||
this.unregisteredUuids.delete(primary.device.getUUIDByKind(uuidKind)); | ||
} | ||
rateLimit({ source, target }) { | ||
@@ -284,2 +291,5 @@ this.rateLimitCountByPair.set(`${source}:${target}`, 0); | ||
} | ||
isUnregistered(uuid) { | ||
return this.unregisteredUuids.has(uuid); | ||
} | ||
isSendRateLimited({ source, target, }) { | ||
@@ -286,0 +296,0 @@ const key = `${source}:${target}`; |
@@ -36,2 +36,4 @@ /// <reference types="node" /> | ||
getContact({ device }: PrimaryDevice, uuidKind?: UUIDKind): Proto.IContactRecord | undefined; | ||
removeContact({ device }: PrimaryDevice, uuidKind?: UUIDKind): StorageState; | ||
mergeContact(primary: PrimaryDevice, diff: Proto.IContactRecord): StorageState; | ||
pin(primary: PrimaryDevice, uuidKind?: UUIDKind): StorageState; | ||
@@ -52,2 +54,3 @@ unpin(primary: PrimaryDevice, uuidKind?: UUIDKind): StorageState; | ||
private replaceItem; | ||
private removeItem; | ||
private changePin; | ||
@@ -54,0 +57,0 @@ private changeGroupPin; |
@@ -188,2 +188,16 @@ "use strict"; | ||
} | ||
removeContact({ device }, uuidKind = types_1.UUIDKind.ACI) { | ||
return this.removeItem(item => item.isContact(device, uuidKind)); | ||
} | ||
mergeContact(primary, diff) { | ||
const { device } = primary; | ||
return this | ||
.removeItem(item => item.isContact(device, types_1.UUIDKind.ACI)) | ||
.removeItem(item => item.isContact(device, types_1.UUIDKind.PNI)) | ||
.addContact(primary, { | ||
pni: device.getUUIDByKind(types_1.UUIDKind.PNI), | ||
...diff, | ||
}) | ||
.unpin(primary, types_1.UUIDKind.PNI); | ||
} | ||
pin(primary, uuidKind = types_1.UUIDKind.ACI) { | ||
@@ -219,11 +233,3 @@ return this.changePin(primary, uuidKind, true); | ||
removeRecord(find) { | ||
const itemIndex = this.items.findIndex((item) => find(item.toRecord())); | ||
if (itemIndex === -1) { | ||
throw new Error('Record not found'); | ||
} | ||
const newItems = [ | ||
...this.items.slice(0, itemIndex), | ||
...this.items.slice(itemIndex + 1), | ||
]; | ||
return new StorageState(this.version, newItems); | ||
return this.removeItem((item) => find(item.toRecord())); | ||
} | ||
@@ -310,2 +316,13 @@ getAllGroupRecords() { | ||
} | ||
removeItem(find) { | ||
const itemIndex = this.items.findIndex((item) => find(item)); | ||
if (itemIndex === -1) { | ||
throw new Error('Record not found'); | ||
} | ||
const newItems = [ | ||
...this.items.slice(0, itemIndex), | ||
...this.items.slice(itemIndex + 1), | ||
]; | ||
return new StorageState(this.version, newItems); | ||
} | ||
changePin({ device }, uuidKind, isPinned) { | ||
@@ -312,0 +329,0 @@ const deviceUuid = device.getUUIDByKind(uuidKind); |
@@ -149,2 +149,3 @@ /// <reference types="node" /> | ||
issueExpiringProfileKeyCredential({ uuid, profileKeyCommitment }: Device, request: ProfileKeyCredentialRequest): Promise<Buffer | undefined>; | ||
abstract isUnregistered(uuid: UUID): boolean; | ||
abstract isSendRateLimited(options: IsSendRateLimitedOptions): boolean; | ||
@@ -151,0 +152,0 @@ protected set certificate(value: ServerCertificate); |
@@ -209,2 +209,5 @@ "use strict"; | ||
async prepareMultiDeviceMessage(source, targetUUID, messages) { | ||
if (this.isUnregistered(targetUUID)) { | ||
return { status: 'unknown' }; | ||
} | ||
const devices = await this.getAllDevicesByUUID(targetUUID); | ||
@@ -211,0 +214,0 @@ if (devices.length === 0) { |
@@ -33,2 +33,5 @@ "use strict"; | ||
} | ||
if (this.server.isUnregistered(uuid)) { | ||
return [404, { error: 'Unregistered' }]; | ||
} | ||
const accessError = this.checkAccessKey(target, headers); | ||
@@ -183,2 +186,5 @@ if (accessError !== undefined) { | ||
} | ||
if (this.server.isUnregistered(targetUUID)) { | ||
return [404, { error: 'Unregistered' }]; | ||
} | ||
if (this.device && | ||
@@ -185,0 +191,0 @@ this.server.isSendRateLimited({ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
3366798
61501
8