@haraka/test-fixtures 0.0.0-stage → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +346 -0
- package/LICENSE +21 -0
- package/README.md +263 -2
- package/config/smtp.ini +64 -0
- package/index.js +41 -0
- package/lib/assertions.js +111 -0
- package/lib/connection.js +601 -0
- package/lib/dns.js +206 -0
- package/lib/helpers.js +150 -0
- package/lib/hooks.js +123 -0
- package/lib/invoke.js +55 -0
- package/lib/line_socket.js +68 -0
- package/lib/logger.js +125 -0
- package/lib/plugin.js +313 -0
- package/lib/stub.js +50 -0
- package/lib/transaction.js +270 -0
- package/package.json +72 -4
- package/types/index.d.ts +19 -0
- package/types/lib/assertions.d.ts +54 -0
- package/types/lib/connection.d.ts +150 -0
- package/types/lib/dns.d.ts +15 -0
- package/types/lib/helpers.d.ts +98 -0
- package/types/lib/hooks.d.ts +54 -0
- package/types/lib/invoke.d.ts +26 -0
- package/types/lib/line_socket.d.ts +14 -0
- package/types/lib/logger.d.ts +42 -0
- package/types/lib/plugin.d.ts +30 -0
- package/types/lib/stub.d.ts +38 -0
- package/types/lib/transaction.d.ts +72 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Address } from '@haraka/email-address';
|
|
2
|
+
/**
|
|
3
|
+
* Typed per-hook helpers.
|
|
4
|
+
*
|
|
5
|
+
* const { rc, msg } = await callMail(plugin, conn, 'user@host')
|
|
6
|
+
*
|
|
7
|
+
* Each helper:
|
|
8
|
+
* - takes natural args (string addresses, not [new Address('<x>'), {}])
|
|
9
|
+
* - resolves method name from plugin.hooks[hookName] when possible
|
|
10
|
+
* - returns Promise<{rc, msg}> via the dual-mode invoke() dispatcher,
|
|
11
|
+
* passing the expected 4.0 hook arity so the dispatcher can tell a
|
|
12
|
+
* genuine 4.0 async hook from a 3.x callback hook declared `async`
|
|
13
|
+
*
|
|
14
|
+
* For plugins that export the hook method under a non-default name
|
|
15
|
+
* (e.g. aliases registers 'aliases' for 'rcpt' via
|
|
16
|
+
* `this.register_hook('rcpt', 'aliases')`), the helper finds it via
|
|
17
|
+
* plugin.hooks (populated by register_hook). Callers can also pass
|
|
18
|
+
* an explicit method name as the last argument when they need to bypass
|
|
19
|
+
* the registry — useful for plugins that expose multiple methods on
|
|
20
|
+
* one hook (priority ordering, etc.).
|
|
21
|
+
*/
|
|
22
|
+
export declare const resolveMethod: (plugin: any, hookName: any, explicit: any) => any;
|
|
23
|
+
export declare const toAddress: (v: any) => any;
|
|
24
|
+
export type LoadedPlugin = import('./plugin.js').LoadedPlugin;
|
|
25
|
+
export type Connection = import('./connection.js').Connection;
|
|
26
|
+
export type HookResult = {
|
|
27
|
+
rc: any;
|
|
28
|
+
msg: any;
|
|
29
|
+
};
|
|
30
|
+
export declare const callConnect: (plugin: LoadedPlugin, conn: Connection, method?: string) => Promise<HookResult>;
|
|
31
|
+
export declare const callHelo: (plugin: LoadedPlugin, conn: Connection, arg: string, method?: string) => Promise<HookResult>;
|
|
32
|
+
export declare const callEhlo: (plugin: LoadedPlugin, conn: Connection, arg: string, method?: string) => Promise<HookResult>;
|
|
33
|
+
export declare const callMail: (plugin: LoadedPlugin, conn: Connection, addr: string | Address, params?: object | string, method?: string) => Promise<HookResult>;
|
|
34
|
+
export declare const callRcpt: (plugin: LoadedPlugin, conn: Connection, addr: string | Address, params?: object | string, method?: string) => Promise<HookResult>;
|
|
35
|
+
/**
|
|
36
|
+
* @param {LoadedPlugin} plugin
|
|
37
|
+
* @param {Connection} conn
|
|
38
|
+
* @param {string | Address} rcpt
|
|
39
|
+
* @param {string} [method] call this method instead of the hook's registered one
|
|
40
|
+
* @returns {Promise<HookResult>}
|
|
41
|
+
*/
|
|
42
|
+
export declare const callRcptOk: (plugin: LoadedPlugin, conn: Connection, rcpt: string | Address, method?: string) => Promise<HookResult>;
|
|
43
|
+
export declare const callData: (plugin: LoadedPlugin, conn: Connection, method?: string) => Promise<HookResult>;
|
|
44
|
+
export declare const callDataPost: (plugin: LoadedPlugin, conn: Connection, method?: string) => Promise<HookResult>;
|
|
45
|
+
export declare const callQueue: (plugin: LoadedPlugin, conn: Connection, method?: string) => Promise<HookResult>;
|
|
46
|
+
/**
|
|
47
|
+
* @param {LoadedPlugin} plugin
|
|
48
|
+
* @param {Connection} conn
|
|
49
|
+
* @param {string} msg the queue's response
|
|
50
|
+
* @param {string} [method] call this method instead of the hook's registered one
|
|
51
|
+
* @returns {Promise<HookResult>}
|
|
52
|
+
*/
|
|
53
|
+
export declare const callQueueOk: (plugin: LoadedPlugin, conn: Connection, msg: string, method?: string) => Promise<HookResult>;
|
|
54
|
+
export declare const callDisconnect: (plugin: LoadedPlugin, conn: Connection, method?: string) => Promise<HookResult>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dual-mode hook dispatcher.
|
|
3
|
+
*
|
|
4
|
+
* Haraka 3.x plugin hooks are callback-style:
|
|
5
|
+
*
|
|
6
|
+
* export function hook_mail(next, connection, params) {
|
|
7
|
+
* next(DENY, 'no thanks')
|
|
8
|
+
* }
|
|
9
|
+
*
|
|
10
|
+
* Haraka 4.0 plan an async/return-value style:
|
|
11
|
+
*
|
|
12
|
+
* export async function hook_mail(connection, params) {
|
|
13
|
+
* return [DENY, 'no thanks'] // or { rc: DENY, msg: '...' } or just DENY
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* `invoke` accepts either shape. The 4.0 path is taken only when the function
|
|
17
|
+
* is `async` AND its declared arity matches the expected 4.0 arity for the
|
|
18
|
+
* hook (supplied by the typed call<Hook> helpers). This distinguishes a
|
|
19
|
+
* genuine 4.0 hook from a 3.x callback hook that happens to be declared
|
|
20
|
+
* `async` so it can `await` internally before invoking `next`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function invoke(plugin: any, method: any, callArgs: any, opts?: {}): Promise<any>;
|
|
23
|
+
export declare function normalize(value: any): {
|
|
24
|
+
rc: any;
|
|
25
|
+
msg: any;
|
|
26
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Events from 'node:events';
|
|
2
|
+
export declare class Socket extends Events {
|
|
3
|
+
port: any;
|
|
4
|
+
host: any;
|
|
5
|
+
setTimeout: import("./stub.js").Stub;
|
|
6
|
+
setKeepAlive: import("./stub.js").Stub;
|
|
7
|
+
destroy: import("./stub.js").Stub;
|
|
8
|
+
writable: boolean;
|
|
9
|
+
readable: boolean;
|
|
10
|
+
constructor(port: any, host: any);
|
|
11
|
+
write(data: any, encoding: any, callback: any): boolean;
|
|
12
|
+
end(data: any, encoding: any, callback: any): void;
|
|
13
|
+
}
|
|
14
|
+
export declare function connect(port: any, host: any, cb: any): Socket;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type LogMethod = ((...args: any[]) => any) & Partial<Pick<import('./stub.js').Stub, 'called' | 'callCount' | 'calls' | 'args'>>;
|
|
2
|
+
/**
|
|
3
|
+
* A log method; a recording stub() when makeConnection() gets stubLogs.
|
|
4
|
+
* @typedef {((...args: any[]) => any) & Partial<Pick<import('./stub.js').Stub, 'called' | 'callCount' | 'calls' | 'args'>>} LogMethod
|
|
5
|
+
*/
|
|
6
|
+
declare const logger: {
|
|
7
|
+
levels: {
|
|
8
|
+
DATA: number;
|
|
9
|
+
PROTOCOL: number;
|
|
10
|
+
DEBUG: number;
|
|
11
|
+
INFO: number;
|
|
12
|
+
NOTICE: number;
|
|
13
|
+
WARN: number;
|
|
14
|
+
ERROR: number;
|
|
15
|
+
CRIT: number;
|
|
16
|
+
ALERT: number;
|
|
17
|
+
EMERG: number;
|
|
18
|
+
};
|
|
19
|
+
formats: {
|
|
20
|
+
DEFAULT: string;
|
|
21
|
+
LOGFMT: string;
|
|
22
|
+
JSON: string;
|
|
23
|
+
};
|
|
24
|
+
loglevel: number;
|
|
25
|
+
format: string;
|
|
26
|
+
timestamps: boolean;
|
|
27
|
+
deferred_logs: any[];
|
|
28
|
+
log: (level: any, data: any) => true | undefined;
|
|
29
|
+
set_loglevel: (level: any) => void;
|
|
30
|
+
would_log: (level: any) => boolean;
|
|
31
|
+
set_format: (format: any) => void;
|
|
32
|
+
set_timestamps: (value: any) => void;
|
|
33
|
+
log_if_level: (level: any, key: any, plugin: any) => () => true | undefined;
|
|
34
|
+
add_log_methods: (object: any, plugin: any) => void;
|
|
35
|
+
};
|
|
36
|
+
export type Level = 'DATA' | 'PROTOCOL' | 'DEBUG' | 'INFO' | 'NOTICE' | 'WARN' | 'ERROR' | 'CRIT' | 'ALERT' | 'EMERG';
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {'DATA' | 'PROTOCOL' | 'DEBUG' | 'INFO' | 'NOTICE' | 'WARN' | 'ERROR' | 'CRIT' | 'ALERT' | 'EMERG'} Level
|
|
39
|
+
*/
|
|
40
|
+
/** @type {typeof logger & { [L in Level as `LOG${L}`]: number } & { [L in Level as `log${Lowercase<L>}`]: LogMethod }} */
|
|
41
|
+
declare const typed: typeof logger & { [L in Level as `LOG${L}`]: number; } & { [L in Level as `log${Lowercase<L>}`]: LogMethod; };
|
|
42
|
+
export { typed as default, typed as 'module.exports' };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type LoadedPlugin = Plugin & Record<string, any>;
|
|
2
|
+
/** @typedef {Plugin & Record<string, any>} LoadedPlugin a Plugin with its module's exports */
|
|
3
|
+
declare class Plugin {
|
|
4
|
+
name: any;
|
|
5
|
+
base: {};
|
|
6
|
+
timeout: number;
|
|
7
|
+
plugin_path: string | undefined;
|
|
8
|
+
config: import("@haraka/config").Config;
|
|
9
|
+
hooks: {};
|
|
10
|
+
last_err: string;
|
|
11
|
+
server: {
|
|
12
|
+
notes: {};
|
|
13
|
+
};
|
|
14
|
+
hasPackageJson: boolean | undefined;
|
|
15
|
+
isModule: boolean | undefined;
|
|
16
|
+
constructor(name: any);
|
|
17
|
+
register(): void;
|
|
18
|
+
haraka_require(name: any): any;
|
|
19
|
+
core_require(name: any): any;
|
|
20
|
+
_has_package_json(candidate_path: any): boolean | undefined;
|
|
21
|
+
_get_plugin_path(name: any): string | undefined;
|
|
22
|
+
_get_config(): import("@haraka/config").Config;
|
|
23
|
+
register_hook(hook_name: any, method_name: any, priority: any): void;
|
|
24
|
+
_get_code(pi_path: any): string;
|
|
25
|
+
inherits(parent_name: any): void;
|
|
26
|
+
_make_custom_require(): (module: any) => any;
|
|
27
|
+
_compile(): void;
|
|
28
|
+
}
|
|
29
|
+
declare const LoadablePlugin: (new (name: string) => LoadedPlugin) & typeof Plugin;
|
|
30
|
+
export { LoadablePlugin as default, LoadablePlugin as 'module.exports' };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {{
|
|
3
|
+
* (...args: any[]): any,
|
|
4
|
+
* called: boolean,
|
|
5
|
+
* callCount: number,
|
|
6
|
+
* calls: any[][],
|
|
7
|
+
* args: any[] | undefined,
|
|
8
|
+
* thisArg: any,
|
|
9
|
+
* reset(): void,
|
|
10
|
+
* }} Stub
|
|
11
|
+
*/
|
|
12
|
+
export type Stub = {
|
|
13
|
+
(...args: any[]): any;
|
|
14
|
+
called: boolean;
|
|
15
|
+
callCount: number;
|
|
16
|
+
calls: any[][];
|
|
17
|
+
args: any[] | undefined;
|
|
18
|
+
thisArg: any;
|
|
19
|
+
reset(): void;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Creates a stub function that records calls.
|
|
23
|
+
*
|
|
24
|
+
* Properties on the returned stub:
|
|
25
|
+
* .called {boolean} true after the first call
|
|
26
|
+
* .callCount {number} number of times called
|
|
27
|
+
* .calls {Array} each element is an Array of arguments from one call
|
|
28
|
+
* .args {Array} arguments from the most recent call (undefined if never called)
|
|
29
|
+
* .thisArg {*} `this` from the most recent call
|
|
30
|
+
* .reset() resets all tracking state
|
|
31
|
+
*
|
|
32
|
+
* @param {*} [returnValue] - value the stub returns when called
|
|
33
|
+
* @returns {Stub}
|
|
34
|
+
*/
|
|
35
|
+
export declare function stub(returnValue?: any): Stub;
|
|
36
|
+
export declare namespace stub {
|
|
37
|
+
export { stub };
|
|
38
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import Notes from '@haraka/notes';
|
|
2
|
+
export type LogMethod = import('./logger.js').LogMethod;
|
|
3
|
+
/** @typedef {import('./logger.js').LogMethod} LogMethod */
|
|
4
|
+
export declare class Transaction {
|
|
5
|
+
uuid: string;
|
|
6
|
+
cfg: any;
|
|
7
|
+
mail_from: any;
|
|
8
|
+
rcpt_to: any[];
|
|
9
|
+
header_lines: any[];
|
|
10
|
+
data_lines: any[];
|
|
11
|
+
attachment_start_hooks: any[];
|
|
12
|
+
banner: string[] | null;
|
|
13
|
+
body_filters: any[];
|
|
14
|
+
data_bytes: number;
|
|
15
|
+
header_pos: number;
|
|
16
|
+
found_hb_sep: boolean;
|
|
17
|
+
body: any;
|
|
18
|
+
parse_body: boolean;
|
|
19
|
+
notes: Notes;
|
|
20
|
+
header: any;
|
|
21
|
+
message_stream: any;
|
|
22
|
+
discard_data: boolean;
|
|
23
|
+
resetting: boolean;
|
|
24
|
+
rcpt_count: {
|
|
25
|
+
accept: number;
|
|
26
|
+
tempfail: number;
|
|
27
|
+
reject: number;
|
|
28
|
+
};
|
|
29
|
+
msg_status: any;
|
|
30
|
+
data_post_start: any;
|
|
31
|
+
data_post_delay: number;
|
|
32
|
+
encoding: string;
|
|
33
|
+
mime_part_count: number;
|
|
34
|
+
/** @type {LogMethod} */ logdata: LogMethod;
|
|
35
|
+
/** @type {LogMethod} */ logprotocol: LogMethod;
|
|
36
|
+
/** @type {LogMethod} */ logdebug: LogMethod;
|
|
37
|
+
/** @type {LogMethod} */ loginfo: LogMethod;
|
|
38
|
+
/** @type {LogMethod} */ lognotice: LogMethod;
|
|
39
|
+
/** @type {LogMethod} */ logwarn: LogMethod;
|
|
40
|
+
/** @type {LogMethod} */ logerror: LogMethod;
|
|
41
|
+
/** @type {LogMethod} */ logcrit: LogMethod;
|
|
42
|
+
/** @type {LogMethod} */ logalert: LogMethod;
|
|
43
|
+
/** @type {LogMethod} */ logemerg: LogMethod;
|
|
44
|
+
/**
|
|
45
|
+
* @param {string} [uuid]
|
|
46
|
+
* @param {any} [cfg]
|
|
47
|
+
*/
|
|
48
|
+
constructor(uuid?: string, cfg?: any);
|
|
49
|
+
ensure_body(): void;
|
|
50
|
+
remove_final_cr(data: any): any;
|
|
51
|
+
add_dot_stuffing_and_ensure_crlf_newlines(data: any): any;
|
|
52
|
+
add_data(line: any): void;
|
|
53
|
+
/** @param {() => void} [cb] */
|
|
54
|
+
end_data(cb?: () => void): void;
|
|
55
|
+
add_header(key: any, value: any): void;
|
|
56
|
+
add_leading_header(key: any, value: any): void;
|
|
57
|
+
reset_headers(): void;
|
|
58
|
+
remove_header(key: any): void;
|
|
59
|
+
attachment_hooks(start: any): void;
|
|
60
|
+
/**
|
|
61
|
+
* @param {string} text
|
|
62
|
+
* @param {string} [html]
|
|
63
|
+
*/
|
|
64
|
+
set_banner(text: string, html?: string): void;
|
|
65
|
+
add_body_filter(ct_match: any, filter: any): void;
|
|
66
|
+
incr_mime_count(): void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @param {string} [uuid]
|
|
70
|
+
* @param {object} [cfg]
|
|
71
|
+
*/
|
|
72
|
+
export declare function createTransaction(uuid?: string, cfg?: object): Transaction;
|