Support PNI in QualifiedAddress.parse
This commit is contained in:
parent
0b629c9f70
commit
7bad05f5a0
3 changed files with 18 additions and 15 deletions
|
@ -48,6 +48,7 @@ const {
|
|||
|
||||
describe('SignalProtocolStore', () => {
|
||||
const ourAci = generateAci();
|
||||
const ourPni = generatePni();
|
||||
const theirAci = generateAci();
|
||||
let store: SignalProtocolStore;
|
||||
let identityKey: KeyPairType;
|
||||
|
@ -1385,6 +1386,21 @@ describe('SignalProtocolStore', () => {
|
|||
await store.archiveSiblingSessions(id.address, { zone });
|
||||
});
|
||||
|
||||
it('should not throw in archiveSession on PNI', async () => {
|
||||
const id = new QualifiedAddress(ourPni, new Address(theirAci, 1));
|
||||
|
||||
await store.storeSession(id, getSessionRecord(true));
|
||||
|
||||
await store.archiveSession(id);
|
||||
|
||||
const { devices, emptyServiceIds } = await store.getOpenDevices(ourPni, [
|
||||
theirAci,
|
||||
]);
|
||||
|
||||
assert.deepEqual(devices, []);
|
||||
assert.deepEqual(emptyServiceIds, [theirAci]);
|
||||
});
|
||||
|
||||
it('can be concurrently re-entered after waiting', async () => {
|
||||
const a = new Zone('a');
|
||||
const b = new Zone('b');
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { strictAssert } from '../util/assert';
|
||||
|
||||
import type { ServiceIdString } from './ServiceId';
|
||||
import { isServiceIdString } from './ServiceId';
|
||||
|
||||
export type AddressStringType = `${ServiceIdString}.${number}`;
|
||||
|
||||
const ADDRESS_REGEXP = /^([:0-9a-f-]+).(\d+)$/i;
|
||||
|
||||
export class Address {
|
||||
constructor(
|
||||
public readonly serviceId: ServiceIdString,
|
||||
|
@ -20,15 +15,6 @@ export class Address {
|
|||
return `${this.serviceId}.${this.deviceId}`;
|
||||
}
|
||||
|
||||
public static parse(value: string): Address {
|
||||
const match = value.match(ADDRESS_REGEXP);
|
||||
strictAssert(match != null, `Invalid Address: ${value}`);
|
||||
const [whole, serviceId, deviceId] = match;
|
||||
strictAssert(whole === value, 'Integrity check');
|
||||
strictAssert(isServiceIdString(serviceId), 'Their service id is incorrect');
|
||||
return Address.create(serviceId, parseInt(deviceId, 10));
|
||||
}
|
||||
|
||||
public static create(serviceId: ServiceIdString, deviceId: number): Address {
|
||||
return new Address(serviceId, deviceId);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ import { isServiceIdString } from './ServiceId';
|
|||
import type { AddressStringType } from './Address';
|
||||
import { Address } from './Address';
|
||||
|
||||
const QUALIFIED_ADDRESS_REGEXP = /^([:0-9a-f-]+):([:0-9a-f-]+).(\d+)$/i;
|
||||
const QUALIFIED_ADDRESS_REGEXP =
|
||||
/^((?:PNI:)?[:0-9a-f-]+):((?:PNI:)?[:0-9a-f-]+).(\d+)$/i;
|
||||
|
||||
export type QualifiedAddressCreateOptionsType = Readonly<{
|
||||
ourServiceId: ServiceIdString;
|
||||
|
|
Loading…
Add table
Reference in a new issue