Skip to content

Commit aacc8e1

Browse files
committed
Add tests for decodeRecoveryKey
1 parent 87bd00e commit aacc8e1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2024 The Matrix.org Foundation C.I.C.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { decodeRecoveryKey, encodeRecoveryKey } from "../../../src/crypto-api";
18+
19+
describe("recovery key", () => {
20+
describe("decodeRecoveryKey", () => {
21+
it("should thrown an incorrect parity", () => {
22+
expect(() => decodeRecoveryKey("miaou")).toThrow("Incorrect parity");
23+
});
24+
25+
it("should thrown an incorrect length error", () => {
26+
const key = [0, 1];
27+
const encodedKey = encodeRecoveryKey(key);
28+
29+
expect(() => decodeRecoveryKey(encodedKey!)).toThrow("Incorrect length");
30+
});
31+
32+
it("should decode a valid encoded key", () => {
33+
const key = Array.from({ length: 32 }, (_, i) => i);
34+
const encodedKey = encodeRecoveryKey(key);
35+
36+
expect(decodeRecoveryKey(encodedKey!)).toEqual(new Uint8Array(key));
37+
});
38+
});
39+
});

0 commit comments

Comments
 (0)