Skip to content

Commit

Permalink
Merge branch 'main' into jwk
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 authored and lauckhart committed Aug 7, 2023
2 parents 6c4e685 + 5fb93a8 commit b70ae7b
Show file tree
Hide file tree
Showing 49 changed files with 1,483 additions and 1,174 deletions.
37 changes: 29 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/matter-node.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@
"@types/bn.js": "^5.1.1",
"@types/bytebuffer": "^5.0.44",
"@types/elliptic": "^6.4.14",
"@types/jest": "^29.5.3",
"@types/node-localstorage": "^1.3.0",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"bn.js": "^5.2.1",
"jest": "^29.5.0",
"eslint": "^8.40.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5",
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { FabricIndex, VendorId, FabricId, NodeId } from "@project-chip/matter.js
import { ByteArray } from "@project-chip/matter.js/util";
import { Attributes, ClusterServerObj, Commands, Events } from "@project-chip/matter.js/cluster";
import { Endpoint } from "@project-chip/matter.js/device";
import { PrivateKey } from "../../src/crypto/export";
import { PrivateKey } from "@project-chip/matter.js/crypto";

export const ZERO = new ByteArray(1);
const PRIVATE_KEY = new ByteArray(32);
Expand Down
2 changes: 1 addition & 1 deletion packages/matter-node.js/test/crypto/CryptoTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as assert from "assert";
import { CryptoNode } from "../../src/crypto/CryptoNode";
import * as crypto from "crypto";
import { ByteArray } from "@project-chip/matter.js/util";
import { Key, PrivateKey, PublicKey } from "../../src/crypto/export";
import { Key, PrivateKey, PublicKey } from "@project-chip/matter.js/crypto";

const KEY = ByteArray.fromHex("abf227feffea8c38e688ddcbffc459f1");
const ENCRYPTED_DATA = ByteArray.fromHex("c4527bd6965518e8382edbbd28f27f42492d0766124f9961a772");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import * as assert from "assert";
import { TlvEncryptedDataSigma2, TlvEncryptedDataSigma3, TlvSignedData } from "@project-chip/matter.js/session";
import { ByteArray } from "@project-chip/matter.js/util";
import { PublicKey } from "@project-chip/matter.js/crypto";
import { CryptoNode } from "../../../src/crypto/CryptoNode";
import { PublicKey } from "../../../src/crypto/export";

const cryptoNode = new CryptoNode();

Expand Down
5 changes: 4 additions & 1 deletion packages/matter.js/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Config } from 'jest';

const config: Config = {
testMatch: ["<rootDir>/test/**/*.ts"],
testMatch: ["<rootDir>/test/**/*Test.ts"],
preset: "ts-jest",
testEnvironment: "node",
collectCoverage: true,
Expand All @@ -10,6 +10,9 @@ const config: Config = {
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.[jt]s$': '$1',
},
setupFiles: [
"<rootDir>/test/support/define-globals.ts"
],
maxWorkers: "25%", // to make sure jest is not using all available resources
};

Expand Down
6 changes: 3 additions & 3 deletions packages/matter.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"build": "npm run build-cjs && npm run build-es",
"build-clean": "npm run clean && npm run build",
"build-doc": "typedoc --excludeExternals --plugin typedoc-plugin-missing-exports --plugin typedoc-plugin-markdown --gitRemote upstream --tsconfig tsconfig.dist-cjs.json",
"test-node": "TZ=utc NODE_OPTIONS=--experimental-vm-modules jest",
"test-web": "TZ=utc karma start test/karma.conf.cjs",
"test-node": "NODE_OPTIONS=--experimental-vm-modules jest",
"test-web": "karma start test/karma.conf.cjs",
"test": "npm run test-node && npm run test-web"
},
"dependencies": {
Expand All @@ -41,7 +41,7 @@
"devDependencies": {
"@types/bn.js": "^5.1.1",
"@types/elliptic": "^6.4.14",
"@types/jest": "^29.5.1",
"@types/expect": "^24.3.0",
"jest": "^29.5.0",
"karma": "^6.4.2",
"karma-chrome-launcher": "^3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/matter.js/src/cluster/ClusterFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function extendCluster<F extends BitSchema>(
export function validateFeatureSelection(features: string[], validFeatures: { [name: string]: string }) {
for (const f of features) {
if (!validFeatures[f]) {
throw new IllegalClusterError(`"${f} is not a valid feature identifier`);
throw new IllegalClusterError(`"${f}" is not a valid feature identifier`);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/matter.js/src/codec/DnsCodec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class DnsCodec {

static encode({ messageType, transactionId = 0, queries = [], answers = [], authorities = [], additionalRecords = [] }: Partial<DnsMessage>): ByteArray {
if (messageType === undefined) throw new InternalError("Message type must be specified!");
if (queries.length > 0 && messageType !== DnsMessageType.Query) throw new InternalError("Queries can only be included in query messages!");
if (queries.length > 0 && messageType !== DnsMessageType.Query && messageType !== DnsMessageType.TruncatedQuery) throw new InternalError("Queries can only be included in query messages!");
if (authorities.length > 0) throw new NotImplementedError("Authority answers are not supported yet!");

const writer = new DataWriter(Endian.Big);
Expand Down
46 changes: 28 additions & 18 deletions packages/matter.js/test/ble/BtpSessionHandlerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import assert from "assert";
import { Time } from "../../src/time/Time.js";
import { TimeFake } from "../../src/time/TimeFake.js";
import { ByteArray } from "../../src/util/ByteArray.js";
Expand Down Expand Up @@ -38,7 +37,7 @@ describe("BtpSessionHandler", () => {

const result = await writeBlePromise;

assert.deepEqual(result, ByteArray.fromHex("656c04670006"));
expect(result).toEqual(ByteArray.fromHex("656c04670006"))

allowClose = true;
await btpSession.close();
Expand All @@ -65,7 +64,7 @@ describe("BtpSessionHandler", () => {

const result = await writeBlePromise;

assert.deepEqual(result, ByteArray.fromHex("656c04670006"));
expect(result).toEqual(ByteArray.fromHex("656c04670006"))

allowClose = true;
await btpSession.close();
Expand All @@ -92,18 +91,19 @@ describe("BtpSessionHandler", () => {

const result = await writeBlePromise;

assert.deepEqual(result, ByteArray.fromHex("656c04170006"));
expect(result).toEqual(ByteArray.fromHex("656c04170006"))

allowClose = true;
await btpSession.close();
});

it("Client does not share the same supported BTP version", async () => {

const handshakeRequest = ByteArray.fromHex("656c05000000000006");
const { promise: disconnectBlePromise, resolver: disconnectBleResolver } = await getPromiseResolver<void>();

await assert.rejects(async () => {
// change to expect().rejects.toThrow() when no longer using jasmine expect
let error;
try {
const btpSession = await BtpSessionHandler.createFromHandshakeRequest(
100,
handshakeRequest,
Expand All @@ -120,7 +120,10 @@ describe("BtpSessionHandler", () => {
await disconnectBlePromise;

await btpSession.close();
}, BtpProtocolError, "No supported BTP version found in 5");
} catch (e) {
error = e;
}
expect(error).toEqual(new BtpProtocolError("No supported BTP version found in 5"));
});
});

Expand Down Expand Up @@ -165,7 +168,7 @@ describe("BtpSessionHandler", () => {
);

const result = await localWriteBlePromise;
assert.deepEqual(result, ByteArray.fromHex("656c04170006"));
expect(result).toEqual(ByteArray.fromHex("656c04170006"))
});

afterEach(async () => {
Expand Down Expand Up @@ -234,10 +237,10 @@ describe("BtpSessionHandler", () => {
await btpSessionHandler?.handleIncomingBleData(matterMessage);

const matterHandlerResult = await handleMatterMessagePromise;
assert.deepEqual(matterHandlerResult, segmentPayload);
expect(matterHandlerResult).toEqual(segmentPayload)

const result = await writeBlePromise;
assert.deepEqual(result, ByteArray.fromHex("0d00010900090807060504030201"));
expect(result).toEqual(ByteArray.fromHex("0d00010900090807060504030201"))
});

it("received bytes more than fragment size", async () => {
Expand Down Expand Up @@ -270,7 +273,14 @@ describe("BtpSessionHandler", () => {
});

it("Btp packet must not be 0", async () => {
await assert.rejects(async () => await btpSessionHandler?.sendMatterMessage(ByteArray.fromHex("")), BtpFlowError, "BTP packet must not be empty");
// change to expect().rejects.toThrow() when no longer using jasmine expect
let error;
try {
await btpSessionHandler?.sendMatterMessage(ByteArray.fromHex(""))
} catch (e) {
error = e;
}
expect(error).toEqual(new BtpFlowError("BTP packet must not be empty"));
});

it("handles a correct two segment long Matter Message", async () => {
Expand Down Expand Up @@ -326,9 +336,9 @@ describe("BtpSessionHandler", () => {

const matterHandlerResult = await handleMatterMessagePromise;

assert.deepEqual(matterHandlerResult, segmentPayload);
assert.deepEqual(promiseResolver[0], ByteArray.fromHex("0901011200030201090807060504030201090807"));
assert.deepEqual(promiseResolver[1], ByteArray.fromHex("0602060504"));
expect(matterHandlerResult).toEqual(segmentPayload)
expect(promiseResolver[0]).toEqual(ByteArray.fromHex("0901011200030201090807060504030201090807"))
expect(promiseResolver[1]).toEqual(ByteArray.fromHex("0602060504"))
});

it("triggers timeout as did not send ack within 5 sec", async () => {
Expand Down Expand Up @@ -369,8 +379,8 @@ describe("BtpSessionHandler", () => {
const result = await writeBlePromise;
const matterHandlerResult = await handleMatterMessagePromise;

assert.deepEqual(result, ByteArray.fromHex("080001"));
assert.deepEqual(matterHandlerResult, segmentPayload);
expect(result).toEqual(ByteArray.fromHex("080001"))
expect(matterHandlerResult).toEqual(segmentPayload)
});

it("triggers timeout as did not receive ack within 15 sec", async () => {
Expand Down Expand Up @@ -476,10 +486,10 @@ describe("BtpSessionHandler", () => {

await btpSessionHandler?.handleIncomingBleData(matterMessage);
const matterHandlerResult = await handleMatterMessagePromise;
assert.deepEqual(matterHandlerResult, segmentPayload);
expect(matterHandlerResult).toEqual(segmentPayload)

const result = await writeBlePromise;
assert.deepEqual(result, ByteArray.fromHex("0d00010900090807060504030201"));
expect(result).toEqual(ByteArray.fromHex("0d00010900090807060504030201"))
}
});
});
Expand Down
Loading

0 comments on commit b70ae7b

Please sign in to comment.