From d15ae6339654f53ea34c2929829bb70669ef25c9 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Wed, 17 Aug 2022 16:31:18 -0700 Subject: [PATCH] Test that the zkgroup serverPublicParams are up to date --- ts/test-node/util/zkgroup_test.ts | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ts/test-node/util/zkgroup_test.ts diff --git a/ts/test-node/util/zkgroup_test.ts b/ts/test-node/util/zkgroup_test.ts new file mode 100644 index 000000000..f17a6a365 --- /dev/null +++ b/ts/test-node/util/zkgroup_test.ts @@ -0,0 +1,38 @@ +// Copyright 2022 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import { assert } from 'chai'; +import * as fs from 'node:fs'; +import path from 'node:path'; +import { ServerPublicParams } from '@signalapp/libsignal-client/zkgroup'; + +describe('zkgroup', () => { + describe('serverPublicParams', () => { + const configDir = 'config'; + + for (const file of fs.readdirSync(configDir)) { + if (!file.endsWith('.json')) { + continue; + } + const contents = fs.readFileSync(path.join(configDir, file), { + encoding: 'utf-8', + }); + const serverPublicParamsBase64: string | undefined = + JSON.parse(contents).serverPublicParams; + + let test: (() => void) | undefined; + if (serverPublicParamsBase64 !== undefined) { + test = () => { + const serverPublicParams = new ServerPublicParams( + Buffer.from(serverPublicParamsBase64, 'base64') + ); + assert(serverPublicParams); + }; + } else { + // Mark as "pending" / skipped to show we didn't miss a file. + test = undefined; + } + it(`valid in ${file}`, test); + } + }); +});