web_plsql 0.5.0 → 0.6.0
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/README.md +123 -110
- package/examples/server_apex.js +28 -0
- package/examples/server_sample.js +30 -0
- package/examples/sql/{doc_table.sql → doctable.sql} +1 -1
- package/examples/sql/install.sql +6 -9
- package/examples/sql/sample_package.sql +27 -0
- package/examples/sql/sample_package_body.sql +245 -0
- package/examples/static/sample.css +11 -10
- package/package.json +90 -83
- package/src/cgi.js +127 -0
- package/src/error.js +24 -0
- package/src/errorPage.js +296 -0
- package/src/file.js +77 -0
- package/src/handlerLogger.js +21 -0
- package/src/handlerMetrics.js +46 -0
- package/src/handlerPlSql.js +65 -0
- package/src/handlerUpload.js +32 -0
- package/src/index.js +17 -0
- package/src/oracle.js +80 -0
- package/src/parsePage.js +193 -0
- package/src/procedure.js +260 -0
- package/src/procedureError.js +40 -0
- package/src/procedureNamed.js +233 -0
- package/src/procedureSanitize.js +215 -0
- package/src/procedureVariable.js +57 -0
- package/src/request.js +103 -0
- package/src/{requestError.ts → requestError.js} +8 -4
- package/src/sendResponse.js +104 -0
- package/src/server.js +106 -0
- package/src/shutdown.js +53 -0
- package/src/stream.js +28 -0
- package/src/trace.js +74 -0
- package/src/tty.js +48 -0
- package/src/types.js +146 -0
- package/src/upload.js +92 -0
- package/src/version.js +23 -0
- package/types/cgi.d.ts +4 -0
- package/types/error.d.ts +1 -0
- package/types/errorPage.d.ts +10 -0
- package/types/file.d.ts +5 -0
- package/types/handlerLogger.d.ts +2 -0
- package/types/handlerMetrics.d.ts +4 -0
- package/types/handlerPlSql.d.ts +8 -0
- package/types/handlerUpload.d.ts +7 -0
- package/types/index.d.ts +10 -0
- package/types/oracle.d.ts +5 -0
- package/types/parsePage.d.ts +3 -0
- package/types/procedure.d.ts +10 -0
- package/types/procedureError.d.ts +23 -0
- package/types/procedureNamed.d.ts +14 -0
- package/types/procedureSanitize.d.ts +14 -0
- package/types/procedureVariable.d.ts +9 -0
- package/types/request.d.ts +7 -0
- package/types/requestError.d.ts +8 -0
- package/types/sendResponse.d.ts +4 -0
- package/types/server.d.ts +7 -0
- package/types/shutdown.d.ts +2 -0
- package/types/stream.d.ts +1 -0
- package/types/trace.d.ts +5 -0
- package/types/tty.d.ts +4 -0
- package/types/types.d.ts +251 -0
- package/types/upload.d.ts +5 -0
- package/types/version.d.ts +7 -0
- package/.editorconfig +0 -8
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -347
- package/CHANGELOG.md +0 -127
- package/examples/apex.js +0 -70
- package/examples/credentials.js +0 -22
- package/examples/oracledb_example.js +0 -30
- package/examples/sample.js +0 -101
- package/examples/sql/sample.pkb +0 -223
- package/examples/sql/sample.pks +0 -24
- package/jest.config.js +0 -204
- package/src/cgi.ts +0 -95
- package/src/config.ts +0 -97
- package/src/errorPage.ts +0 -286
- package/src/fileUpload.ts +0 -126
- package/src/index.ts +0 -65
- package/src/page.ts +0 -275
- package/src/procedure.ts +0 -360
- package/src/procedureError.ts +0 -27
- package/src/request.ts +0 -139
- package/src/stream.ts +0 -26
- package/src/trace.ts +0 -194
- package/test/.eslintrc.json +0 -5
- package/test/__tests__/cgi.ts +0 -96
- package/test/__tests__/config.ts +0 -41
- package/test/__tests__/errorPage.ts +0 -101
- package/test/__tests__/oracledb_mock.ts +0 -98
- package/test/__tests__/server.ts +0 -495
- package/test/__tests__/stream.ts +0 -21
- package/test/mock/oracledb.ts +0 -85
- package/test/static/static.html +0 -1
- package/tsconfig.json +0 -24
- package/tsconfig.src.json +0 -23
package/src/trace.ts
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Trace utilities
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import mkdirp from 'mkdirp';
|
|
8
|
-
import util from 'util';
|
|
9
|
-
import express from 'express';
|
|
10
|
-
|
|
11
|
-
const TRACE_ROOT_DIRECTORY = 'trace';
|
|
12
|
-
const SEPARATOR_LINE = '*'.repeat(132);
|
|
13
|
-
|
|
14
|
-
export class Trace {
|
|
15
|
-
_enabled: boolean;
|
|
16
|
-
_directory: string;
|
|
17
|
-
_filename: string;
|
|
18
|
-
_id: number;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Instantiate a new trace object.
|
|
22
|
-
*
|
|
23
|
-
* @param {'on' | 'off' | 'test'} trace - Tracing.
|
|
24
|
-
*/
|
|
25
|
-
constructor(trace: 'on' | 'off' | 'test') {
|
|
26
|
-
this._enabled = trace !== 'off';
|
|
27
|
-
this._directory = getTimestampDirectory();
|
|
28
|
-
this._filename = '';
|
|
29
|
-
this._id = 0;
|
|
30
|
-
|
|
31
|
-
// istanbul ignore if
|
|
32
|
-
if (!this._enabled) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// create the trace directory
|
|
37
|
-
try {
|
|
38
|
-
mkdirp.sync(this._directory);
|
|
39
|
-
if (trace === 'on') {
|
|
40
|
-
// istanbul ignore next
|
|
41
|
-
console.log(`Tracing to the directory "${this._directory}" is enabled.`);
|
|
42
|
-
}
|
|
43
|
-
} catch (e) {
|
|
44
|
-
// istanbul ignore next
|
|
45
|
-
console.error(`Unable to create new trace directory "${this._directory}"`, e);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Start a new trace session for a new request.
|
|
51
|
-
* This adds a trace line to the trace.log file and creating a new request trace file.
|
|
52
|
-
*
|
|
53
|
-
* @param {express.Request} req - The req object represents the HTTP request.
|
|
54
|
-
*/
|
|
55
|
-
start(req: express.Request): void {
|
|
56
|
-
// istanbul ignore if
|
|
57
|
-
if (!this._enabled) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
interface TCustomRequest extends express.Request {
|
|
62
|
-
uniqueRequestID: number;
|
|
63
|
-
}
|
|
64
|
-
const customRequest = req as TCustomRequest;
|
|
65
|
-
|
|
66
|
-
// Create the next unique request id
|
|
67
|
-
customRequest.uniqueRequestID = ++this._id;
|
|
68
|
-
|
|
69
|
-
// append to the trace index
|
|
70
|
-
appendSync(path.join(this._directory, 'trace.log'), `${customRequest.uniqueRequestID.toString().padEnd(10)} - ${getTimestamp()} - ${customRequest.originalUrl}\n`);
|
|
71
|
-
|
|
72
|
-
// compute the trace filename
|
|
73
|
-
this._filename = path.join(this._directory, customRequest.uniqueRequestID.toString() + '.log');
|
|
74
|
-
|
|
75
|
-
// write the initial request information
|
|
76
|
-
this.append(SEPARATOR_LINE +
|
|
77
|
-
getSection('TIMESTAMP', getTimestamp()) +
|
|
78
|
-
getSection('REQUEST ID', customRequest.uniqueRequestID.toString()) +
|
|
79
|
-
getSection('REQUEST', Trace.inspectRequest(req)) +
|
|
80
|
-
SEPARATOR_LINE +
|
|
81
|
-
'\n');
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Write new message to the trace file.
|
|
86
|
-
*
|
|
87
|
-
* @param {string} text - Text to append.
|
|
88
|
-
*/
|
|
89
|
-
write(text: string): void {
|
|
90
|
-
// istanbul ignore else
|
|
91
|
-
if (this._enabled) {
|
|
92
|
-
this.append(`${getTimestamp()}:\n${trimRight(text)}\n${SEPARATOR_LINE}\n`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Append text to the trace file.
|
|
98
|
-
*
|
|
99
|
-
* @param {string} text - Text to append.
|
|
100
|
-
*/
|
|
101
|
-
append(text: string): void {
|
|
102
|
-
// istanbul ignore else
|
|
103
|
-
if (this._enabled) {
|
|
104
|
-
appendSync(this._filename, text);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Return a string representation of the value.
|
|
110
|
-
*
|
|
111
|
-
* @param {unknown} value - Any value.
|
|
112
|
-
* @returns {string} - The string representation.
|
|
113
|
-
*/
|
|
114
|
-
static inspect(value: unknown): string {
|
|
115
|
-
return util.inspect(value, {showHidden: false, depth: null, colors: false});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Return a string representation of the request.
|
|
120
|
-
*
|
|
121
|
-
* @param {express.Request} req - express.Request.
|
|
122
|
-
* @param {boolean} simple - Set to false to see all public properties of the request.
|
|
123
|
-
* @returns {string} - The string representation.
|
|
124
|
-
*/
|
|
125
|
-
static inspectRequest(req: express.Request, simple: boolean = true): string {
|
|
126
|
-
type RequestKeysType = keyof express.Request;
|
|
127
|
-
const simpleRequest: any = {};
|
|
128
|
-
|
|
129
|
-
// istanbul ignore else
|
|
130
|
-
if (simple) {
|
|
131
|
-
['originalUrl', 'params', 'query', 'url', 'method', 'body', 'files', 'secret', 'cookies'].forEach(key => {
|
|
132
|
-
if (req[key as RequestKeysType]) {
|
|
133
|
-
simpleRequest[key] = req[key as RequestKeysType];
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
} else {
|
|
137
|
-
Object.keys(req).filter(key => typeof key === 'string' && key.length > 1 && key[0] !== '_').forEach(key => {
|
|
138
|
-
simpleRequest[key] = req[key as RequestKeysType];
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return util.inspect(simpleRequest, {showHidden: false, depth: null, colors: false});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Append text to the trace file.
|
|
148
|
-
*
|
|
149
|
-
* @param {string} filename - Trace file name.
|
|
150
|
-
* @param {string} text - Text to append.
|
|
151
|
-
*/
|
|
152
|
-
function appendSync(filename: string, text: string): void {
|
|
153
|
-
try {
|
|
154
|
-
fs.appendFileSync(filename, text);
|
|
155
|
-
} catch (e) {
|
|
156
|
-
// istanbul ignore next
|
|
157
|
-
console.error(`Unable to write to trace file "${filename}"`, e, text);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/*
|
|
162
|
-
* get a section of a trace message
|
|
163
|
-
*/
|
|
164
|
-
function getSection(section: string, text: string): string {
|
|
165
|
-
return `\n${section}\n${'='.repeat(section.length)}\n${text}\n`;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/*
|
|
169
|
-
* get a timestamp
|
|
170
|
-
*/
|
|
171
|
-
function getTimestamp(): string {
|
|
172
|
-
return new Date().toISOString();
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/*
|
|
176
|
-
* get a new directory name based on the current timestamp
|
|
177
|
-
*/
|
|
178
|
-
function getTimestampDirectory(): string {
|
|
179
|
-
return path.join(TRACE_ROOT_DIRECTORY, getTimestamp().replace(/(-|:)/g, ''));
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/*
|
|
183
|
-
* trim any cr/lf at the end of the string
|
|
184
|
-
*/
|
|
185
|
-
function trimRight(text: string): string {
|
|
186
|
-
let s = text;
|
|
187
|
-
|
|
188
|
-
while (s[s.length] === '\n' || s[s.length] === '\r') {
|
|
189
|
-
// istanbul ignore next
|
|
190
|
-
s = s.slice(0, -1);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return s;
|
|
194
|
-
}
|
package/test/.eslintrc.json
DELETED
package/test/__tests__/cgi.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import {describe, it, expect} from '@jest/globals';
|
|
2
|
-
import {getCGI} from '../../src/cgi';
|
|
3
|
-
import express from 'express';
|
|
4
|
-
import os from 'os';
|
|
5
|
-
import type {oracleExpressMiddleware$options} from '../../src/config';
|
|
6
|
-
|
|
7
|
-
describe('cgi', () => {
|
|
8
|
-
it('with a proper configuration object and request', () => {
|
|
9
|
-
const PORT = 4711;
|
|
10
|
-
const ORIGINAL_URL = '/pls/base/package.procedure?p=1#1';
|
|
11
|
-
const DOCUMENT_TABLE_NAME = 'doc-table';
|
|
12
|
-
const REMOTE_ADDRESS = '127.0.0.1';
|
|
13
|
-
|
|
14
|
-
const req = {
|
|
15
|
-
protocol: 'http',
|
|
16
|
-
originalUrl: ORIGINAL_URL,
|
|
17
|
-
method: 'GET',
|
|
18
|
-
params: {
|
|
19
|
-
name: 'index.html'
|
|
20
|
-
},
|
|
21
|
-
httpVersion: '1.1',
|
|
22
|
-
ip: REMOTE_ADDRESS,
|
|
23
|
-
get(name: string) {
|
|
24
|
-
switch (name.toLowerCase()) {
|
|
25
|
-
case 'port':
|
|
26
|
-
return PORT.toString();
|
|
27
|
-
case 'host':
|
|
28
|
-
return 'HOST';
|
|
29
|
-
case 'user-agent':
|
|
30
|
-
return 'USER-AGENT';
|
|
31
|
-
case 'accept':
|
|
32
|
-
return 'ACCEPT';
|
|
33
|
-
case 'accept-encoding':
|
|
34
|
-
return 'ACCEPT-ENCODING';
|
|
35
|
-
case 'accept-language':
|
|
36
|
-
return 'ACCEPT-LANGUAGE';
|
|
37
|
-
case 'referer':
|
|
38
|
-
case 'referrer':
|
|
39
|
-
return 'HTTP-REFERER';
|
|
40
|
-
default:
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
cookies: {
|
|
45
|
-
cookie1: 'value1',
|
|
46
|
-
cookie2: 'value2'
|
|
47
|
-
},
|
|
48
|
-
connection: {
|
|
49
|
-
remoteAddress: REMOTE_ADDRESS
|
|
50
|
-
},
|
|
51
|
-
socket: {
|
|
52
|
-
localPort: PORT
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const options = {
|
|
57
|
-
doctable: DOCUMENT_TABLE_NAME
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const cgi = getCGI(req as unknown as express.Request, options as unknown as oracleExpressMiddleware$options);
|
|
61
|
-
|
|
62
|
-
expect(Object.keys(cgi)).toHaveLength(29);
|
|
63
|
-
|
|
64
|
-
expect(cgi).toStrictEqual({
|
|
65
|
-
'PLSQL_GATEWAY': 'WebDb',
|
|
66
|
-
'GATEWAY_IVERSION': '2',
|
|
67
|
-
'SERVER_SOFTWARE': 'web_plsql',
|
|
68
|
-
'GATEWAY_INTERFACE': 'CGI/1.1',
|
|
69
|
-
'SERVER_PORT': PORT.toString(),
|
|
70
|
-
'SERVER_NAME': os.hostname(),
|
|
71
|
-
'REQUEST_METHOD': 'GET',
|
|
72
|
-
'PATH_INFO': 'index.html',
|
|
73
|
-
'SCRIPT_NAME': '/pls/base',
|
|
74
|
-
'REMOTE_ADDR': REMOTE_ADDRESS,
|
|
75
|
-
'SERVER_PROTOCOL': 'HTTP/1.1',
|
|
76
|
-
'REQUEST_PROTOCOL': 'HTTP',
|
|
77
|
-
'REMOTE_USER': '',
|
|
78
|
-
'HTTP_USER_AGENT': 'USER-AGENT',
|
|
79
|
-
'HTTP_X_FORWARDED_FOR': '',
|
|
80
|
-
'HTTP_HOST': 'HOST',
|
|
81
|
-
'HTTP_ACCEPT': 'ACCEPT',
|
|
82
|
-
'HTTP_ACCEPT_ENCODING': 'ACCEPT-ENCODING',
|
|
83
|
-
'HTTP_ACCEPT_LANGUAGE': 'ACCEPT-LANGUAGE',
|
|
84
|
-
'HTTP_REFERER': 'HTTP-REFERER',
|
|
85
|
-
'WEB_AUTHENT_PREFIX': '',
|
|
86
|
-
'DAD_NAME': 'base',
|
|
87
|
-
'DOC_ACCESS_PATH': 'doc',
|
|
88
|
-
'DOCUMENT_TABLE': DOCUMENT_TABLE_NAME,
|
|
89
|
-
'PATH_ALIAS': '',
|
|
90
|
-
'REQUEST_CHARSET': 'UTF8',
|
|
91
|
-
'REQUEST_IANA_CHARSET': 'UTF-8',
|
|
92
|
-
'SCRIPT_PREFIX': '/pls',
|
|
93
|
-
'HTTP_COOKIE': 'cookie1=value1;cookie2=value2;'
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
});
|
package/test/__tests__/config.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import {describe, it, expect} from '@jest/globals';
|
|
2
|
-
import {validate} from '../../src/config';
|
|
3
|
-
|
|
4
|
-
describe('configuration options', () => {
|
|
5
|
-
it('should allow the following options', () => {
|
|
6
|
-
[
|
|
7
|
-
undefined, // eslint-disable-line no-undefined
|
|
8
|
-
{},
|
|
9
|
-
{cgi: {fast: 'on'}},
|
|
10
|
-
{pathAlias: {alias: 'r', procedure: 'p'}},
|
|
11
|
-
{errorStyle: 'debug'}
|
|
12
|
-
].forEach(options => {
|
|
13
|
-
expect(typeof validate(options as unknown as Record<string, unknown>)).toBe('object');
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('configuration errors', () => {
|
|
19
|
-
[
|
|
20
|
-
{config: null, error: 'Invalid configuration object was given'},
|
|
21
|
-
{config: {invalid: ''}, error: 'Invalid configuration options "invalid"'},
|
|
22
|
-
{config: {defaultPage: 1}, error: 'The option "defaultPage" must be of type string and cannot be empty'},
|
|
23
|
-
{config: {defaultPage: ''}, error: 'The option "defaultPage" must be of type string and cannot be empty'},
|
|
24
|
-
{config: {doctable: 1}, error: 'The option "doctable" must be of type string and cannot be empty'},
|
|
25
|
-
{config: {doctable: ''}, error: 'The option "doctable" must be of type string and cannot be empty'},
|
|
26
|
-
{config: {cgi: ''}, error: 'The option "cgi" must be an object where all keys and values are of type string'},
|
|
27
|
-
{config: {cgi: {a: 1}}, error: 'The option "cgi" must be an object where all keys and values are of type string'},
|
|
28
|
-
{config: {pathAlias: {alias: 'r', procedure: ''}}, error: 'The option "pathAlias" must be an object with the non-empty string properties "alias" and "procedure"'},
|
|
29
|
-
{config: {errorStyle: ''}, error: 'The optional option "errorStyle" must be "basic" or "debug"'},
|
|
30
|
-
{config: {errorStyle: 'on'}, error: 'The optional option "errorStyle" must be "basic" or "debug"'},
|
|
31
|
-
{config: {trace: true}, error: 'The optional option "trace" must be "on" or "off"'},
|
|
32
|
-
{config: {trace: ''}, error: 'The optional option "trace" must be "on" or "off"'},
|
|
33
|
-
{config: {trace: 'enabled'}, error: 'The optional option "trace" must be "on" or "off"'},
|
|
34
|
-
].forEach(test => {
|
|
35
|
-
it(`should throw the exception "${test.error}"`, () => {
|
|
36
|
-
expect(() => {
|
|
37
|
-
validate(test.config as unknown as Record<string, unknown>);
|
|
38
|
-
}).toThrow(test.error);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import {describe, beforeAll, afterAll, it, expect} from '@jest/globals';
|
|
2
|
-
import {errorPage} from '../../src/errorPage';
|
|
3
|
-
import {RequestError} from '../../src/requestError';
|
|
4
|
-
import {ProcedureError} from '../../src/procedureError';
|
|
5
|
-
import {oracleExpressMiddleware$options} from '../../src/config';
|
|
6
|
-
|
|
7
|
-
describe('errorPage', () => {
|
|
8
|
-
let errorSave: any;
|
|
9
|
-
|
|
10
|
-
beforeAll(() => {
|
|
11
|
-
errorSave = console.error;
|
|
12
|
-
console.error = () => {}; // eslint-disable-line @typescript-eslint/no-empty-function
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
afterAll(() => {
|
|
16
|
-
console.error = errorSave;
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
let errorText = '';
|
|
20
|
-
let errorHtml = '';
|
|
21
|
-
|
|
22
|
-
const options: oracleExpressMiddleware$options = {
|
|
23
|
-
errorStyle: 'debug',
|
|
24
|
-
trace: 'off'
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const req: any = {};
|
|
28
|
-
const res: any = {
|
|
29
|
-
status() {
|
|
30
|
-
return this;
|
|
31
|
-
},
|
|
32
|
-
send(error: string) {
|
|
33
|
-
errorHtml = error;
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const trace: any = {
|
|
38
|
-
write(error: string) {
|
|
39
|
-
errorText = error;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
it('should report a "error message" in text and html format', () => {
|
|
44
|
-
errorPage(req, res, options, trace, new Error('error message'));
|
|
45
|
-
|
|
46
|
-
expect(/error message/.test(errorText)).toBeTruthy();
|
|
47
|
-
expect(/ERROR/.test(errorText)).toBeTruthy();
|
|
48
|
-
expect(/REQUEST/.test(errorText)).toBeTruthy();
|
|
49
|
-
expect(/error message/.test(errorHtml)).toBeTruthy();
|
|
50
|
-
expect(/TIMESTAMP/.test(errorHtml)).toBeTruthy();
|
|
51
|
-
expect(/ERROR/.test(errorHtml)).toBeTruthy();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should report a "Error" in text and html format', () => {
|
|
55
|
-
errorPage(req, res, options, trace, new Error('throw Error'));
|
|
56
|
-
|
|
57
|
-
expect(/throw Error/.test(errorText)).toBeTruthy();
|
|
58
|
-
expect(/ERROR/.test(errorText)).toBeTruthy();
|
|
59
|
-
expect(/REQUEST/.test(errorText)).toBeTruthy();
|
|
60
|
-
expect(/throw Error/.test(errorHtml)).toBeTruthy();
|
|
61
|
-
expect(/TIMESTAMP/.test(errorHtml)).toBeTruthy();
|
|
62
|
-
expect(/ERROR/.test(errorHtml)).toBeTruthy();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should report a "RequestError" in text and html format', () => {
|
|
66
|
-
errorPage(req, res, options, trace, new RequestError('throw RequestError'));
|
|
67
|
-
|
|
68
|
-
expect(/throw RequestError/.test(errorText)).toBeTruthy();
|
|
69
|
-
expect(/ERROR/.test(errorText)).toBeTruthy();
|
|
70
|
-
expect(/REQUEST/.test(errorText)).toBeTruthy();
|
|
71
|
-
expect(/throw RequestError/.test(errorHtml)).toBeTruthy();
|
|
72
|
-
expect(/TIMESTAMP/.test(errorHtml)).toBeTruthy();
|
|
73
|
-
expect(/ERROR/.test(errorHtml)).toBeTruthy();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should report a "ProcedureError" in text and html format', () => {
|
|
77
|
-
const environment = {dad: 'dad'};
|
|
78
|
-
const sql = 'sql';
|
|
79
|
-
const bind = {p1: '1'};
|
|
80
|
-
|
|
81
|
-
errorPage(req, res, options, trace, new ProcedureError('throw ProcedureError', environment, sql, bind));
|
|
82
|
-
|
|
83
|
-
expect(/throw ProcedureError/.test(errorText)).toBeTruthy();
|
|
84
|
-
expect(/ERROR/.test(errorText)).toBeTruthy();
|
|
85
|
-
expect(/REQUEST/.test(errorText)).toBeTruthy();
|
|
86
|
-
expect(/PROCEDURE/.test(errorText)).toBeTruthy();
|
|
87
|
-
expect(/ENVIRONMENT/.test(errorText)).toBeTruthy();
|
|
88
|
-
expect(/throw ProcedureError/.test(errorHtml)).toBeTruthy();
|
|
89
|
-
expect(/TIMESTAMP/.test(errorHtml)).toBeTruthy();
|
|
90
|
-
expect(/ERROR/.test(errorHtml)).toBeTruthy();
|
|
91
|
-
expect(/PROCEDURE/.test(errorHtml)).toBeTruthy();
|
|
92
|
-
expect(/ENVIRONMENT/.test(errorHtml)).toBeTruthy();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should only report a "404" error when in basic mode', () => {
|
|
96
|
-
options.errorStyle = 'basic';
|
|
97
|
-
errorPage(req, res, options, trace, new Error('error message'));
|
|
98
|
-
|
|
99
|
-
expect(/error message/.test(errorText)).toBeTruthy();
|
|
100
|
-
});
|
|
101
|
-
});
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import {describe, beforeEach, it, expect} from '@jest/globals';
|
|
2
|
-
import {setExecuteCallback, createPool, Connection, getConnection, ConnectionPool, Lob, BLOB} from '../mock/oracledb';
|
|
3
|
-
|
|
4
|
-
describe('oracledb', () => {
|
|
5
|
-
it('createPool', async () => {
|
|
6
|
-
const connectionPool = await _createPool();
|
|
7
|
-
expect(connectionPool).toBeInstanceOf(ConnectionPool);
|
|
8
|
-
return connectionPool;
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('getConnection', async () => {
|
|
12
|
-
const connection = await _getConnection();
|
|
13
|
-
expect(connection).toBeInstanceOf(Connection);
|
|
14
|
-
return connection;
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('ConnectionPool', () => {
|
|
19
|
-
it('getConnection', async () => {
|
|
20
|
-
const connectionPool = await _createPool();
|
|
21
|
-
const connection = await connectionPool.getConnection();
|
|
22
|
-
|
|
23
|
-
expect(connection).toBeInstanceOf(Connection);
|
|
24
|
-
|
|
25
|
-
return connection;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('close', async () => {
|
|
29
|
-
const connectionPool = await _createPool();
|
|
30
|
-
await connectionPool.close();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe('Connection', () => {
|
|
35
|
-
it('getConnection', async () => {
|
|
36
|
-
const connection = await _getConnection();
|
|
37
|
-
expect(connection).toBeInstanceOf(Connection);
|
|
38
|
-
return connection;
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('createLob', async () => {
|
|
42
|
-
const connection = await _getConnection();
|
|
43
|
-
const lob = await connection.createLob(BLOB);
|
|
44
|
-
expect(lob).toBeInstanceOf(Lob);
|
|
45
|
-
return lob;
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('release', async () => {
|
|
49
|
-
const connection = await _getConnection();
|
|
50
|
-
return connection.release();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('Connection.execute', () => {
|
|
55
|
-
beforeEach(() => {
|
|
56
|
-
setExecuteCallback();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('execute', async () => {
|
|
60
|
-
const connection = await _getConnection();
|
|
61
|
-
expect(await connection.execute('select * from dual')).toStrictEqual({});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('execute with execution callback', async () => {
|
|
65
|
-
const connection = await _getConnection();
|
|
66
|
-
const SQL = 'select * from dual';
|
|
67
|
-
|
|
68
|
-
// register an execute callback
|
|
69
|
-
setExecuteCallback((sql: string) => {
|
|
70
|
-
expect(sql).toBe(SQL);
|
|
71
|
-
return {sql: SQL};
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
expect(await connection.execute(SQL)).toStrictEqual({sql: SQL});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
/*
|
|
79
|
-
* get connection pool
|
|
80
|
-
*/
|
|
81
|
-
function _createPool() {
|
|
82
|
-
return createPool({
|
|
83
|
-
user: 'sample',
|
|
84
|
-
password: 'sample',
|
|
85
|
-
connectString: 'localhost:1521/TEST'
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/*
|
|
90
|
-
* get connection
|
|
91
|
-
*/
|
|
92
|
-
function _getConnection() {
|
|
93
|
-
return getConnection({
|
|
94
|
-
user: 'sample',
|
|
95
|
-
password: 'sample',
|
|
96
|
-
connectString: 'localhost:1521/TEST'
|
|
97
|
-
});
|
|
98
|
-
}
|