mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Add PolicyWorker test
This commit is contained in:
parent
5f5d0bc324
commit
7e00b9f9a2
4 changed files with 28 additions and 4 deletions
|
|
@ -1,2 +0,0 @@
|
||||||
// @ts-ignore Don't try to access the env from this worker.
|
|
||||||
Deno.env = new Map<string, string>();
|
|
||||||
14
packages/ditto/workers/policy.test.ts
Normal file
14
packages/ditto/workers/policy.test.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { DittoConf } from '@ditto/conf';
|
||||||
|
import { generateSecretKey, nip19 } from 'nostr-tools';
|
||||||
|
|
||||||
|
import { PolicyWorker } from './policy.ts';
|
||||||
|
|
||||||
|
Deno.test('PolicyWorker', () => {
|
||||||
|
const conf = new DittoConf(
|
||||||
|
new Map([
|
||||||
|
['DITTO_NSEC', nip19.nsecEncode(generateSecretKey())],
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
new PolicyWorker(conf);
|
||||||
|
});
|
||||||
|
|
@ -3,6 +3,8 @@ import { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/nostrify';
|
||||||
import { logi } from '@soapbox/logi';
|
import { logi } from '@soapbox/logi';
|
||||||
import * as Comlink from 'comlink';
|
import * as Comlink from 'comlink';
|
||||||
|
|
||||||
|
import { errorJson } from '@/utils/log.ts';
|
||||||
|
|
||||||
import type { CustomPolicy } from '@/workers/policy.worker.ts';
|
import type { CustomPolicy } from '@/workers/policy.worker.ts';
|
||||||
|
|
||||||
export class PolicyWorker implements NPolicy {
|
export class PolicyWorker implements NPolicy {
|
||||||
|
|
@ -85,6 +87,15 @@ export class PolicyWorker implements NPolicy {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logi({
|
||||||
|
level: 'error',
|
||||||
|
ns: 'ditto.system.policy',
|
||||||
|
msg: 'Failed to load custom policy',
|
||||||
|
path: conf.policy,
|
||||||
|
error: errorJson(e),
|
||||||
|
enabled: false,
|
||||||
|
});
|
||||||
|
|
||||||
throw new Error(`DITTO_POLICY (error importing policy): ${conf.policy}`);
|
throw new Error(`DITTO_POLICY (error importing policy): ${conf.policy}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import './deno-env.ts'; // HACK should be removed when `@/config.ts` is removed.
|
|
||||||
|
|
||||||
import { DittoConf } from '@ditto/conf';
|
import { DittoConf } from '@ditto/conf';
|
||||||
import { DittoPolyPg } from '@ditto/db';
|
import { DittoPolyPg } from '@ditto/db';
|
||||||
import '@soapbox/safe-fetch/load';
|
import '@soapbox/safe-fetch/load';
|
||||||
|
|
@ -10,6 +8,9 @@ import * as Comlink from 'comlink';
|
||||||
import { ReadOnlySigner } from '@/signers/ReadOnlySigner.ts';
|
import { ReadOnlySigner } from '@/signers/ReadOnlySigner.ts';
|
||||||
import { DittoPgStore } from '@/storages/DittoPgStore.ts';
|
import { DittoPgStore } from '@/storages/DittoPgStore.ts';
|
||||||
|
|
||||||
|
// @ts-ignore Don't try to access the env from this worker.
|
||||||
|
Deno.env = new Map<string, string>();
|
||||||
|
|
||||||
/** Serializable object the worker can use to set up the state. */
|
/** Serializable object the worker can use to set up the state. */
|
||||||
interface PolicyInit {
|
interface PolicyInit {
|
||||||
/** Path to the policy module (https, jsr, file, etc) */
|
/** Path to the policy module (https, jsr, file, etc) */
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue