Skip to content

Commit

Permalink
Merge pull request #405 from dajiaji/update-bun-test
Browse files Browse the repository at this point in the history
Update bun test
  • Loading branch information
dajiaji authored Oct 6, 2024
2 parents 10ea146 + 92b9425 commit 844f50b
Show file tree
Hide file tree
Showing 30 changed files with 491 additions and 892 deletions.
58 changes: 2 additions & 56 deletions .github/workflows/ci_bun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ permissions:
jobs:
test:
runs-on: ubuntu-latest

# strategy:
# matrix:
# bun-version: [0.6.x, 0.7.x, 0.8.x, 1.x]

steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
Expand All @@ -28,58 +23,9 @@ jobs:
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install esbuild
run: npm install -g esbuild
- name: Prepare test
run: |
deno task npm
deno task bun-link
- name: Run test for ./packages/core
working-directory: ./packages/core/test/runtimes/bun
run: |
bun install
nohup bun src/index.ts &
sleep 3
deno test --import-map=../../../../../import_map.json core.spec.ts --allow-net --config ../../../deno.json
- name: Run test for ./packages/chacha20poly1305
working-directory: ./packages/chacha20poly1305/test/runtimes/bun
run: |
bun install
nohup bun src/index.ts &
sleep 3
deno test --import-map=../../../../../import_map.json chacha20poly1305.spec.ts --allow-net --config ../../../deno.json
- name: Run test for ./packages/dhkem-x25519
working-directory: ./packages/dhkem-x25519/test/runtimes/bun
run: |
bun install
nohup bun src/index.ts &
sleep 3
deno test --import-map=../../../../../import_map.json dhkem-x25519.spec.ts --allow-net --config ../../../deno.json
- name: Run test for ./packages/dhkem-x448
working-directory: ./packages/dhkem-x448/test/runtimes/bun
run: |
bun install
nohup bun src/index.ts &
sleep 3
deno test --import-map=../../../../../import_map.json dhkem-x448.spec.ts --allow-net --config ../../../deno.json
- name: Run test for ./packages/dhkem-secp256k1
working-directory: ./packages/dhkem-secp256k1/test/runtimes/bun
run: |
bun install
nohup bun src/index.ts &
sleep 3
deno test --import-map=../../../../../import_map.json dhkem-secp256k1.spec.ts --allow-net --config ../../../deno.json
- name: Run test for ./packages/hybridkem-x25519-kyber768
working-directory: ./packages/hybridkem-x25519-kyber768/test/runtimes/bun
run: |
bun install
nohup bun src/index.ts &
sleep 3
deno test --import-map=../../../../../import_map.json hybridkem-x25519-kyber768.spec.ts --allow-net --config ../../../deno.json
- name: Run test for ./packages/hpke-js
working-directory: ./packages/hpke-js/test/runtimes/bun
run: |
bun install
nohup bun run src/index.ts &
sleep 3
deno test --import-map=../../../../../import_map.json hpke.spec.ts --allow-net --config ../../../deno.json
- name: Run test
run: deno task test:bun
10 changes: 9 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
]
},
"tasks": {
"test:all": "deno task test && deno task test:cloudflare",
"test:all": "deno task test && deno task test:cloudflare && deno task test:bun",
"test": "deno fmt && deno lint && deno test --import-map=./import_map.json -A --fail-fast --doc --coverage=coverage --parallel --allow-read",
"test:common": "cd packages/common && deno task test",
"test:core": "cd packages/core && deno task test",
Expand All @@ -62,6 +62,14 @@
"test:cloudflare:dhkem-secp256k1": "cd packages/dhkem-secp256k1 && deno task test:cloudflare",
"test:cloudflare:hybridkem-x25519-kyber768": "cd packages/hybridkem-x25519-kyber768 && deno task test:cloudflare",
"test:cloudflare:hpke-js": "cd packages/hpke-js && deno task test:cloudflare",
"test:bun": "deno task test:bun:core && deno task test:bun:chacha20poly1305 && deno task test:bun:dhkem-x25519 && deno task test:bun:dhkem-x448 && deno task test:bun:dhkem-secp256k1 && deno task test:bun:hybridkem-x25519-kyber768 && deno task test:bun:hpke-js",
"test:bun:core": "cd packages/core && deno task test:bun",
"test:bun:chacha20poly1305": "cd packages/chacha20poly1305 && deno task test:bun",
"test:bun:dhkem-x25519": "cd packages/dhkem-x25519 && deno task test:bun",
"test:bun:dhkem-x448": "cd packages/dhkem-x448 && deno task test:bun",
"test:bun:dhkem-secp256k1": "cd packages/dhkem-secp256k1 && deno task test:bun",
"test:bun:hybridkem-x25519-kyber768": "cd packages/hybridkem-x25519-kyber768 && deno task test:bun",
"test:bun:hpke-js": "cd packages/hpke-js && deno task test:bun",
"cov": "deno coverage ./coverage --lcov --exclude='test'",
"npm": "deno task dnt && deno task npm-link && deno task npm-pack",
"dnt": "deno task dnt:common && deno task dnt:core && deno task dnt:chacha20poly1305 && deno task dnt:dhkem-x25519 && deno task dnt:dhkem-x448 && deno task dnt:dhkem-secp256k1 && deno task dnt:hybridkem-x25519-kyber768 && deno task dnt:hpke-js",
Expand Down
1 change: 1 addition & 0 deletions packages/chacha20poly1305/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"tasks": {
"test": "deno fmt && deno lint && deno test --import-map=../../import_map.json -A --fail-fast --doc --coverage=coverage --parallel --allow-read",
"test:cloudflare": "cd test/runtimes/cloudflare && npm install && npm link @hpke/common @hpke/chacha20poly1305 && npm run test",
"test:bun": "cd test/runtimes/bun && bun install && bun test",
"cov": "deno coverage ./coverage --lcov --exclude='test'",
"dnt": "deno run --import-map=../../npm/import_map.json -A dnt.ts",
"minify": "esbuild ../../npm/packages/chacha20poly1305/esm/chacha20poly1305/mod.js --bundle --format=esm --minify"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,77 @@
import { assertEquals } from "@std/assert";
import { describe, it } from "@std/testing/bdd";
import { expect, test } from "bun:test";

describe("Bun", () => {
describe("GET /test", () => {
it("should return ok", async () => {
for (const kem of ["0x0010", "0x0011", "0x0012"]) {
for (const kdf of ["0x0001", "0x0002", "0x0003"]) {
const res = await fetch(
`http://localhost:3005/test?kem=${kem}&kdf=${kdf}`,
);
assertEquals("ok", await res.text());
}
import type { KdfInterface, KemInterface } from "@hpke/core";

import {
// AeadId,
// Aes128Gcm,
// Aes256Gcm,
CipherSuite,
DhkemP256HkdfSha256,
DhkemP384HkdfSha384,
DhkemP521HkdfSha512,
// ExportOnly,
HkdfSha256,
HkdfSha384,
HkdfSha512,
KdfId,
KemId,
} from "@hpke/core";

import { Chacha20Poly1305 } from "@hpke/chacha20poly1305";

function createKem(id: number): KemInterface {
switch (id) {
case KemId.DhkemP256HkdfSha256:
return new DhkemP256HkdfSha256();
case KemId.DhkemP384HkdfSha384:
return new DhkemP384HkdfSha384();
case KemId.DhkemP521HkdfSha512:
return new DhkemP521HkdfSha512();
default:
break;
}
throw new Error("ng: invalid kem");
}

function createKdf(id: number): KdfInterface {
switch (id) {
case KdfId.HkdfSha256:
return new HkdfSha256();
case KdfId.HkdfSha384:
return new HkdfSha384();
case KdfId.HkdfSha512:
return new HkdfSha512();
default:
break;
}
throw new Error("ng: invalid kdf");
}

test("bun - normal cases", async () => {
const aead = new Chacha20Poly1305();
for (const kem of [0x0010, 0x0011, 0x0012]) {
for (const kdf of [0x0001, 0x0002, 0x0003]) {
try {
const suite = new CipherSuite({
kem: createKem(kem),
kdf: createKdf(kdf),
aead: aead,
});
const rkp = await suite.kem.generateKeyPair();
const sender = await suite.createSenderContext({
recipientPublicKey: rkp.publicKey,
});
const recipient = await suite.createRecipientContext({
recipientKey: rkp,
enc: sender.enc,
});
const ct = await sender.seal(new TextEncoder().encode("hello world!"));
const pt = await recipient.open(ct);
expect(new TextDecoder().decode(pt)).toBe("hello world!");
} catch (e: unknown) {
expect().fail("ng: " + (e as Error).message);
}
});
});
}
}
});
8 changes: 0 additions & 8 deletions packages/chacha20poly1305/test/runtimes/bun/src/index.ts

This file was deleted.

88 changes: 0 additions & 88 deletions packages/chacha20poly1305/test/runtimes/bun/src/server.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/core/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"tasks": {
"test": "deno fmt && deno lint && deno test --import-map=../../import_map.json -A --fail-fast --doc --coverage=coverage --parallel --allow-read",
"test:cloudflare": "cd test/runtimes/cloudflare && npm install && npm link @hpke/core && npm run test",
"test:bun": "cd test/runtimes/bun && bun install && bun test",
"cov": "deno coverage ./coverage --lcov --exclude='test'",
"dnt": "deno run --import-map=../../npm/import_map.json -A dnt.ts",
"minify": "esbuild ../../npm/packages/core/esm/mod.js --bundle --format=esm --minify"
Expand Down
Loading

0 comments on commit 844f50b

Please sign in to comment.