Skip to content

Commit

Permalink
util: asUint8Array test case with SharedArrayBuffer
Browse files Browse the repository at this point in the history
Change %j to $prop in test case names.
  • Loading branch information
yoursunny committed Dec 3, 2024
1 parent 5815b91 commit 5a3d958
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
8 changes: 4 additions & 4 deletions pkg/keychain/tests/key/signing.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { describe, expect, test } from "vitest";
import { Certificate, createVerifier, EcCurve, ECDSA, Ed25519, generateSigningKey, HMAC, KeyChain, RSA, RsaModulusLength, SigningAlgorithmListFull } from "../..";

describe.each(EcCurve.Choices)("ECDSA %s", (curve) => {
test.each(TestSignVerify.PacketTable)("sign-verify %j", async ({ Packet }) => {
test.each(TestSignVerify.PacketTable)("sign-verify $PacketType", async ({ Packet }) => {
const [pvtA, pubA] = await generateSigningKey("/A/KEY/x", ECDSA, { curve });
const [pvtB, pubB] = await generateSigningKey("/B/KEY/x", ECDSA, { curve });

Expand Down Expand Up @@ -48,7 +48,7 @@ describe.each(EcCurve.Choices)("ECDSA %s", (curve) => {
});

describe.each(RsaModulusLength.Choices)("RSA %d", (modulusLength) => {
describe.each(TestSignVerify.PacketTable)("sign-verify %j", ({ Packet }) => {
describe.each(TestSignVerify.PacketTable)("sign-verify $PacketType", ({ Packet }) => {
test("", { timeout: 15000 }, async () => {
const [pvtA, pubA] = await generateSigningKey("/A/KEY/x", RSA, { modulusLength });
const [pvtB, pubB] = await generateSigningKey("/B/KEY/x", RSA, { modulusLength });
Expand Down Expand Up @@ -77,7 +77,7 @@ describe.each(RsaModulusLength.Choices)("RSA %d", (modulusLength) => {
});

describe("HMAC", () => {
test.each(TestSignVerify.PacketTable)("sign-verify %j", async ({ Packet }) => {
test.each(TestSignVerify.PacketTable)("sign-verify $PacketType", async ({ Packet }) => {
const [pvtA, pubA] = await generateSigningKey("/A/KEY/x", HMAC);
const [pvtB, pubB] = await generateSigningKey("/B/KEY/x", HMAC);

Expand Down Expand Up @@ -111,7 +111,7 @@ print(pkt.hex())
*/

describe("Ed25519", () => {
test.each(TestSignVerify.PacketTable)("sign-verify %j", async ({ Packet }) => {
test.each(TestSignVerify.PacketTable)("sign-verify $PacketType", async ({ Packet }) => {
const [pvtA, pubA] = await generateSigningKey("/A/KEY/x", Ed25519);
const [pvtB, pubB] = await generateSigningKey("/B/KEY/x", Ed25519);

Expand Down
2 changes: 1 addition & 1 deletion pkg/naming-convention1/tests/mod.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const TABLE: Row[] = [
},
];

test.each(TABLE)("%j", ({ marker, convention }) => {
test.each(TABLE)("marker $marker", ({ marker, convention }) => {
const markerHex = marker.toString(16).padStart(2, "0");
const name = new Name().append(convention, 0x00010203).append(convention, 0x0405n);
expect(name.at(0)).toEqualComponent(`%${markerHex}%00%01%02%03`);
Expand Down
2 changes: 1 addition & 1 deletion pkg/ndncert/tests/server-client.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ test("probe entries and redirects", async () => {
checkCaProfile(retrieved, subProfile, "sub_CA");
});

test.each(TABLE)("challenge %j", async ({
test.each(TABLE)("challenge $summary", async ({
makeChallengeLists,
clientShouldFail = false,
}) => {
Expand Down
2 changes: 1 addition & 1 deletion pkg/packet/tests/digest-comp.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const TABLE = [
{ CompType: ParamsDigest, tt: TT.ParametersSha256DigestComponent, altUriPrefix: "params-sha256" },
] as Row[];

test.each(TABLE)("DigestComp %j", ({ CompType, tt, altUriPrefix }) => {
test.each(TABLE)("DigestComp $tt", ({ CompType, tt, altUriPrefix }) => {
expect(NamingConvention.isConvention(CompType)).toBeTruthy();

const digest = new Uint8Array(32);
Expand Down
6 changes: 3 additions & 3 deletions pkg/packet/tests/signing.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const TABLE = [
},
] as Row[];

test.each(TABLE)("sign %j", async ({ Packet }) => {
test.each(TABLE)("sign $pkt", async ({ Packet }) => {
const pkt = new Packet(new Name("/A"));
pkt.sigInfo = new SigInfo(SigType.HmacWithSha256, Uint8Array.of(0xA0, 0xA1));
await expect(ALGO1.sign(pkt)).rejects.toThrow(/mock-signing-error/);
Expand All @@ -107,7 +107,7 @@ test.each(TABLE)("sign %j", async ({ Packet }) => {
expect(() => Encoder.encode(pkt)).not.toThrow();
});

test.each(TABLE)("verify %j", async ({ Packet, checkWire }) => {
test.each(TABLE)("verify $pkt", async ({ Packet, checkWire }) => {
const src = new Packet(new Name("/A"));
src.sigInfo = new SigInfo(SigType.Sha256);
await ALGO0.sign(src);
Expand Down Expand Up @@ -136,7 +136,7 @@ test("digestSigning simple", async () => {
await expect(digestSigning.verify(data)).rejects.toThrow();
});

test.each(TestSignVerify.PacketTable)("digestSigning %j", async ({ Packet }) => {
test.each(TestSignVerify.PacketTable)("digestSigning $PacketType", async ({ Packet }) => {
const record = await TestSignVerify.execute(Packet, digestSigning, digestSigning, digestSigning, digestSigning);
TestSignVerify.check(record, { deterministic: true, sameAB: true });
});
Expand Down
4 changes: 2 additions & 2 deletions pkg/repo/tests/endpoint-producer.t.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "@ndn/packet/test-fixture/expect";

import { consume, DataStoreBuffer, produce, type Producer, type ProducerHandler, type ProducerOptions } from "@ndn/endpoint";
import { consume, DataStoreBuffer, produce, type Producer, type ProducerOptions } from "@ndn/endpoint";
import { Forwarder } from "@ndn/fw";
import { generateSigningKey } from "@ndn/keychain";
import { Data, Interest } from "@ndn/packet";
Expand Down Expand Up @@ -54,7 +54,7 @@ test("prefill buffer", async () => {
expect(handler).toHaveBeenCalledTimes(1);
});

test.each([false, true])("autoBuffer %j", async (autoBuffer) => {
test.each([false, true])("autoBuffer %o", async (autoBuffer) => {
const pOpts = await makeBufferedProducer(undefined, { autoBuffer });
const handler = vi.fn(async (interest: Interest, { dataBuffer }: Producer) => {
void interest;
Expand Down
16 changes: 8 additions & 8 deletions pkg/trust-schema/tests/hierarchical.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const TABLE: Row[] = [
describe("success", () => {
let ctx: Context;
beforeAll(async () => { ctx = await Context.create({}); });
test.each(TABLE)("%j", async (row) => {
test.each(TABLE)("$summary", async (row) => {
await ctx.testSigner(row, async (signer, data) => {
await signer.sign(data);
if (row.signerMustLpm ?? true) {
Expand All @@ -198,7 +198,7 @@ describe("success same name", () => {
name2: "/root/site/group",
});
});
test.each(TABLE)("%j", async (row) => {
test.each(TABLE)("$summary", async (row) => {
await ctx.testVerifier(row, async (verifier, data) => {
await verifier.verify(data);
});
Expand All @@ -212,7 +212,7 @@ describe("data non-hierarchical", () => {
dataName: "/data",
});
});
test.each(TABLE)("%j", async (row) => {
test.each(TABLE)("$summary", async (row) => {
await ctx.testSigner(row, async (signer, data) => {
await expect(signer.sign(data)).rejects.toThrow();
});
Expand All @@ -229,7 +229,7 @@ describe("cert non-hierarchical", () => {
name1: "/root/other-site",
});
});
test.each(TABLE)("%j", async (row) => {
test.each(TABLE)("$summary", async (row) => {
await ctx.testVerifier(row, async (verifier, data) => {
await expect(verifier.verify(data)).rejects.toThrow();
});
Expand All @@ -248,7 +248,7 @@ describe("bad signature", () => {
},
});
});
test.each(TABLE)("%j", async (row) => {
test.each(TABLE)("$summary", async (row) => {
await ctx.testVerifier(row, async (verifier, data) => {
await expect(verifier.verify(data)).rejects.toThrow(/bad/);
});
Expand All @@ -265,7 +265,7 @@ describe("root expired", () => {
},
});
});
test.each(TABLE)("%j", async (row) => {
test.each(TABLE)("$summary", async (row) => {
await ctx.testVerifier(row, async (verifier, data) => {
await expect(verifier.verify(data)).rejects.toThrow(/expired/);
});
Expand All @@ -282,7 +282,7 @@ describe("cert expired", () => {
},
});
});
test.each(TABLE)("%j", async (row) => {
test.each(TABLE)("$summary", async (row) => {
await ctx.testVerifier(row, async (verifier, data) => {
await expect(verifier.verify(data)).rejects.toThrow(/expired/);
});
Expand All @@ -299,7 +299,7 @@ describe("no KeyLocator", () => {
}
});
});
test.each(TABLE)("%j", async (row) => {
test.each(TABLE)("$summary", async (row) => {
await ctx.testVerifier(row, async (verifier, data) => {
await expect(verifier.verify(data)).rejects.toThrow(/KeyLocator/);
});
Expand Down
10 changes: 6 additions & 4 deletions pkg/util/tests/buffer.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { expect, test } from "vitest";
import { asDataView, asUint8Array } from "..";

test.each([
{ title: "asUint8Array", T: Uint8Array, f: asUint8Array },
{ title: "asDataView", T: DataView, f: asDataView },
])("asArrayBufferView %j", ({ T, f }) => {
const ab = new ArrayBuffer(17);
{ B: ArrayBuffer, T: Uint8Array, f: asUint8Array },
{ B: SharedArrayBuffer, T: Uint8Array, f: asUint8Array },
{ B: ArrayBuffer, T: DataView, f: asDataView },
{ B: SharedArrayBuffer, T: DataView, f: asDataView },
])("$f $B", ({ B, T, f }) => {
const ab = new B(17);
const u8 = new Uint8Array(ab, 4, 11);
const dv = new DataView(ab, 3, 8);

Expand Down

0 comments on commit 5a3d958

Please sign in to comment.