Skip to content

Commit

Permalink
Update testkit with larger compressed tests and npm packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
FiloSottile committed Jan 26, 2025
1 parent 2dd8802 commit 857cf37
Show file tree
Hide file tree
Showing 118 changed files with 20 additions and 2,307 deletions.
8 changes: 8 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@stylistic/eslint-plugin": "2.13.0",
"@types/node": "22.10.5",
"@vitest/browser": "2.1.8",
"cctv-age": "0.1.0",
"esbuild": "0.24.2",
"eslint": "9.18.0",
"eslint-plugin-tsdoc": "0.4.0",
Expand Down
34 changes: 11 additions & 23 deletions tests/testkit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,9 @@ import { decryptSTREAM, encryptSTREAM } from "../lib/stream.js"
import { forceWebCryptoOff } from "../lib/x25519.js"
import { hkdf } from "@noble/hashes/hkdf"
import { sha256 } from "@noble/hashes/sha256"
import { hex, base64 } from "@scure/base"
import { hex } from "@scure/base"
import { Decrypter, armor } from "../lib/index.js"

declare module "@vitest/browser/context" {
interface BrowserCommands {
listTestkitFiles: () => Promise<string[]>
readTestkitFile: (name: string) => Promise<string>
}
}

let listTestkitFiles: () => Promise<string[]>
let readTestkitFile: (name: string) => Promise<Uint8Array>
if (expect.getState().environment === "node") {
const { readdir, readFile } = await import("fs/promises")
listTestkitFiles = () => readdir("./tests/testkit")
readTestkitFile = (name) => readFile("./tests/testkit/" + name)
} else {
const { commands } = await import("@vitest/browser/context")
listTestkitFiles = commands.listTestkitFiles
readTestkitFile = async (name) => base64.decode(await commands.readTestkitFile(name))
}
import * as testkit from "cctv-age"

describe("CCTV testkit", async function () {
interface Vector {
Expand All @@ -33,8 +15,7 @@ describe("CCTV testkit", async function () {
body: Uint8Array,
}
const vectors: Vector[] = []
for (const name of await listTestkitFiles()) {
const contents = await readTestkitFile(name)
for (const [name, contents] of Object.entries(testkit)) {

Check failure on line 18 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Unsafe argument of type error typed assigned to a parameter of type `{ [s: string]: unknown; } | ArrayLike<unknown>`

Check failure on line 18 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Unsafe argument of type error typed assigned to a parameter of type `{ [s: string]: unknown; } | ArrayLike<unknown>`

Check failure on line 18 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Unsafe argument of type error typed assigned to a parameter of type `{ [s: string]: unknown; } | ArrayLike<unknown>`

Check failure on line 18 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Unsafe argument of type error typed assigned to a parameter of type `{ [s: string]: unknown; } | ArrayLike<unknown>`

Check failure on line 18 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Unsafe argument of type error typed assigned to a parameter of type `{ [s: string]: unknown; } | ArrayLike<unknown>`

Check failure on line 18 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Unsafe argument of type error typed assigned to a parameter of type `{ [s: string]: unknown; } | ArrayLike<unknown>`
const sepIdx = findSeparator(contents)
const header = new TextDecoder().decode(contents.subarray(0, sepIdx))

Check failure on line 20 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Unsafe argument of type error typed assigned to a parameter of type `AllowSharedBufferSource | undefined`

Check failure on line 20 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Unsafe call of a(n) `error` type typed value

Check failure on line 20 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Unsafe argument of type error typed assigned to a parameter of type `AllowSharedBufferSource | undefined`

Check failure on line 20 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Unsafe call of a(n) `error` type typed value

Check failure on line 20 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Unsafe argument of type error typed assigned to a parameter of type `AllowSharedBufferSource | undefined`

Check failure on line 20 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Unsafe call of a(n) `error` type typed value

Check failure on line 20 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Unsafe argument of type error typed assigned to a parameter of type `AllowSharedBufferSource | undefined`

Check failure on line 20 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Unsafe call of a(n) `error` type typed value

Check failure on line 20 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Unsafe argument of type error typed assigned to a parameter of type `AllowSharedBufferSource | undefined`

Check failure on line 20 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Unsafe call of a(n) `error` type typed value

Check failure on line 20 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Unsafe argument of type error typed assigned to a parameter of type `AllowSharedBufferSource | undefined`

Check failure on line 20 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Unsafe call of a(n) `error` type typed value
const body = contents.subarray(sepIdx + 2)

Check failure on line 21 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Unsafe assignment of an error typed value

Check failure on line 21 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Unsafe call of a(n) `error` type typed value

Check failure on line 21 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Unsafe assignment of an error typed value

Check failure on line 21 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Unsafe call of a(n) `error` type typed value

Check failure on line 21 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Unsafe assignment of an error typed value

Check failure on line 21 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Unsafe call of a(n) `error` type typed value

Check failure on line 21 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Unsafe assignment of an error typed value

Check failure on line 21 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Unsafe call of a(n) `error` type typed value

Check failure on line 21 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Unsafe assignment of an error typed value

Check failure on line 21 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Unsafe call of a(n) `error` type typed value

Check failure on line 21 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Unsafe assignment of an error typed value

Check failure on line 21 in tests/testkit.test.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Unsafe call of a(n) `error` type typed value
Expand All @@ -46,6 +27,13 @@ describe("CCTV testkit", async function () {
if (!vector.meta.expect) {
throw Error("no metadata found in " + name)
}
if (vector.meta.compressed === "zlib") {
vector.body = new Uint8Array(await new Response(
new Blob([vector.body]).stream().pipeThrough(new DecompressionStream("deflate"))
).arrayBuffer())
} else if (vector.meta.compressed) {
throw Error("unknown compression: " + vector.meta.compressed)
}
vectors.push(vector)
}

Expand Down Expand Up @@ -125,5 +113,5 @@ function findSeparator(data: Uint8Array): number {
return i
}
}
return -1
throw Error("no separator found")
}
13 changes: 0 additions & 13 deletions tests/testkit/armor

This file was deleted.

14 changes: 0 additions & 14 deletions tests/testkit/armor_crlf

This file was deleted.

13 changes: 0 additions & 13 deletions tests/testkit/armor_empty_line_begin

This file was deleted.

13 changes: 0 additions & 13 deletions tests/testkit/armor_empty_line_end

This file was deleted.

13 changes: 0 additions & 13 deletions tests/testkit/armor_eol_between_padding

This file was deleted.

13 changes: 0 additions & 13 deletions tests/testkit/armor_full_last_line

This file was deleted.

Loading

0 comments on commit 857cf37

Please sign in to comment.