2023-03-26 16:29:35 -05:00
|
|
|
import { assertEquals } from './deps.ts';
|
|
|
|
|
|
|
|
import pipeline from './pipeline.ts';
|
|
|
|
import noopPolicy from './policies/noop-policy.ts';
|
|
|
|
import readOnlyPolicy from './policies/read-only-policy.ts';
|
|
|
|
import { buildInputMessage } from './test.ts';
|
|
|
|
|
|
|
|
Deno.test('passes events through multiple policies', async () => {
|
|
|
|
const msg = buildInputMessage();
|
|
|
|
|
|
|
|
const result = await pipeline(msg, [
|
|
|
|
noopPolicy,
|
|
|
|
readOnlyPolicy,
|
|
|
|
]);
|
|
|
|
|
|
|
|
assertEquals(result.action, 'reject');
|
2023-03-28 18:52:53 -05:00
|
|
|
assertEquals(result.msg, 'blocked: the relay is read-only');
|
2023-03-26 16:29:35 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test('short-circuits on the first reject', async () => {
|
|
|
|
const msg = buildInputMessage();
|
|
|
|
|
|
|
|
const result = await pipeline(msg, [
|
|
|
|
readOnlyPolicy,
|
|
|
|
noopPolicy,
|
|
|
|
]);
|
|
|
|
|
|
|
|
assertEquals(result.action, 'reject');
|
2023-03-28 18:52:53 -05:00
|
|
|
assertEquals(result.msg, 'blocked: the relay is read-only');
|
2023-03-26 16:29:35 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test('accepts when all policies accept', async () => {
|
|
|
|
const msg = buildInputMessage();
|
|
|
|
|
|
|
|
const result = await pipeline(msg, [
|
|
|
|
noopPolicy,
|
|
|
|
noopPolicy,
|
|
|
|
noopPolicy,
|
|
|
|
]);
|
|
|
|
|
|
|
|
assertEquals(result.action, 'accept');
|
|
|
|
});
|