Use DoH for query fallback
This commit is contained in:
parent
f61d8f38b0
commit
0e606c45b0
2 changed files with 234 additions and 37 deletions
67
ts/test-node/util/dns_test.ts
Normal file
67
ts/test-node/util/dns_test.ts
Normal file
|
@ -0,0 +1,67 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
|
||||
import { DNSCache } from '../../util/dns';
|
||||
import { SECOND } from '../../util/durations';
|
||||
|
||||
const NOW = 1680726906000;
|
||||
|
||||
describe('dns/DNSCache', () => {
|
||||
let sandbox: sinon.SinonSandbox;
|
||||
let cache: DNSCache;
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox();
|
||||
cache = new DNSCache();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
it('should cache records and pick a random one', () => {
|
||||
sandbox.useFakeTimers({
|
||||
now: NOW,
|
||||
});
|
||||
|
||||
const result = cache.setAndPick('signal.org', 4, [
|
||||
{
|
||||
data: '10.0.0.1',
|
||||
expiresAt: NOW + SECOND,
|
||||
},
|
||||
{
|
||||
data: '10.0.0.2',
|
||||
expiresAt: NOW + SECOND,
|
||||
},
|
||||
]);
|
||||
|
||||
assert.oneOf(result, ['10.0.0.1', '10.0.0.2']);
|
||||
});
|
||||
|
||||
it('should invalidate cache after expiration', () => {
|
||||
const clock = sandbox.useFakeTimers({
|
||||
now: NOW,
|
||||
});
|
||||
|
||||
cache.setAndPick('signal.org', 4, [
|
||||
{
|
||||
data: '10.0.0.1',
|
||||
expiresAt: NOW + SECOND,
|
||||
},
|
||||
{
|
||||
data: '10.0.0.2',
|
||||
expiresAt: NOW + 2 * SECOND,
|
||||
},
|
||||
]);
|
||||
|
||||
assert.oneOf(cache.get('signal.org', 4), ['10.0.0.1', '10.0.0.2']);
|
||||
|
||||
clock.tick(SECOND);
|
||||
assert.strictEqual(cache.get('signal.org', 4), '10.0.0.2');
|
||||
|
||||
clock.tick(SECOND);
|
||||
assert.strictEqual(cache.get('signal.org', 4), undefined);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue