Merge branch 'develop' into Bubble-bericht

This commit is contained in:
Ayush PS 2021-05-07 18:32:38 +05:30
parent f367d617c5
commit c843387043
264 changed files with 7383 additions and 3268 deletions

View file

@ -84,22 +84,22 @@ describe('MegolmExportEncryption', function() {
it('should handle missing header', function() {
const input=stringToArray(`-----`);
return MegolmExportEncryption.decryptMegolmKeyFile(input, '')
.then((res) => {
throw new Error('expected to throw');
}, (error) => {
expect(error.message).toEqual('Header line not found');
});
.then((res) => {
throw new Error('expected to throw');
}, (error) => {
expect(error.message).toEqual('Header line not found');
});
});
it('should handle missing trailer', function() {
const input=stringToArray(`-----BEGIN MEGOLM SESSION DATA-----
-----`);
return MegolmExportEncryption.decryptMegolmKeyFile(input, '')
.then((res) => {
throw new Error('expected to throw');
}, (error) => {
expect(error.message).toEqual('Trailer line not found');
});
.then((res) => {
throw new Error('expected to throw');
}, (error) => {
expect(error.message).toEqual('Trailer line not found');
});
});
it('should handle a too-short body', function() {
@ -109,11 +109,11 @@ cissyYBxjsfsAn
-----END MEGOLM SESSION DATA-----
`);
return MegolmExportEncryption.decryptMegolmKeyFile(input, '')
.then((res) => {
throw new Error('expected to throw');
}, (error) => {
expect(error.message).toEqual('Invalid file: too short');
});
.then((res) => {
throw new Error('expected to throw');
}, (error) => {
expect(error.message).toEqual('Invalid file: too short');
});
});
// TODO find a subtlecrypto shim which doesn't break this test

View file

@ -26,7 +26,7 @@ describe("mkClient self-test", function() {
["@TF:h", true],
["@FT:h", false],
["@FF:h", false]],
)("behaves well for user trust %s", (userId, trust) => {
)("behaves well for user trust %s", (userId, trust) => {
expect(mkClient().checkUserTrust(userId).isCrossSigningVerified()).toBe(trust);
});
@ -35,7 +35,7 @@ describe("mkClient self-test", function() {
["@TF:h", false],
["@FT:h", true],
["@FF:h", false]],
)("behaves well for device trust %s", (userId, trust) => {
)("behaves well for device trust %s", (userId, trust) => {
expect(mkClient().checkDeviceTrust(userId, "device").isVerified()).toBe(trust);
});
});
@ -128,7 +128,7 @@ describe("shieldStatusForMembership self-trust behaviour", function() {
describe("shieldStatusForMembership other-trust behaviour", function() {
beforeAll(() => {
DMRoomMap._sharedInstance = {
DMRoomMap.sharedInstance = {
getUserIdForRoomId: (roomId) => roomId === "DM" ? "@any:h" : null,
};
});

View file

@ -22,6 +22,7 @@ import {
arrayHasOrderChange,
arrayMerge,
arraySeed,
arrayTrimFill,
arrayUnion,
ArrayUtil,
GroupedArray,
@ -64,6 +65,38 @@ describe('arrays', () => {
});
});
describe('arrayTrimFill', () => {
it('should shrink arrays', () => {
const input = [1, 2, 3];
const output = [1, 2];
const seed = [4, 5, 6];
const result = arrayTrimFill(input, output.length, seed);
expect(result).toBeDefined();
expect(result).toHaveLength(output.length);
expect(result).toEqual(output);
});
it('should expand arrays', () => {
const input = [1, 2, 3];
const output = [1, 2, 3, 4, 5];
const seed = [4, 5, 6];
const result = arrayTrimFill(input, output.length, seed);
expect(result).toBeDefined();
expect(result).toHaveLength(output.length);
expect(result).toEqual(output);
});
it('should keep arrays the same', () => {
const input = [1, 2, 3];
const output = [1, 2, 3];
const seed = [4, 5, 6];
const result = arrayTrimFill(input, output.length, seed);
expect(result).toBeDefined();
expect(result).toHaveLength(output.length);
expect(result).toEqual(output);
});
});
describe('arraySeed', () => {
it('should create an array of given length', () => {
const val = 1;

33
test/utils/test-utils.ts Normal file
View file

@ -0,0 +1,33 @@
/*
Copyright 2021 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { MatrixClient } from "matrix-js-sdk/src/client";
import { AsyncStoreWithClient } from "../../src/stores/AsyncStoreWithClient";
// These methods make some use of some private methods on the AsyncStoreWithClient to simplify getting into a consistent
// ready state without needing to wire up a dispatcher and pretend to be a js-sdk client.
export const setupAsyncStoreWithClient = async (store: AsyncStoreWithClient<any>, client: MatrixClient) => {
// @ts-ignore
store.readyStore.useUnitTestClient(client);
// @ts-ignore
await store.onReady();
};
export const resetAsyncStoreWithClient = async (store: AsyncStoreWithClient<any>) => {
// @ts-ignore
await store.onNotReady();
};