Skip to content

Commit

Permalink
test: verify signature of job posted to worker
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Jan 25, 2024
1 parent 795ced7 commit ce1c058
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 7 deletions.
91 changes: 85 additions & 6 deletions deno.lock

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

1 change: 1 addition & 0 deletions dev_deps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { default as pluginFactory } from 'https://raw.githubusercontent.com/hyper63/hyper/hyper%40v4.3.2/packages/core/utils/plugin-schema.ts'
export { cache as cachePort } from 'https://raw.githubusercontent.com/hyper63/hyper/hyper-port-cache%40v2.0.0/packages/port-cache/mod.ts'
export { createHyperVerify } from 'https://raw.githubusercontent.com/hyper63/hyper/hyper-connect%40v0.11.0/packages/connect/deno/mod.ts'

// std lib deps
export { deferred } from 'https://deno.land/[email protected]/async/deferred.ts'
Expand Down
10 changes: 9 additions & 1 deletion test/suite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// deno-lint-ignore-file no-explicit-any require-await
import { assert, assertEquals, assertObjectMatch } from '../dev_deps.ts'
import { assert, assertEquals, assertObjectMatch, createHyperVerify } from '../dev_deps.ts'

import { adapter } from '../adapter.ts'
import { ImplConfig } from '../types.ts'
Expand Down Expand Up @@ -147,12 +147,20 @@ async (
*/
if (isMockFetch) {
worker = new Promise((resolve) => {
const hyperVerify = createHyperVerify('foobar', '5m')

innerMockFetch = async (url: string, options: any) => {
assertEquals(url, target)
assertEquals(options.method, 'POST')
assertEquals(JSON.parse(options.body), job)
assertEquals(options.headers['Content-Type'], 'application/json')
assert(options.headers['X-HYPER-SIGNATURE'])
assert(
hyperVerify(
options.headers['X-HYPER-SIGNATURE'],
JSON.parse(options.body),
).ok,
)

resolve(undefined)

Expand Down

0 comments on commit ce1c058

Please sign in to comment.